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 (
|
type (
|
||||||
V01 struct {
|
V01 struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
can context.CancelFunc
|
can context.CancelFunc
|
||||||
src raw.Raw
|
src raw.Raw
|
||||||
cfg config
|
cfg config
|
||||||
|
telemetryc chan message
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -35,12 +36,14 @@ func NewV01(ctx context.Context, src raw.Raw) *V01 {
|
||||||
yaml.Unmarshal(b, &cfg)
|
yaml.Unmarshal(b, &cfg)
|
||||||
ctx, can := context.WithCancel(ctx)
|
ctx, can := context.WithCancel(ctx)
|
||||||
result := &V01{
|
result := &V01{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
can: can,
|
can: can,
|
||||||
src: src,
|
src: src,
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
|
telemetryc: make(chan message),
|
||||||
}
|
}
|
||||||
go result.listen()
|
go result.listen()
|
||||||
|
go result.dotelemetry()
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,7 +74,25 @@ func (v01 *V01) Read() []button.Button {
|
||||||
return buttons
|
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) {
|
func (v01 *V01) telemetry(msg message) {
|
||||||
|
select {
|
||||||
|
case v01.telemetryc <- msg:
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v01 *V01) _telemetry(msg message) {
|
||||||
// TODO oof
|
// TODO oof
|
||||||
v01.cfg.lock.Lock()
|
v01.cfg.lock.Lock()
|
||||||
defer v01.cfg.lock.Unlock()
|
defer v01.cfg.lock.Unlock()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue