forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grove_drivers.go
104 lines (92 loc) · 2.94 KB
/
grove_drivers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package aio
import (
"time"
)
// GroveRotaryDriver represents an analog rotary dial with a Grove connector
type GroveRotaryDriver struct {
*AnalogSensorDriver
}
// NewGroveRotaryDriver returns a new GroveRotaryDriver with a polling interval of
// 10 Milliseconds given an AnalogReader and pin.
//
// Optionally accepts:
//
// time.Duration: Interval at which the AnalogSensor is polled for new information
//
// Adds the following API Commands:
//
// "Read" - See AnalogSensor.Read
func NewGroveRotaryDriver(a AnalogReader, pin string, v ...time.Duration) *GroveRotaryDriver {
return &GroveRotaryDriver{
AnalogSensorDriver: NewAnalogSensorDriver(a, pin, v...),
}
}
// GroveLightSensorDriver represents an analog light sensor
// with a Grove connector
type GroveLightSensorDriver struct {
*AnalogSensorDriver
}
// NewGroveLightSensorDriver returns a new GroveLightSensorDriver with a polling interval of
// 10 Milliseconds given an AnalogReader and pin.
//
// Optionally accepts:
//
// time.Duration: Interval at which the AnalogSensor is polled for new information
//
// Adds the following API Commands:
//
// "Read" - See AnalogSensor.Read
func NewGroveLightSensorDriver(a AnalogReader, pin string, v ...time.Duration) *GroveLightSensorDriver {
return &GroveLightSensorDriver{
AnalogSensorDriver: NewAnalogSensorDriver(a, pin, v...),
}
}
// GrovePiezoVibrationSensorDriver represents an analog vibration sensor
// with a Grove connector
type GrovePiezoVibrationSensorDriver struct {
*AnalogSensorDriver
}
// NewGrovePiezoVibrationSensorDriver returns a new GrovePiezoVibrationSensorDriver with a polling interval of
// 10 Milliseconds given an AnalogReader and pin.
//
// Optionally accepts:
//
// time.Duration: Interval at which the AnalogSensor is polled for new information
//
// Adds the following API Commands:
//
// "Read" - See AnalogSensor.Read
func NewGrovePiezoVibrationSensorDriver(a AnalogReader, pin string, v ...time.Duration) *GrovePiezoVibrationSensorDriver {
sensor := &GrovePiezoVibrationSensorDriver{
AnalogSensorDriver: NewAnalogSensorDriver(a, pin, v...),
}
sensor.AddEvent(Vibration)
if err := sensor.On(sensor.Event(Data), func(data interface{}) {
if data.(int) > 1000 {
sensor.Publish(sensor.Event(Vibration), data)
}
}); err != nil {
panic(err)
}
return sensor
}
// GroveSoundSensorDriver represents a analog sound sensor
// with a Grove connector
type GroveSoundSensorDriver struct {
*AnalogSensorDriver
}
// NewGroveSoundSensorDriver returns a new GroveSoundSensorDriver with a polling interval of
// 10 Milliseconds given an AnalogReader and pin.
//
// Optionally accepts:
//
// time.Duration: Interval at which the AnalogSensor is polled for new information
//
// Adds the following API Commands:
//
// "Read" - See AnalogSensor.Read
func NewGroveSoundSensorDriver(a AnalogReader, pin string, v ...time.Duration) *GroveSoundSensorDriver {
return &GroveSoundSensorDriver{
AnalogSensorDriver: NewAnalogSensorDriver(a, pin, v...),
}
}