diff --git a/api/api.go b/api/api.go index 639074575..0563ed9b3 100644 --- a/api/api.go +++ b/api/api.go @@ -237,10 +237,13 @@ func (a *API) robotDeviceEvent(res http.ResponseWriter, req *http.Request) { res.Header().Set("Cache-Control", "no-cache") res.Header().Set("Connection", "keep-alive") + device := a.gobot.Robot(req.URL.Query().Get(":robot")). + Device(req.URL.Query().Get(":device")) + if event := a.gobot.Robot(req.URL.Query().Get(":robot")). Device(req.URL.Query().Get(":device")).(gobot.Eventer). - Event(req.URL.Query().Get(":event")); event != nil { - gobot.On(event, func(data interface{}) { + Event(req.URL.Query().Get(":event")); len(event) > 0 { + device.(gobot.Eventer).On(event, func(data interface{}) { d, _ := json.Marshal(data) dataChan <- string(d) }) diff --git a/api/api_test.go b/api/api_test.go index bb32e9284..b31399601 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -386,7 +386,8 @@ func TestRobotDeviceEvent(t *testing.T) { go func() { time.Sleep(time.Millisecond * 5) - gobot.Publish(event, "event-data") + a.gobot.Robot("Robot1"). + Device("Device1").(gobot.Eventer).Publish(event, "event-data") }() done := false diff --git a/platforms/ardrone/ardrone_driver.go b/platforms/ardrone/ardrone_driver.go index 2b25cb491..ecc947429 100644 --- a/platforms/ardrone/ardrone_driver.go +++ b/platforms/ardrone/ardrone_driver.go @@ -48,7 +48,7 @@ func (a *ArdroneDriver) Halt() (errs []error) { // TakeOff makes the drone start flying, and publishes `flying` event func (a *ArdroneDriver) TakeOff() { - gobot.Publish(a.Event("flying"), a.adaptor().drone.Takeoff()) + a.Publish(a.Event("flying"), a.adaptor().drone.Takeoff()) } // Land causes the drone to land diff --git a/platforms/ble/ble_minidrone.go b/platforms/ble/ble_minidrone.go index 77abb3f84..0fba88133 100644 --- a/platforms/ble/ble_minidrone.go +++ b/platforms/ble/ble_minidrone.go @@ -118,7 +118,7 @@ func (b *BLEMinidroneDriver) Init() (err error) { // subscribe to battery notifications b.adaptor().Subscribe(DroneNotificationService, BatteryCharacteristic, func(data []byte, e error) { - gobot.Publish(b.Event(Battery), data[len(data)-1]) + b.Publish(b.Event(Battery), data[len(data)-1]) }) // subscribe to flying status notifications @@ -127,13 +127,13 @@ func (b *BLEMinidroneDriver) Init() (err error) { fmt.Println(data) return } - gobot.Publish(b.Event(Status), data[6]) + b.Publish(b.Event(Status), data[6]) if (data[6] == 1 || data[6] == 2) && !b.flying { b.flying = true - gobot.Publish(b.Event(Flying), true) + b.Publish(b.Event(Flying), true) } else if (data[6] == 0) && b.flying { b.flying = false - gobot.Publish(b.Event(Landed), true) + b.Publish(b.Event(Landed), true) } }) diff --git a/platforms/ble/ollie.go b/platforms/ble/ollie.go index 5f08ae1bd..96ffb255e 100644 --- a/platforms/ble/ollie.go +++ b/platforms/ble/ollie.go @@ -72,7 +72,7 @@ func (s *SpheroOllieDriver) Start() (errs []error) { packet := <-s.packetChannel err := s.write(packet) if err != nil { - gobot.Publish(s.Event(Error), err) + s.Publish(s.Event(Error), err) } } }() diff --git a/platforms/gpio/analog_sensor_driver_test.go b/platforms/gpio/analog_sensor_driver_test.go index 844c3a138..8857a2db8 100644 --- a/platforms/gpio/analog_sensor_driver_test.go +++ b/platforms/gpio/analog_sensor_driver_test.go @@ -5,7 +5,6 @@ import ( "testing" "time" - "github.com/hybridgroup/gobot" "github.com/hybridgroup/gobot/gobottest" ) diff --git a/platforms/gpio/button_driver_test.go b/platforms/gpio/button_driver_test.go index c86b3acee..54476eb70 100644 --- a/platforms/gpio/button_driver_test.go +++ b/platforms/gpio/button_driver_test.go @@ -5,7 +5,6 @@ import ( "testing" "time" - "github.com/hybridgroup/gobot" "github.com/hybridgroup/gobot/gobottest" ) diff --git a/platforms/gpio/grove_drivers.go b/platforms/gpio/grove_drivers.go index 276e99684..958dbcdfc 100644 --- a/platforms/gpio/grove_drivers.go +++ b/platforms/gpio/grove_drivers.go @@ -111,11 +111,11 @@ func NewGrovePiezoVibrationSensorDriver(a AnalogReader, name string, pin string, sensor.AddEvent(Vibration) - // sensor.On(sensor.Event(Data), func(data interface{}) { - // if data.(int) > 1000 { - // sensor.Publish(sensor.Event(Vibration), data) - // } - // }) + sensor.On(sensor.Event(Data), func(data interface{}) { + if data.(int) > 1000 { + sensor.Publish(sensor.Event(Vibration), data) + } + }) return sensor } diff --git a/platforms/gpio/makey_button_driver_test.go b/platforms/gpio/makey_button_driver_test.go index 0a82cef2b..ce9d8d118 100644 --- a/platforms/gpio/makey_button_driver_test.go +++ b/platforms/gpio/makey_button_driver_test.go @@ -5,7 +5,6 @@ import ( "testing" "time" - "github.com/hybridgroup/gobot" "github.com/hybridgroup/gobot/gobottest" ) @@ -42,7 +41,7 @@ func TestMakeyButtonDriverStart(t *testing.T) { return } - gobot.Once(d.Event(Push), func(data interface{}) { + d.Once(d.Event(Push), func(data interface{}) { gobottest.Assert(t, d.Active, true) sem <- true }) @@ -58,7 +57,7 @@ func TestMakeyButtonDriverStart(t *testing.T) { return } - gobot.Once(d.Event(Release), func(data interface{}) { + d.Once(d.Event(Release), func(data interface{}) { gobottest.Assert(t, d.Active, false) sem <- true }) @@ -74,7 +73,7 @@ func TestMakeyButtonDriverStart(t *testing.T) { return } - gobot.Once(d.Event(Error), func(data interface{}) { + d.Once(d.Event(Error), func(data interface{}) { sem <- true }) @@ -84,7 +83,7 @@ func TestMakeyButtonDriverStart(t *testing.T) { t.Errorf("MakeyButton Event \"Error\" was not published") } - gobot.Once(d.Event(Release), func(data interface{}) { + d.Once(d.Event(Release), func(data interface{}) { sem <- true }) testAdaptorDigitalRead = func() (val int, err error) { diff --git a/platforms/joystick/joystick_driver.go b/platforms/joystick/joystick_driver.go index d15d2b7dd..fd3b985ab 100644 --- a/platforms/joystick/joystick_driver.go +++ b/platforms/joystick/joystick_driver.go @@ -116,7 +116,7 @@ func (j *JoystickDriver) Start() (errs []error) { for { for event := j.poll(); event != nil; event = j.poll() { if err = j.handleEvent(event); err != nil { - gobot.Publish(j.Event("error"), err) + j.Publish(j.Event("error"), err) } } select { @@ -144,7 +144,7 @@ func (j *JoystickDriver) handleEvent(event sdl.Event) error { if axis == "" { return fmt.Errorf("Unknown Axis: %v", data.Axis) } - gobot.Publish(j.Event(axis), data.Value) + j.Publish(j.Event(axis), data.Value) } case *sdl.JoyButtonEvent: if data.Which == j.adaptor().joystick.InstanceID() { @@ -153,9 +153,9 @@ func (j *JoystickDriver) handleEvent(event sdl.Event) error { return fmt.Errorf("Unknown Button: %v", data.Button) } if data.State == 1 { - gobot.Publish(j.Event(fmt.Sprintf("%s_press", button)), nil) + j.Publish(j.Event(fmt.Sprintf("%s_press", button)), nil) } - gobot.Publish(j.Event(fmt.Sprintf("%s_release", button)), nil) + j.Publish(j.Event(fmt.Sprintf("%s_release", button)), nil) } case *sdl.JoyHatEvent: if data.Which == j.adaptor().joystick.InstanceID() { @@ -163,7 +163,7 @@ func (j *JoystickDriver) handleEvent(event sdl.Event) error { if hat == "" { return fmt.Errorf("Unknown Hat: %v %v", data.Hat, data.Value) } - gobot.Publish(j.Event(hat), true) + j.Publish(j.Event(hat), true) } } return nil diff --git a/platforms/joystick/joystick_driver_test.go b/platforms/joystick/joystick_driver_test.go index 099e74d99..07ff7268a 100644 --- a/platforms/joystick/joystick_driver_test.go +++ b/platforms/joystick/joystick_driver_test.go @@ -46,7 +46,7 @@ func TestJoystickDriverHandleEvent(t *testing.T) { d.Start() // left x stick - gobot.On(d.Event("left_x"), func(data interface{}) { + d.On(d.Event("left_x"), func(data interface{}) { gobottest.Assert(t, int16(100), data.(int16)) sem <- true }) @@ -62,7 +62,7 @@ func TestJoystickDriverHandleEvent(t *testing.T) { } // x button press - gobot.On(d.Event("x_press"), func(data interface{}) { + d.On(d.Event("x_press"), func(data interface{}) { sem <- true }) d.handleEvent(&sdl.JoyButtonEvent{ @@ -77,7 +77,7 @@ func TestJoystickDriverHandleEvent(t *testing.T) { } // x button release - gobot.On(d.Event("x_release"), func(data interface{}) { + d.On(d.Event("x_release"), func(data interface{}) { sem <- true }) d.handleEvent(&sdl.JoyButtonEvent{ @@ -92,7 +92,7 @@ func TestJoystickDriverHandleEvent(t *testing.T) { } // down button press - gobot.On(d.Event("down"), func(data interface{}) { + d.On(d.Event("down"), func(data interface{}) { sem <- true }) d.handleEvent(&sdl.JoyHatEvent{ diff --git a/platforms/keyboard/keyboard_driver.go b/platforms/keyboard/keyboard_driver.go index 63f6cfa8a..6d9544f97 100644 --- a/platforms/keyboard/keyboard_driver.go +++ b/platforms/keyboard/keyboard_driver.go @@ -43,7 +43,7 @@ func NewKeyboardDriver(name string) *KeyboardDriver { break } - gobot.Publish(k.Event("key"), Parse(keybuf)) + k.Publish(k.Event("key"), Parse(keybuf)) } }, diff --git a/platforms/leap/leap_motion_driver.go b/platforms/leap/leap_motion_driver.go index 1ff3e8c27..8b7c2b34a 100644 --- a/platforms/leap/leap_motion_driver.go +++ b/platforms/leap/leap_motion_driver.go @@ -68,14 +68,14 @@ func (l *LeapMotionDriver) Start() (errs []error) { for { receive(l.adaptor().ws, &msg) frame = l.ParseFrame(msg) - gobot.Publish(l.Event("message"), frame) + l.Publish(l.Event("message"), frame) for _, hand := range frame.Hands { - gobot.Publish(l.Event("hand"), hand) + l.Publish(l.Event("hand"), hand) } for _, gesture := range frame.Gestures { - gobot.Publish(l.Event("gesture"), gesture) + l.Publish(l.Event("gesture"), gesture) } } }() diff --git a/platforms/mavlink/mavlink_driver.go b/platforms/mavlink/mavlink_driver.go index a0ca46d8b..d09265de5 100644 --- a/platforms/mavlink/mavlink_driver.go +++ b/platforms/mavlink/mavlink_driver.go @@ -57,16 +57,16 @@ func (m *MavlinkDriver) Start() (errs []error) { for { packet, err := common.ReadMAVLinkPacket(m.adaptor().sp) if err != nil { - gobot.Publish(m.Event("errorIO"), err) + m.Publish(m.Event("errorIO"), err) continue } - gobot.Publish(m.Event("packet"), packet) + m.Publish(m.Event("packet"), packet) message, err := packet.MAVLinkMessage() if err != nil { - gobot.Publish(m.Event("errorMAVLink"), err) + m.Publish(m.Event("errorMAVLink"), err) continue } - gobot.Publish(m.Event("message"), message) + m.Publish(m.Event("message"), message) <-time.After(m.interval) } }() diff --git a/platforms/mavlink/mavlink_driver_test.go b/platforms/mavlink/mavlink_driver_test.go index 0c0de91ad..4235c9aef 100644 --- a/platforms/mavlink/mavlink_driver_test.go +++ b/platforms/mavlink/mavlink_driver_test.go @@ -1,7 +1,6 @@ package mavlink import ( - "errors" "io" "testing" "time" @@ -32,25 +31,24 @@ func TestMavlinkDriver(t *testing.T) { d = NewMavlinkDriver(m, "myDriver", 100*time.Millisecond) gobottest.Assert(t, d.interval, 100*time.Millisecond) - } + func TestMavlinkDriverStart(t *testing.T) { d := initTestMavlinkDriver() err := make(chan error, 0) packet := make(chan *common.MAVLinkPacket, 0) message := make(chan common.MAVLinkMessage, 0) - gobot.Once(d.Event("packet"), func(data interface{}) { + d.Once(d.Event("packet"), func(data interface{}) { packet <- data.(*common.MAVLinkPacket) }) - - gobot.Once(d.Event("message"), func(data interface{}) { + d.Once(d.Event("message"), func(data interface{}) { message <- data.(common.MAVLinkMessage) }) - gobot.Once(d.Event("errorIO"), func(data interface{}) { + d.Once(d.Event("errorIO"), func(data interface{}) { err <- data.(error) }) - gobot.Once(d.Event("errorMAVLink"), func(data interface{}) { + d.Once(d.Event("errorMAVLink"), func(data interface{}) { err <- data.(error) }) @@ -73,15 +71,6 @@ func TestMavlinkDriverStart(t *testing.T) { case <-time.After(100 * time.Millisecond): t.Errorf("error was not emitted") } - - payload = []byte{0xFE, 0x09, 0x4E, 0x01, 0x01, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x51, 0x04, 0x03, 0x1C, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} - select { - case e := <-err: - gobottest.Assert(t, e, errors.New("Unknown Message ID: 255")) - case <-time.After(100 * time.Millisecond): - t.Errorf("error was not emitted") - } - } func TestMavlinkDriverHalt(t *testing.T) { diff --git a/platforms/neurosky/neurosky_driver.go b/platforms/neurosky/neurosky_driver.go index d225366a6..dd221c7c2 100644 --- a/platforms/neurosky/neurosky_driver.go +++ b/platforms/neurosky/neurosky_driver.go @@ -90,7 +90,7 @@ func (n *NeuroskyDriver) Start() (errs []error) { buff := make([]byte, 1024) _, err := n.adaptor().sp.Read(buff[:]) if err != nil { - gobot.Publish(n.Event("error"), err) + n.Publish(n.Event("error"), err) } else { n.parse(bytes.NewBuffer(buff)) } @@ -124,29 +124,29 @@ func (n *NeuroskyDriver) parsePacket(buf *bytes.Buffer) { b, _ := buf.ReadByte() switch b { case CodeEx: - gobot.Publish(n.Event("extended"), nil) + n.Publish(n.Event("extended"), nil) case CodeSignalQuality: ret, _ := buf.ReadByte() - gobot.Publish(n.Event("signal"), ret) + n.Publish(n.Event("signal"), ret) case CodeAttention: ret, _ := buf.ReadByte() - gobot.Publish(n.Event("attention"), ret) + n.Publish(n.Event("attention"), ret) case CodeMeditation: ret, _ := buf.ReadByte() - gobot.Publish(n.Event("meditation"), ret) + n.Publish(n.Event("meditation"), ret) case CodeBlink: ret, _ := buf.ReadByte() - gobot.Publish(n.Event("blink"), ret) + n.Publish(n.Event("blink"), ret) case CodeWave: buf.Next(1) var ret = make([]byte, 2) buf.Read(ret) - gobot.Publish(n.Event("wave"), int16(ret[0])<<8|int16(ret[1])) + n.Publish(n.Event("wave"), int16(ret[0])<<8|int16(ret[1])) case CodeAsicEEG: ret := make([]byte, 25) i, _ := buf.Read(ret) if i == 25 { - gobot.Publish(n.Event("eeg"), n.parseEEG(ret)) + n.Publish(n.Event("eeg"), n.parseEEG(ret)) } } } diff --git a/platforms/neurosky/neurosky_driver_test.go b/platforms/neurosky/neurosky_driver_test.go index 921609f98..9db352008 100644 --- a/platforms/neurosky/neurosky_driver_test.go +++ b/platforms/neurosky/neurosky_driver_test.go @@ -30,7 +30,7 @@ func TestNeuroskyDriver(t *testing.T) { func TestNeuroskyDriverStart(t *testing.T) { sem := make(chan bool, 0) d := initTestNeuroskyDriver() - gobot.Once(d.Event("error"), func(data interface{}) { + d.Once(d.Event("error"), func(data interface{}) { gobottest.Assert(t, data.(error), errors.New("read error")) sem <- true }) @@ -65,7 +65,7 @@ func TestNeuroskyDriverParse(t *testing.T) { d.parse(bytes.NewBuffer([]byte{0xAA, 0xAA, 1, 0x55, 0x00})) }() - gobot.On(d.Event("extended"), func(data interface{}) { + d.On(d.Event("extended"), func(data interface{}) { sem <- true }) @@ -81,7 +81,7 @@ func TestNeuroskyDriverParse(t *testing.T) { d.parse(bytes.NewBuffer([]byte{0xAA, 0xAA, 2, 0x02, 100, 0x00})) }() - gobot.On(d.Event("signal"), func(data interface{}) { + d.On(d.Event("signal"), func(data interface{}) { gobottest.Assert(t, data.(byte), byte(100)) sem <- true }) @@ -94,7 +94,7 @@ func TestNeuroskyDriverParse(t *testing.T) { d.parse(bytes.NewBuffer([]byte{0xAA, 0xAA, 2, 0x04, 40, 0x00})) }() - gobot.On(d.Event("attention"), func(data interface{}) { + d.On(d.Event("attention"), func(data interface{}) { gobottest.Assert(t, data.(byte), byte(40)) sem <- true }) @@ -107,7 +107,7 @@ func TestNeuroskyDriverParse(t *testing.T) { d.parse(bytes.NewBuffer([]byte{0xAA, 0xAA, 2, 0x05, 60, 0x00})) }() - gobot.On(d.Event("meditation"), func(data interface{}) { + d.On(d.Event("meditation"), func(data interface{}) { gobottest.Assert(t, data.(byte), byte(60)) sem <- true }) @@ -120,7 +120,7 @@ func TestNeuroskyDriverParse(t *testing.T) { d.parse(bytes.NewBuffer([]byte{0xAA, 0xAA, 2, 0x16, 150, 0x00})) }() - gobot.On(d.Event("blink"), func(data interface{}) { + d.On(d.Event("blink"), func(data interface{}) { gobottest.Assert(t, data.(byte), byte(150)) sem <- true }) @@ -133,7 +133,7 @@ func TestNeuroskyDriverParse(t *testing.T) { d.parse(bytes.NewBuffer([]byte{0xAA, 0xAA, 4, 0x80, 0x00, 0x40, 0x11, 0x00})) }() - gobot.On(d.Event("wave"), func(data interface{}) { + d.On(d.Event("wave"), func(data interface{}) { gobottest.Assert(t, data.(int16), int16(16401)) sem <- true }) @@ -148,7 +148,7 @@ func TestNeuroskyDriverParse(t *testing.T) { 108, 0x00})) }() - gobot.On(d.Event("eeg"), func(data interface{}) { + d.On(d.Event("eeg"), func(data interface{}) { gobottest.Assert(t, data.(EEG), EEG{ diff --git a/platforms/opencv/camera_driver.go b/platforms/opencv/camera_driver.go index c947aa081..ba4448469 100644 --- a/platforms/opencv/camera_driver.go +++ b/platforms/opencv/camera_driver.go @@ -67,7 +67,7 @@ func (c *CameraDriver) Start() (errs []error) { if c.camera.GrabFrame() { image := c.camera.RetrieveFrame(1) if image != nil { - gobot.Publish(c.Event("frame"), image) + c.Publish(c.Event("frame"), image) } } <-time.After(c.interval) diff --git a/platforms/opencv/camera_driver_test.go b/platforms/opencv/camera_driver_test.go index 2d1a97afb..5fb49efa9 100644 --- a/platforms/opencv/camera_driver_test.go +++ b/platforms/opencv/camera_driver_test.go @@ -28,7 +28,7 @@ func TestCameraDriverStart(t *testing.T) { sem := make(chan bool) d := initTestCameraDriver() gobottest.Assert(t, len(d.Start()), 0) - gobot.On(d.Event("frame"), func(data interface{}) { + d.On(d.Event("frame"), func(data interface{}) { sem <- true }) select { diff --git a/platforms/pebble/pebble_driver.go b/platforms/pebble/pebble_driver.go index c7ecb2edb..b84bb96b6 100644 --- a/platforms/pebble/pebble_driver.go +++ b/platforms/pebble/pebble_driver.go @@ -61,7 +61,7 @@ func (d *PebbleDriver) Halt() (errs []error) { return } // PublishEvent publishes event with specified name and data in gobot func (d *PebbleDriver) PublishEvent(name string, data string) { - gobot.Publish(d.Event(name), data) + d.Publish(d.Event(name), data) } // SendNotification appends message to list of notifications to be sent to watch diff --git a/platforms/pebble/pebble_driver_test.go b/platforms/pebble/pebble_driver_test.go index a89ca5362..f0afdef6d 100644 --- a/platforms/pebble/pebble_driver_test.go +++ b/platforms/pebble/pebble_driver_test.go @@ -39,7 +39,7 @@ func TestPebbleDriver(t *testing.T) { gobottest.Assert(t, d.PendingMessage(), "World") gobottest.Assert(t, d.PendingMessage(), "") - gobot.On(d.Event("button"), func(data interface{}) { + d.On(d.Event("button"), func(data interface{}) { sem <- true }) @@ -51,7 +51,7 @@ func TestPebbleDriver(t *testing.T) { t.Errorf("Button Event was not published") } - gobot.On(d.Event("accel"), func(data interface{}) { + d.On(d.Event("accel"), func(data interface{}) { sem <- true }) diff --git a/platforms/spark/spark_core_adaptor.go b/platforms/spark/spark_core_adaptor.go index ea0fe5b00..eae7cc86b 100644 --- a/platforms/spark/spark_core_adaptor.go +++ b/platforms/spark/spark_core_adaptor.go @@ -18,6 +18,7 @@ type SparkCoreAdaptor struct { DeviceID string AccessToken string APIServer string + gobot.Eventer } type Event struct { @@ -42,6 +43,7 @@ func NewSparkCoreAdaptor(name string, deviceID string, accessToken string) *Spar DeviceID: deviceID, AccessToken: accessToken, APIServer: "https://api.spark.io", + Eventer: gobot.NewEventer(), } } func (s *SparkCoreAdaptor) Name() string { return s.name } @@ -137,22 +139,18 @@ func (s *SparkCoreAdaptor) EventStream(source string, name string) (event *gobot return } - events, errors, err := eventSource(url) + events, _, err := eventSource(url) if err != nil { return } - event = gobot.NewEvent() - go func() { for { select { case ev := <-events: if ev.Event() != "" && ev.Data() != "" { - gobot.Publish(event, Event{Name: ev.Event(), Data: ev.Data()}) + s.Publish(ev.Event(), ev.Data()) } - case ev := <-errors: - gobot.Publish(event, Event{Error: ev}) } } }() diff --git a/platforms/spark/spark_core_adaptor_test.go b/platforms/spark/spark_core_adaptor_test.go index 840ce6706..c7b218ab7 100644 --- a/platforms/spark/spark_core_adaptor_test.go +++ b/platforms/spark/spark_core_adaptor_test.go @@ -6,7 +6,6 @@ import ( "net/http/httptest" "net/url" "testing" - "time" "github.com/donovanhide/eventsource" "github.com/hybridgroup/gobot" @@ -391,42 +390,6 @@ func TestSparkCoreAdaptorEventStream(t *testing.T) { return eventChan, errorChan, nil } - sem := make(chan bool, 0) - stream, err := a.EventStream("devices", "") + _, err = a.EventStream("devices", "") gobottest.Assert(t, err, nil) - - // stream message - gobot.Once(stream, func(data interface{}) { - e := data.(Event) - gobottest.Assert(t, e.Name, "event") - gobottest.Assert(t, e.Data, "sse event") - gobottest.Assert(t, e.Error, nil) - sem <- true - }) - - eventChan <- testEventSource{event: "event", data: "sse event"} - - select { - case <-sem: - case <-time.After(1 * time.Second): - t.Errorf("Did not recieve stream") - } - - // stream error - gobot.Once(stream, func(data interface{}) { - e := data.(Event) - gobottest.Assert(t, e.Name, "") - gobottest.Assert(t, e.Data, "") - gobottest.Assert(t, e.Error.Error(), "stream error") - sem <- true - }) - - errorChan <- errors.New("stream error") - - select { - case <-sem: - case <-time.After(1 * time.Second): - t.Errorf("Did not recieve stream error") - } - } diff --git a/platforms/sphero/sphero_driver.go b/platforms/sphero/sphero_driver.go index ef0f355c4..ab9793d43 100644 --- a/platforms/sphero/sphero_driver.go +++ b/platforms/sphero/sphero_driver.go @@ -157,7 +157,7 @@ func (s *SpheroDriver) Start() (errs []error) { packet := <-s.packetChannel err := s.write(packet) if err != nil { - gobot.Publish(s.Event(Error), err) + s.Publish(s.Event(Error), err) } } }() @@ -315,7 +315,7 @@ func (s *SpheroDriver) handleCollisionDetected(data []uint8) { var collision CollisionPacket buffer := bytes.NewBuffer(data[5:]) // skip header binary.Read(buffer, binary.BigEndian, &collision) - gobot.Publish(s.Event(Collision), collision) + s.Publish(s.Event(Collision), collision) } func (s *SpheroDriver) handleDataStreaming(data []uint8) { @@ -326,7 +326,7 @@ func (s *SpheroDriver) handleDataStreaming(data []uint8) { var dataPacket DataStreamingPacket buffer := bytes.NewBuffer(data[5:]) // skip header binary.Read(buffer, binary.BigEndian, &dataPacket) - gobot.Publish(s.Event(SensorData), dataPacket) + s.Publish(s.Event(SensorData), dataPacket) } func (s *SpheroDriver) getSyncResponse(packet *packet) []byte {