2015-06-29 18:01:35 -07:00
|
|
|
package gpio
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2015-10-22 16:56:03 -07:00
|
|
|
// GroveRelayDriver represents a Relay with a Grove connector
|
2015-06-29 18:01:35 -07:00
|
|
|
type GroveRelayDriver struct {
|
|
|
|
*RelayDriver
|
|
|
|
}
|
|
|
|
|
2016-09-25 13:36:18 +02:00
|
|
|
// NewGroveRelayDriver return a new GroveRelayDriver given a DigitalWriter and pin.
|
2015-10-22 16:56:03 -07:00
|
|
|
//
|
|
|
|
// Adds the following API Commands:
|
|
|
|
// "Toggle" - See RelayDriver.Toggle
|
|
|
|
// "On" - See RelayDriver.On
|
|
|
|
// "Off" - See RelayDriver.Off
|
2016-09-25 13:36:18 +02:00
|
|
|
func NewGroveRelayDriver(a DigitalWriter, pin string) *GroveRelayDriver {
|
2015-10-22 16:56:03 -07:00
|
|
|
return &GroveRelayDriver{
|
2016-09-25 13:36:18 +02:00
|
|
|
RelayDriver: NewRelayDriver(a, pin),
|
2015-10-22 16:56:03 -07:00
|
|
|
}
|
2015-06-29 18:01:35 -07:00
|
|
|
}
|
|
|
|
|
2015-10-22 16:56:03 -07:00
|
|
|
// GroveRotaryDriver represents an analog rotary dial with a Grove connector
|
|
|
|
type GroveRotaryDriver struct {
|
2015-06-29 18:01:35 -07:00
|
|
|
*AnalogSensorDriver
|
|
|
|
}
|
|
|
|
|
2015-10-22 16:56:03 -07:00
|
|
|
// NewGroveRotaryDriver returns a new GroveRotaryDriver with a polling interval of
|
2016-09-25 13:36:18 +02:00
|
|
|
// 10 Milliseconds given an AnalogReader and pin.
|
2015-10-22 16:56:03 -07:00
|
|
|
//
|
2016-07-13 10:44:47 -06:00
|
|
|
// Optionally accepts:
|
2015-10-22 16:56:03 -07:00
|
|
|
// time.Duration: Interval at which the AnalogSensor is polled for new information
|
|
|
|
//
|
|
|
|
// Adds the following API Commands:
|
|
|
|
// "Read" - See AnalogSensor.Read
|
2016-09-25 13:36:18 +02:00
|
|
|
func NewGroveRotaryDriver(a AnalogReader, pin string, v ...time.Duration) *GroveRotaryDriver {
|
2015-10-22 16:56:03 -07:00
|
|
|
return &GroveRotaryDriver{
|
2016-09-25 13:36:18 +02:00
|
|
|
AnalogSensorDriver: NewAnalogSensorDriver(a, pin, v...),
|
2015-06-29 18:01:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-22 16:56:03 -07:00
|
|
|
// GroveLedDriver represents an LED with a Grove connector
|
|
|
|
type GroveLedDriver struct {
|
|
|
|
*LedDriver
|
2015-06-29 18:01:35 -07:00
|
|
|
}
|
|
|
|
|
2016-09-25 13:36:18 +02:00
|
|
|
// NewGroveLedDriver return a new GroveLedDriver given a DigitalWriter and pin.
|
2015-10-22 16:56:03 -07:00
|
|
|
//
|
|
|
|
// Adds the following API Commands:
|
|
|
|
// "Brightness" - See LedDriver.Brightness
|
|
|
|
// "Toggle" - See LedDriver.Toggle
|
|
|
|
// "On" - See LedDriver.On
|
|
|
|
// "Off" - See LedDriver.Off
|
2016-09-25 13:36:18 +02:00
|
|
|
func NewGroveLedDriver(a DigitalWriter, pin string) *GroveLedDriver {
|
2015-06-29 18:01:35 -07:00
|
|
|
return &GroveLedDriver{
|
2016-09-25 13:36:18 +02:00
|
|
|
LedDriver: NewLedDriver(a, pin),
|
2015-06-29 18:01:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-22 16:56:03 -07:00
|
|
|
// GroveLightSensorDriver represents an analog light sensor
|
|
|
|
// with a Grove connector
|
|
|
|
type GroveLightSensorDriver struct {
|
|
|
|
*AnalogSensorDriver
|
2015-06-29 18:01:35 -07:00
|
|
|
}
|
|
|
|
|
2015-10-22 16:56:03 -07:00
|
|
|
// NewGroveLightSensorDriver returns a new GroveLightSensorDriver with a polling interval of
|
2016-09-25 13:36:18 +02:00
|
|
|
// 10 Milliseconds given an AnalogReader and pin.
|
2015-10-22 16:56:03 -07:00
|
|
|
//
|
2016-07-13 10:44:47 -06:00
|
|
|
// Optionally accepts:
|
2015-10-22 16:56:03 -07:00
|
|
|
// time.Duration: Interval at which the AnalogSensor is polled for new information
|
|
|
|
//
|
|
|
|
// Adds the following API Commands:
|
|
|
|
// "Read" - See AnalogSensor.Read
|
2016-09-25 13:36:18 +02:00
|
|
|
func NewGroveLightSensorDriver(a AnalogReader, pin string, v ...time.Duration) *GroveLightSensorDriver {
|
2015-06-29 18:01:35 -07:00
|
|
|
return &GroveLightSensorDriver{
|
2016-09-25 13:36:18 +02:00
|
|
|
AnalogSensorDriver: NewAnalogSensorDriver(a, pin, v...),
|
2015-06-29 18:01:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-22 16:56:03 -07:00
|
|
|
// GrovePiezoVibrationSensorDriver represents an analog vibration sensor
|
|
|
|
// with a Grove connector
|
|
|
|
type GrovePiezoVibrationSensorDriver struct {
|
|
|
|
*AnalogSensorDriver
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewGrovePiezoVibrationSensorDriver returns a new GrovePiezoVibrationSensorDriver with a polling interval of
|
2016-09-25 13:36:18 +02:00
|
|
|
// 10 Milliseconds given an AnalogReader and pin.
|
2015-10-22 16:56:03 -07:00
|
|
|
//
|
2016-07-13 10:44:47 -06:00
|
|
|
// Optionally accepts:
|
2015-10-22 16:56:03 -07:00
|
|
|
// time.Duration: Interval at which the AnalogSensor is polled for new information
|
|
|
|
//
|
|
|
|
// Adds the following API Commands:
|
|
|
|
// "Read" - See AnalogSensor.Read
|
2016-09-25 13:36:18 +02:00
|
|
|
func NewGrovePiezoVibrationSensorDriver(a AnalogReader, pin string, v ...time.Duration) *GrovePiezoVibrationSensorDriver {
|
2015-07-08 09:29:36 -07:00
|
|
|
sensor := &GrovePiezoVibrationSensorDriver{
|
2016-09-25 13:36:18 +02:00
|
|
|
AnalogSensorDriver: NewAnalogSensorDriver(a, pin, v...),
|
2015-07-08 09:29:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
sensor.AddEvent(Vibration)
|
|
|
|
|
2016-08-30 17:10:50 +02:00
|
|
|
sensor.On(sensor.Event(Data), func(data interface{}) {
|
|
|
|
if data.(int) > 1000 {
|
|
|
|
sensor.Publish(sensor.Event(Vibration), data)
|
|
|
|
}
|
|
|
|
})
|
2015-07-08 09:29:36 -07:00
|
|
|
|
|
|
|
return sensor
|
|
|
|
}
|
|
|
|
|
2015-10-22 16:56:03 -07:00
|
|
|
// GroveBuzzerDriver represents a buzzer
|
|
|
|
// with a Grove connector
|
|
|
|
type GroveBuzzerDriver struct {
|
|
|
|
*BuzzerDriver
|
|
|
|
}
|
|
|
|
|
2016-09-25 13:36:18 +02:00
|
|
|
// NewGroveBuzzerDriver return a new GroveBuzzerDriver given a DigitalWriter and pin.
|
|
|
|
func NewGroveBuzzerDriver(a DigitalWriter, pin string) *GroveBuzzerDriver {
|
2015-10-22 16:56:03 -07:00
|
|
|
return &GroveBuzzerDriver{
|
2016-09-25 13:36:18 +02:00
|
|
|
BuzzerDriver: NewBuzzerDriver(a, pin),
|
2015-10-22 16:56:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GroveButtonDriver represents a button sensor
|
|
|
|
// with a Grove connector
|
|
|
|
type GroveButtonDriver struct {
|
|
|
|
*ButtonDriver
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewGroveButtonDriver returns a new GroveButtonDriver with a polling interval of
|
2016-09-25 13:36:18 +02:00
|
|
|
// 10 Milliseconds given a DigitalReader and pin.
|
2015-10-22 16:56:03 -07:00
|
|
|
//
|
2016-07-13 10:44:47 -06:00
|
|
|
// Optionally accepts:
|
2015-10-22 16:56:03 -07:00
|
|
|
// time.Duration: Interval at which the ButtonDriver is polled for new information
|
2016-09-25 13:36:18 +02:00
|
|
|
func NewGroveButtonDriver(a DigitalReader, pin string, v ...time.Duration) *GroveButtonDriver {
|
2015-10-22 16:56:03 -07:00
|
|
|
return &GroveButtonDriver{
|
2016-09-25 13:36:18 +02:00
|
|
|
ButtonDriver: NewButtonDriver(a, pin, v...),
|
2015-10-22 16:56:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GroveSoundSensorDriver represents a analog sound sensor
|
|
|
|
// with a Grove connector
|
|
|
|
type GroveSoundSensorDriver struct {
|
|
|
|
*AnalogSensorDriver
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewGroveSoundSensorDriver returns a new GroveSoundSensorDriver with a polling interval of
|
2016-09-25 13:36:18 +02:00
|
|
|
// 10 Milliseconds given an AnalogReader and pin.
|
2015-10-22 16:56:03 -07:00
|
|
|
//
|
2016-07-13 10:44:47 -06:00
|
|
|
// Optionally accepts:
|
2015-10-22 16:56:03 -07:00
|
|
|
// time.Duration: Interval at which the AnalogSensor is polled for new information
|
|
|
|
//
|
|
|
|
// Adds the following API Commands:
|
|
|
|
// "Read" - See AnalogSensor.Read
|
2016-09-25 13:36:18 +02:00
|
|
|
func NewGroveSoundSensorDriver(a AnalogReader, pin string, v ...time.Duration) *GroveSoundSensorDriver {
|
2015-06-29 18:01:35 -07:00
|
|
|
return &GroveSoundSensorDriver{
|
2016-09-25 13:36:18 +02:00
|
|
|
AnalogSensorDriver: NewAnalogSensorDriver(a, pin, v...),
|
2015-06-29 18:01:35 -07:00
|
|
|
}
|
|
|
|
}
|
2015-10-22 16:56:03 -07:00
|
|
|
|
|
|
|
// GroveTouchDriver represents a touch button sensor
|
|
|
|
// with a Grove connector
|
|
|
|
type GroveTouchDriver struct {
|
|
|
|
*ButtonDriver
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewGroveTouchDriver returns a new GroveTouchDriver with a polling interval of
|
2016-09-25 13:36:18 +02:00
|
|
|
// 10 Milliseconds given a DigitalReader and pin.
|
2015-10-22 16:56:03 -07:00
|
|
|
//
|
2016-07-13 10:44:47 -06:00
|
|
|
// Optionally accepts:
|
2015-10-22 16:56:03 -07:00
|
|
|
// time.Duration: Interval at which the ButtonDriver is polled for new information
|
2016-09-25 13:36:18 +02:00
|
|
|
func NewGroveTouchDriver(a DigitalReader, pin string, v ...time.Duration) *GroveTouchDriver {
|
2015-10-22 16:56:03 -07:00
|
|
|
return &GroveTouchDriver{
|
2016-09-25 13:36:18 +02:00
|
|
|
ButtonDriver: NewButtonDriver(a, pin, v...),
|
2015-10-22 16:56:03 -07:00
|
|
|
}
|
|
|
|
}
|