telemetry in bg thread and lossy so no block keyboad though i still find it pretty sus

master
Bel LaPointe 2023-03-27 11:03:56 -06:00
parent f619fe9e1b
commit dd1b053efa
1 changed files with 29 additions and 8 deletions

View File

@ -25,6 +25,7 @@ type (
can context.CancelFunc
src raw.Raw
cfg config
telemetryc chan message
}
)
@ -39,8 +40,10 @@ func NewV01(ctx context.Context, src raw.Raw) *V01 {
can: can,
src: src,
cfg: cfg,
telemetryc: make(chan message),
}
go result.listen()
go result.dotelemetry()
return result
}
@ -71,7 +74,25 @@ func (v01 *V01) Read() []button.Button {
return buttons
}
func (v01 *V01) dotelemetry() {
for {
select {
case <-v01.ctx.Done():
return
case msg := <-v01.telemetryc:
v01._telemetry(msg)
}
}
}
func (v01 *V01) telemetry(msg message) {
select {
case v01.telemetryc <- msg:
default:
}
}
func (v01 *V01) _telemetry(msg message) {
// TODO oof
v01.cfg.lock.Lock()
defer v01.cfg.lock.Unlock()