forked from willy77/go-pigpio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwave_chain.go
More file actions
43 lines (33 loc) · 955 Bytes
/
Copy pathwave_chain.go
File metadata and controls
43 lines (33 loc) · 955 Bytes
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
package pigpio
type WaveChain struct {
pi *Pi
data []byte
}
func (wc *WaveChain) Bytes() []byte { return wc.data }
func (wc *WaveChain) append(data []byte) *WaveChain {
wc.data = append(wc.data, data[:]...)
return wc
}
func (wc *WaveChain) Wave(w *Wave) *WaveChain {
return wc.append(convertToBytes(w.handle))
}
func (wc *WaveChain) LoopBegin() *WaveChain {
return wc.append([]byte{255, 0})
}
// TODO wrong loop and delay (x + y*256)
func (wc *WaveChain) LoopEnd(repeat int) *WaveChain {
return wc.append([]byte{255, 0, byte(repeat), byte(repeat << 8)})
}
func (wc *WaveChain) Delay(us int) *WaveChain {
return wc.append([]byte{255, 0, byte(us), byte(us << 8)})
}
func (wc *WaveChain) LoopForever() *WaveChain {
return wc.append([]byte{255, 3})
}
func (wc *WaveChain) Run() error {
r, e := wc.pi.socket.SendCommand(cmdWaveChain, 0, 0, wc.Bytes())
if e != nil || r < 0 {
return newPiError(r, e, "WaveChain.Run()")
}
return nil
}