2025-01-18 14:53:29 +00:00
|
|
|
package hardware
|
|
|
|
|
|
|
|
|
|
import "context"
|
|
|
|
|
|
2025-11-16 21:44:48 +01:00
|
|
|
// 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
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-18 14:53:29 +00:00
|
|
|
// Peripheral represents the methods used to manage a peripheral (input or output hardware)
|
|
|
|
|
type Peripheral interface {
|
2025-11-29 17:42:42 +01:00
|
|
|
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
|
2025-11-16 21:44:48 +01:00
|
|
|
GetSettings() map[string]any // Get the peripheral settings
|
2025-11-14 10:46:24 +00: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-14 10:46:24 +00:00
|
|
|
WaitStop() error // Properly close the peripheral
|
2025-01-18 14:53:29 +00:00
|
|
|
|
2025-11-16 21:44:48 +01:00
|
|
|
GetInfo() PeripheralInfo // Get the peripheral information
|
|
|
|
|
|
2025-01-18 14:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PeripheralInfo represents a peripheral information
|
|
|
|
|
type PeripheralInfo struct {
|
2025-11-14 10:46:24 +00: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-29 20:06:04 +01:00
|
|
|
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
|
2025-01-18 14:53:29 +00:00
|
|
|
}
|