diff --git a/include/effect_matrix.h b/include/effect_matrix.h index 9105525..8b75c30 100644 --- a/include/effect_matrix.h +++ b/include/effect_matrix.h @@ -9,7 +9,7 @@ class MatrixEffectColumn { protected: Window* window; - accum88 x, y; + saccum78 x, y; uint8_t length = 1; uint8_t _direction = 2; bool _random_direction = false; diff --git a/include/effect_tv_static.h b/include/effect_tv_static.h new file mode 100644 index 0000000..eff81e9 --- /dev/null +++ b/include/effect_tv_static.h @@ -0,0 +1,12 @@ +#pragma once +#include "Effect.h" + +class TvStaticEffect : public Effect { +private: + Window* _window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6); +public: + ~TvStaticEffect(); + void loop(uint16_t ms) override; + bool can_be_shown_with_clock() override; + String get_name() override { return "tv_static"; } +}; diff --git a/include/settings.h b/include/settings.h index e2e4c64..1bfdf46 100644 --- a/include/settings.h +++ b/include/settings.h @@ -22,57 +22,61 @@ struct Settings { 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; + uint16_t speed_min = 3; + uint16_t speed_max = 7; } 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; + + struct /* tv_static */ { + uint16_t black_bar_speed = 3500; + } tv_static; } effects; }; diff --git a/platformio.ini b/platformio.ini index cf3a20a..ed69f8b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -21,7 +21,7 @@ lib_deps = ESPAsyncTCP [env:ota] -upload_port = 10.10.2.78 +upload_port = 10.10.2.80 upload_protocol = espota platform = espressif8266 board = esp07 diff --git a/src/effect_big_clock.cpp b/src/effect_big_clock.cpp index 854cb36..dc5e9b6 100644 --- a/src/effect_big_clock.cpp +++ b/src/effect_big_clock.cpp @@ -27,17 +27,10 @@ void BigClockEffect::_draw_seconds() { for (int i=1; i<=seconds; i++) { _draw_border_pixel(i, 0, (i%5==0) ? &_color_seconds_light : &_color_seconds_dark); } - + uint16_t millis = ntpClient.getEpochMillis() % 1000; - /* - // Enable this to have the next pixel move smoothly to its position - if (millis > 0) { - uint8_t part = 60 - ((60 - seconds) * millis / 1000); - _draw_border_pixel(part, &_color_seconds); - } - */ - uint8_t offset = 5 - ((millis % 1000) / 200); - uint8_t part = scale8(millis % 200, 200); + uint8_t offset = 5 - (millis / 200); + uint8_t part = 255 - ((millis % 200) * 256 / 200); uint8_t number_to_show = (60 - seconds - offset) / 5 + 1; for(uint8_t i = 0; isetPixel(x, y, color);*/ accum88 x, y; if (i<=8) { x = ((7+i)<<8) + part; diff --git a/src/effect_matrix.cpp b/src/effect_matrix.cpp index 33f8ff4..476f8f5 100644 --- a/src/effect_matrix.cpp +++ b/src/effect_matrix.cpp @@ -47,7 +47,7 @@ void MatrixEffectColumn::advance(uint16_t ms) { switch(_direction) { case DIR_NORTH: y-=speed * ms; - if ((y>>8) > window->height && (y>>8) + length > window->height) running=false; + if ((y>>8) + length < 0) running=false; break; case DIR_EAST: x+=speed * ms; @@ -59,7 +59,7 @@ void MatrixEffectColumn::advance(uint16_t ms) { break; case DIR_WEST: x-=speed * ms; - if ((x>>8) > window->width && (y>>8) + length > window->width) running=false; + if ((x>>8) + length < 0) running=false; break; } } diff --git a/src/effect_tv_static.cpp b/src/effect_tv_static.cpp new file mode 100644 index 0000000..f0bd56c --- /dev/null +++ b/src/effect_tv_static.cpp @@ -0,0 +1,27 @@ +#include "effect_tv_static.h" + +void TvStaticEffect::loop(uint16_t ms) { + uint8_t dark_position = (millis() % settings.effects.tv_static.black_bar_speed) * _window->width / settings.effects.tv_static.black_bar_speed; + for (uint8_t y=0; y<_window->height; y++) { + uint8_t row_dark_position = (dark_position + y/3) % _window->width; + for (uint8_t x=0; x<_window->width; x++) { + uint8_t brightness = random8(); + uint8_t darkening = 0; + uint8_t distance = x - row_dark_position; + if (distance == 0) darkening = random8(192, 255); + else if (distance == 1) darkening = random8(128, 255); + else if (distance == 2) darkening = random8(92, 192); + else if (distance == 3) darkening = random8(32, 128); + if (darkening > brightness) brightness = 0; + else brightness -= darkening; + CRGB color(brightness, brightness, brightness); + _window->setPixel(x, y, &color); + } + } +} + +bool TvStaticEffect::can_be_shown_with_clock() { return true; } + +TvStaticEffect::~TvStaticEffect() { + delete _window; +} diff --git a/src/effects.cpp b/src/effects.cpp index bc3edf0..45b22d9 100644 --- a/src/effects.cpp +++ b/src/effects.cpp @@ -22,6 +22,7 @@ #include "effect_sines.h" #include "effect_marquee.h" #include "effect_blur2d.h" +#include "effect_tv_static.h" Effect* current_effect; @@ -52,9 +53,10 @@ const EffectEntry effects[] = { /* 21 */ {"sines", true, [](){ return new SinesEffect(); }}, /* 22 */ {"blur2d", true, [](){ return new Blur2DEffect(); }}, /* 23 */ {"marquee", 0, [](){ return new MarqueeEffect(); }}, - /* 24 */ {"night_clock", false, [](){ return new NightClockEffect(); }} + /* 24 */ {"night_clock", false, [](){ return new NightClockEffect(); }}, + /* 25 */ {"tv_static", false, [](){ return new TvStaticEffect(); }}, }; -const uint8_t effects_size = 25; +const uint8_t effects_size = 26; Effect* select_effect(const char* name) { diff --git a/src/http_server.cpp b/src/http_server.cpp index 20c90ab..e48fbd2 100644 --- a/src/http_server.cpp +++ b/src/http_server.cpp @@ -18,9 +18,9 @@ File upload_file; void http_server_handle_file_upload() { if (http_server.uri() != "/upload") return; - + HTTPUpload upload = http_server.upload(); - + if (upload.status == UPLOAD_FILE_START) { String filename = upload.filename; if (!filename.startsWith("/")) filename = "/" + filename; @@ -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

Settings

Known animations:

"; + String message = "Pitrix

Pitrix

Settings

Effect

Known animations:

"; if (!SPIFFS.begin()) { message += "No SPIFFS file system found."; } else { @@ -116,7 +116,7 @@ void http_server_setup() { } String name = http_server.arg("key"); uint16_t value = http_server.arg("value").toInt(); - + if (change_setting(name.c_str(), value)) { if (http_server.hasArg("redir")) { http_server.sendHeader("Location", "/settings"); @@ -150,6 +150,16 @@ void http_server_setup() { } http_server.send(500, "text/plain", "Could not read settings."); }); + http_server.on("/effects", HTTP_GET, [&]() { + String message = "Pitrix effects

Pitrix settings

Back to main page"; + for (int i=0; itype == TYPE_BOOL && new_value > 1) { LOGln("Settings * Data type of %s is boolean, but new value is > 1.", key); @@ -68,7 +70,7 @@ bool change_setting(const char* key, uint16_t new_value) { LOGln("Settings * Data type of %s is uint8_t, but new value is > 0xFF.", key); return false; } - + *(s->value) = new_value; return true; }