diff --git a/include/effect_big_clock.h b/include/effect_big_clock.h index c7fe495..c029c71 100644 --- a/include/effect_big_clock.h +++ b/include/effect_big_clock.h @@ -10,7 +10,7 @@ private: CRGB _color_seconds_moving_light = CRGB(0x666600); CRGB _color_seconds_moving_dark = CRGB(0x660000); - void _draw_seconds(); + void _draw_seconds(uint8_t seconds); void _draw_border_pixel(accum88 pos, CRGB* color); public: diff --git a/include/effect_clock.h b/include/effect_clock.h index 770fc40..343e951 100644 --- a/include/effect_clock.h +++ b/include/effect_clock.h @@ -10,7 +10,7 @@ protected: Window* window = new Window(0, LED_HEIGHT - 6, LED_WIDTH, 6); public: - ~ClockEffect(); + virtual ~ClockEffect(); virtual void loop(uint16_t ms); String get_name() override { return "clock"; } void loop_with_invert(bool invert); @@ -20,5 +20,6 @@ public: class NightClockEffect : public ClockEffect { public: NightClockEffect(); + ~NightClockEffect(); void loop(uint16_t ms) override; }; diff --git a/include/effect_matrix.h b/include/effect_matrix.h index 5ba9990..fbe2e53 100644 --- a/include/effect_matrix.h +++ b/include/effect_matrix.h @@ -48,6 +48,15 @@ public: RandomMatrixEffectColumn(Window* win, uint8_t dir, bool rnd=false) : MatrixEffectColumn(win, dir, rnd) {}; }; +class ColumnMatrixEffectColumn : public MatrixEffectColumn { +protected: + uint8_t _hue; + CRGB _getColor(uint8_t height) override; + void restart(bool completely_random) override; +public: + ColumnMatrixEffectColumn(Window* win, uint8_t dir, bool rnd=false) : MatrixEffectColumn(win, dir, rnd) {}; +}; + class MatrixEffectBase : public Effect { protected: MatrixEffectColumn** _columns; @@ -86,3 +95,11 @@ public: RandomMatrixEffect(); String get_name() override { return "random_matrix"; } }; + +class ColumnMatrixEffect : public MatrixEffectBase { +protected: + void _create() override; +public: + ColumnMatrixEffect(); + String get_name() override { return "column_matrix"; } +}; \ No newline at end of file diff --git a/include/fonts.h b/include/fonts.h index 2217003..d5fb4f7 100644 --- a/include/fonts.h +++ b/include/fonts.h @@ -2,6 +2,7 @@ #include "prototypes.h" extern Font font_numbers3x5; +extern Font font_numbers3x3; extern Font font_numbers3x5_blocky; extern Font font_numbers4x7; extern Font font5x7; diff --git a/include/ntp.h b/include/ntp.h index 1c4298c..24e55ea 100644 --- a/include/ntp.h +++ b/include/ntp.h @@ -1,9 +1,5 @@ #pragma once -#include -#include "my_wifi.h" #include "config.h" - -extern NTPClient ntpClient; -void updateCallback(NTPClient* c); +void time_changed(); void ntp_setup(); diff --git a/platformio.ini b/platformio.ini index 9e3355a..4504865 100644 --- a/platformio.ini +++ b/platformio.ini @@ -16,11 +16,10 @@ env_default = ota lib_deps = PubSubClient https://github.com/fabianonline/FastLED.git - https://github.com/fabianonline/NTPClient.git https://github.com/me-no-dev/ESPAsyncWebServer.git [env:ota] -upload_port = 10.10.2.80 +upload_port = 10.10.2.78 ; .78=prod, .80=dev upload_protocol = espota platform = espressif8266 board = esp07 diff --git a/src/effect_analogclock.cpp b/src/effect_analogclock.cpp index 79be914..0246132 100644 --- a/src/effect_analogclock.cpp +++ b/src/effect_analogclock.cpp @@ -1,6 +1,7 @@ #include "effect_analogclock.h" #include "my_fastled.h" #include "ntp.h" +#include void AnalogClockEffect::loop(uint16_t ms) { window->clear(); @@ -8,10 +9,18 @@ void AnalogClockEffect::loop(uint16_t ms) { CRGB red(0xFF0000); window->circle(8, 8, 7, &white); - uint8_t seconds = ntpClient.getSeconds(); - uint8_t angle = seconds * 256 / 60; - window->lineWithAngle(8, 8, angle, 10, &red); - window->line(1<<8, 1<<8, 12<<8, 4<<8, &white); + time_t now; + tm timeinfo; + time(&now); + localtime_r(&now, &timeinfo); + uint16_t seconds = timeinfo.tm_sec * 1000 + (millis()%1000); + uint16_t angle = seconds * 0x10000 / 60000; + window->lineWithAngle(8, 8, angle, 12, &red); + //window->line(0<<8, 0<<8, 7<<8, 7<<8, &white); + //window->line(15<<8, 0<<8, 8<<8, 7<<8, &red); + //window->line(0<<8, 15<<8, 7<<8, 8<<8, &blue); + //window->line(15<<8, 15<<8, 8<<8, 8<<8, &green); + /*for (uint8_t i=0; i<=12; i++) { window->lineWithAngle(8, 8, 255/12*i, 5, 2, &white); } diff --git a/src/effect_big_clock.cpp b/src/effect_big_clock.cpp index 33569d6..f6b95ef 100644 --- a/src/effect_big_clock.cpp +++ b/src/effect_big_clock.cpp @@ -1,36 +1,39 @@ #include "Effect.h" #include "effect_big_clock.h" #include "fonts.h" -#include "ntp.h" +#include #include "settings.h" void BigClockEffect::loop(uint16_t ms) { window->clear(); - uint8_t h = ntpClient.getHours(); + time_t now; + tm timeinfo; + time(&now); + localtime_r(&now, &timeinfo); + uint8_t h = timeinfo.tm_hour; window->drawChar(&font_numbers3x5_blocky, 6<<8, 2<<8, '0' + (h / 10), &_color_font); window->drawChar(&font_numbers3x5_blocky, 11<<8, 2<<8, '0' + (h % 10), &_color_font); - uint8_t m = ntpClient.getMinutes(); + uint8_t m = timeinfo.tm_min; window->drawChar(&font_numbers3x5_blocky, 6<<8, 9<<8, '0' + (m / 10), &_color_font); window->drawChar(&font_numbers3x5_blocky, 11<<8, 9<<8, '0' + (m % 10), &_color_font); - uint8_t s = ntpClient.getSeconds(); + uint8_t s = timeinfo.tm_sec; if (s & 1) { window->setPixel(3, 10, &_color_font); window->setPixel(3, 12, &_color_font); } - _draw_seconds(); + _draw_seconds(timeinfo.tm_sec); } -void BigClockEffect::_draw_seconds() { - uint8_t seconds = ntpClient.getSeconds(); +void BigClockEffect::_draw_seconds(uint8_t seconds) { for (int i=1; i<=seconds; i++) { _draw_border_pixel(i<<8, (i%5==0) ? &_color_seconds_light : &_color_seconds_dark); } - uint16_t millis = ntpClient.getEpochMillis() % 1000; - accum88 pos = (seconds<<8) + ((settings.effects.big_clock.spacing-1)<<8) * (1000 - millis) / 1000 + (1<<8); + uint16_t mil = millis() % 1000; + accum88 pos = (seconds<<8) + ((settings.effects.big_clock.spacing-1)<<8) * (1000 - mil) / 1000 + (1<<8); uint8_t sec = seconds + 1; while (pos < (60<<8)) { _draw_border_pixel(pos, sec%5==0 ? &_color_seconds_moving_light : &_color_seconds_moving_dark); diff --git a/src/effect_clock.cpp b/src/effect_clock.cpp index 2a90d1f..df441aa 100644 --- a/src/effect_clock.cpp +++ b/src/effect_clock.cpp @@ -42,18 +42,22 @@ void ClockEffect::loop(boolean invert, CRGB fg_color, CRGB bg_color, uint8_t yPo } fg_color = bg_color; } - if (ntpClient.isTimeSet()==false && (ntpClient.getSeconds() & 1)==0) { + /*if (ntpClient.isTimeSet()==false && (ntpClient.getSeconds() & 1)==0) { window->clear(&bg_color); return; - } - int h = ntpClient.getHours(); + }*/ + time_t now; + tm timeinfo; + time(&now); + localtime_r(&now, &timeinfo); + int h = timeinfo.tm_hour; //void drawChar(Font f, uint8_t x, uint8_t y, const char c, CRGB* color, bool mask=false); window->drawChar(&font_numbers3x5, 0<<8, yPos<<8, '0' + (h / 10), &fg_color, invert); window->drawChar(&font_numbers3x5, 4<<8, yPos<<8, '0' + (h % 10), &fg_color, invert); - int m = ntpClient.getMinutes(); + int m = timeinfo.tm_min; window->drawChar(&font_numbers3x5, 9<<8, yPos<<8, '0' + (m / 10), &fg_color, invert); window->drawChar(&font_numbers3x5, 13<<8, yPos<<8, '0' + (m % 10), &fg_color, invert); - if (ntpClient.getSeconds() & 1) { + if (timeinfo.tm_sec & 1) { window->setPixel(7, yPos+1, &fg_color); window->setPixel(7, yPos+3, &fg_color); } @@ -62,3 +66,7 @@ void ClockEffect::loop(boolean invert, CRGB fg_color, CRGB bg_color, uint8_t yPo ClockEffect::~ClockEffect() { delete window; } + +NightClockEffect::~NightClockEffect() { + delete window; +} \ No newline at end of file diff --git a/src/effect_lightspeed.cpp b/src/effect_lightspeed.cpp index 0b1883d..1984fe1 100644 --- a/src/effect_lightspeed.cpp +++ b/src/effect_lightspeed.cpp @@ -48,7 +48,7 @@ void LightspeedEffectStar::_init() { _distance = 0; _speed = random16(128, 2<<8); _target = random16(25<<8, 35<<8); - _saturation = random8(20); + _saturation = random8(100); } void LightspeedEffectStar::loop(Window* win) { diff --git a/src/effect_matrix.cpp b/src/effect_matrix.cpp index e602b2d..75e4976 100644 --- a/src/effect_matrix.cpp +++ b/src/effect_matrix.cpp @@ -127,6 +127,18 @@ void RandomMatrixEffectColumn::restart(bool completely_random) { _hue = random8(); } +CRGB ColumnMatrixEffectColumn::_getColor(uint8_t i) { + CRGB color; + uint8_t dist = abs(length / 2 - i); + color = CHSV(_hue, 255, 255 - dist * 5); + return color; +} + +void ColumnMatrixEffectColumn::restart(bool completely_random) { + MatrixEffectColumn::restart(completely_random); + _hue = random8(); +} + @@ -174,6 +186,15 @@ void RainbowMatrixEffect::_create() { for (int i=0; i<_count; i++) _columns[i] = new RainbowMatrixEffectColumn(window, MatrixEffectColumn::DIR_SOUTH); } +ColumnMatrixEffect::ColumnMatrixEffect() { + _init(); + _create(); +} + +void ColumnMatrixEffect::_create() { + for (int i=0; i<_count; i++) _columns[i] = new ColumnMatrixEffectColumn(window, MatrixEffectColumn::DIR_NORTH); +} + MatrixEffectBase::~MatrixEffectBase() { _delete(); } diff --git a/src/effect_pixelclock.cpp b/src/effect_pixelclock.cpp index 677c977..79aff2a 100644 --- a/src/effect_pixelclock.cpp +++ b/src/effect_pixelclock.cpp @@ -16,15 +16,20 @@ PixelClockEffect::~PixelClockEffect() { void PixelClockEffect::loop(uint16_t ms) { uint8_t x, y; // Temporary variables for calculating positions window->clear(); + time_t now; + tm timeinfo; + time(&now); + localtime_r(&now, &timeinfo); + // Seconds - uint8_t seconds = ntpClient.getSeconds(); + uint8_t seconds = timeinfo.tm_sec; for (uint8_t s=0; s<60; s++) { x = window->width - 1 - s/10; y = window->height - 1 - (s % 10); if (ssetPixel(x, y, _color_seconds); } - uint8_t minutes = ntpClient.getMinutes(); + uint8_t minutes = timeinfo.tm_min; for (uint8_t m=0; m<60; m++) { x = 6 - m/10; y = window->height - 1 - (m % 10); diff --git a/src/effect_timer.cpp b/src/effect_timer.cpp index 66eceeb..6310e0e 100644 --- a/src/effect_timer.cpp +++ b/src/effect_timer.cpp @@ -9,7 +9,8 @@ void TimerEffect::loop(uint16_t ms) { CRGB bg_color(0x000000); CRGB fg_color(0xCCCCCC); - unsigned long now = ntpClient.getEpochTime() - NTP_OFFSET; + time_t now; + time(&now); long diff = timer - now; window->clear(&bg_color); if (diff < 0 && (now & 1)==0) return; diff --git a/src/fonts.cpp b/src/fonts.cpp index 616a1e1..1868d72 100644 --- a/src/fonts.cpp +++ b/src/fonts.cpp @@ -16,6 +16,22 @@ bool font_numbers3x5_check(const char c) { return c>='0' && c<='9'; } uint16_t font_numbers3x5_get(const char c) { return c - '0'; } Font font_numbers3x5 = {3, 5, &font_numbers3x5_data[0], font_numbers3x5_check, font_numbers3x5_get}; +const uint8_t font_numbers3x3_data[] PROGMEM = { + B111, B101, B111, // 0 + B101, B111, B001, // 1 + B100, B111, B001, // 2 + B101, B111, B111, // 3 + B110, B010, B111, // 4 + B001, B111, B100, // 5 + B111, B011, B011, // 6 + B100, B100, B111, // 7 + B011, B111, B111, // 8 + B110, B110, B111, // 9 +}; +bool font_numbers3x3_check(const char c) { return c>='0' && c<='9'; } +uint16_t font_numbers3x3_get(const char c) { return c - '0'; } +Font font_numbers3x3 = {3, 3, &font_numbers3x3_data[0], font_numbers3x3_check, font_numbers3x3_get}; + const uint8_t font_numbers3x5_blocky_data[] PROGMEM = { B11111, B10001, B11111, // 0 B00000, B11111, B00000, // 1 @@ -150,12 +166,6 @@ const uint8_t font5x7_data[] PROGMEM = { 0x08, 0x08, 0x2A, 0x1C, 0x08, // -> 0x08, 0x1C, 0x2A, 0x08, 0x08, // <- }; - bool font5x7_check(const char c) { return c>=' ' && c<='}'; } - uint16_t font5x7_get(const char c) { return c - ' '; } - Font font5x7 = {5, 7, &font5x7_data[0], font5x7_check, font5x7_get}; - - - diff --git a/src/http_server.cpp b/src/http_server.cpp index d4a0958..8ff1363 100644 --- a/src/http_server.cpp +++ b/src/http_server.cpp @@ -201,9 +201,9 @@ void http_server_setup() { }); http_server.on("/effects", HTTP_GET, [&](AsyncWebServerRequest* request) { String message = F("Pitrix effects

