Skip to content

Commit

Permalink
refs #6: launch loop in go func so that Start will return for test ve…
Browse files Browse the repository at this point in the history
…rification
  • Loading branch information
colemanserious committed May 16, 2016
1 parent d2a2b2d commit 18468b0
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions furby/furby_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ var commands = map[string]string{
"laugh": "863-laugh.wav",
"fart": "865-fart.wav",
"whisper": "719-whisper.wav",
"sleep": "718-sleep.wav",
"listen": "820-listen.wav",
"sleep": "718-sleep.wav",
"listen": "820-listen.wav",
}

var commandList = []string{}
Expand Down Expand Up @@ -84,16 +84,19 @@ func (f *FurbyDriver) Connection() gobot.Connection {
}

func (f *FurbyDriver) Start() (errs []error) {
go f.keepListening()

// keep furby "listening" and awake. Keeps it from uttering silly things
// other than the silly ones we want it to give..
f.ExecuteCommand("listen")
fmt.Println("Started Furby driver")
return
}

// Keep telling it to listen - it forgets.
// keep furby "listening" and awake. Keeps it from uttering silly things
// other than the silly ones we want it to give..
func (f *FurbyDriver) keepListening() {
f.ExecuteCommand("listen")
gobot.Every(40*time.Second, func() {
f.ExecuteCommand("listen")
})
return
}

func (f *FurbyDriver) Halt() (errs []error) {
Expand All @@ -112,7 +115,7 @@ func (f *FurbyDriver) Pin() string { return f.pin }
func (f *FurbyDriver) On() (err error) {
fmt.Println("Turning furby on ")
if err = f.connection.DigitalWrite(f.Pin(), 1); err != nil {
fmt.Println("Unable to turn furby on: %v",err)
fmt.Println("Unable to turn furby on: %v", err)
return err
}
f.high = true
Expand Down Expand Up @@ -144,8 +147,8 @@ func (f *FurbyDriver) ExecuteCommand(command string) (err error) {

if !f.State() {
f.On()
}
}

if file, ok := commands[command]; ok {
f.soundQueue <- file
return
Expand Down

0 comments on commit 18468b0

Please sign in to comment.