This commit is contained in:
2024-03-24 16:29:24 +01:00
parent 84f8222b30
commit 4a528eb4b7
44 changed files with 5438 additions and 328 deletions

71
lib/src/serial_proto.rs Normal file
View File

@ -0,0 +1,71 @@
pub mod owned {
use alloc::string::String;
use msgpck::{MsgPack, MsgUnpack};
use crate::layer::Layers;
#[derive(Debug, MsgPack, MsgUnpack)]
pub struct LogRecord {
/// Milliseconds since boot
pub timestamp: u64,
pub level: String,
pub message: String,
}
/// Press the switch with the provided index.
#[derive(Debug, MsgPack, MsgUnpack)]
pub struct SwitchPress(pub u16);
/// Release the switch with the provided index.
#[derive(Debug, MsgPack, MsgUnpack)]
pub struct SwitchRelease(pub u16);
/// Change to the layer at the provided coordinates in the layer matrix.
#[derive(Debug, MsgPack, MsgUnpack)]
pub struct ChangeLayer {
pub x: u16,
pub y: u16,
}
#[derive(Debug, MsgPack, MsgUnpack)]
pub enum DeviceMsg {
Log(LogRecord),
SwitchPress(SwitchPress),
SwitchRelease(SwitchRelease),
ChangeLayer(ChangeLayer),
Layers(Layers),
}
#[derive(Debug, MsgPack, MsgUnpack)]
pub enum HostMsg {
GetLayers,
}
}
pub mod borrowed {
use msgpck::MsgPack;
use super::owned::*;
use crate::{layer::Layers, util::DisplayPack};
#[derive(Debug, MsgPack)]
pub struct LogRecord<'a> {
/// Milliseconds since boot
pub timestamp: u64,
pub level: DisplayPack<log::Level>,
pub message: DisplayPack<&'a core::fmt::Arguments<'a>>,
}
#[derive(Debug, MsgPack)]
pub enum DeviceMsg<'a> {
Log(LogRecord<'a>),
SwitchPress(SwitchPress),
SwitchRelease(SwitchRelease),
ChangeLayer(ChangeLayer),
Layers(&'a Layers),
}
}