Files
dmxconnect/hardware/OS2LDriver.go

62 lines
1.6 KiB
Go
Raw Normal View History

2024-12-23 17:22:37 +01:00
package hardware
import (
"context"
"fmt"
"math/rand"
2024-12-26 14:55:55 +01:00
"strings"
2024-12-23 17:22:37 +01:00
)
// OS2LDriver represents how the protocol is defined
type OS2LDriver struct {
peripherals map[string]Peripheral // The list of peripherals
}
// NewOS2LDriver creates a new OS2L driver
func NewOS2LDriver() *OS2LDriver {
return &OS2LDriver{
peripherals: make(map[string]Peripheral),
}
}
// Initialize initializes the MIDI driver
func (d *OS2LDriver) Initialize() error {
fmt.Println("OS2L driver initialized")
return nil
}
// CreatePeripheral creates a new OS2L peripheral
func (d *OS2LDriver) CreatePeripheral(ctx context.Context) (Peripheral, error) {
// Create a random serial number for this peripheral
2024-12-26 14:55:55 +01:00
randomSerialNumber := strings.ToUpper(fmt.Sprintf("%08x", rand.Intn(1<<32)))
2024-12-23 17:22:37 +01:00
peripheral := NewOS2LPeripheral("OS2L", randomSerialNumber)
d.peripherals[randomSerialNumber] = peripheral
return peripheral, nil
}
// RemovePeripheral removes an OS2L dev
func (d *OS2LDriver) RemovePeripheral(serialNumber string) error {
delete(d.peripherals, serialNumber)
return nil
}
// GetName returns the name of the driver
func (d *OS2LDriver) GetName() string {
return "OS2L"
}
// GetPeripheral gets the peripheral that correspond to the specified ID
func (d *OS2LDriver) GetPeripheral(peripheralID string) (Peripheral, bool) {
// Return the specified peripheral
peripheral := d.peripherals[peripheralID]
if peripheral == nil {
return nil, false
}
return peripheral, true
}
// Scan scans the interfaces compatible with the MIDI protocol
func (d *OS2LDriver) Scan(ctx context.Context) error {
return nil
}