strand_led_box_comms/
lib.rs1#![cfg_attr(not(feature = "std"), no_std)]
15#![warn(missing_docs)]
16
17extern crate serde;
18
19#[cfg(not(feature = "std"))]
20extern crate core as std;
21
22use serde::{Deserialize, Serialize};
23
24pub const MAX_INTENSITY: u16 = 16000;
26pub const COMM_VERSION: u16 = 3;
28pub const BAUD_RATE: u32 = 230_400;
30
31#[derive(Debug, PartialEq, Serialize, Deserialize, Clone, Copy)]
33#[cfg_attr(feature = "print-defmt", derive(defmt::Format))]
34pub enum ToDevice {
35 DeviceState(DeviceState),
37 EchoRequest8((u8, u8, u8, u8, u8, u8, u8, u8)),
39 VersionRequest,
41}
42
43#[derive(Debug, PartialEq, Serialize, Deserialize, Clone, Copy)]
45#[cfg_attr(feature = "print-defmt", derive(defmt::Format))]
46pub enum FromDevice {
47 DeviceState(DeviceState),
49 EchoResponse8((u8, u8, u8, u8, u8, u8, u8, u8)),
51 VersionResponse(u16),
53 StateWasSet,
55}
56
57#[derive(Debug, PartialEq, Serialize, Deserialize, Clone, Copy)]
59#[cfg_attr(feature = "print-defmt", derive(defmt::Format))]
60pub struct DeviceState {
61 pub ch1: ChannelState,
63 pub ch2: ChannelState,
65 pub ch3: ChannelState,
67 pub ch4: ChannelState,
69}
70
71impl DeviceState {
72 pub const fn default() -> DeviceState {
74 DeviceState {
75 ch1: ChannelState::default(1),
76 ch2: ChannelState::default(2),
77 ch3: ChannelState::default(3),
78 ch4: ChannelState::default(4),
79 }
80 }
81}
82
83impl Default for DeviceState {
84 fn default() -> DeviceState {
85 DeviceState::default()
86 }
87}
88
89#[derive(Debug, PartialEq, Serialize, Deserialize, Clone, Copy)]
91#[cfg_attr(feature = "print-defmt", derive(defmt::Format))]
92pub struct ChannelState {
93 pub num: u8,
95 pub on_state: OnState,
97 pub intensity: u16,
99}
100
101impl ChannelState {
102 pub const fn default(num: u8) -> ChannelState {
104 ChannelState {
105 num,
106 on_state: OnState::Off,
107 intensity: MAX_INTENSITY,
108 }
109 }
110}
111
112impl Default for ChannelState {
113 fn default() -> ChannelState {
114 ChannelState::default(1)
115 }
116}
117
118#[derive(Debug, PartialEq, Serialize, Deserialize, Clone, Copy)]
120#[cfg_attr(feature = "print-defmt", derive(defmt::Format))]
121#[derive(Default)]
122pub enum OnState {
123 #[default]
124 Off,
126 ConstantOn,
128}
129
130impl std::fmt::Display for OnState {
131 fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> {
132 std::fmt::Debug::fmt(self, fmt)
133 }
134}
135
136#[cfg(feature = "std")]
137impl strand_cam_enum_iter::EnumIter for OnState {
138 fn variants() -> Vec<Self> {
139 vec![OnState::Off, OnState::ConstantOn]
140 }
141}