Settings are now properly global and can be changed.
This commit is contained in:
parent
2b50691067
commit
0f1d4abe04
@ -29,79 +29,3 @@ typedef struct {
|
|||||||
uint16_t x;
|
uint16_t x;
|
||||||
uint16_t y;
|
uint16_t y;
|
||||||
} Coords;
|
} 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;
|
|
||||||
|
83
include/settings.h
Normal file
83
include/settings.h
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
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);
|
@ -110,21 +110,6 @@ bool change_current_effect(String payload) {
|
|||||||
return true;
|
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() {
|
void setup_effects() {
|
||||||
current_effect = new CycleEffect();
|
current_effect = new CycleEffect();
|
||||||
}
|
}
|
||||||
|
74
src/settings.cpp
Normal file
74
src/settings.cpp
Normal file
@ -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; i<all_settings_size; i++) {
|
||||||
|
if (strcmp(key, all_settings[i].name)==0) {
|
||||||
|
s = &all_settings[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (s==NULL) {
|
||||||
|
LOGln("Settings * No setting matching the name %s found.", key);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check data size
|
||||||
|
if (s->type == 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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user