Files
esdi/devices/uidevice/device.go
T
esilva b364931c80 automatic setup for devices
Its not close to being done and still need to work out the flows due to
who arrives first: telemetry or the peripheral?
2026-09-21 15:27:42 +01:00

61 lines
980 B
Go

package uidevice
import (
"esdi/peripheral"
"esdi/telemetry"
)
type UIDevice struct {
dataChan chan telemetry.TelemetryData
}
const NAME = "UIView"
func NewUIDevice() (peripheral.Peripheral, error) {
return &UIDevice{
dataChan: make(chan telemetry.TelemetryData, 1),
}, nil
}
func (uid *UIDevice) Close() error {
if uid.dataChan != nil {
close(uid.dataChan)
}
return nil
}
func (uid *UIDevice) Setup(provider string) error {
return nil
}
func (uid *UIDevice) SendData(data *telemetry.TelemetryData) error {
if data == nil {
return peripheral.ErrInvalidData
}
select {
case uid.dataChan <- *data:
default:
// Drop frame if buffer is full
}
return nil
}
func (uid *UIDevice) Name() string {
return NAME
}
func (uid *UIDevice) DataChannel() <-chan telemetry.TelemetryData {
return uid.dataChan
}
func (uid *UIDevice) RequiredFields() []telemetry.FieldID {
return []telemetry.FieldID{
telemetry.Speed,
telemetry.Gear,
telemetry.RPM,
}
}