1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
use serde;
use serde::{Serialize, Deserialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
use crate::structures::cfg::cfg_hw::cfg_hw_led::Led;
use crate::structures::none_function;


pub mod cfg_hw_led;


/// Hardware info
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Hw {

    /// Led info
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    pub led: Option<Led>,

    /// List of color order maps
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    pub com: Option<Vec<ColorOrderMap>>,

    /// Info about connected buttons
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    pub btn: Option<Btn>,

    /// info about IR receiver
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    pub ir: Option<Ir>,

    /// info about relay
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    pub relay: Option<Relay>,

    /// baud rate/100
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    pub baud: Option<u16>,

    /// interface info
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    #[serde(rename = "if")]
    pub if_field: Option<If>,
}


#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Btn {

    /// just information about max number of buttons (not actually used)
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    pub max: Option<u8>,

    /// idfk
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    pub pull: Option<bool>,

    /// balls, testicles
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    pub ins: Option<Vec<In3>>,

    /// Touch threshold
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    pub tt: Option<u8>,

    /// button Publish Mqtt
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    pub mqtt: Option<bool>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Relay {
    /// pin for the relay
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    pub pin: Option<i8>,

    /// negate output
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    pub rev: Option<bool>,
}




#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ColorOrderMap {

    /// Probably the start index?
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    pub start: Option<u16>,

    /// stop index? probably?, could not find in latest source, but its in the WLED 14.0 binary
    #[serde(skip_serializing)]
    #[serde(default = "none_function")]
    pub stop: Option<u16>,

    /// length ig?
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    pub len: Option<u16>,

    /// Whatever the fuck 'order' is
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    pub order: Option<u8>,
}


#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ButtonMacros {
    /// preset to apply when button is pressed once, or default behaviour if 0.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    #[serde(rename = "0")]
    pub macro_button: Option<u8>,

    /// preset to apply when button is pressed for a long time, or default behaviour if 0.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    #[serde(rename = "1")]
    pub macro_long_press: Option<u8>,

    /// preset to apply when button is pressed twice, or default behaviour if 0.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    #[serde(rename = "2")]
    pub macro_double_press: Option<u8>,

}


#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Ir {

    /// Pin for this sensor. presumably fucking explodes if negative
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    pub pin: Option<i8>,

    /// IR type 0 is disabled, go scour the undocumented WLED source code for the rest
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    #[serde(rename = "type")]
    pub type_field: Option<u8>,

    /// apply IR to all selected segments; who knows what happens when false
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    pub sel: Option<bool>,
}


#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct If {
    /// [i2c_sda pin, i2c_scl pin]
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    #[serde(rename = "i2c-pin")]
    pub i2c_pin: Option<[i8; 2]>,

    /// [spi_mosi pin, spi_sclk pin, spi_miso pin]
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    #[serde(rename = "spi-pin")]
    pub spi_pin: Option<[i8; 3]>,
}


#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct In3 {

    /// Button type
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    #[serde(rename = "type")]
    pub type_field: Option<ButtonType>,

    /// Button pin
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    pub pin: Option<Vec<i8>>,

    /// Button macros
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "none_function")]
    pub macros: Option<ButtonMacros>,
}



/// Various types
#[allow(non_camel_case_types)]
#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug, Clone)]
#[repr(u8)]
pub enum ButtonType {
    /// None
    BTN_TYPE_NONE,
    /// Reserved
    BTN_TYPE_RESERVED,
    /// Push button that is considered "pushed" when at logic low
    BTN_TYPE_PUSH,
    /// Push button that is considered "pushed" when at logic high
    BTN_TYPE_PUSH_ACT_HIGH,
    /// A switch with no defined on or off
    BTN_TYPE_SWITCH,
    /// PIR sensor
    BTN_TYPE_PIR_SENSOR,
    /// Touch sensor (presumably using the built in touch sensor of the ESP32)
    BTN_TYPE_TOUCH,
    /// Not really a button, but there you go
    BTN_TYPE_ANALOG,
    /// BTN_TYPE_ANALOG, but inverted
    BTN_TYPE_ANALOG_INVERTED,
    /// Reserved to keep some semblance of backwards compatibility when new WLED versions come out with more AP behaviours
    RSVD1,
    /// Reserved to keep some semblance of backwards compatibility when new WLED versions come out with more AP behaviours
    RSVD2,
    /// Reserved to keep some semblance of backwards compatibility when new WLED versions come out with more AP behaviours
    RSVD3,
    /// Reserved to keep some semblance of backwards compatibility when new WLED versions come out with more AP behaviours
    RSVD4,
    /// Reserved to keep some semblance of backwards compatibility when new WLED versions come out with more AP behaviours
    RSVD5,
    /// Reserved to keep some semblance of backwards compatibility when new WLED versions come out with more AP behaviours
    RSVD6,

}