diff --git a/src/device/input/parse/v01/v01.go b/src/device/input/parse/v01/v01.go index b65729c..d0a4ebe 100644 --- a/src/device/input/parse/v01/v01.go +++ b/src/device/input/parse/v01/v01.go @@ -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()