forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grove_drivers.go
176 lines (154 loc) · 5.46 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package gpio
import (
"time"
)
// GroveRelayDriver represents a Relay with a Grove connector
type GroveRelayDriver struct {
*RelayDriver
}
// NewGroveRelayDriver return a new GroveRelayDriver given a DigitalWriter, name and pin.
//
// Adds the following API Commands:
// "Toggle" - See RelayDriver.Toggle
// "On" - See RelayDriver.On
// "Off" - See RelayDriver.Off
func NewGroveRelayDriver(a DigitalWriter, name string, pin string) *GroveRelayDriver {
return &GroveRelayDriver{
RelayDriver: NewRelayDriver(a, name, pin),
}
}
// 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, name 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, name string, pin string, v ...time.Duration) *GroveRotaryDriver {
return &GroveRotaryDriver{
AnalogSensorDriver: NewAnalogSensorDriver(a, name, pin, v...),
}
}
// GroveLedDriver represents an LED with a Grove connector
type GroveLedDriver struct {
*LedDriver
}
// NewGroveLedDriver return a new GroveLedDriver given a DigitalWriter, name and pin.
//
// Adds the following API Commands:
// "Brightness" - See LedDriver.Brightness
// "Toggle" - See LedDriver.Toggle
// "On" - See LedDriver.On
// "Off" - See LedDriver.Off
func NewGroveLedDriver(a DigitalWriter, name string, pin string) *GroveLedDriver {
return &GroveLedDriver{
LedDriver: NewLedDriver(a, name, pin),
}
}
// 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, name 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, name string, pin string, v ...time.Duration) *GroveLightSensorDriver {
return &GroveLightSensorDriver{
AnalogSensorDriver: NewAnalogSensorDriver(a, name, 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, name 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, name string, pin string, v ...time.Duration) *GrovePiezoVibrationSensorDriver {
sensor := &GrovePiezoVibrationSensorDriver{
AnalogSensorDriver: NewAnalogSensorDriver(a, name, pin, v...),
}
sensor.AddEvent(Vibration)
sensor.On(sensor.Event(Data), func(data interface{}) {
if data.(int) > 1000 {
sensor.Publish(sensor.Event(Vibration), data)
}
})
return sensor
}
// GroveBuzzerDriver represents a buzzer
// with a Grove connector
type GroveBuzzerDriver struct {
*BuzzerDriver
}
// NewGroveBuzzerDriver return a new GroveBuzzerDriver given a DigitalWriter, name and pin.
func NewGroveBuzzerDriver(a DigitalWriter, name string, pin string) *GroveBuzzerDriver {
return &GroveBuzzerDriver{
BuzzerDriver: NewBuzzerDriver(a, name, pin),
}
}
// GroveButtonDriver represents a button sensor
// with a Grove connector
type GroveButtonDriver struct {
*ButtonDriver
}
// NewGroveButtonDriver returns a new GroveButtonDriver with a polling interval of
// 10 Milliseconds given a DigitalReader, name and pin.
//
// Optionally accepts:
// time.Duration: Interval at which the ButtonDriver is polled for new information
func NewGroveButtonDriver(a DigitalReader, name string, pin string, v ...time.Duration) *GroveButtonDriver {
return &GroveButtonDriver{
ButtonDriver: NewButtonDriver(a, name, pin, v...),
}
}
// 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, name 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, name string, pin string, v ...time.Duration) *GroveSoundSensorDriver {
return &GroveSoundSensorDriver{
AnalogSensorDriver: NewAnalogSensorDriver(a, name, pin, v...),
}
}
// GroveTouchDriver represents a touch button sensor
// with a Grove connector
type GroveTouchDriver struct {
*ButtonDriver
}
// NewGroveTouchDriver returns a new GroveTouchDriver with a polling interval of
// 10 Milliseconds given a DigitalReader, name and pin.
//
// Optionally accepts:
// time.Duration: Interval at which the ButtonDriver is polled for new information
func NewGroveTouchDriver(a DigitalReader, name string, pin string, v ...time.Duration) *GroveTouchDriver {
return &GroveTouchDriver{
ButtonDriver: NewButtonDriver(a, name, pin, v...),
}
}