Skip to content

Commit

Permalink
BROKEN VERSION - Halfway through revamping the config struct
Browse files Browse the repository at this point in the history
  • Loading branch information
connornishijima committed May 29, 2024
1 parent 129e39b commit 7d25f48
Show file tree
Hide file tree
Showing 32 changed files with 382 additions and 749 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"span": "cpp",
"random": "cpp",
"list": "cpp",
"limits": "cpp"
"limits": "cpp",
"typeinfo": "cpp"
}
}
2 changes: 1 addition & 1 deletion data/js/websockets_connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ function connect_to_emotiscope() {
attempt_to_reach_emotiscope_interval = setInterval(attempt_to_reach_emotiscope, 250);

setInterval(function(){
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");
wstx("EMO~config|brightness|float|0.991|slider|1|softness|float|1.000|slider|1");
}, 500);
};

Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[env:esp32-s3-devkitc-1]
platform = https://github.com/platformio/platform-espressif32.git#develop
platform_packages =
platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.0-rc3
platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.0
platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/esp32-arduino-libs.git#idf-release/v5.1
board = esp32-s3-devkitc-1
framework = arduino
Expand Down
1 change: 0 additions & 1 deletion src/EMOTISCOPE_FIRMWARE.ino
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
#include "vu.h" // ................. Tracks music loudness from moment to moment
#include "goertzel.h" // ........... GDFT or God Damn Fast Transform is implemented here
#include "tempo.h" // .............. Comupation of (and syncronization) to the music tempo
#include "audio_debug.h" // ........ Print audio data over UART
#include "screensaver.h" // ........ Colorful dots play on screen when no audio is present
#include "standby.h" // ............ Handles sleep/wake + animations
#include "light_modes.h" // ........ Definition and handling of light modes
Expand Down
6 changes: 0 additions & 6 deletions src/audio_debug.h

This file was deleted.

226 changes: 41 additions & 185 deletions src/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,10 @@
#include <stdlib.h>
#include <string.h>

#define COMMAND_QUEUE_SLOTS (32)

command command_queue[COMMAND_QUEUE_SLOTS];
uint16_t commands_queued = 0;

extern float clip_float(float input);
extern int16_t set_lightshow_mode_by_name(char* name);
extern void transmit_to_client_in_slot(const char* message, uint8_t client_slot);
extern void reboot_into_wifi_config_mode();;

// Function to return the selected index as a null-terminated string with custom delimiter
// The result is stored in the provided buffer
bool load_substring_from_split_index(const char* input, int index, char* result, size_t result_size, char delimiter = '|') {
// Ensure input and result buffer are not NULL
if (input == NULL || result == NULL) {
return false;
}

int len = strlen(input);
int start = 0;
int end = 0;
int current_index = 0;
extern void reboot_into_wifi_config_mode();

// Iterate over the input to find the desired index
for (int i = 0; i <= len; i++) {
// Check for custom delimiter or end of string
if (input[i] == delimiter || input[i] == '\0') {
if (current_index == index) {
end = i;
break;
}
start = i + 1;
current_index++;
}
}

// Check if the index was not found or if the result buffer is too small
int segment_length = end - start;
if (current_index != index || segment_length + 1 > result_size) {
return false;
}

// Copy the substring to the result buffer
memset(result, 0, result_size);
strncpy(result, input + start, segment_length);
result[segment_length] = '\0';

return true;
}

void shift_command_queue_left() {
memmove(command_queue, command_queue + 1, (COMMAND_QUEUE_SLOTS - 1) * (sizeof(command)));
memset(command_queue + COMMAND_QUEUE_SLOTS - 1, 0, 1 * sizeof(command));
}

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

