diff --git a/platforms/i2c/blinkm_driver.go b/platforms/i2c/blinkm_driver.go index cb59908f..bc96ca57 100644 --- a/platforms/i2c/blinkm_driver.go +++ b/platforms/i2c/blinkm_driver.go @@ -12,11 +12,11 @@ type BlinkMDriver struct { func NewBlinkMDriver(a I2cInterface, name string) *BlinkMDriver { b := &BlinkMDriver{ - Driver: gobot.Driver{ - Name: name, - Commands: make(map[string]func(map[string]interface{}) interface{}), - Adaptor: a.(gobot.AdaptorInterface), - }, + Driver: *gobot.NewDriver( + name, + "BlinkMDriver", + a.(gobot.AdaptorInterface), + ), } b.Driver.AddCommand("FirmwareVersion", func(params map[string]interface{}) interface{} { @@ -44,7 +44,7 @@ func NewBlinkMDriver(a I2cInterface, name string) *BlinkMDriver { } func (b *BlinkMDriver) adaptor() I2cInterface { - return b.Driver.Adaptor.(I2cInterface) + return b.Driver.Adaptor().(I2cInterface) } func (b *BlinkMDriver) Start() bool { diff --git a/platforms/i2c/hmc6352_driver.go b/platforms/i2c/hmc6352_driver.go index abce42b2..0c684e6e 100644 --- a/platforms/i2c/hmc6352_driver.go +++ b/platforms/i2c/hmc6352_driver.go @@ -12,22 +12,23 @@ type HMC6352Driver struct { func NewHMC6352Driver(a I2cInterface, name string) *HMC6352Driver { return &HMC6352Driver{ - Driver: gobot.Driver{ - Name: name, - Adaptor: a.(gobot.AdaptorInterface), - }, + Driver: *gobot.NewDriver( + name, + "HMC6352Driver", + a.(gobot.AdaptorInterface), + ), } } func (h *HMC6352Driver) adaptor() I2cInterface { - return h.Driver.Adaptor.(I2cInterface) + return h.Driver.Adaptor().(I2cInterface) } func (h *HMC6352Driver) Start() bool { h.adaptor().I2cStart(0x21) h.adaptor().I2cWrite([]byte("A")) - gobot.Every(h.Interval, func() { + gobot.Every(h.Interval(), func() { h.adaptor().I2cWrite([]byte("A")) ret := h.adaptor().I2cRead(2) if len(ret) == 2 { diff --git a/platforms/i2c/test_helper.go b/platforms/i2c/test_helper.go index 7c37d1c9..9d1ce502 100644 --- a/platforms/i2c/test_helper.go +++ b/platforms/i2c/test_helper.go @@ -16,8 +16,9 @@ func (t *i2cTestAdaptor) Finalize() bool { return true } func newI2cTestAdaptor(name string) *i2cTestAdaptor { return &i2cTestAdaptor{ - Adaptor: gobot.Adaptor{ - Name: name, - }, + Adaptor: *gobot.NewAdaptor( + name, + "I2cTestAdaptor", + ), } } diff --git a/platforms/i2c/wiichuck_driver.go b/platforms/i2c/wiichuck_driver.go index c120c161..52148f49 100644 --- a/platforms/i2c/wiichuck_driver.go +++ b/platforms/i2c/wiichuck_driver.go @@ -12,16 +12,12 @@ type WiichuckDriver struct { } func NewWiichuckDriver(a I2cInterface, name string) *WiichuckDriver { - return &WiichuckDriver{ - Driver: gobot.Driver{ - Name: name, - Events: map[string]*gobot.Event{ - "z_button": gobot.NewEvent(), - "c_button": gobot.NewEvent(), - "joystick": gobot.NewEvent(), - }, - Adaptor: a.(gobot.AdaptorInterface), - }, + w := &WiichuckDriver{ + Driver: *gobot.NewDriver( + name, + "WiichuckDriver", + a.(gobot.AdaptorInterface), + ), joystick: map[string]float64{ "sy_origin": -1, "sx_origin": -1, @@ -33,15 +29,20 @@ func NewWiichuckDriver(a I2cInterface, name string) *WiichuckDriver { "c": 0, }, } + + w.AddEvent("z") + w.AddEvent("c") + w.AddEvent("joystick") + return w } func (w *WiichuckDriver) adaptor() I2cInterface { - return w.Driver.Adaptor.(I2cInterface) + return w.Driver.Adaptor().(I2cInterface) } func (w *WiichuckDriver) Start() bool { w.adaptor().I2cStart(0x52) - gobot.Every(w.Interval, func() { + gobot.Every(w.Interval(), func() { w.adaptor().I2cWrite([]byte{0x40, 0x00}) w.adaptor().I2cWrite([]byte{0x00}) newValue := w.adaptor().I2cRead(6) @@ -93,15 +94,15 @@ func (w *WiichuckDriver) adjustOrigins() { func (w *WiichuckDriver) updateButtons() { if w.data["c"] == 0 { - gobot.Publish(w.Events["c_button"], true) + gobot.Publish(w.Event("c"), true) } if w.data["z"] == 0 { - gobot.Publish(w.Events["z_button"], true) + gobot.Publish(w.Event("z"), true) } } func (w *WiichuckDriver) updateJoystick() { - gobot.Publish(w.Events["joystick"], map[string]float64{ + gobot.Publish(w.Event("joystick"), map[string]float64{ "x": w.calculateJoystickValue(w.data["sx"], w.joystick["sx_origin"]), "y": w.calculateJoystickValue(w.data["sy"], w.joystick["sy_origin"]), })