2025-01-18 14:53:29 +00:00
|
|
|
package hardware
|
|
|
|
|
|
|
|
|
|
import "context"
|
|
|
|
|
|
|
|
|
|
// Peripheral represents the methods used to manage a peripheral (input or output hardware)
|
|
|
|
|
type Peripheral interface {
|
2025-08-31 11:15:38 +02:00
|
|
|
Connect(context.Context) error // Connect the peripheral
|
2025-11-13 13:01:06 +01:00
|
|
|
SetEventCallback(func(any)) // Callback is called when an event is emitted from the peripheral
|
2025-11-13 16:00:50 +01:00
|
|
|
Disconnect(context.Context) error // Disconnect the peripheral
|
2025-08-31 11:15:38 +02:00
|
|
|
Activate(context.Context) error // Activate the peripheral
|
|
|
|
|
Deactivate(context.Context) error // Deactivate the peripheral
|
2025-11-13 16:00:50 +01:00
|
|
|
SetSettings(context.Context, map[string]any) error // Set a peripheral setting
|
2025-08-31 11:15:38 +02:00
|
|
|
SetDeviceProperty(context.Context, uint32, byte) error // Update a device property
|
2025-11-12 13:42:38 +01:00
|
|
|
WaitStop() error // Properly close the peripheral
|
2025-01-18 14:53:29 +00:00
|
|
|
|
2025-11-13 16:00:50 +01:00
|
|
|
GetInfo() PeripheralInfo // Get the peripheral information
|
|
|
|
|
GetSettings() map[string]any // Get the peripheral settings
|
2025-01-18 14:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PeripheralInfo represents a peripheral information
|
|
|
|
|
type PeripheralInfo struct {
|
2025-11-13 16:00:50 +01:00
|
|
|
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
|
2025-01-18 14:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PeripheralFinder represents how compatible peripheral drivers are implemented
|
|
|
|
|
type PeripheralFinder interface {
|
2025-11-13 16:00:50 +01:00
|
|
|
Initialize() error // Initializes the protocol
|
|
|
|
|
OnArrival(cb func(p PeripheralInfo)) // Callback function when a peripheral arrives
|
|
|
|
|
OnRemoval(cb func(p PeripheralInfo)) // Callback function when a peripheral goes away
|
|
|
|
|
Start(context.Context) error // Start the detection
|
|
|
|
|
WaitStop() error // Waiting for finder to close
|
|
|
|
|
ForceScan() // Explicitly scans for peripherals
|
|
|
|
|
RegisterPeripheral(context.Context, PeripheralInfo) (string, error) // Registers a new peripheral data
|
|
|
|
|
UnregisterPeripheral(context.Context, PeripheralInfo) error // Unregisters an existing peripheral
|
|
|
|
|
GetPeripheralSettings(string) (map[string]any, error) // Gets the peripheral settings
|
|
|
|
|
SetPeripheralSettings(context.Context, string, map[string]any) error // Sets the peripheral settings
|
|
|
|
|
GetName() string // Get the name of the finder
|
2025-01-18 14:53:29 +00:00
|
|
|
}
|