Skip to content

Commit

Permalink
Add collision event
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Oct 29, 2013
1 parent d212172 commit 05ecda9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions examples/roll.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main
import (
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot-sphero"
"fmt"
)

func main() {
Expand All @@ -25,6 +26,13 @@ func main() {

sphero.Stop()

go func() {
for{
gobot.On(sphero.Events["Collision"])
fmt.Println("Collision Detected!")
}
}()

gobot.Every("1s", func(){
sphero.Roll(100, uint16(gobot.Random(0, 360)))
})
Expand Down
6 changes: 3 additions & 3 deletions sphero_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package gobotSphero

import (
"github.com/hybridgroup/gobot"
"fmt"
)

type packet struct {
Expand All @@ -20,6 +19,7 @@ type SpheroDriver struct {

func NewSphero(sa *SpheroAdaptor) *SpheroDriver {
s := new(SpheroDriver)
s.Events = make(map[string]chan interface{})
s.SpheroAdaptor = sa
return s
}
Expand Down Expand Up @@ -60,6 +60,7 @@ func (sd *SpheroDriver) ConfigureCollisionDetection() {
dlen := len(packet.body) + 1
packet.header = []uint8{0xFF, 0xFF, 0x02, 0x12, sd.seq, uint8(dlen)}
packet.checksum = sd.calculateChecksum(packet)
sd.Events["Collision"] = make(chan interface{}, 1024)
sd.write(packet)
}

Expand Down Expand Up @@ -116,8 +117,7 @@ func (sd *SpheroDriver) handleMessageEvents() {
}

func (sd *SpheroDriver) handleCollisionDetected(data []uint8) {
//publish(event_topic_name("collision"), data)
fmt.Println("Collision")
sd.Events["Collision"] <- data
}

func (sd *SpheroDriver) readHeader() []uint8 {
Expand Down

0 comments on commit 05ecda9

Please sign in to comment.