Initial Commit
This commit is contained in:
11
common/Cargo.toml
Normal file
11
common/Cargo.toml
Normal file
@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "common"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0.137", features = ["derive"] }
|
||||
|
||||
[dependencies.lighter_lib]
|
||||
git = "https://git.nubo.sh/hulthe/lighter.git"
|
||||
#path = "../../lighter/lib"
|
||||
65
common/src/lib.rs
Normal file
65
common/src/lib.rs
Normal file
@ -0,0 +1,65 @@
|
||||
use lighter_lib::{BulbColor, BulbId, BulbMode};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
#[non_exhaustive]
|
||||
pub enum ServerMessage {
|
||||
InfoPage {
|
||||
html: String,
|
||||
},
|
||||
|
||||
/// Update the state of a bulb
|
||||
BulbMode {
|
||||
id: BulbId,
|
||||
mode: BulbMode,
|
||||
},
|
||||
|
||||
BulbMap(BulbMap),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
#[non_exhaustive]
|
||||
pub enum ClientMessage {
|
||||
//SubscribeToInfo,
|
||||
//SubscribeToBulbs,
|
||||
GetBulbs,
|
||||
SetBulbColor { id: BulbId, color: BulbColor },
|
||||
SetBulbPower { id: BulbId, power: bool },
|
||||
}
|
||||
|
||||
/// A geometric description of rooms/groups of light bulbs
|
||||
#[derive(Default, Deserialize, Serialize, Debug, Clone)]
|
||||
pub struct BulbMap {
|
||||
pub groups: Vec<BulbGroup>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug, Clone)]
|
||||
pub struct BulbGroup {
|
||||
pub name: String,
|
||||
pub bulbs: Vec<BulbId>,
|
||||
pub x: u32,
|
||||
pub y: u32,
|
||||
pub shape: BulbGroupShape,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug, Clone, Copy)]
|
||||
pub enum BulbGroupShape {
|
||||
Circle { r: u32 },
|
||||
Rectangle { w: u32, h: u32 },
|
||||
}
|
||||
|
||||
impl BulbGroupShape {
|
||||
pub fn height(&self) -> u32 {
|
||||
match self {
|
||||
&Self::Circle { r } => r,
|
||||
&Self::Rectangle { h, .. } => h,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn width(&self) -> u32 {
|
||||
match self {
|
||||
&Self::Circle { r } => r,
|
||||
&Self::Rectangle { w, .. } => w,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user