mirror of https://git.sr.ht/~michalr/go-satel
Send events in batches
This commit is contained in:
parent
6b3159eed0
commit
053187c5d1
12
satel.go
12
satel.go
|
@ -8,12 +8,16 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Event struct {
|
type BasicEventElement struct {
|
||||||
Type ChangeType
|
Type ChangeType
|
||||||
Index int
|
Index int
|
||||||
Value bool
|
Value bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Event struct {
|
||||||
|
BasicEvents []BasicEventElement
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
EventsQueueSize int
|
EventsQueueSize int
|
||||||
LongCommands bool
|
LongCommands bool
|
||||||
|
@ -125,16 +129,18 @@ func (s *Satel) readRawEvents() {
|
||||||
if cmd == 0xEF {
|
if cmd == 0xEF {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
basicElements := make([]BasicEventElement, 0)
|
||||||
for i, bb := range bytes {
|
for i, bb := range bytes {
|
||||||
for j := 0; j < 8; j++ {
|
for j := 0; j < 8; j++ {
|
||||||
index := byte(1 << j)
|
index := byte(1 << j)
|
||||||
s.Events <- Event{
|
basicElements = append(basicElements, BasicEventElement{
|
||||||
Type: ChangeType(cmd),
|
Type: ChangeType(cmd),
|
||||||
Index: i*8 + j,
|
Index: i*8 + j,
|
||||||
Value: bb&index != 0,
|
Value: bb&index != 0,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
s.Events <- Event{basicElements}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Satel) read() {
|
func (s *Satel) read() {
|
||||||
|
|
Loading…
Reference in New Issue