Pitrix settings

Back to main page"); - char buffer[150]; + char buffer[500]; for (int i=0; i"), effects[i].name, effects[i].name); + snprintf_P(buffer, 500, PSTR(""), effects[i].name, effects[i].name); message += buffer; } message += F("
%s
%s
"); diff --git a/src/ntp.cpp b/src/ntp.cpp index 35e2593..b8f3271 100644 --- a/src/ntp.cpp +++ b/src/ntp.cpp @@ -1,13 +1,26 @@ -#include +#include +#include +#include +#include #include "my_fastled.h" -void updateCallback(NTPClient* c) { +/*void updateCallback(NTPClient* c) { random16_add_entropy(c->getEpochMillis() & 0xFFFF); -} + LOGln("Received current time. Epoch is %lu.", ntpClient.getEpochTime()); +}*/ -WiFiUDP ntpUDP; -NTPClient ntpClient(ntpUDP, NTP_SERVER, NTP_OFFSET, NTP_INTERVAL); +void time_changed() { + random16_add_entropy(millis() & 0xFFFF); + time_t now; + tm timeinfo; + time(&now); + localtime_r(&now, &timeinfo); + char time_s[30]; + strftime(time_s, 30, "%a %d.%m.%Y %T", &timeinfo); + LOGln("NTP * Received time: %s", time_s); +} void ntp_setup() { - ntpClient.setUpdateCallback(updateCallback); + settimeofday_cb(time_changed); + configTime(TZ_Europe_Berlin, "de.pool.ntp.org"); } diff --git a/src/pitrix.cpp b/src/pitrix.cpp index f1b778a..fd4e1e0 100644 --- a/src/pitrix.cpp +++ b/src/pitrix.cpp @@ -45,7 +45,6 @@ void setup() { ntp_setup(); ota_setup(); fastled_setup(); - ntpClient.begin(); #ifdef HTTP_SERVER_ENABLE http_server_setup(); #endif @@ -76,7 +75,6 @@ void loop() { return; } - ntpClient.update(); #ifdef MQTT_ENABLE mqtt_loop(); #endif