This commit is contained in:
Fabian Schlenz 2020-04-29 09:28:22 +02:00
commit 402d7f5d75
17 changed files with 129 additions and 47 deletions

View File

@ -10,7 +10,7 @@ private:
CRGB _color_seconds_moving_light = CRGB(0x666600); CRGB _color_seconds_moving_light = CRGB(0x666600);
CRGB _color_seconds_moving_dark = CRGB(0x660000); CRGB _color_seconds_moving_dark = CRGB(0x660000);
void _draw_seconds(); void _draw_seconds(uint8_t seconds);
void _draw_border_pixel(accum88 pos, CRGB* color); void _draw_border_pixel(accum88 pos, CRGB* color);
public: public:

View File

@ -10,7 +10,7 @@ protected:
Window* window = new Window(0, LED_HEIGHT - 6, LED_WIDTH, 6); Window* window = new Window(0, LED_HEIGHT - 6, LED_WIDTH, 6);
public: public:
~ClockEffect(); virtual ~ClockEffect();
virtual void loop(uint16_t ms); virtual void loop(uint16_t ms);
String get_name() override { return "clock"; } String get_name() override { return "clock"; }
void loop_with_invert(bool invert); void loop_with_invert(bool invert);
@ -20,5 +20,6 @@ public:
class NightClockEffect : public ClockEffect { class NightClockEffect : public ClockEffect {
public: public:
NightClockEffect(); NightClockEffect();
~NightClockEffect();
void loop(uint16_t ms) override; void loop(uint16_t ms) override;
}; };

View File

@ -48,6 +48,15 @@ public:
RandomMatrixEffectColumn(Window* win, uint8_t dir, bool rnd=false) : MatrixEffectColumn(win, dir, rnd) {}; 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 { class MatrixEffectBase : public Effect {
protected: protected:
MatrixEffectColumn** _columns; MatrixEffectColumn** _columns;
@ -86,3 +95,11 @@ public:
RandomMatrixEffect(); RandomMatrixEffect();
String get_name() override { return "random_matrix"; } String get_name() override { return "random_matrix"; }
}; };
class ColumnMatrixEffect : public MatrixEffectBase {
protected:
void _create() override;
public:
ColumnMatrixEffect();
String get_name() override { return "column_matrix"; }
};

View File

@ -2,6 +2,7 @@
#include "prototypes.h" #include "prototypes.h"
extern Font font_numbers3x5; extern Font font_numbers3x5;
extern Font font_numbers3x3;
extern Font font_numbers3x5_blocky; extern Font font_numbers3x5_blocky;
extern Font font_numbers4x7; extern Font font_numbers4x7;
extern Font font5x7; extern Font font5x7;

View File

@ -1,9 +1,5 @@
#pragma once #pragma once
#include <NTPClient.h>
#include "my_wifi.h"
#include "config.h" #include "config.h"
void time_changed();
extern NTPClient ntpClient;
void updateCallback(NTPClient* c);
void ntp_setup(); void ntp_setup();

View File

@ -16,11 +16,10 @@ env_default = ota
lib_deps = lib_deps =
PubSubClient PubSubClient
https://github.com/fabianonline/FastLED.git https://github.com/fabianonline/FastLED.git
https://github.com/fabianonline/NTPClient.git
https://github.com/me-no-dev/ESPAsyncWebServer.git https://github.com/me-no-dev/ESPAsyncWebServer.git
[env:ota] [env:ota]
upload_port = 10.10.2.80 upload_port = 10.10.2.78 ; .78=prod, .80=dev
upload_protocol = espota upload_protocol = espota
platform = espressif8266 platform = espressif8266
board = esp07 board = esp07

View File

