pokeys_thread/
commands.rs

1use log::LevelFilter;
2use pokeys_lib::models::DeviceModel;
3use pokeys_lib::{ServoConfig, USPIBridgeConfig};
4
5/// Commands that can be sent to device threads
6#[derive(Debug, Clone)]
7pub enum DeviceCommand {
8    /// Start the device thread
9    Start,
10    /// Pause the device thread
11    Pause,
12    /// Terminate the device thread
13    Terminate,
14    /// Restart the device thread
15    Restart,
16    /// Get the current status of the device thread
17    GetStatus,
18    /// Set a digital output pin
19    SetDigitalOutput { pin: u32, value: bool },
20    /// Set an analog output
21    SetAnalogOutput { pin: u32, value: u32 },
22    /// Set PWM duty cycle
23    SetPwmDuty { channel: usize, duty: u32 },
24    /// Configure a servo
25    ConfigureServo { pin: u8, config: ServoConfig },
26    /// Set servo angle
27    SetServoAngle { pin: u8, angle: f32 },
28    /// Set servo speed
29    SetServoSpeed { pin: u8, speed: f32 },
30    /// Stop servo
31    StopServo { pin: u8 },
32    /// I2C write operation
33    I2cWrite { address: u8, data: Vec<u8> },
34    /// I2C read operation
35    I2cRead { address: u8, length: u8 },
36    /// I2C write then read operation
37    I2cWriteRead {
38        address: u8,
39        write_data: Vec<u8>,
40        read_length: u8,
41    },
42    /// I2C bus scan
43    I2cScan,
44    /// Configure uSPIBridge
45    ConfigureUSPIBridge { config: USPIBridgeConfig },
46    /// Send uSPIBridge command
47    USPIBridgeCommand { command: Vec<u8> },
48    /// Bulk set digital outputs
49    SetDigitalOutputsBulk { pin_states: Vec<(u32, bool)> },
50    /// Bulk set PWM duty cycles
51    SetPwmDutiesBulk { channel_duties: Vec<(usize, u32)> },
52    /// Bulk read analog inputs
53    ReadAnalogInputsBulk { pins: Vec<u32> },
54    /// Check pin capability
55    CheckPinCapability { pin: u8, capability: String },
56    /// Validate pin operation
57    ValidatePinOperation { pin: u8, operation: String },
58    /// Configure an encoder
59    ConfigureEncoder {
60        encoder_index: u32,
61        pin_a: u32,
62        pin_b: u32,
63        enabled: bool,
64        sampling_4x: bool,
65    },
66    /// Reset a digital counter
67    ResetDigitalCounter { pin: u32 },
68    /// Set pin function
69    SetPinFunction {
70        pin: u32,
71        pin_function: pokeys_lib::PinFunction,
72    },
73    /// Custom command with raw parameters
74    Custom {
75        request_type: u8,
76        param1: u8,
77        param2: u8,
78        param3: u8,
79        param4: u8,
80    },
81    /// Set log level
82    SetLogLevel(LevelFilter),
83    /// Update device model
84    UpdateModel(DeviceModel),
85}