forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers_test.go
105 lines (96 loc) · 3.23 KB
/
helpers_test.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
package gpio
import "sync"
type gpioTestBareAdaptor struct{}
func (t *gpioTestBareAdaptor) Connect() (err error) { return }
func (t *gpioTestBareAdaptor) Finalize() (err error) { return }
func (t *gpioTestBareAdaptor) Name() string { return "" }
func (t *gpioTestBareAdaptor) SetName(n string) {}
type gpioTestDigitalWriter struct {
gpioTestBareAdaptor
}
func (t *gpioTestDigitalWriter) DigitalWrite(string, byte) (err error) { return }
type gpioTestAdaptor struct {
name string
port string
mtx sync.Mutex
testAdaptorDigitalWrite func(pin string, val byte) (err error)
testAdaptorServoWrite func(pin string, val byte) (err error)
testAdaptorPwmWrite func(pin string, val byte) (err error)
testAdaptorAnalogRead func(ping string) (val int, err error)
testAdaptorDigitalRead func(ping string) (val int, err error)
}
func (t *gpioTestAdaptor) TestAdaptorDigitalWrite(f func(pin string, val byte) (err error)) {
t.mtx.Lock()
defer t.mtx.Unlock()
t.testAdaptorDigitalWrite = f
}
func (t *gpioTestAdaptor) TestAdaptorServoWrite(f func(pin string, val byte) (err error)) {
t.mtx.Lock()
defer t.mtx.Unlock()
t.testAdaptorServoWrite = f
}
func (t *gpioTestAdaptor) TestAdaptorPwmWrite(f func(pin string, val byte) (err error)) {
t.mtx.Lock()
defer t.mtx.Unlock()
t.testAdaptorPwmWrite = f
}
func (t *gpioTestAdaptor) TestAdaptorAnalogRead(f func(pin string) (val int, err error)) {
t.mtx.Lock()
defer t.mtx.Unlock()
t.testAdaptorAnalogRead = f
}
func (t *gpioTestAdaptor) TestAdaptorDigitalRead(f func(pin string) (val int, err error)) {
t.mtx.Lock()
defer t.mtx.Unlock()
t.testAdaptorDigitalRead = f
}
func (t *gpioTestAdaptor) ServoWrite(pin string, val byte) (err error) {
t.mtx.Lock()
defer t.mtx.Unlock()
return t.testAdaptorServoWrite(pin, val)
}
func (t *gpioTestAdaptor) PwmWrite(pin string, val byte) (err error) {
t.mtx.Lock()
defer t.mtx.Unlock()
return t.testAdaptorPwmWrite(pin, val)
}
func (t *gpioTestAdaptor) AnalogRead(pin string) (val int, err error) {
t.mtx.Lock()
defer t.mtx.Unlock()
return t.testAdaptorAnalogRead(pin)
}
func (t *gpioTestAdaptor) DigitalRead(pin string) (val int, err error) {
t.mtx.Lock()
defer t.mtx.Unlock()
return t.testAdaptorDigitalRead(pin)
}
func (t *gpioTestAdaptor) DigitalWrite(pin string, val byte) (err error) {
t.mtx.Lock()
defer t.mtx.Unlock()
return t.testAdaptorDigitalWrite(pin, val)
}
func (t *gpioTestAdaptor) Connect() (err error) { return }
func (t *gpioTestAdaptor) Finalize() (err error) { return }
func (t *gpioTestAdaptor) Name() string { return t.name }
func (t *gpioTestAdaptor) SetName(n string) { t.name = n }
func (t *gpioTestAdaptor) Port() string { return t.port }
func newGpioTestAdaptor() *gpioTestAdaptor {
return &gpioTestAdaptor{
port: "/dev/null",
testAdaptorDigitalWrite: func(pin string, val byte) (err error) {
return nil
},
testAdaptorServoWrite: func(pin string, val byte) (err error) {
return nil
},
testAdaptorPwmWrite: func(pin string, val byte) (err error) {
return nil
},
testAdaptorAnalogRead: func(pin string) (val int, err error) {
return 99, nil
},
testAdaptorDigitalRead: func(pin string) (val int, err error) {
return 1, nil
},
}
}