From 053187c5d1a0839648fd1eacd952793ed1c54bc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Rudowicz?= Date: Tue, 5 Mar 2024 21:52:59 +0100 Subject: [PATCH] Send events in batches --- satel.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/satel.go b/satel.go index eadc443..52892ee 100644 --- a/satel.go +++ b/satel.go @@ -8,12 +8,16 @@ import ( "time" ) -type Event struct { +type BasicEventElement struct { Type ChangeType Index int Value bool } +type Event struct { + BasicEvents []BasicEventElement +} + type Config struct { EventsQueueSize int LongCommands bool @@ -125,16 +129,18 @@ func (s *Satel) readRawEvents() { if cmd == 0xEF { return } + basicElements := make([]BasicEventElement, 0) for i, bb := range bytes { for j := 0; j < 8; j++ { index := byte(1 << j) - s.Events <- Event{ + basicElements = append(basicElements, BasicEventElement{ Type: ChangeType(cmd), Index: i*8 + j, Value: bb&index != 0, - } + }) } } + s.Events <- Event{basicElements} } func (s *Satel) read() {