Initial Commit

This commit is contained in:
2022-07-29 01:36:18 +02:00
commit e7baf561bd
32 changed files with 4394 additions and 0 deletions

11
common/Cargo.toml Normal file
View 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
View 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,
}
}
}