diff --git a/platforms/gpio/analog_sensor_driver.go b/platforms/gpio/analog_sensor_driver.go index d61e7fea..4e39c4ed 100644 --- a/platforms/gpio/analog_sensor_driver.go +++ b/platforms/gpio/analog_sensor_driver.go @@ -22,7 +22,7 @@ type AnalogSensorDriver struct { // // Adds the following API Commands: // "Read" - See AnalogSensor.Read -func NewAnalogSensorDriver(a AnalogReader, name string, pin string) *AnalogSensorDriver { +func NewAnalogSensorDriver(a AnalogReader, name string, pin string, v ...time.Duration) *AnalogSensorDriver { d := &AnalogSensorDriver{ name: name, connection: a.(gobot.Connection), @@ -32,6 +32,10 @@ func NewAnalogSensorDriver(a AnalogReader, name string, pin string) *AnalogSenso interval: 10 * time.Millisecond, } + if len(v) > 0 { + d.interval = v[0] + } + d.AddEvent("data") d.AddEvent("error") d.AddCommand("Read", func(params map[string]interface{}) interface{} { diff --git a/platforms/gpio/makey_button_driver.go b/platforms/gpio/makey_button_driver.go index b3fe8c63..d5caaeb8 100644 --- a/platforms/gpio/makey_button_driver.go +++ b/platforms/gpio/makey_button_driver.go @@ -20,7 +20,7 @@ type MakeyButtonDriver struct { } // NewMakeyButtonDriver returns a new MakeyButtonDriver given a DigitalRead, name and pin. -func NewMakeyButtonDriver(a DigitalReader, name string, pin string) *MakeyButtonDriver { +func NewMakeyButtonDriver(a DigitalReader, name string, pin string, v ...time.Duration) *MakeyButtonDriver { m := &MakeyButtonDriver{ name: name, connection: a.(gobot.Connection), @@ -30,6 +30,10 @@ func NewMakeyButtonDriver(a DigitalReader, name string, pin string) *MakeyButton interval: 10 * time.Millisecond, } + if len(v) > 0 { + m.interval = v[0] + } + m.AddEvent("error") m.AddEvent("push") m.AddEvent("release") diff --git a/platforms/i2c/hmc6352_driver.go b/platforms/i2c/hmc6352_driver.go index b4fe8409..feaef44f 100644 --- a/platforms/i2c/hmc6352_driver.go +++ b/platforms/i2c/hmc6352_driver.go @@ -29,8 +29,7 @@ func (h *HMC6352Driver) adaptor() I2cInterface { return h.Connection().(I2cInterface) } -// Start writes initialization bytes and reads from adaptor -// using specified interval to update Heading +// Start initialized the hmc6352 func (h *HMC6352Driver) Start() (errs []error) { if err := h.adaptor().I2cStart(0x21); err != nil { return []error{err} diff --git a/platforms/i2c/mpl115a2_driver.go b/platforms/i2c/mpl115a2_driver.go index 994e8b6a..cd9095f0 100644 --- a/platforms/i2c/mpl115a2_driver.go +++ b/platforms/i2c/mpl115a2_driver.go @@ -38,13 +38,17 @@ type MPL115A2Driver struct { } // NewMPL115A2Driver creates a new driver with specified name and i2c interface -func NewMPL115A2Driver(a I2cInterface, name string) *MPL115A2Driver { +func NewMPL115A2Driver(a I2cInterface, name string, v ...time.Duration) *MPL115A2Driver { m := &MPL115A2Driver{ name: name, connection: a.(gobot.Connection), Eventer: gobot.NewEventer(), interval: 10 * time.Millisecond, } + + if len(v) > 0 { + m.interval = v[0] + } m.AddEvent("error") return m } diff --git a/platforms/i2c/mpu6050_driver.go b/platforms/i2c/mpu6050_driver.go index 66d14e62..0e0d89c2 100644 --- a/platforms/i2c/mpu6050_driver.go +++ b/platforms/i2c/mpu6050_driver.go @@ -32,23 +32,28 @@ type ThreeDData struct { } type MPU6050Driver struct { - name string - connection gobot.Connection - interval time.Duration - gobot.Eventer + name string + connection gobot.Connection + interval time.Duration Accelerometer ThreeDData Gyroscope ThreeDData Temperature int16 + gobot.Eventer } // NewMPU6050Driver creates a new driver with specified name and i2c interface -func NewMPU6050Driver(a I2cInterface, name string) *MPU6050Driver { +func NewMPU6050Driver(a I2cInterface, name string, v ...time.Duration) *MPU6050Driver { m := &MPU6050Driver{ name: name, connection: a.(gobot.Connection), interval: 10 * time.Millisecond, Eventer: gobot.NewEventer(), } + + if len(v) > 0 { + m.interval = v[0] + } + m.AddEvent("error") return m } diff --git a/platforms/i2c/wiichuck_driver.go b/platforms/i2c/wiichuck_driver.go index 2f854ce8..9c92dbf7 100644 --- a/platforms/i2c/wiichuck_driver.go +++ b/platforms/i2c/wiichuck_driver.go @@ -24,7 +24,7 @@ type WiichuckDriver struct { // "z"- Get's triggered every interval amount of time if the z button is pressed // "c" - Get's triggered every interval amount of time if the c button is pressed // "joystick" - Get's triggered every "interval" amount of time if a joystick event occured, you can access values x, y -func NewWiichuckDriver(a I2cInterface, name string) *WiichuckDriver { +func NewWiichuckDriver(a I2cInterface, name string, v ...time.Duration) *WiichuckDriver { w := &WiichuckDriver{ name: name, connection: a.(gobot.Connection), @@ -42,6 +42,10 @@ func NewWiichuckDriver(a I2cInterface, name string) *WiichuckDriver { }, } + if len(v) > 0 { + w.interval = v[0] + } + w.AddEvent("z") w.AddEvent("c") w.AddEvent("joystick") diff --git a/platforms/joystick/joystick_driver.go b/platforms/joystick/joystick_driver.go index 52127443..044c5a37 100644 --- a/platforms/joystick/joystick_driver.go +++ b/platforms/joystick/joystick_driver.go @@ -17,10 +17,10 @@ type JoystickDriver struct { name string interval time.Duration connection gobot.Connection - gobot.Eventer configPath string config joystickConfig poll func() sdl.Event + gobot.Eventer } // pair is a JSON representation of name and id @@ -50,7 +50,7 @@ type joystickConfig struct { // It adds the following events: // (button)_press - triggered when (button) is pressed // (button)_release - triggered when (button) is released -func NewJoystickDriver(a *JoystickAdaptor, name string, config string) *JoystickDriver { +func NewJoystickDriver(a *JoystickAdaptor, name string, config string, v ...time.Duration) *JoystickDriver { d := &JoystickDriver{ name: name, connection: a, @@ -59,6 +59,11 @@ func NewJoystickDriver(a *JoystickAdaptor, name string, config string) *Joystick poll: func() sdl.Event { return sdl.PollEvent() }, + interval: 10 * time.Millisecond, + } + + if len(v) > 0 { + d.interval = v[0] } d.AddEvent("error") diff --git a/platforms/mavlink/mavlink_driver.go b/platforms/mavlink/mavlink_driver.go index 2ffd123f..8f573fe7 100644 --- a/platforms/mavlink/mavlink_driver.go +++ b/platforms/mavlink/mavlink_driver.go @@ -24,7 +24,7 @@ type MavlinkInterface interface { // It add the following events: // "packet" - triggered when a new packet is read // "message" - triggered when a new valid message is processed -func NewMavlinkDriver(a *MavlinkAdaptor, name string) *MavlinkDriver { +func NewMavlinkDriver(a *MavlinkAdaptor, name string, v ...time.Duration) *MavlinkDriver { m := &MavlinkDriver{ name: name, connection: a, @@ -32,6 +32,10 @@ func NewMavlinkDriver(a *MavlinkAdaptor, name string) *MavlinkDriver { interval: 10 * time.Millisecond, } + if len(v) > 0 { + m.interval = v[0] + } + m.AddEvent("packet") m.AddEvent("message") m.AddEvent("error") diff --git a/platforms/opencv/camera_driver.go b/platforms/opencv/camera_driver.go index 7312f013..9b12aae3 100644 --- a/platforms/opencv/camera_driver.go +++ b/platforms/opencv/camera_driver.go @@ -22,7 +22,7 @@ type CameraDriver struct { // NewCameraDriver creates a new driver with specified name and source. // It also creates a start function to either set camera as a File or Camera capture. -func NewCameraDriver(name string, source interface{}) *CameraDriver { +func NewCameraDriver(name string, source interface{}, v ...time.Duration) *CameraDriver { c := &CameraDriver{ name: name, Eventer: gobot.NewEventer(), @@ -41,6 +41,10 @@ func NewCameraDriver(name string, source interface{}) *CameraDriver { }, } + if len(v) > 0 { + c.interval = v[0] + } + c.AddEvent("frame") return c