Skip to content

Commit 7d25f48

Browse files
BROKEN VERSION - Halfway through revamping the config struct
1 parent 129e39b commit 7d25f48

32 files changed

+382
-749
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"span": "cpp",
2525
"random": "cpp",
2626
"list": "cpp",
27-
"limits": "cpp"
27+
"limits": "cpp",
28+
"typeinfo": "cpp"
2829
}
2930
}

data/js/websockets_connection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ function connect_to_emotiscope() {
286286
attempt_to_reach_emotiscope_interval = setInterval(attempt_to_reach_emotiscope, 250);
287287

288288
setInterval(function(){
289-
wstx("EMO~stats|CPU-FPS|249.12|GPU-FPS|471.37~config|brightness|float|0.991|slider|softness|float|1.000|slider~modes|0Analog|0Spectrum");
289+
wstx("EMO~config|brightness|float|0.991|slider|1|softness|float|1.000|slider|1");
290290
}, 500);
291291
};
292292

platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
[env:esp32-s3-devkitc-1]
1212
platform = https://github.com/platformio/platform-espressif32.git#develop
1313
platform_packages =
14-
platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.0-rc3
14+
platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.0
1515
platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/esp32-arduino-libs.git#idf-release/v5.1
1616
board = esp32-s3-devkitc-1
1717
framework = arduino

src/EMOTISCOPE_FIRMWARE.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
#include "vu.h" // ................. Tracks music loudness from moment to moment
9696
#include "goertzel.h" // ........... GDFT or God Damn Fast Transform is implemented here
9797
#include "tempo.h" // .............. Comupation of (and syncronization) to the music tempo
98-
#include "audio_debug.h" // ........ Print audio data over UART
9998
#include "screensaver.h" // ........ Colorful dots play on screen when no audio is present
10099
#include "standby.h" // ............ Handles sleep/wake + animations
101100
#include "light_modes.h" // ........ Definition and handling of light modes

src/audio_debug.h

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/commands.h

Lines changed: 41 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,10 @@
22
#include <stdlib.h>
33
#include <string.h>
44

5-
#define COMMAND_QUEUE_SLOTS (32)
6-
7-
command command_queue[COMMAND_QUEUE_SLOTS];
8-
uint16_t commands_queued = 0;
9-
105
extern float clip_float(float input);
116
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();
278

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-
}
599

6010
void unrecognized_command_error(char* command){
6111
printf("UNRECOGNIZED COMMAND: %s\n", command);
@@ -78,109 +28,109 @@ void parse_command(char* command, PsychicWebSocketRequest *request) {
7828
// Get brightness value
7929
fetch_substring(command, '|', 2);
8030
float setting_value = clip_float(atof(substring));
81-
configuration.brightness = setting_value;
31+
configuration.brightness.value.f32 = setting_value;
8232

83-
update_ui(UI_NEEDLE_EVENT, configuration.brightness);
33+
update_ui(UI_NEEDLE_EVENT, setting_value);
8434
}
8535
else if (fastcmp(substring, "softness")) {
8636
// Get softness value
8737
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;
9040

91-
update_ui(UI_NEEDLE_EVENT, configuration.softness);
41+
update_ui(UI_NEEDLE_EVENT, setting_value);
9242
}
9343
else if (fastcmp(substring, "speed")) {
9444
// Get speed value
9545
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;
9848

99-
update_ui(UI_NEEDLE_EVENT, configuration.speed);
49+
update_ui(UI_NEEDLE_EVENT, setting_value);
10050
}
10151
else if (fastcmp(substring, "blur")) {
10252
// Get blur value
10353
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;
10656

107-
//update_ui(UI_NEEDLE_EVENT, configuration.blur);
57+
update_ui(UI_NEEDLE_EVENT, setting_value);
10858
}
10959
else if (fastcmp(substring, "color")) {
11060
// Get color value
11161
fetch_substring(command, '|', 2);
11262
float setting_value = clip_float(atof(substring));
113-
configuration.color = setting_value;
63+
configuration.color.value.f32 = setting_value;
11464

115-
//update_ui(UI_HUE_EVENT, configuration.hue);
65+
update_ui(UI_HUE_EVENT, setting_value);
11666
}
11767
else if (fastcmp(substring, "mirror_mode")) {
11868
// Get mirror_mode value
11969
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;
12272
}
12373
else if (fastcmp(substring, "warmth")) {
12474
// Get warmth value
12575
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;
12878

129-
update_ui(UI_NEEDLE_EVENT, configuration.warmth);
79+
update_ui(UI_NEEDLE_EVENT, setting_value);
13080
}
13181
else if (fastcmp(substring, "color_range")) {
13282
// Get color_range value
13383
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;
13686

137-
//update_ui(UI_HUE_EVENT, configuration.hue);
87+
update_ui(UI_HUE_EVENT, setting_value);
13888
}
13989
else if (fastcmp(substring, "saturation")) {
14090
// Get saturation value
14191
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;
14494

145-
//update_ui(UI_NEEDLE_EVENT, configuration.saturation);
95+
update_ui(UI_HUE_EVENT, setting_value);
14696
}
14797
else if (fastcmp(substring, "background")) {
14898
// Get background value
14999
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;
152102

153-
update_ui(UI_NEEDLE_EVENT, configuration.background);
103+
update_ui(UI_NEEDLE_EVENT, setting_value);
154104
}
155105
else if (fastcmp(substring, "screensaver")) {
156106
// Get screensaver value
157107
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;
160110
}
161111
else if (fastcmp(substring, "temporal_dithering")){
162112
// Get temporal_dithering value
163113
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;
166116
}
167117
else if (fastcmp(substring, "reverse_color_range")){
168118
// Get reverse_color_range value
169119
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;
172122
}
173123
else if (fastcmp(substring, "auto_color_cycle")){
174124
// Get auto_color_cycle value
175125
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;
178128
}
179-
else if (fastcmp(substring, "show_interface")){
129+
else if (fastcmp(substring, "show_ui")){
180130
// Get show_interface value
181131
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;
184134
}
185135

186136
else if (fastcmp(substring, "mode")) {
@@ -212,71 +162,9 @@ void parse_command(char* command, PsychicWebSocketRequest *request) {
212162
if (fastcmp(substring, "config")) {
213163
// Wake on command
214164
EMOTISCOPE_ACTIVE = true;
215-
sync_configuration_to_client();
216165
load_menu_toggles();
217166
}
218167

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-
280168
// If getting version number
281169
else if (fastcmp(substring, "version")) {
282170
char command_string[128];
@@ -343,8 +231,8 @@ void parse_command(char* command, PsychicWebSocketRequest *request) {
343231
}
344232
}
345233
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);
348236
}
349237
else if (fastcmp(substring, "self_test")) {
350238
if(t_now_ms >= 1000){ // Wait 1 second before checking boot button
@@ -361,42 +249,10 @@ void parse_command(char* command, PsychicWebSocketRequest *request) {
361249
load_toggles_relevant_to_mode(next_mode_index);
362250
broadcast("reload_config");
363251
}
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-
}
369252

370253
else{
371254
unrecognized_command_error(substring);
372255
}
373256

374257
// 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;
402258
}

0 commit comments

Comments
 (0)