telemetry in bg thread and lossy so no block keyboad though i still find it pretty sus
parent
f619fe9e1b
commit
dd1b053efa
|
|
@ -21,10 +21,11 @@ var (
|
|||
|
||||
type (
|
||||
V01 struct {
|
||||
ctx context.Context
|
||||
can context.CancelFunc
|
||||
src raw.Raw
|
||||
cfg config
|
||||
ctx context.Context
|
||||
can context.CancelFunc
|
||||
src raw.Raw
|
||||
cfg config
|
||||
telemetryc chan message
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -35,12 +36,14 @@ func NewV01(ctx context.Context, src raw.Raw) *V01 {
|
|||
yaml.Unmarshal(b, &cfg)
|
||||
ctx, can := context.WithCancel(ctx)
|
||||
result := &V01{
|
||||
ctx: ctx,
|
||||
can: can,
|
||||
src: src,
|
||||
cfg: cfg,
|
||||
ctx: ctx,
|
||||
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()
|
||||
|
|
|
|||
Loading…
Reference in New Issue