-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
grove_drivers.go
91 lines (76 loc) · 2.88 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
package aio
import "gobot.io/x/gobot/v2"
// GroveRotaryDriver represents an analog rotary dial with a Grove connector
type GroveRotaryDriver struct {
*AnalogSensorDriver
}
// NewGroveRotaryDriver returns a new driver for grove rotary dial, given an AnalogReader and pin.
//
// Supported options: see [aio.NewAnalogSensorDriver]
// Adds the following API Commands: see [aio.NewAnalogSensorDriver]
func NewGroveRotaryDriver(a AnalogReader, pin string, opts ...interface{}) *GroveRotaryDriver {
d := GroveRotaryDriver{
AnalogSensorDriver: NewAnalogSensorDriver(a, pin, opts...),
}
d.driverCfg.name = gobot.DefaultName("GroveRotary")
return &d
}
// GroveLightSensorDriver represents an analog light sensor
// with a Grove connector
type GroveLightSensorDriver struct {
*AnalogSensorDriver
}
// NewGroveLightSensorDriver returns a new driver for grove light sensor, given an AnalogReader and pin.
//
// Supported options: see [aio.NewAnalogSensorDriver]
// Adds the following API Commands: see [aio.NewAnalogSensorDriver]
func NewGroveLightSensorDriver(a AnalogReader, pin string, opts ...interface{}) *GroveLightSensorDriver {
d := GroveLightSensorDriver{
AnalogSensorDriver: NewAnalogSensorDriver(a, pin, opts...),
}
d.driverCfg.name = gobot.DefaultName("GroveLightSensor")
return &d
}
// GrovePiezoVibrationSensorDriver represents an analog vibration sensor with a Grove connector
type GrovePiezoVibrationSensorDriver struct {
*AnalogSensorDriver
}
// NewGrovePiezoVibrationSensorDriver returns a new driver for grove piezo vibration sensor, given an AnalogReader
// and pin.
//
// Supported options: see [aio.NewAnalogSensorDriver]
// Adds the following API Commands: see [aio.NewAnalogSensorDriver]
func NewGrovePiezoVibrationSensorDriver(
a AnalogReader,
pin string,
opts ...interface{},
) *GrovePiezoVibrationSensorDriver {
d := &GrovePiezoVibrationSensorDriver{
AnalogSensorDriver: NewAnalogSensorDriver(a, pin, opts...),
}
d.driverCfg.name = gobot.DefaultName("GrovePiezoVibrationSensor")
d.AddEvent(Vibration)
if err := d.On(d.Event(Data), func(data interface{}) {
if data.(int) > 1000 { //nolint:forcetypeassert // no error return value, so there is no better way
d.Publish(d.Event(Vibration), data)
}
}); err != nil {
panic(err)
}
return d
}
// GroveSoundSensorDriver represents a analog sound sensor with a Grove connector
type GroveSoundSensorDriver struct {
*AnalogSensorDriver
}
// NewGroveSoundSensorDriver returns a new driver for grove sound sensor, given an AnalogReader and pin.
//
// Supported options: see [aio.NewAnalogSensorDriver]
// Adds the following API Commands: see [aio.NewAnalogSensorDriver]
func NewGroveSoundSensorDriver(a AnalogReader, pin string, opts ...interface{}) *GroveSoundSensorDriver {
d := GroveSoundSensorDriver{
AnalogSensorDriver: NewAnalogSensorDriver(a, pin, opts...),
}
d.driverCfg.name = gobot.DefaultName("GroveSoundSensor")
return &d
}