Skip to content

Commit

Permalink
Add GrovePiezoVibrationSensorDriver
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Jul 8, 2015
1 parent 81bc4d2 commit ae67df6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions platforms/gpio/gpio.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const (
Error = "error"
// Data event
Data = "data"
// Vibration event
Vibration = "vibration"
)

// PwmWriter interface represents an Adaptor which has Pwm capabilities
Expand Down
21 changes: 21 additions & 0 deletions platforms/gpio/grove_drivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var _ gobot.Driver = (*GroveSoundSensorDriver)(nil)
var _ gobot.Driver = (*GroveButtonDriver)(nil)
var _ gobot.Driver = (*GroveBuzzerDriver)(nil)
var _ gobot.Driver = (*GroveLightSensorDriver)(nil)
var _ gobot.Driver = (*GrovePiezoVibrationSensorDriver)(nil)
var _ gobot.Driver = (*GroveLedDriver)(nil)
var _ gobot.Driver = (*GroveRotaryDriver)(nil)
var _ gobot.Driver = (*GroveRelayDriver)(nil)
Expand All @@ -31,6 +32,10 @@ type GroveLightSensorDriver struct {
*AnalogSensorDriver
}

type GrovePiezoVibrationSensorDriver struct {
*AnalogSensorDriver
}

type GroveBuzzerDriver struct {
*BuzzerDriver
}
Expand Down Expand Up @@ -89,6 +94,22 @@ func NewGroveLightSensorDriver(a AnalogReader, name string, pin string, v ...tim
}
}

func NewGrovePiezoVibrationSensorDriver(a AnalogReader, name string, pin string, v ...time.Duration) *GrovePiezoVibrationSensorDriver {
sensor := &GrovePiezoVibrationSensorDriver{
AnalogSensorDriver: NewAnalogSensorDriver(a, name, pin, v...),
}

sensor.AddEvent(Vibration)

gobot.On(sensor.Event(Data), func(data interface{}) {
if data.(int) == 1023 {
gobot.Publish(sensor.Event(Vibration), data)
}
})

return sensor
}

func NewGroveSoundSensorDriver(a AnalogReader, name string, pin string, v ...time.Duration) *GroveSoundSensorDriver {
return &GroveSoundSensorDriver{
AnalogSensorDriver: NewAnalogSensorDriver(a, name, pin, v...),
Expand Down

0 comments on commit ae67df6

Please sign in to comment.