2
2
#include <stdlib.h>
3
3
#include <string.h>
4
4
5
- #define COMMAND_QUEUE_SLOTS (32)
6
-
7
- command command_queue [COMMAND_QUEUE_SLOTS ];
8
- uint16_t commands_queued = 0 ;
9
-
10
5
extern float clip_float (float input );
11
6
extern int16_t set_lightshow_mode_by_name (char * name );
12
- extern void transmit_to_client_in_slot (const char * message , uint8_t client_slot );
13
- extern void reboot_into_wifi_config_mode ();;
14
-
15
- // Function to return the selected index as a null-terminated string with custom delimiter
16
- // The result is stored in the provided buffer
17
- bool load_substring_from_split_index (const char * input , int index , char * result , size_t result_size , char delimiter = '|' ) {
18
- // Ensure input and result buffer are not NULL
19
- if (input == NULL || result == NULL ) {
20
- return false ;
21
- }
22
-
23
- int len = strlen (input );
24
- int start = 0 ;
25
- int end = 0 ;
26
- int current_index = 0 ;
7
+ extern void reboot_into_wifi_config_mode ();
27
8
28
- // Iterate over the input to find the desired index
29
- for (int i = 0 ; i <= len ; i ++ ) {
30
- // Check for custom delimiter or end of string
31
- if (input [i ] == delimiter || input [i ] == '\0' ) {
32
- if (current_index == index ) {
33
- end = i ;
34
- break ;
35
- }
36
- start = i + 1 ;
37
- current_index ++ ;
38
- }
39
- }
40
-
41
- // Check if the index was not found or if the result buffer is too small
42
- int segment_length = end - start ;
43
- if (current_index != index || segment_length + 1 > result_size ) {
44
- return false;
45
- }
46
-
47
- // Copy the substring to the result buffer
48
- memset (result , 0 , result_size );
49
- strncpy (result , input + start , segment_length );
50
- result [segment_length ] = '\0' ;
51
-
52
- return true;
53
- }
54
-
55
- void shift_command_queue_left () {
56
- memmove (command_queue , command_queue + 1 , (COMMAND_QUEUE_SLOTS - 1 ) * (sizeof (command )));
57
- memset (command_queue + COMMAND_QUEUE_SLOTS - 1 , 0 , 1 * sizeof (command ));
58
- }
59
9
60
10
void unrecognized_command_error (char * command ){
61
11
printf ("UNRECOGNIZED COMMAND: %s\n" , command );
@@ -78,109 +28,109 @@ void parse_command(char* command, PsychicWebSocketRequest *request) {
78
28
// Get brightness value
79
29
fetch_substring (command , '|' , 2 );
80
30
float setting_value = clip_float (atof (substring ));
81
- configuration .brightness = setting_value ;
31
+ configuration .brightness . value . f32 = setting_value ;
82
32
83
- update_ui (UI_NEEDLE_EVENT , configuration . brightness );
33
+ update_ui (UI_NEEDLE_EVENT , setting_value );
84
34
}
85
35
else if (fastcmp (substring , "softness" )) {
86
36
// Get softness value
87
37
fetch_substring (command , '|' , 2 );
88
- float setting_value = atof (substring );
89
- configuration .softness = setting_value ;
38
+ float setting_value = clip_float ( atof (substring ) );
39
+ configuration .softness . value . f32 = setting_value ;
90
40
91
- update_ui (UI_NEEDLE_EVENT , configuration . softness );
41
+ update_ui (UI_NEEDLE_EVENT , setting_value );
92
42
}
93
43
else if (fastcmp (substring , "speed" )) {
94
44
// Get speed value
95
45
fetch_substring (command , '|' , 2 );
96
- float setting_value = atof (substring );
97
- configuration .speed = setting_value ;
46
+ float setting_value = clip_float ( atof (substring ) );
47
+ configuration .speed . value . f32 = setting_value ;
98
48
99
- update_ui (UI_NEEDLE_EVENT , configuration . speed );
49
+ update_ui (UI_NEEDLE_EVENT , setting_value );
100
50
}
101
51
else if (fastcmp (substring , "blur" )) {
102
52
// Get blur value
103
53
fetch_substring (command , '|' , 2 );
104
- float setting_value = atof (substring );
105
- configuration .blur = setting_value ;
54
+ float setting_value = clip_float ( atof (substring ) );
55
+ configuration .blur . value . f32 = setting_value ;
106
56
107
- // update_ui(UI_NEEDLE_EVENT, configuration.blur );
57
+ update_ui (UI_NEEDLE_EVENT , setting_value );
108
58
}
109
59
else if (fastcmp (substring , "color" )) {
110
60
// Get color value
111
61
fetch_substring (command , '|' , 2 );
112
62
float setting_value = clip_float (atof (substring ));
113
- configuration .color = setting_value ;
63
+ configuration .color . value . f32 = setting_value ;
114
64
115
- // update_ui(UI_HUE_EVENT, configuration.hue);
65
+ update_ui (UI_HUE_EVENT , setting_value );
116
66
}
117
67
else if (fastcmp (substring , "mirror_mode" )) {
118
68
// Get mirror_mode value
119
69
fetch_substring (command , '|' , 2 );
120
- bool setting_value = (bool )atoi (substring );
121
- configuration .mirror_mode = setting_value ;
70
+ uint32_t setting_value = (bool )atoi (substring );
71
+ configuration .mirror_mode . value . u32 = setting_value ;
122
72
}
123
73
else if (fastcmp (substring , "warmth" )) {
124
74
// Get warmth value
125
75
fetch_substring (command , '|' , 2 );
126
- float setting_value = atof (substring );
127
- configuration .warmth = setting_value ;
76
+ float setting_value = clip_float ( atof (substring ) );
77
+ configuration .warmth . value . f32 = setting_value ;
128
78
129
- update_ui (UI_NEEDLE_EVENT , configuration . warmth );
79
+ update_ui (UI_NEEDLE_EVENT , setting_value );
130
80
}
131
81
else if (fastcmp (substring , "color_range" )) {
132
82
// Get color_range value
133
83
fetch_substring (command , '|' , 2 );
134
- float setting_value = atof (substring );
135
- configuration .color_range = setting_value ;
84
+ float setting_value = clip_float ( atof (substring ) );
85
+ configuration .color_range . value . f32 = setting_value ;
136
86
137
- // update_ui(UI_HUE_EVENT, configuration.hue );
87
+ update_ui (UI_HUE_EVENT , setting_value );
138
88
}
139
89
else if (fastcmp (substring , "saturation" )) {
140
90
// Get saturation value
141
91
fetch_substring (command , '|' , 2 );
142
- float setting_value = atof (substring );
143
- configuration .saturation = sqrt ( sqrt ( clip_float ( setting_value ))) ;
92
+ float setting_value = sqrt ( sqrt ( clip_float ( atof (substring ))) );
93
+ configuration .saturation . value . f32 = setting_value ;
144
94
145
- // update_ui(UI_NEEDLE_EVENT, configuration.saturation );
95
+ update_ui (UI_HUE_EVENT , setting_value );
146
96
}
147
97
else if (fastcmp (substring , "background" )) {
148
98
// Get background value
149
99
fetch_substring (command , '|' , 2 );
150
- float setting_value = atof (substring );
151
- configuration .background = setting_value ;
100
+ float setting_value = clip_float ( atof (substring ) );
101
+ configuration .background . value . f32 = setting_value ;
152
102
153
- update_ui (UI_NEEDLE_EVENT , configuration . background );
103
+ update_ui (UI_NEEDLE_EVENT , setting_value );
154
104
}
155
105
else if (fastcmp (substring , "screensaver" )) {
156
106
// Get screensaver value
157
107
fetch_substring (command , '|' , 2 );
158
- bool setting_value = (bool )atoi (substring );
159
- configuration .screensaver = setting_value ;
108
+ uint32_t setting_value = (bool )atoi (substring );
109
+ configuration .screensaver . value . u32 = setting_value ;
160
110
}
161
111
else if (fastcmp (substring , "temporal_dithering" )){
162
112
// Get temporal_dithering value
163
113
fetch_substring (command , '|' , 2 );
164
- bool setting_value = (bool )atoi (substring );
165
- configuration .temporal_dithering = setting_value ;
114
+ uint32_t setting_value = (bool )atoi (substring );
115
+ configuration .temporal_dithering . value . u32 = setting_value ;
166
116
}
167
117
else if (fastcmp (substring , "reverse_color_range" )){
168
118
// Get reverse_color_range value
169
119
fetch_substring (command , '|' , 2 );
170
- bool setting_value = (bool )atoi (substring );
171
- configuration .reverse_color_range = setting_value ;
120
+ uint32_t setting_value = (bool )atoi (substring );
121
+ configuration .reverse_color_range . value . u32 = setting_value ;
172
122
}
173
123
else if (fastcmp (substring , "auto_color_cycle" )){
174
124
// Get auto_color_cycle value
175
125
fetch_substring (command , '|' , 2 );
176
- bool setting_value = (bool )atoi (substring );
177
- configuration .auto_color_cycle = setting_value ;
126
+ uint32_t setting_value = (bool )atoi (substring );
127
+ configuration .auto_color_cycle . value . u32 = setting_value ;
178
128
}
179
- else if (fastcmp (substring , "show_interface " )){
129
+ else if (fastcmp (substring , "show_ui " )){
180
130
// Get show_interface value
181
131
fetch_substring (command , '|' , 2 );
182
- bool setting_value = (bool )atoi (substring );
183
- configuration .show_interface = setting_value ;
132
+ uint32_t setting_value = (bool )atoi (substring );
133
+ configuration .show_ui . value . u32 = setting_value ;
184
134
}
185
135
186
136
else if (fastcmp (substring , "mode" )) {
@@ -212,71 +162,9 @@ void parse_command(char* command, PsychicWebSocketRequest *request) {
212
162
if (fastcmp (substring , "config" )) {
213
163
// Wake on command
214
164
EMOTISCOPE_ACTIVE = true;
215
- sync_configuration_to_client ();
216
165
load_menu_toggles ();
217
166
}
218
167
219
- // If getting mode list
220
- else if (fastcmp (substring , "modes" )) {
221
- request -> client ()-> sendMessage ("clear_modes" );
222
-
223
- uint16_t num_modes = sizeof (light_modes ) / sizeof (light_mode );
224
- for (uint16_t mode_index = 0 ; mode_index < num_modes ; mode_index ++ ){
225
- char command_string [128 ];
226
- uint8_t mode_type = (uint8_t )light_modes [mode_index ].type ;
227
-
228
- snprintf (command_string , 128 , "new_mode|%d|%d|%.64s" , mode_index , mode_type , light_modes [mode_index ].name );
229
- request -> client ()-> sendMessage (command_string );
230
- }
231
-
232
- request -> client ()-> sendMessage ("modes_ready" );
233
- }
234
- // If getting slider list
235
- else if (fastcmp (substring , "sliders" )) {
236
- request -> client ()-> sendMessage ("clear_sliders" );
237
-
238
- for (uint16_t i = 0 ; i < sliders_active ; i ++ ){
239
- char command_string [128 ];
240
- snprintf (command_string , 128 , "new_slider|%s|%.3f|%.3f|%.3f" , sliders [i ].name , sliders [i ].slider_min , sliders [i ].slider_max , sliders [i ].slider_step );
241
- request -> client ()-> sendMessage (command_string );
242
- }
243
-
244
- request -> client ()-> sendMessage ("sliders_ready" );
245
- }
246
-
247
- // If getting toggle list
248
- else if (fastcmp (substring , "toggles" )) {
249
- request -> client ()-> sendMessage ("clear_toggles" );
250
-
251
- for (uint16_t i = 0 ; i < toggles_active ; i ++ ){
252
- char command_string [128 ];
253
- snprintf (command_string , 128 , "new_toggle|%s" , toggles [i ].name );
254
- request -> client ()-> sendMessage (command_string );
255
- }
256
-
257
- request -> client ()-> sendMessage ("toggles_ready" );
258
- }
259
-
260
- // If getting menu toggle list
261
- else if (fastcmp (substring , "menu_toggles" )) {
262
- request -> client ()-> sendMessage ("clear_menu_toggles" );
263
-
264
- for (uint16_t i = 0 ; i < menu_toggles_active ; i ++ ){
265
- char command_string [128 ];
266
- snprintf (command_string , 128 , "new_menu_toggle|%s" , menu_toggles [i ].name );
267
- request -> client ()-> sendMessage (command_string );
268
- }
269
-
270
- request -> client ()-> sendMessage ("menu_toggles_ready" );
271
- }
272
-
273
- // If getting touch values
274
- else if (fastcmp (substring , "touch_vals" )) {
275
- char command_string [128 ];
276
- snprintf (command_string , 128 , "touch_vals|%lu|%lu|%lu" , uint32_t (touch_pins [0 ].touch_value ), uint32_t (touch_pins [1 ].touch_value ), uint32_t (touch_pins [2 ].touch_value ));
277
- request -> client ()-> sendMessage (command_string );
278
- }
279
-
280
168
// If getting version number
281
169
else if (fastcmp (substring , "version" )) {
282
170
char command_string [128 ];
@@ -343,8 +231,8 @@ void parse_command(char* command, PsychicWebSocketRequest *request) {
343
231
}
344
232
}
345
233
else if (fastcmp (substring , "perform_update" )) {
346
- // extern void perform_update(int16_t client_slot );
347
- // perform_update(com.origin_client_slot );
234
+ extern void perform_update (PsychicWebSocketRequest * request );
235
+ perform_update (request );
348
236
}
349
237
else if (fastcmp (substring , "self_test" )) {
350
238
if (t_now_ms >= 1000 ){ // Wait 1 second before checking boot button
@@ -361,42 +249,10 @@ void parse_command(char* command, PsychicWebSocketRequest *request) {
361
249
load_toggles_relevant_to_mode (next_mode_index );
362
250
broadcast ("reload_config" );
363
251
}
364
- else if (fastcmp (substring , "start_debug_recording" )) {
365
- audio_recording_index = 0 ;
366
- memset (audio_debug_recording , 0 , sizeof (int16_t )* MAX_AUDIO_RECORDING_SAMPLES );
367
- audio_recording_live = true;
368
- }
369
252
370
253
else {
371
254
unrecognized_command_error (substring );
372
255
}
373
256
374
257
// printf("current brightness value: %.3f\n", configuration.brightness);
375
- }
376
-
377
- void process_command_queue () {
378
- if (commands_queued > 0 ) {
379
- //parse_command(t_now_ms, command_queue[0]);
380
- shift_command_queue_left ();
381
- commands_queued -= 1 ;
382
- }
383
- }
384
-
385
- bool queue_command (const char * command , uint16_t length , uint8_t client_slot ) {
386
- if (length < MAX_COMMAND_LENGTH ) {
387
- if (commands_queued < COMMAND_QUEUE_SLOTS - 1 ) {
388
- memset (command_queue [commands_queued ].command , 0 , MAX_COMMAND_LENGTH );
389
- memcpy (command_queue [commands_queued ].command , command , length );
390
- command_queue [commands_queued ].origin_client_slot = client_slot ;
391
- commands_queued += 1 ;
392
- }
393
- else {
394
- return false;
395
- }
396
- }
397
- else {
398
- return false;
399
- }
400
-
401
- return true;
402
258
}
0 commit comments