update_ui(UI_NEEDLE_EVENT, configuration.brightness);
update_ui(UI_NEEDLE_EVENT, setting_value);
}
else if (fastcmp(substring, "softness")) {
// Get softness value
fetch_substring(command, '|', 2);
float setting_value = atof(substring);
configuration.softness = setting_value;
float setting_value = clip_float(atof(substring));
configuration.softness.value.f32 = setting_value;

update_ui(UI_NEEDLE_EVENT, configuration.softness);
update_ui(UI_NEEDLE_EVENT, setting_value);
}
else if (fastcmp(substring, "speed")) {
// Get speed value
fetch_substring(command, '|', 2);
float setting_value = atof(substring);
configuration.speed = setting_value;
float setting_value = clip_float(atof(substring));
configuration.speed.value.f32 = setting_value;

update_ui(UI_NEEDLE_EVENT, configuration.speed);
update_ui(UI_NEEDLE_EVENT, setting_value);
}
else if (fastcmp(substring, "blur")) {
// Get blur value
fetch_substring(command, '|', 2);
float setting_value = atof(substring);
configuration.blur = setting_value;
float setting_value = clip_float(atof(substring));
configuration.blur.value.f32 = setting_value;

//update_ui(UI_NEEDLE_EVENT, configuration.blur);
update_ui(UI_NEEDLE_EVENT, setting_value);
}
else if (fastcmp(substring, "color")) {
// Get color value
fetch_substring(command, '|', 2);
float setting_value = clip_float(atof(substring));
configuration.color = setting_value;
configuration.color.value.f32 = setting_value;

//update_ui(UI_HUE_EVENT, configuration.hue);
update_ui(UI_HUE_EVENT, setting_value);
}
else if (fastcmp(substring, "mirror_mode")) {
// Get mirror_mode value
fetch_substring(command, '|', 2);
bool setting_value = (bool)atoi(substring);
configuration.mirror_mode = setting_value;
uint32_t setting_value = (bool)atoi(substring);
configuration.mirror_mode.value.u32 = setting_value;
}
else if (fastcmp(substring, "warmth")) {
// Get warmth value
fetch_substring(command, '|', 2);
float setting_value = atof(substring);
configuration.warmth = setting_value;
float setting_value = clip_float(atof(substring));
configuration.warmth.value.f32 = setting_value;

update_ui(UI_NEEDLE_EVENT, configuration.warmth);
update_ui(UI_NEEDLE_EVENT, setting_value);
}
else if (fastcmp(substring, "color_range")) {
// Get color_range value
fetch_substring(command, '|', 2);
float setting_value = atof(substring);
configuration.color_range = setting_value;
float setting_value = clip_float(atof(substring));
configuration.color_range.value.f32 = setting_value;

//update_ui(UI_HUE_EVENT, configuration.hue);
update_ui(UI_HUE_EVENT, setting_value);
}
else if (fastcmp(substring, "saturation")) {
// Get saturation value
fetch_substring(command, '|', 2);
float setting_value = atof(substring);
configuration.saturation = sqrt(sqrt(clip_float(setting_value)));
float setting_value = sqrt(sqrt(clip_float(atof(substring))));
configuration.saturation.value.f32 = setting_value;

//update_ui(UI_NEEDLE_EVENT, configuration.saturation);
update_ui(UI_HUE_EVENT, setting_value);
}
else if (fastcmp(substring, "background")) {
// Get background value
fetch_substring(command, '|', 2);
float setting_value = atof(substring);
configuration.background = setting_value;
float setting_value = clip_float(atof(substring));
configuration.background.value.f32 = setting_value;

update_ui(UI_NEEDLE_EVENT, configuration.background);
update_ui(UI_NEEDLE_EVENT, setting_value);
}
else if (fastcmp(substring, "screensaver")) {
// Get screensaver value
fetch_substring(command, '|', 2);
bool setting_value = (bool)atoi(substring);
configuration.screensaver = setting_value;
uint32_t setting_value = (bool)atoi(substring);
configuration.screensaver.value.u32 = setting_value;
}
else if (fastcmp(substring, "temporal_dithering")){
// Get temporal_dithering value
fetch_substring(command, '|', 2);
bool setting_value = (bool)atoi(substring);
configuration.temporal_dithering = setting_value;
uint32_t setting_value = (bool)atoi(substring);
configuration.temporal_dithering.value.u32 = setting_value;
}
else if (fastcmp(substring, "reverse_color_range")){
// Get reverse_color_range value
fetch_substring(command, '|', 2);
bool setting_value = (bool)atoi(substring);
configuration.reverse_color_range = setting_value;
uint32_t setting_value = (bool)atoi(substring);
configuration.reverse_color_range.value.u32 = setting_value;
}
else if (fastcmp(substring, "auto_color_cycle")){
// Get auto_color_cycle value
fetch_substring(command, '|', 2);
bool setting_value = (bool)atoi(substring);
configuration.auto_color_cycle = setting_value;
uint32_t setting_value = (bool)atoi(substring);
configuration.auto_color_cycle.value.u32 = setting_value;
}
else if (fastcmp(substring, "show_interface")){
else if (fastcmp(substring, "show_ui")){
// Get show_interface value
fetch_substring(command, '|', 2);
bool setting_value = (bool)atoi(substring);
configuration.show_interface = setting_value;
uint32_t setting_value = (bool)atoi(substring);
configuration.show_ui.value.u32 = setting_value;
}

else if (fastcmp(substring, "mode")) {
Expand Down Expand Up @@ -212,71 +162,9 @@ void parse_command(char* command, PsychicWebSocketRequest *request) {
if (fastcmp(substring, "config")) {
// Wake on command
EMOTISCOPE_ACTIVE = true;
sync_configuration_to_client();
load_menu_toggles();
}

// If getting mode list
else if (fastcmp(substring, "modes")) {
request->client()->sendMessage("clear_modes");

uint16_t num_modes = sizeof(light_modes) / sizeof(light_mode);
for(uint16_t mode_index = 0; mode_index < num_modes; mode_index++){
char command_string[128];
uint8_t mode_type = (uint8_t)light_modes[mode_index].type;

snprintf(command_string, 128, "new_mode|%d|%d|%.64s", mode_index, mode_type, light_modes[mode_index].name);
request->client()->sendMessage(command_string);
}

request->client()->sendMessage("modes_ready");
}
// If getting slider list
else if (fastcmp(substring, "sliders")) {
request->client()->sendMessage("clear_sliders");

for(uint16_t i = 0; i < sliders_active; i++){
char command_string[128];
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);
request->client()->sendMessage(command_string);
}

request->client()->sendMessage("sliders_ready");
}

// If getting toggle list
else if (fastcmp(substring, "toggles")) {
request->client()->sendMessage("clear_toggles");

for(uint16_t i = 0; i < toggles_active; i++){
char command_string[128];
snprintf(command_string, 128, "new_toggle|%s", toggles[i].name);
request->client()->sendMessage(command_string);
}

request->client()->sendMessage("toggles_ready");
}

// If getting menu toggle list
else if (fastcmp(substring, "menu_toggles")) {
request->client()->sendMessage("clear_menu_toggles");

for(uint16_t i = 0; i < menu_toggles_active; i++){
char command_string[128];
snprintf(command_string, 128, "new_menu_toggle|%s", menu_toggles[i].name);
request->client()->sendMessage(command_string);
}

request->client()->sendMessage("menu_toggles_ready");
}

// If getting touch values
else if (fastcmp(substring, "touch_vals")) {
char command_string[128];
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));
request->client()->sendMessage(command_string);
}

