Init
This commit is contained in:
commit
76b43a0386
38 changed files with 5003 additions and 0 deletions
1
kdash_protocol/.gitignore
vendored
Normal file
1
kdash_protocol/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
12
kdash_protocol/Cargo.toml
Normal file
12
kdash_protocol/Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "kdash_protocol"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
chrono = { version = "0.4.38", features = ["serde"] }
|
||||
chrono-tz = { version = "0.10.0", features = ["serde"] }
|
||||
cron = { version = "0.13.0", features = ["serde"] }
|
||||
serde = { version = "1.0.214", features = ["derive"] }
|
||||
serde_with = { version = "3.11.0", features = ["chrono_0_4"] }
|
||||
validated_newtype = "0.1.1"
|
68
kdash_protocol/src/lib.rs
Normal file
68
kdash_protocol/src/lib.rs
Normal file
|
@ -0,0 +1,68 @@
|
|||
use chrono::Duration;
|
||||
use chrono_tz::Tz;
|
||||
use cron::Schedule;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validated_newtype::validated_newtype;
|
||||
|
||||
validated_newtype! {
|
||||
#[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Serialize, Clone, Copy)]
|
||||
u8 => pub Percent
|
||||
if |n: &u8| *n <= 100;
|
||||
error "percent must in range 0-100"
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
|
||||
pub struct Config {
|
||||
pub name: String,
|
||||
pub battery: BatteryConfig,
|
||||
pub time: TimeConfig,
|
||||
pub device: DeviceConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
|
||||
pub struct BatteryConfig {
|
||||
pub alert: Percent,
|
||||
pub low: Percent,
|
||||
pub restart_powerd_threshold: Percent,
|
||||
}
|
||||
|
||||
#[serde_with::serde_as]
|
||||
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
|
||||
pub struct TimeConfig {
|
||||
pub timezone: Tz,
|
||||
|
||||
pub update_schedule: Schedule,
|
||||
|
||||
#[serde_as(as = "serde_with::DurationSeconds<i64>")]
|
||||
pub delay_on_error: Duration,
|
||||
|
||||
#[serde_as(as = "serde_with::DurationSeconds<i64>")]
|
||||
pub delay_before_suspend: Duration,
|
||||
|
||||
#[serde_as(as = "serde_with::DurationSeconds<i64>")]
|
||||
pub delay_low_battery: Duration,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
|
||||
pub struct DeviceConfig {
|
||||
pub use_rtc: bool,
|
||||
pub full_refresh: bool,
|
||||
pub orientation: Orientation,
|
||||
pub status_box_location: Corner,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq)]
|
||||
pub enum Orientation {
|
||||
PortraitUp,
|
||||
PortraitDown,
|
||||
LandscapeLeft,
|
||||
LandscapeRight,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq)]
|
||||
pub enum Corner {
|
||||
TopLeft,
|
||||
TopRight,
|
||||
BottomLeft,
|
||||
BottomRight,
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue