wled_json_api_library/structures/cfg/cfg_hw/
mod.rs

1use serde;
2use serde::{Serialize, Deserialize};
3use serde_repr::{Deserialize_repr, Serialize_repr};
4use crate::structures::cfg::cfg_hw::cfg_hw_led::Led;
5use crate::structures::none_function;
6
7
8pub mod cfg_hw_led;
9
10
11/// Hardware info
12#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
13#[serde(rename_all = "camelCase")]
14pub struct Hw {
15
16    /// Led info
17    #[serde(skip_serializing_if = "Option::is_none")]
18    #[serde(default = "none_function")]
19    pub led: Option<Led>,
20
21    /// List of color order maps
22    #[serde(skip_serializing_if = "Option::is_none")]
23    #[serde(default = "none_function")]
24    pub com: Option<Vec<ColorOrderMap>>,
25
26    /// Info about connected buttons
27    #[serde(skip_serializing_if = "Option::is_none")]
28    #[serde(default = "none_function")]
29    pub btn: Option<Btn>,
30
31    /// info about IR receiver
32    #[serde(skip_serializing_if = "Option::is_none")]
33    #[serde(default = "none_function")]
34    pub ir: Option<Ir>,
35
36    /// info about relay
37    #[serde(skip_serializing_if = "Option::is_none")]
38    #[serde(default = "none_function")]
39    pub relay: Option<Relay>,
40
41    /// baud rate/100
42    #[serde(skip_serializing_if = "Option::is_none")]
43    #[serde(default = "none_function")]
44    pub baud: Option<u16>,
45
46    /// interface info
47    #[serde(skip_serializing_if = "Option::is_none")]
48    #[serde(default = "none_function")]
49    #[serde(rename = "if")]
50    pub if_field: Option<If>,
51}
52
53
54#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
55#[serde(rename_all = "camelCase")]
56pub struct Btn {
57
58    /// just information about max number of buttons (not actually used)
59    #[serde(skip_serializing_if = "Option::is_none")]
60    #[serde(default = "none_function")]
61    pub max: Option<u8>,
62
63    /// idfk
64    #[serde(skip_serializing_if = "Option::is_none")]
65    #[serde(default = "none_function")]
66    pub pull: Option<bool>,
67
68    /// balls, testicles
69    #[serde(skip_serializing_if = "Option::is_none")]
70    #[serde(default = "none_function")]
71    pub ins: Option<Vec<In3>>,
72
73    /// Touch threshold
74    #[serde(skip_serializing_if = "Option::is_none")]
75    #[serde(default = "none_function")]
76    pub tt: Option<u8>,
77
78    /// button Publish Mqtt
79    #[serde(skip_serializing_if = "Option::is_none")]
80    #[serde(default = "none_function")]
81    pub mqtt: Option<bool>,
82}
83
84#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
85#[serde(rename_all = "camelCase")]
86pub struct Relay {
87    /// pin for the relay
88    #[serde(skip_serializing_if = "Option::is_none")]
89    #[serde(default = "none_function")]
90    pub pin: Option<i8>,
91
92    /// negate output
93    #[serde(skip_serializing_if = "Option::is_none")]
94    #[serde(default = "none_function")]
95    pub rev: Option<bool>,
96}
97
98
99
100
101#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
102#[serde(rename_all = "camelCase")]
103pub struct ColorOrderMap {
104
105    /// Probably the start index?
106    #[serde(skip_serializing_if = "Option::is_none")]
107    #[serde(default = "none_function")]
108    pub start: Option<u16>,
109
110    /// stop index? probably?, could not find in latest source, but its in the WLED 14.0 binary
111    #[serde(skip_serializing)]
112    #[serde(default = "none_function")]
113    pub stop: Option<u16>,
114
115    /// length ig?
116    #[serde(skip_serializing_if = "Option::is_none")]
117    #[serde(default = "none_function")]
118    pub len: Option<u16>,
119
120    /// Whatever the fuck 'order' is
121    #[serde(skip_serializing_if = "Option::is_none")]
122    #[serde(default = "none_function")]
123    pub order: Option<u8>,
124}
125
126
127#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
128#[serde(rename_all = "camelCase")]
129pub struct ButtonMacros {
130    /// preset to apply when button is pressed once, or default behaviour if 0.
131    #[serde(skip_serializing_if = "Option::is_none")]
132    #[serde(default = "none_function")]
133    #[serde(rename = "0")]
134    pub macro_button: Option<u8>,
135
136    /// preset to apply when button is pressed for a long time, or default behaviour if 0.
137    #[serde(skip_serializing_if = "Option::is_none")]
138    #[serde(default = "none_function")]
139    #[serde(rename = "1")]
140    pub macro_long_press: Option<u8>,
141
142    /// preset to apply when button is pressed twice, or default behaviour if 0.
143    #[serde(skip_serializing_if = "Option::is_none")]
144    #[serde(default = "none_function")]
145    #[serde(rename = "2")]
146    pub macro_double_press: Option<u8>,
147
148}
149
150
151#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
152#[serde(rename_all = "camelCase")]
153pub struct Ir {
154
155    /// Pin for this sensor. presumably fucking explodes if negative
156    #[serde(skip_serializing_if = "Option::is_none")]
157    #[serde(default = "none_function")]
158    pub pin: Option<i8>,
159
160    /// IR type 0 is disabled, go scour the undocumented WLED source code for the rest
161    #[serde(skip_serializing_if = "Option::is_none")]
162    #[serde(default = "none_function")]
163    #[serde(rename = "type")]
164    pub type_field: Option<u8>,
165
166    /// apply IR to all selected segments; who knows what happens when false
167    #[serde(skip_serializing_if = "Option::is_none")]
168    #[serde(default = "none_function")]
169    pub sel: Option<bool>,
170}
171
172
173#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
174#[serde(rename_all = "camelCase")]
175pub struct If {
176    /// [i2c_sda pin, i2c_scl pin]
177    #[serde(skip_serializing_if = "Option::is_none")]
178    #[serde(default = "none_function")]
179    #[serde(rename = "i2c-pin")]
180    pub i2c_pin: Option<[i8; 2]>,
181
182    /// [spi_mosi pin, spi_sclk pin, spi_miso pin]
183    #[serde(skip_serializing_if = "Option::is_none")]
184    #[serde(default = "none_function")]
185    #[serde(rename = "spi-pin")]
186    pub spi_pin: Option<[i8; 3]>,
187}
188
189
190#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
191#[serde(rename_all = "camelCase")]
192pub struct In3 {
193
194    /// Button type
195    #[serde(skip_serializing_if = "Option::is_none")]
196    #[serde(default = "none_function")]
197    #[serde(rename = "type")]
198    pub type_field: Option<ButtonType>,
199
200    /// Button pin
201    #[serde(skip_serializing_if = "Option::is_none")]
202    #[serde(default = "none_function")]
203    pub pin: Option<Vec<i8>>,
204
205    /// Button macros
206    #[serde(skip_serializing_if = "Option::is_none")]
207    #[serde(default = "none_function")]
208    pub macros: Option<ButtonMacros>,
209}
210
211
212
213/// Various types
214#[allow(non_camel_case_types)]
215#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug, Clone)]
216#[repr(u8)]
217pub enum ButtonType {
218    /// None
219    BTN_TYPE_NONE,
220    /// Reserved
221    BTN_TYPE_RESERVED,
222    /// Push button that is considered "pushed" when at logic low
223    BTN_TYPE_PUSH,
224    /// Push button that is considered "pushed" when at logic high
225    BTN_TYPE_PUSH_ACT_HIGH,
226    /// A switch with no defined on or off
227    BTN_TYPE_SWITCH,
228    /// PIR sensor
229    BTN_TYPE_PIR_SENSOR,
230    /// Touch sensor (presumably using the built in touch sensor of the ESP32)
231    BTN_TYPE_TOUCH,
232    /// Not really a button, but there you go
233    BTN_TYPE_ANALOG,
234    /// BTN_TYPE_ANALOG, but inverted
235    BTN_TYPE_ANALOG_INVERTED,
236    /// Reserved to keep some semblance of backwards compatibility when new WLED versions come out with more AP behaviours
237    RSVD1,
238    /// Reserved to keep some semblance of backwards compatibility when new WLED versions come out with more AP behaviours
239    RSVD2,
240    /// Reserved to keep some semblance of backwards compatibility when new WLED versions come out with more AP behaviours
241    RSVD3,
242    /// Reserved to keep some semblance of backwards compatibility when new WLED versions come out with more AP behaviours
243    RSVD4,
244    /// Reserved to keep some semblance of backwards compatibility when new WLED versions come out with more AP behaviours
245    RSVD5,
246    /// Reserved to keep some semblance of backwards compatibility when new WLED versions come out with more AP behaviours
247    RSVD6,
248
249}
250
251
252