forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers_test.go
105 lines (96 loc) · 2.94 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() (err error)
testAdaptorServoWrite func() (err error)
testAdaptorPwmWrite func() (err error)
testAdaptorAnalogRead func() (val int, err error)
testAdaptorDigitalRead func() (val int, err error)
}
func (t *gpioTestAdaptor) TestAdaptorDigitalWrite(f func() (err error)) {
t.mtx.Lock()
defer t.mtx.Unlock()
t.testAdaptorDigitalWrite = f
}
func (t *gpioTestAdaptor) TestAdaptorServoWrite(f func() (err error)) {
t.mtx.Lock()
defer t.mtx.Unlock()
t.testAdaptorServoWrite = f
}
func (t *gpioTestAdaptor) TestAdaptorPwmWrite(f func() (err error)) {
t.mtx.Lock()
defer t.mtx.Unlock()
t.testAdaptorPwmWrite = f
}
func (t *gpioTestAdaptor) TestAdaptorAnalogRead(f func() (val int, err error)) {
t.mtx.Lock()
defer t.mtx.Unlock()
t.testAdaptorAnalogRead = f
}
func (t *gpioTestAdaptor) TestAdaptorDigitalRead(f func() (val int, err error)) {
t.mtx.Lock()
defer t.mtx.Unlock()
t.testAdaptorDigitalRead = f
}
func (t *gpioTestAdaptor) ServoWrite(string, byte) (err error) {
t.mtx.Lock()
defer t.mtx.Unlock()
return t.testAdaptorServoWrite()
}
func (t *gpioTestAdaptor) PwmWrite(string, byte) (err error) {
t.mtx.Lock()
defer t.mtx.Unlock()
return t.testAdaptorPwmWrite()
}
func (t *gpioTestAdaptor) AnalogRead(string) (val int, err error) {
t.mtx.Lock()
defer t.mtx.Unlock()
return t.testAdaptorAnalogRead()
}
func (t *gpioTestAdaptor) DigitalRead(string) (val int, err error) {
t.mtx.Lock()
defer t.mtx.Unlock()
return t.testAdaptorDigitalRead()
}
func (t *gpioTestAdaptor) DigitalWrite(string, byte) (err error) {
t.mtx.Lock()
defer t.mtx.Unlock()
return t.testAdaptorDigitalWrite()
}
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() (err error) {
return nil
},
testAdaptorServoWrite: func() (err error) {
return nil
},
testAdaptorPwmWrite: func() (err error) {
return nil
},
testAdaptorAnalogRead: func() (val int, err error) {
return 99, nil
},
testAdaptorDigitalRead: func() (val int, err error) {
return 1, nil
},
}
}