forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrove_drivers.go
104 lines (91 loc) · 2.98 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 gpio
import (
"time"
)
// GroveRelayDriver represents a Relay with a Grove connector
type GroveRelayDriver struct {
*RelayDriver
}
// NewGroveRelayDriver return a new GroveRelayDriver given a DigitalWriter and pin.
//
// Adds the following API Commands:
// "Toggle" - See RelayDriver.Toggle
// "On" - See RelayDriver.On
// "Off" - See RelayDriver.Off
func NewGroveRelayDriver(a DigitalWriter, pin string) *GroveRelayDriver {
return &GroveRelayDriver{
RelayDriver: NewRelayDriver(a, pin),
}
}
// GroveLedDriver represents an LED with a Grove connector
type GroveLedDriver struct {
*LedDriver
}
// NewGroveLedDriver return a new GroveLedDriver given a DigitalWriter 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, pin string) *GroveLedDriver {
return &GroveLedDriver{
LedDriver: NewLedDriver(a, pin),
}
}
// GroveBuzzerDriver represents a buzzer
// with a Grove connector
type GroveBuzzerDriver struct {
*BuzzerDriver
}
// NewGroveBuzzerDriver return a new GroveBuzzerDriver given a DigitalWriter and pin.
func NewGroveBuzzerDriver(a DigitalWriter, pin string) *GroveBuzzerDriver {
return &GroveBuzzerDriver{
BuzzerDriver: NewBuzzerDriver(a, 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 and pin.
//
// Optionally accepts:
// time.Duration: Interval at which the ButtonDriver is polled for new information
func NewGroveButtonDriver(a DigitalReader, pin string, v ...time.Duration) *GroveButtonDriver {
return &GroveButtonDriver{
ButtonDriver: NewButtonDriver(a, 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 and pin.
//
// Optionally accepts:
// time.Duration: Interval at which the ButtonDriver is polled for new information
func NewGroveTouchDriver(a DigitalReader, pin string, v ...time.Duration) *GroveTouchDriver {
return &GroveTouchDriver{
ButtonDriver: NewButtonDriver(a, pin, v...),
}
}
// GroveMagneticSwitchDriver represent a magnetic
// switch sensor with a Grove connector
type GroveMagneticSwitchDriver struct {
*ButtonDriver
}
// NewGroveMagneticSwitchDriver returns a new GroveMagneticSwitchDriver 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 NewGroveMagneticSwitchDriver(a DigitalReader, pin string, v ...time.Duration) *GroveMagneticSwitchDriver {
return &GroveMagneticSwitchDriver{
ButtonDriver: NewButtonDriver(a, pin, v...),
}
}