75 lines
2.9 KiB
C++
75 lines
2.9 KiB
C++
#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;
|
|
}
|