diff --git a/include/prototypes.h b/include/prototypes.h index 4ee26c4..0b24543 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -29,79 +29,3 @@ typedef struct { uint16_t x; uint16_t y; } Coords; - -enum SettingType { - TYPE_UINT8, - TYPE_UINT16, - TYPE_BOOL -}; - -typedef struct { - const char* name; - uint16_t* value; - SettingType type; -} Setting; - -struct /* settings */{ - uint16_t fps = 50; - - struct /* effects */ { - struct /* cycle */ { - uint16_t time = 300; - uint16_t random = 1; - } cycle ; - - struct /* matrix */ { - uint16_t length_min = 4; - uint16_t length_max = 20; - uint16_t speed_min = 1; - uint16_t speed_max = 10; - } matrix; - - struct /* confetti */ { - uint16_t pixels_per_loop = 2; - } confetti; - - struct /* dvd */ { - uint16_t width = 3; - uint16_t height = 2; - } dvd; - - struct /* dynamic */ { - uint16_t single_loop_time = 40; - uint16_t multi_loop_time = 1400; - uint16_t big_loop_time = 50; - uint16_t big_size = 3; - } dynamic; - - struct /* fire */ { - uint16_t cooldown = 192; - uint16_t spark_chance = 5; - } fire; - - struct /* firework */ { - uint16_t drag = 255; - uint16_t bounce = 200; - uint16_t gravity = 10; - uint16_t sparks = 12; - } firework; - - struct /* gol */ { - uint16_t start_percentage = 90; - uint16_t blend_speed = 10; - uint16_t restart_after_steps = 100; - } gol; - - struct /* sines */ { - uint16_t count = 5; - } sines; - - struct /* snake */ { - uint16_t direction_change = 5; - uint16_t slowdown = 2; - } snake; - } effects; -} settings; - -extern Setting all_settings[]; -extern const uint8_t all_settings_size; diff --git a/include/settings.h b/include/settings.h new file mode 100644 index 0000000..bf1b3f0 --- /dev/null +++ b/include/settings.h @@ -0,0 +1,83 @@ +#pragma once + +#include + +enum SettingType { + TYPE_UINT8, + TYPE_UINT16, + TYPE_BOOL +}; + +typedef struct { + const char* name; + uint16_t* value; + SettingType type; +} Setting; + +struct Settings { + uint16_t fps = 50; + + struct /* effects */ { + struct /* cycle */ { + uint16_t time = 300; + uint16_t random = 1; + } cycle ; + + struct /* matrix */ { + uint16_t length_min = 4; + uint16_t length_max = 20; + uint16_t speed_min = 1; + uint16_t speed_max = 10; + } matrix; + + struct /* confetti */ { + uint16_t pixels_per_loop = 2; + } confetti; + + struct /* dvd */ { + uint16_t width = 3; + uint16_t height = 2; + uint16_t speed = 50; + } dvd; + + struct /* dynamic */ { + uint16_t single_loop_time = 40; + uint16_t multi_loop_time = 1400; + uint16_t big_loop_time = 50; + uint16_t big_size = 3; + } dynamic; + + struct /* fire */ { + uint16_t cooldown = 192; + uint16_t spark_chance = 5; + } fire; + + struct /* firework */ { + uint16_t drag = 255; + uint16_t bounce = 200; + uint16_t gravity = 10; + uint16_t sparks = 12; + } firework; + + struct /* gol */ { + uint16_t start_percentage = 90; + uint16_t blend_speed = 10; + uint16_t restart_after_steps = 100; + } gol; + + struct /* sines */ { + uint16_t count = 5; + } sines; + + struct /* snake */ { + uint16_t direction_change = 5; + uint16_t slowdown = 2; + } snake; + } effects; +}; + +extern Settings settings; +extern Setting all_settings[]; +extern const uint8_t all_settings_size; + +bool change_setting(const char* key, uint16_t new_value); diff --git a/src/effects.cpp b/src/effects.cpp index 4e22258..bc3edf0 100644 --- a/src/effects.cpp +++ b/src/effects.cpp @@ -110,21 +110,6 @@ bool change_current_effect(String payload) { return true; } -const char* cycle_effects[] = { - "sinematrix3", - "single_dynamic", "multi_dynamic", "big_dynamic", - "matrix", "rainbow_matrix", "random_matrix", - "confetti", "random_confetti", - "snake", - "gol", - "twirl", - "sines", - "blur2d", - "firework", - "big_clock", - "dvd"}; -uint8_t cycle_effects_count = 17; - void setup_effects() { current_effect = new CycleEffect(); } diff --git a/src/settings.cpp b/src/settings.cpp new file mode 100644 index 0000000..fd0ca02 --- /dev/null +++ b/src/settings.cpp @@ -0,0 +1,74 @@ +#include "settings.h" +#include "config.h" + +Settings settings; + +Setting all_settings[] = { + {"fps", &settings.fps, TYPE_UINT8}, + + {"effects.confetti.pixels_per_loop", &settings.effects.confetti.pixels_per_loop, TYPE_UINT8}, + + {"effects.cycle.random", &settings.effects.cycle.random, TYPE_BOOL}, + {"effects.cycle.time", &settings.effects.cycle.time, TYPE_UINT16}, + + {"effects.dvd.width", &settings.effects.dvd.width, TYPE_UINT8}, + {"effects.dvd.height", &settings.effects.dvd.height, TYPE_UINT8}, + {"effects.dvd.speed", &settings.effects.dvd.speed, TYPE_UINT8}, + + {"effects.dynamic.single_loop_time", &settings.effects.dynamic.single_loop_time, TYPE_UINT16}, + {"effects.dynamic.multi_loop_time", &settings.effects.dynamic.multi_loop_time, TYPE_UINT16}, + {"effects.dynamic.big_loop_time", &settings.effects.dynamic.big_loop_time, TYPE_UINT16}, + {"effects.dynamic.big_size", &settings.effects.dynamic.big_size, TYPE_UINT8}, + + {"effects.fire.cooldown", &settings.effects.fire.cooldown, TYPE_UINT8}, + {"effects.fire.spark_chance", &settings.effects.fire.spark_chance, TYPE_UINT8}, + + {"effects.firework.drag", &settings.effects.firework.drag, TYPE_UINT8}, + {"effects.firework.bounce", &settings.effects.firework.bounce, TYPE_UINT8}, + {"effects.firework.gravity", &settings.effects.firework.gravity, TYPE_UINT8}, + {"effects.firework.sparks", &settings.effects.firework.sparks, TYPE_UINT8}, + + {"effects.gol.start_percentage", &settings.effects.gol.start_percentage, TYPE_UINT8}, + {"effects.gol.blend_speed", &settings.effects.gol.blend_speed, TYPE_UINT8}, + {"effects.gol.restart_after_steps", &settings.effects.gol.restart_after_steps, TYPE_UINT8}, + + {"effects.matrix.length_min", &settings.effects.matrix.length_min, TYPE_UINT8}, + {"effects.matrix.length_max", &settings.effects.matrix.length_max, TYPE_UINT8}, + {"effects.matrix.speed_min", &settings.effects.matrix.speed_min, TYPE_UINT8}, + {"effects.matrix.speed_max", &settings.effects.matrix.speed_max, TYPE_UINT8}, + + {"effects.sines.count", &settings.effects.sines.count, TYPE_UINT8}, + + {"effects.snake.direction_change", &settings.effects.snake.direction_change, TYPE_UINT8} +}; + +const uint8_t all_settings_size = 25; + +bool change_setting(const char* key, uint16_t new_value) { + LOGln("Settings * Trying to set setting %s to new value %d...", key, new_value); + Setting* s = NULL; + for (uint8_t i=0; itype == TYPE_BOOL && new_value > 1) { + LOGln("Settings * Data type of %s is boolean, but new value is > 1.", key); + return false; + } + if (s->type == TYPE_UINT8 && new_value>0xFF) { + LOGln("Settings * Data type of %s is uint8_t, but new value is > 0xFF.", key); + return false; + } + + *(s->value) = new_value; + LOGln("Settings * Success. New value for %s is %d.", key, new_value); + return true; +}