// If getting version number
else if (fastcmp(substring, "version")) {
char command_string[128];
Expand Down Expand Up @@ -343,8 +231,8 @@ void parse_command(char* command, PsychicWebSocketRequest *request) {
}
}
else if (fastcmp(substring, "perform_update")) {
//extern void perform_update(int16_t client_slot);
//perform_update(com.origin_client_slot);
extern void perform_update(PsychicWebSocketRequest *request);
perform_update(request);
}
else if (fastcmp(substring, "self_test")) {
if(t_now_ms >= 1000){ // Wait 1 second before checking boot button
Expand All @@ -361,42 +249,10 @@ void parse_command(char* command, PsychicWebSocketRequest *request) {
load_toggles_relevant_to_mode(next_mode_index);
broadcast("reload_config");
}
else if (fastcmp(substring, "start_debug_recording")) {
audio_recording_index = 0;
memset(audio_debug_recording, 0, sizeof(int16_t)*MAX_AUDIO_RECORDING_SAMPLES);
audio_recording_live = true;
}

else{
unrecognized_command_error(substring);
}

// printf("current brightness value: %.3f\n", configuration.brightness);
}

void process_command_queue() {
if (commands_queued > 0) {
//parse_command(t_now_ms, command_queue[0]);
shift_command_queue_left();
commands_queued -= 1;
}
}

bool queue_command(const char* command, uint16_t length, uint8_t client_slot) {
if (length < MAX_COMMAND_LENGTH) {
if (commands_queued < COMMAND_QUEUE_SLOTS - 1) {
memset(command_queue[commands_queued].command, 0, MAX_COMMAND_LENGTH);
memcpy(command_queue[commands_queued].command, command, length);
command_queue[commands_queued].origin_client_slot = client_slot;
commands_queued += 1;
}
else {
return false;
}
}
else {
return false;
}

return true;
}
Loading

0 comments on commit 7d25f48

Please sign in to comment.