In short: added the ability to detect when a device has disconnected. From this we have to achieve a way of: - reconnecting the device - re-subscribing to the fields it needs (it should already be subscribed since the ESDI didn't stop tho - but for the sake of it, or in case a device joins later) - start sending data to it (which should be automatic given how we are handling the devices)
44 lines
810 B
Go
44 lines
810 B
Go
// Package devices is a peripheral factory
|
|
package devices
|
|
|
|
import (
|
|
"esdi/devices/cdashdisplay"
|
|
"esdi/devices/uidevice"
|
|
"esdi/peripheral"
|
|
)
|
|
|
|
type Device struct {
|
|
Name string
|
|
Discover func() (peripheral.Peripheral, error)
|
|
}
|
|
|
|
var List map[string]*Device = map[string]*Device{
|
|
uidevice.NAME: {
|
|
Name: uidevice.NAME,
|
|
Discover: DiscoverUIDevice,
|
|
},
|
|
cdashdisplay.NAME: {
|
|
Name: cdashdisplay.NAME,
|
|
Discover: DiscoverCDashDisplay,
|
|
},
|
|
}
|
|
|
|
func DiscoverUIDevice() (peripheral.Peripheral, error) {
|
|
uidev, err := uidevice.NewUIDevice()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return uidev, nil
|
|
}
|
|
|
|
func DiscoverCDashDisplay() (peripheral.Peripheral, error) {
|
|
// Create a cdashdisplay
|
|
display, err := cdashdisplay.NewCDashDisplay()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return display, nil
|
|
}
|