@ -1,6 +1,7 @@
#include "effect_analogclock.h" #include "effect_analogclock.h"
#include "my_fastled.h" #include "my_fastled.h"
#include "ntp.h" #include "ntp.h"
#include <time.h>
void AnalogClockEffect::loop(uint16_t ms) { void AnalogClockEffect::loop(uint16_t ms) {
window->clear(); window->clear();
@ -8,10 +9,18 @@ void AnalogClockEffect::loop(uint16_t ms) {
CRGB red(0xFF0000); CRGB red(0xFF0000);
window->circle(8, 8, 7, &white); window->circle(8, 8, 7, &white);
uint8_t seconds = ntpClient.getSeconds(); time_t now;
uint8_t angle = seconds * 256 / 60; tm timeinfo;
window->lineWithAngle(8, 8, angle, 10, &red); time(&now);
window->line(1<<8, 1<<8, 12<<8, 4<<8, &white); 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++) { /*for (uint8_t i=0; i<=12; i++) {
window->lineWithAngle(8, 8, 255/12*i, 5, 2, &white); window->lineWithAngle(8, 8, 255/12*i, 5, 2, &white);
} }

View File

@ -1,36 +1,39 @@
#include "Effect.h" #include "Effect.h"
#include "effect_big_clock.h" #include "effect_big_clock.h"
#include "fonts.h" #include "fonts.h"
#include "ntp.h" #include <time.h>
#include "settings.h" #include "settings.h"
void BigClockEffect::loop(uint16_t ms) { void BigClockEffect::loop(uint16_t ms) {
window->clear(); 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, 6<<8, 2<<8, '0' + (h / 10), &_color_font);
window->drawChar(&font_numbers3x5_blocky, 11<<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, 6<<8, 9<<8, '0' + (m / 10), &_color_font);
window->drawChar(&font_numbers3x5_blocky, 11<<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) { if (s & 1) {
window->setPixel(3, 10, &_color_font); window->setPixel(3, 10, &_color_font);
window->setPixel(3, 12, &_color_font); window->setPixel(3, 12, &_color_font);
} }
_draw_seconds(); _draw_seconds(timeinfo.tm_sec);
} }
void BigClockEffect::_draw_seconds() { void BigClockEffect::_draw_seconds(uint8_t seconds) {
uint8_t seconds = ntpClient.getSeconds();
for (int i=1; i<=seconds; i++) { for (int i=1; i<=seconds; i++) {
_draw_border_pixel(i<<8, (i%5==0) ? &_color_seconds_light : &_color_seconds_dark); _draw_border_pixel(i<<8, (i%5==0) ? &_color_seconds_light : &_color_seconds_dark);
} }
uint16_t millis = ntpClient.getEpochMillis() % 1000; uint16_t mil = millis() % 1000;
accum88 pos = (seconds<<8) + ((settings.effects.big_clock.spacing-1)<<8) * (1000 - millis) / 1000 + (1<<8); accum88 pos = (seconds<<8) + ((settings.effects.big_clock.spacing-1)<<8) * (1000 - mil) / 1000 + (1<<8);
uint8_t sec = seconds + 1; uint8_t sec = seconds + 1;
while (pos < (60<<8)) { while (pos < (60<<8)) {
_draw_border_pixel(pos, sec%5==0 ? &_color_seconds_moving_light : &_color_seconds_moving_dark); _draw_border_pixel(pos, sec%5==0 ? &_color_seconds_moving_light : &_color_seconds_moving_dark);

View File

@ -42,18 +42,22 @@ void ClockEffect::loop(boolean invert, CRGB fg_color, CRGB bg_color, uint8_t yPo
} }
fg_color = bg_color; fg_color = bg_color;
} }
if (ntpClient.isTimeSet()==false && (ntpClient.getSeconds() & 1)==0) { /*if (ntpClient.isTimeSet()==false && (ntpClient.getSeconds() & 1)==0) {
window->clear(&bg_color); window->clear(&bg_color);
return; 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); //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, 0<<8, yPos<<8, '0' + (h / 10), &fg_color, invert);
window->drawChar(&font_numbers3x5, 4<<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, 9<<8, yPos<<8, '0' + (m / 10), &fg_color, invert);
window->drawChar(&font_numbers3x5, 13<<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+1, &fg_color);
window->setPixel(7, yPos+3, &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() { ClockEffect::~ClockEffect() {
delete window; delete window;
} }
NightClockEffect::~NightClockEffect() {
delete window;
}

View File

@ -48,7 +48,7 @@ void LightspeedEffectStar::_init() {
_distance = 0; _distance = 0;
_speed = random16(128, 2<<8); _speed = random16(128, 2<<8);
_target = random16(25<<8, 35<<8); _target = random16(25<<8, 35<<8);
_saturation = random8(20); _saturation = random8(100);
} }
void LightspeedEffectStar::loop(Window* win) { void LightspeedEffectStar::loop(Window* win) {

View File

@ -127,6 +127,18 @@ void RandomMatrixEffectColumn::restart(bool completely_random) {
_hue = random8(); _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); 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() { MatrixEffectBase::~MatrixEffectBase() {
_delete(); _delete();
} }

View File

@ -16,15 +16,20 @@ PixelClockEffect::~PixelClockEffect() {
void PixelClockEffect::loop(uint16_t ms) { void PixelClockEffect::loop(uint16_t ms) {
uint8_t x, y; // Temporary variables for calculating positions uint8_t x, y; // Temporary variables for calculating positions
window->clear(); window->clear();
time_t now;
tm timeinfo;
time(&now);
localtime_r(&now, &timeinfo);
// Seconds // Seconds
uint8_t seconds = ntpClient.getSeconds(); uint8_t seconds = timeinfo.tm_sec;
for (uint8_t s=0; s<60; s++) { for (uint8_t s=0; s<60; s++) {
x = window->width - 1 - s/10; x = window->width - 1 - s/10;
y = window->height - 1 - (s % 10); y = window->height - 1 - (s % 10);
if (s<seconds) window->setPixel(x, y, _color_seconds); if (s<seconds) window->setPixel(x, y, _color_seconds);
} }
uint8_t minutes = ntpClient.getMinutes(); uint8_t minutes = timeinfo.tm_min;
for (uint8_t m=0; m<60; m++) { for (uint8_t m=0; m<60; m++) {
x = 6 - m/10; x = 6 - m/10;
y = window->height - 1 - (m % 10); y = window->height - 1 - (m % 10);

View File

@ -9,7 +9,8 @@ void TimerEffect::loop(uint16_t ms) {
CRGB bg_color(0x000000); CRGB bg_color(0x000000);
CRGB fg_color(0xCCCCCC); CRGB fg_color(0xCCCCCC);
unsigned long now = ntpClient.getEpochTime() - NTP_OFFSET; time_t now;
time(&now);
long diff = timer - now; long diff = timer - now;
window->clear(&bg_color); window->clear(&bg_color);
if (diff < 0 && (now & 1)==0) return; if (diff < 0 && (now & 1)==0) return;

View File

@ -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'; } 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}; 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 = { const uint8_t font_numbers3x5_blocky_data[] PROGMEM = {
B11111, B10001, B11111, // 0 B11111, B10001, B11111, // 0
B00000, B11111, B00000, // 1 B00000, B11111, B00000, // 1
@ -150,12 +166,6 @@ const uint8_t font5x7_data[] PROGMEM = {
0x08, 0x08, 0x2A, 0x1C, 0x08, // -> 0x08, 0x08, 0x2A, 0x1C, 0x08, // ->
0x08, 0x1C, 0x2A, 0x08, 0x08, // <- 0x08, 0x1C, 0x2A, 0x08, 0x08, // <-
}; };
bool font5x7_check(const char c) { return c>=' ' && c<='}'; } bool font5x7_check(const char c) { return c>=' ' && c<='}'; }
uint16_t font5x7_get(const char c) { return c - ' '; } uint16_t font5x7_get(const char c) { return c - ' '; }
Font font5x7 = {5, 7, &font5x7_data[0], font5x7_check, font5x7_get}; Font font5x7 = {5, 7, &font5x7_data[0], font5x7_check, font5x7_get};

View File

@ -201,9 +201,9 @@ void http_server_setup() {
}); });
http_server.on("/effects", HTTP_GET, [&](AsyncWebServerRequest* request) { http_server.on("/effects", HTTP_GET, [&](AsyncWebServerRequest* request) {
String message = F("<html><head><title>Pitrix effects</title></head><body><h1>Pitrix settings</h1><a href='/'>Back to main page</a><table>"); String message = F("<html><head><title>Pitrix effects</title></head><body><h1>Pitrix settings</h1><a href='/'>Back to main page</a><table>");
char buffer[150]; char buffer[500];
for (int i=0; i<effects_size; i++) { for (int i=0; i<effects_size; i++) {
snprintf_P(buffer, 150, PSTR("<tr><td>%s</td><td><form method='post' action='/effects'><input type='hidden' name='name' value='%s'><input type='hidden' name='redir' value='1'><input type='submit' value='Select'></form></td></tr>"), effects[i].name, effects[i].name); snprintf_P(buffer, 500, PSTR("<tr><td>%s</td><td><form method='post' action='/effects'><input type='hidden' name='name' value='%s'><input type='hidden' name='redir' value='1'><input type='submit' value='Select'></form></td></tr>"), effects[i].name, effects[i].name);
message += buffer; message += buffer;
} }
message += F("</table></body></html>"); message += F("</table></body></html>");

View File

@ -1,13 +1,26 @@
#include <ntp.h> #include <sntp.h>
#include <coredecls.h>
#include <time.h>
#include <TZ.h>
#include "my_fastled.h" #include "my_fastled.h"
void updateCallback(NTPClient* c) { /*void updateCallback(NTPClient* c) {
random16_add_entropy(c->getEpochMillis() & 0xFFFF); random16_add_entropy(c->getEpochMillis() & 0xFFFF);
} LOGln("Received current time. Epoch is %lu.", ntpClient.getEpochTime());
}*/
WiFiUDP ntpUDP; void time_changed() {
NTPClient ntpClient(ntpUDP, NTP_SERVER, NTP_OFFSET, NTP_INTERVAL); 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() { void ntp_setup() {
ntpClient.setUpdateCallback(updateCallback); settimeofday_cb(time_changed);
configTime(TZ_Europe_Berlin, "de.pool.ntp.org");
} }

View File

@ -45,7 +45,6 @@ void setup() {
ntp_setup(); ntp_setup();
ota_setup(); ota_setup();
fastled_setup(); fastled_setup();
ntpClient.begin();
#ifdef HTTP_SERVER_ENABLE #ifdef HTTP_SERVER_ENABLE
http_server_setup(); http_server_setup();
#endif #endif
@ -76,7 +75,6 @@ void loop() {
return; return;
} }
ntpClient.update();
#ifdef MQTT_ENABLE #ifdef MQTT_ENABLE
mqtt_loop(); mqtt_loop();
#endif #endif