Files
dmxconnect/hardware/interfaces.go

57 lines
2.8 KiB
Go

package hardware
import "context"
// MappingInfo is the configuration for each device
type MappingInfo struct {
DeviceInfo struct {
Name string `yaml:"name"`
Manufacturer string `yaml:"manufacturer"`
Type string `yaml:"type"`
} `yaml:"device"`
Features map[string]any `yaml:"features"`
}
// Device represents the methods used to manage a device (logic element include in a Peripheral)
type Device interface {
Configure() error // Load the mapping for the device
}
// Peripheral represents the methods used to manage a peripheral (input or output hardware)
type Peripheral interface {
Connect(context.Context) error // Connect the peripheral
// SetEventCallback(func(any)) // Callback is called when an event is emitted from the peripheral
Disconnect(context.Context) error // Disconnect the peripheral
Activate(context.Context) error // Activate the peripheral
Deactivate(context.Context) error // Deactivate the peripheral
// AddDevice(Device) error // Add a device to the peripheral
// RemoveDevice(Device) error // Remove a device to the peripheral
GetSettings() map[string]any // Get the peripheral settings
SetSettings(context.Context, map[string]any) error // Set a peripheral setting
SetDeviceProperty(context.Context, uint32, byte) error // Update a device property
WaitStop() error // Properly close the peripheral
GetInfo() PeripheralInfo // Get the peripheral information
}
// PeripheralInfo represents a peripheral information
type PeripheralInfo struct {
Name string `yaml:"name"` // Name of the peripheral
SerialNumber string `yaml:"sn"` // S/N of the peripheral
ProtocolName string `yaml:"protocol"` // Protocol name of the peripheral
Settings map[string]any `yaml:"settings"` // Peripheral settings
}
// PeripheralFinder represents how compatible peripheral drivers are implemented
type PeripheralFinder interface {
Initialize() error // Initializes the protocol
Create(ctx context.Context, peripheralInfo PeripheralInfo) error // Manually create a peripheral
Remove(ctx context.Context, peripheral Peripheral) error // Manually remove a peripheral
OnArrival(cb func(context.Context, Peripheral, bool)) // Callback function when a peripheral arrives
OnRemoval(cb func(context.Context, Peripheral)) // Callback function when a peripheral goes away
Start(context.Context) error // Start the detection
WaitStop() error // Waiting for finder to close
GetName() string // Get the name of the finder
}