feat: DevicePlugin Task1 — Message enum扩展(DeviceCommand/Response/Event + 7个辅助类型)

This commit is contained in:
showen
2026-03-13 06:22:53 +08:00
parent f83e18d43b
commit 4d1b830563
4 changed files with 199 additions and 0 deletions

View File

@@ -56,6 +56,11 @@ pub enum Message {
Shutdown,
PluginReady(String),
// ── 设备管理 ──
DeviceCommand(DeviceCommand),
DeviceResponse(DeviceResponse),
DeviceEvent(DeviceEvent),
// ── 扩展(未来插件用) ──
Custom {
kind: String,
@@ -91,3 +96,133 @@ pub enum WifiCommand {
ApStart { ssid: String, password: String },
ApStop,
}
// ── 设备管理 ──
/// 像素格式
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum PixelFormat {
/// RGBA 8888 格式(每像素 4 字节)
RGBA8888,
/// RGB 888 格式(每像素 3 字节)
RGB888,
/// RGB 565 格式(每像素 2 字节)
RGB565,
}
/// 传感器类型
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum SensorType {
/// 温度传感器
Temperature,
/// 湿度传感器
Humidity,
/// 光线传感器
Light,
/// 接近传感器
Proximity,
}
/// 触摸动作
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum TouchAction {
/// 按下
Down,
/// 移动
Move,
/// 抬起
Up,
}
/// 设备能力
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum DeviceCapability {
/// 显示屏
Display,
/// 触摸屏
Touch,
/// 按钮
Buttons,
/// 音频
Audio,
/// 电池
Battery,
/// 背光
Backlight,
/// 传感器
Sensors,
/// 帧缓冲
Framebuffer,
/// GPIO
GPIO,
}
/// 设备命令(业务插件 → DevicePlugin
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum DeviceCommand {
/// 获取显示信息
GetDisplayInfo,
/// 设置亮度0-100
SetBrightness(u8),
/// 设置背光开关
SetBacklight(bool),
/// 写入帧缓冲
WriteFramebuffer { data: Vec<u8>, format: PixelFormat },
/// 设置防息屏
SetSleepInhibit(bool),
/// 获取电池电量
GetBatteryLevel,
/// 设置音量0-100
SetVolume(u8),
/// 播放音频
PlayAudio { path: String },
/// 获取触摸事件
GetTouchEvents,
/// 获取按钮状态
GetButtonState,
/// 获取传感器数据
GetSensorData(SensorType),
/// 自定义命令
CustomCommand {
subsystem: String,
payload: serde_json::Value,
},
}
/// 设备响应DevicePlugin → 请求者)
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum DeviceResponse {
/// 显示信息
DisplayInfo {
width: u32,
height: u32,
format: PixelFormat,
},
/// 传感器数据
SensorData { sensor: SensorType, value: f64 },
/// 电池电量0-100
BatteryLevel(u8),
/// 操作成功
Ok,
/// 操作失败
Error(String),
/// 自定义响应
Custom(serde_json::Value),
}
/// 设备事件DevicePlugin → 广播)
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum DeviceEvent {
/// 触摸事件
TouchEvent { x: i32, y: i32, action: TouchAction },
/// 按钮事件
ButtonEvent { button: u8, pressed: bool },
/// 电池电量低
BatteryLow(u8),
/// 显示器已连接
DisplayConnected,
/// 显示器已断开
DisplayDisconnected,
/// 传感器警报
SensorAlert { sensor: SensorType, value: f64 },
}

View File

@@ -77,6 +77,9 @@ fn message_label(message: &Message) -> String {
Message::ScreenLockRequest(value) => format!("screen_lock:{value}"),
Message::CursorVisibility(value) => format!("cursor_visibility:{value}"),
Message::WifiCommand(_) => "wifi_command".to_string(),
Message::DeviceCommand(_) => "device_command".to_string(),
Message::DeviceResponse(_) => "device_response".to_string(),
Message::DeviceEvent(_) => "device_event".to_string(),
}
}