229 lines
5.0 KiB
Rust
229 lines
5.0 KiB
Rust
use crate::core::config::AppConfig;
|
||
use serde::{Deserialize, Serialize};
|
||
|
||
/// 消息信封:包含来源、目的地、消息体
|
||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||
pub struct Envelope {
|
||
pub from: String,
|
||
pub to: Destination,
|
||
pub message: Message,
|
||
}
|
||
|
||
/// 消息目的地
|
||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||
pub enum Destination {
|
||
/// 点对点发送给指定插件
|
||
Plugin(String),
|
||
/// 广播给所有插件
|
||
Broadcast,
|
||
/// 发给管理层自身
|
||
Manager,
|
||
}
|
||
|
||
/// 所有插件间通信的类型安全消息
|
||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||
pub enum Message {
|
||
// ── 播放控制 ──
|
||
PlayerCommand(PlayerCommand),
|
||
PlayerStatus(PlayerStatusData),
|
||
Trigger {
|
||
name: String,
|
||
value: String,
|
||
},
|
||
StateChanged {
|
||
old_state: String,
|
||
new_state: String,
|
||
},
|
||
|
||
// ── 屏幕管理 ──
|
||
ScreenLockRequest(bool),
|
||
CursorVisibility(bool),
|
||
|
||
// ── 网络 ──
|
||
WifiCommand(WifiCommand),
|
||
WifiResult(String),
|
||
WifiProvisioned {
|
||
ssid: String,
|
||
ip: String,
|
||
},
|
||
|
||
// ── 配置 ──
|
||
/// 配置重载广播需要经过 JSON/FFI 路径,因此这里保存可序列化的 AppConfig。
|
||
ConfigReloaded(AppConfig),
|
||
ConfigReloadRequest,
|
||
|
||
// ── 系统 ──
|
||
Shutdown,
|
||
PluginReady(String),
|
||
|
||
// ── 设备管理 ──
|
||
DeviceCommand(DeviceCommand),
|
||
DeviceResponse(DeviceResponse),
|
||
DeviceEvent(DeviceEvent),
|
||
|
||
// ── 扩展(未来插件用) ──
|
||
Custom {
|
||
kind: String,
|
||
payload: String,
|
||
},
|
||
}
|
||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||
pub enum PlayerCommand {
|
||
Play,
|
||
Pause,
|
||
Next,
|
||
Previous,
|
||
Goto(usize),
|
||
ChangeScene(String),
|
||
}
|
||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||
pub struct PlayerStatusData {
|
||
pub running: bool,
|
||
pub paused: bool,
|
||
pub in_transition: bool,
|
||
pub current_index: usize,
|
||
pub playlist_length: usize,
|
||
pub current_video: Option<String>,
|
||
}
|
||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||
pub enum WifiCommand {
|
||
Scan,
|
||
Connect { ssid: String, password: String },
|
||
Status,
|
||
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, PartialEq)]
|
||
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 },
|
||
}
|