diff --git a/include/config.sample.h b/include/config.sample.h index 2e096da..1faa716 100644 --- a/include/config.sample.h +++ b/include/config.sample.h @@ -3,6 +3,7 @@ #include #define FASTLED_INTERNAL #include +#include "prototypes.h" //#define DEBUG // Uncomment this to enable Debug messages via Serial and, if enabled, MQTT. //#define CONFIG_USABLE // Uncomment this by removing the // at the beginning! @@ -49,39 +50,35 @@ #define MONITOR_LOOP_TIME_THRESHOLD 500 #define MONITOR_LOOP_TIME_COUNT_MAX 10 -#define EFFECT_CYCLE_TIME 300 // Time in seconds between cycling effects. -#define EFFECT_CYCLE_RANDOM true +// settings.effects.cycle.time = 300; // Time in seconds between cycling effects. +// settings.effects.cycle.random = true; -#define EFFECT_MATRIX_LENGTH_MIN 4 -#define EFFECT_MATRIX_LENGTH_MAX 20 -#define EFFECT_MATRIX_SPEED_MIN 50 -#define EFFECT_MATRIX_SPEED_MAX 135 +// settings.effects.matrix.length_min = 4; +// settings.effects.matrix.length_max = 20; +// settings.effects.matrix.speed_min = 1; +// settings.effects.matrix.speed_max = 10; -#define EFFECT_SINGLE_DYNAMIC_LOOP_TIME 40 -#define EFFECT_MULTI_DYNAMIC_LOOP_TIME 1400 -#define EFFECT_BIG_DYNAMIC_LOOP_TIME 50 -#define EFFECT_BIG_DYNAMIC_SIZE 3 +// .dynamic.single_loop_time = 40; +// .dynamic.multi_loop_time = 1400; +// .dynamic.big_loop_time = 50; +// .dynamic.big_size = 3; -#define EFFECT_CONFETTI_PIXELS_PER_LOOP 2 +// .fire.cooldown = 192; +// .fire.spark_chance = 5; -#define EFFECT_SNAKE_DIRECTION_CHANGE 10 -#define EFFECT_SNAKE_SLOWDOWN 2 +// .firework.drag = 255; +// .firework.bounce = 200; +// .firework.gravity = 10; +// .firework.sparks = 12; -#define EFFECT_FIRE_COOLDOWN 192 -#define EFFECT_FIRE_SPARK_CHANCE 5 +// .gol.start_percentage = 90; +// .gol.blend_speed = 10; +// .gol.restart_after_steps = 100; -#define EFFECT_FIREWORK_SHOT_CHANCE 200 -#define EFFECT_FIREWORK_BLUR 200 -#define EFFECT_FIREWORK_FADEOUT_SPEED 5 +// .sines.count = 5; -#define EFFECT_GOL_START_PERCENTAGE 90 -#define EFFECT_GOL_BLEND_SPEED 10 -#define EFFECT_GOL_RESTART_AFTER_STEPS 100 - -#define EFFECT_DVD_WIDTH 3 -#define EFFECT_DVD_HEIGHT 2 - -#define EFFECT_SINES_COUNT 5 +// .snake.direction_change = 5; +// .snake.slowdown = 2; // Stop editing here diff --git a/include/effect_firework.h b/include/effect_firework.h index b7ee0a5..4f1b53d 100644 --- a/include/effect_firework.h +++ b/include/effect_firework.h @@ -6,11 +6,6 @@ enum FireworkDotType { FIREWORK_DOT_NONE, FIREWORK_DOT_SHELL, FIREWORK_DOT_SPARK }; -#define EFFECT_FIREWORK_DRAG 255 -#define EFFECT_FIREWORK_BOUNCE 200 -#define EFFECT_FIREWORK_GRAVITY 10 -#define EFFECT_FIREWORK_SPARKS 12 - class FireworkEffect; class FireworkEffectDot { @@ -49,7 +44,7 @@ private: CRGB _burst_color; FireworkEffectDot* _dot; - FireworkEffectDot* _sparks[EFFECT_FIREWORK_SPARKS]; + FireworkEffectDot** _sparks; public: FireworkEffect(); ~FireworkEffect(); diff --git a/include/effect_sines.h b/include/effect_sines.h index b6407c9..d1684d0 100644 --- a/include/effect_sines.h +++ b/include/effect_sines.h @@ -20,7 +20,7 @@ public: class SinesEffect : public Effect { private: - SinesEffectSinus* _sinus[EFFECT_SINES_COUNT]; + SinesEffectSinus** _sinus; uint8_t _step = 0; public: SinesEffect(); diff --git a/include/prototypes.h b/include/prototypes.h index 6318c5d..4ee26c4 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -2,6 +2,9 @@ #include +extern uint8_t baseHue; +extern char hostname[30]; + typedef struct { uint8_t width; uint8_t height; @@ -27,5 +30,78 @@ typedef struct { uint16_t y; } Coords; -extern uint8_t baseHue; -extern char hostname[30]; +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/src/effect_confetti.cpp b/src/effect_confetti.cpp index e83dba4..3caccf6 100644 --- a/src/effect_confetti.cpp +++ b/src/effect_confetti.cpp @@ -5,7 +5,7 @@ void ConfettiEffect::loop(uint16_t ms) { window->fadeToBlackBy(3); - for (int i=0; iaddPixelColor(random16(LED_COUNT), &color); } diff --git a/src/effect_cycle.cpp b/src/effect_cycle.cpp index 26480f1..24811f1 100644 --- a/src/effect_cycle.cpp +++ b/src/effect_cycle.cpp @@ -11,8 +11,8 @@ CycleEffect::~CycleEffect() { } void CycleEffect::changeEffect() { - int new_id; - if (EFFECT_CYCLE_RANDOM) { + uint8_t new_id; + if (settings.effects.cycle.random && _effects_count>1) { do { new_id = random8(cycle_effects_count); } while (new_id == effect_id); diff --git a/src/effect_dvd.cpp b/src/effect_dvd.cpp index 5f23079..5239661 100644 --- a/src/effect_dvd.cpp +++ b/src/effect_dvd.cpp @@ -7,11 +7,11 @@ void DvdEffect::loop(uint16_t ms) { _x += _x_dir; _y += _y_dir; - if (_x == 0 || _x + EFFECT_DVD_WIDTH >= window->width) { + if (_x == 0 || _x + settings.effects.dvd.width >= window->width) { _x_dir = -_x_dir; dir_changed = true; } - if (_y == 0 || _y + EFFECT_DVD_HEIGHT >= window->height) { + if (_y == 0 || _y + settings.effects.dvd.height >= window->height) { _y_dir = -_y_dir; dir_changed = true; } @@ -19,7 +19,7 @@ void DvdEffect::loop(uint16_t ms) { window->clear(); - for (int x=0; xsetPixel(_x + x, _y + y, (CRGB*)&_color); } diff --git a/src/effect_dynamic.cpp b/src/effect_dynamic.cpp index ed02044..21c2d48 100644 --- a/src/effect_dynamic.cpp +++ b/src/effect_dynamic.cpp @@ -11,7 +11,7 @@ void SingleDynamicEffect::init() { } void SingleDynamicEffect::loop(uint16_t ms) { - EVERY_N_MILLISECONDS( EFFECT_SINGLE_DYNAMIC_LOOP_TIME ) { + EVERY_N_MILLISECONDS( settings.effects.dynamic.single_loop_time ) { tiles[random8(tile_count)] = CHSV(baseHue + random8(64), 180, 255); } this->draw(); @@ -29,7 +29,7 @@ boolean SingleDynamicEffect::can_be_shown_with_clock() { } void MultiDynamicEffect::loop(uint16_t ms) { - EVERY_N_MILLISECONDS( EFFECT_MULTI_DYNAMIC_LOOP_TIME ) { + EVERY_N_MILLISECONDS( settings.effects.dynamic.multi_loop_time ) { for (int i=0; idraw(); @@ -40,23 +40,15 @@ BigDynamicEffect::~BigDynamicEffect() { } void BigDynamicEffect::loop(uint16_t ms) { - EVERY_N_MILLISECONDS( EFFECT_BIG_DYNAMIC_LOOP_TIME ) { - uint8_t x = random8(0, window->width - EFFECT_BIG_DYNAMIC_SIZE + 1); - uint8_t y = random8(0, window->height - EFFECT_BIG_DYNAMIC_SIZE + 1); + EVERY_N_MILLISECONDS( settings.effects.dynamic.big_loop_time ) { + uint8_t x = random8(0, window->width - settings.effects.dynamic.big_size + 1); + uint8_t y = random8(0, window->height - settings.effects.dynamic.big_size + 1); CRGB color = CHSV(random8(), 255, 255); CRGB black(0x000000); - for (uint8_t ix=0; ixsetPixel(x+ix, y+iy, &color); } - /*for (uint8_t ix=0; ixsetPixel(x-1+ix, y-1, &black); - window->setPixel(x-1+ix, y+EFFECT_BIG_DYNAMIC_SIZE+1, &black); - } - for (uint8_t iy=0; iysetPixel(x-1, y-1+iy, &black); - window->setPixel(x+EFFECT_BIG_DYNAMIC_SIZE+1, y-1+iy, &black); - }*/ } } diff --git a/src/effect_fire.cpp b/src/effect_fire.cpp index 3db457b..0cf53e6 100644 --- a/src/effect_fire.cpp +++ b/src/effect_fire.cpp @@ -22,11 +22,11 @@ void FireEffect::loop(uint16_t ms) { } void FireEffect::cooldown() { - for(int i=0; i<(this->window->width * this->window->height); i++) this->data[i] = scale8(this->data[i], EFFECT_FIRE_COOLDOWN); // 240 or something + for(int i=0; i<(this->window->width * this->window->height); i++) this->data[i] = scale8(this->data[i], settings.effects.fire.cooldown); } void FireEffect::spark() { - for(int x=0; xwindow->width; x++) if (random8(EFFECT_FIRE_SPARK_CHANCE)==0) this->data[x] = this->spark_temp(); + for(int x=0; xwindow->width; x++) if (random8(settings.effects.fire.spark_chance)==0) this->data[x] = this->spark_temp(); } inline uint8_t FireEffect::spark_temp() { diff --git a/src/effect_firework.cpp b/src/effect_firework.cpp index 31c9e77..0810db6 100644 --- a/src/effect_firework.cpp +++ b/src/effect_firework.cpp @@ -56,13 +56,13 @@ void FireworkEffectDot::draw() { void FireworkEffectDot::move() { if (!show) return; - _yv -= EFFECT_FIREWORK_GRAVITY; - _xv = _scale15by8_local(_xv, EFFECT_FIREWORK_DRAG); - _yv = _scale15by8_local(_yv, EFFECT_FIREWORK_DRAG); + _yv -= settings.effects.firework.gravity; + _xv = _scale15by8_local(_xv, settings.effects.firework.drag); + _yv = _scale15by8_local(_yv, settings.effects.firework.drag); if (type == FIREWORK_DOT_SPARK) { - _xv = _scale15by8_local(_xv, EFFECT_FIREWORK_DRAG); - _yv = _scale15by8_local(_yv, EFFECT_FIREWORK_DRAG); + _xv = _scale15by8_local(_xv, settings.effects.firework.drag); + _yv = _scale15by8_local(_yv, settings.effects.firework.drag); _color.nscale8(255); if (!_color) { show = 0; @@ -75,7 +75,7 @@ void FireworkEffectDot::move() { show = 0; } else { _yv = -_yv; - _yv = _scale15by8_local(_yv, EFFECT_FIREWORK_BOUNCE); + _yv = _scale15by8_local(_yv, settings.effects.firework.bounce); if (_yv < 500) { show = 0; } @@ -143,7 +143,7 @@ void FireworkEffect::loop(uint16_t ms) { window->clear(); _dot->move(); _dot->draw(); - for (int i=0; imove(); _sparks[i]->draw(); } @@ -159,7 +159,7 @@ void FireworkEffect::loop(uint16_t ms) { } if (_skyburst) { - int nsparks = random8(EFFECT_FIREWORK_SPARKS / 2, EFFECT_FIREWORK_SPARKS + 1); + int nsparks = random8(settings.effects.firework.sparks / 2, settings.effects.firework.sparks + 1); for (int i=0; isky_burst(_burst_x, _burst_y, _burst_yv, _burst_color); _skyburst = 0; @@ -169,14 +169,15 @@ void FireworkEffect::loop(uint16_t ms) { FireworkEffect::FireworkEffect() { _dot = new FireworkEffectDot(window, this); - for (int i=0; iwindow->count; i++) { - _data[i] = random8() < EFFECT_GOL_START_PERCENTAGE ? 1 : 0; + _data[i] = random8() < settings.effects.gol.start_percentage ? 1 : 0; } _old_hue = _hue; _hue = random8(); @@ -30,11 +30,11 @@ GolEffect::~GolEffect() { } void GolEffect::loop(uint16_t ms) { - if (EFFECT_GOL_BLEND_SPEED + _blend > 255) { + if (settings.effects.gol.blend_speed + _blend > 255) { _blend = 0; _advance(); } else { - _blend += EFFECT_GOL_BLEND_SPEED; + _blend += settings.effects.gol.blend_speed; } _draw(); @@ -43,7 +43,7 @@ void GolEffect::loop(uint16_t ms) { void GolEffect::_advance() { _step++; _old_hue = _hue; - if (_step >= EFFECT_GOL_RESTART_AFTER_STEPS) { + if (_step >= settings.effects.gol.restart_after_steps) { _initialize(); } else { for(uint16_t i=0; iwindow->count; i++) { diff --git a/src/effect_matrix.cpp b/src/effect_matrix.cpp index 28ae6e3..f12b158 100644 --- a/src/effect_matrix.cpp +++ b/src/effect_matrix.cpp @@ -38,9 +38,9 @@ void MatrixEffectColumn::restart(bool completely_random) { } } - length = random8(EFFECT_MATRIX_LENGTH_MIN, EFFECT_MATRIX_LENGTH_MAX); + length = random8(settings.effects.matrix.length_min, settings.effects.matrix.length_max); running = true; - speed = random8(EFFECT_MATRIX_SPEED_MIN, EFFECT_MATRIX_SPEED_MAX); + speed = random8(settings.effects.matrix.speed_min, settings.effects.matrix.speed_max); } void MatrixEffectColumn::advance(uint16_t ms) { diff --git a/src/effect_sines.cpp b/src/effect_sines.cpp index cebe57f..6a4255a 100644 --- a/src/effect_sines.cpp +++ b/src/effect_sines.cpp @@ -25,13 +25,14 @@ void SinesEffectSinus::loop(uint16_t ms) { } SinesEffect::SinesEffect() { - for (int i=0; ishift_down_and_blur(); - for (int i=0; iloop(ms); } } diff --git a/src/effect_snake.cpp b/src/effect_snake.cpp index 1007d3e..cf03fac 100644 --- a/src/effect_snake.cpp +++ b/src/effect_snake.cpp @@ -11,8 +11,8 @@ SnakeEffect::~SnakeEffect() { } void SnakeEffect::loop(uint16_t ms) { - if (run++ % EFFECT_SNAKE_SLOWDOWN == 0) { // Change the coordinates only on every n-th run. - if (random8(EFFECT_SNAKE_DIRECTION_CHANGE)==0 || is_turn_needed()) turn_random(); + if (run++ % settings.effects.snake.slowdown == 0) { // Change the coordinates only on every n-th run. + if (random8(settings.effects.snake.direction_change)==0 || is_turn_needed()) turn_random(); this->coords = update_position(this->coords, this->direction); } diff --git a/src/effects.cpp b/src/effects.cpp index b245af5..b0174b8 100644 --- a/src/effects.cpp +++ b/src/effects.cpp @@ -1,4 +1,5 @@ #include "effects.h" +#include "config.h" #include "my_fastled.h" #include #include "effect_bell.h" diff --git a/src/http_server.cpp b/src/http_server.cpp index 786cfee..49dd6b2 100644 --- a/src/http_server.cpp +++ b/src/http_server.cpp @@ -42,7 +42,7 @@ void http_server_setup() { PGM_P text_plain = PSTR("text/plain"); http_server.on("/", HTTP_GET, [&](){ LOGln("HTTP * GET /"); - String message = "Pitrix

Pitrix

Known animations:

"; + String message = "Pitrix

Pitrix

Settings

Known animations:

"; if (!SPIFFS.begin()) { message += "No SPIFFS file system found."; } else { @@ -57,6 +57,18 @@ void http_server_setup() { message += ""; http_server.send(200, "text/html", message); }); + http_server.on("/settings", HTTP_GET, [&]() { + String message = "Pitrix settings

Pitrix settings

Back to main page"; + for (int i=0; i