Compare commits

...

3 Commits

6 changed files with 60 additions and 32 deletions

View File

@ -6,10 +6,12 @@ class BigClockEffect : public Effect {
private: private:
CRGB _color_font = CRGB(0xAAAAAA); CRGB _color_font = CRGB(0xAAAAAA);
CRGB _color_seconds_light = CRGB(0xFFFF00); CRGB _color_seconds_light = CRGB(0xFFFF00);
CRGB _color_seconds_dark = CRGB(0xFF0000); CRGB _color_seconds_dark = CRGB(0xAA0000);
CRGB _color_seconds_moving_light = CRGB(0x666600);
CRGB _color_seconds_moving_dark = CRGB(0x660000);
void _draw_seconds(); void _draw_seconds();
void _draw_border_pixel(uint8_t second, uint8_t part, CRGB* color); void _draw_border_pixel(accum88 pos, CRGB* color);
public: public:
void loop(uint16_t ms); void loop(uint16_t ms);

View File

@ -32,6 +32,10 @@ struct Settings {
uint16_t random_count = 32; uint16_t random_count = 32;
} matrix; } matrix;
struct /* big_clock */ {
uint16_t spacing = 5;
} big_clock;
struct /* confetti */ { struct /* confetti */ {
uint16_t pixels_per_loop = 2; uint16_t pixels_per_loop = 2;
} confetti; } confetti;
@ -75,7 +79,7 @@ struct Settings {
uint16_t direction_change = 5; uint16_t direction_change = 5;
uint16_t slowdown = 2; uint16_t slowdown = 2;
} snake; } snake;
struct /* tv_static */ { struct /* tv_static */ {
uint16_t black_bar_speed = 3500; uint16_t black_bar_speed = 3500;
} tv_static; } tv_static;

View File

@ -2,6 +2,7 @@
#include "effect_big_clock.h" #include "effect_big_clock.h"
#include "fonts.h" #include "fonts.h"
#include "ntp.h" #include "ntp.h"
#include "settings.h"
void BigClockEffect::loop(uint16_t ms) { void BigClockEffect::loop(uint16_t ms) {
window->clear(); window->clear();
@ -25,35 +26,35 @@ void BigClockEffect::loop(uint16_t ms) {
void BigClockEffect::_draw_seconds() { void BigClockEffect::_draw_seconds() {
uint8_t seconds = ntpClient.getSeconds(); uint8_t seconds = ntpClient.getSeconds();
for (int i=1; i<=seconds; i++) { for (int i=1; i<=seconds; i++) {
_draw_border_pixel(i, 0, (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 millis = ntpClient.getEpochMillis() % 1000;
uint8_t offset = 5 - (millis / 200); accum88 pos = (seconds<<8) + ((settings.effects.big_clock.spacing-1)<<8) * (1000 - millis) / 1000 + (1<<8);
uint8_t part = 255 - ((millis % 200) * 256 / 200); uint8_t sec = seconds + 1;
uint8_t number_to_show = (60 - seconds - offset) / 5 + 1; while (pos < (60<<8)) {
for(uint8_t i = 0; i<number_to_show; i++) { _draw_border_pixel(pos, sec%5==0 ? &_color_seconds_moving_light : &_color_seconds_moving_dark);
uint8_t pos = seconds + offset + i*5; pos += settings.effects.big_clock.spacing<<8;
_draw_border_pixel(pos, part, (seconds + i + 1)%5==0 ? &_color_seconds_light : &_color_seconds_dark); sec++;
} }
} }
void BigClockEffect::_draw_border_pixel(uint8_t i, uint8_t part, CRGB* color) { void BigClockEffect::_draw_border_pixel(accum88 i, CRGB* color) {
accum88 x, y; accum88 x, y;
if (i<=8) { if (i<(8<<8)) {
x = ((7+i)<<8) + part; x = i + (7<<8);
y = 0; y = 0;
} else if (i<=23) { } else if (i<(23<<8)) {
x = 15<<8; x = 15<<8;
y = ((i-8)<<8) + part; y = i - (8<<8);
} else if (i<=38) { } else if (i<(38<<8)) {
x = ((38-i)<<8) - part; x = (38<<8) - i;
y = 15<<8; y = 15<<8;
} else if (i<=53) { } else if (i<(53<<8)) {
x = 0; x = 0;
y = ((53-i)<<8) - part; y = (53<<8) - i;
} else if (i<=60) { } else if (i<=(60<<8)) {
x = ((i-53)<<8) + part; x = i - (53<<8);
y = 0; y = 0;
} else { } else {
return; return;

View File

@ -2,7 +2,7 @@
#include "functions.h" #include "functions.h"
boolean TwirlEffect::can_be_shown_with_clock() { return true; }; boolean TwirlEffect::can_be_shown_with_clock() { return true; };
boolean TwirlEffect::clock_as_mask() { return true; }; boolean TwirlEffect::clock_as_mask() { return false; };
void TwirlEffect::loop(uint16_t ms) { void TwirlEffect::loop(uint16_t ms) {
double center_x = _real_center_x; // - (cos8(_center_offset_angle)>>6); double center_x = _real_center_x; // - (cos8(_center_offset_angle)>>6);

View File

@ -63,7 +63,7 @@ void http_server_setup() {
Setting s = all_settings[i]; Setting s = all_settings[i];
uint16_t default_value = setting_default(&s); uint16_t default_value = setting_default(&s);
uint16_t value = *(s.value); uint16_t value = *(s.value);
message += "<tr><td>"; message += "<tr><td>";
if (default_value != value) { if (default_value != value) {
message += "<strong>"; message += "<strong>";
@ -155,11 +155,30 @@ void http_server_setup() {
for (int i=0; i<effects_size; i++) { for (int i=0; i<effects_size; i++) {
message += "<tr><td>"; message += "<tr><td>";
message += effects[i].name; message += effects[i].name;
message += "</td></tr>"; message += "</td><td><form method='post' action='/effects'><input type='hidden' name='name' value='";
message += effects[i].name;
message += "'><input type='hidden' name='redir' value='1'><input type='submit' value='Select'></form></td></tr>";
} }
message += "</table></body></html>"; message += "</table></body></html>";
http_server.send(200, "text/html", message); http_server.send(200, "text/html", message);
}); });
http_server.on("/effects", HTTP_POST, [&]() {
if (!http_server.hasArg("name")) {
http_server.send(400, "text/plain", "Missing argument 'name'.");
return;
}
String name = http_server.arg("name");
if (change_current_effect(name)) {
if (http_server.hasArg("redir")) {
http_server.sendHeader("Location", "/effects");
http_server.send(301);
} else {
http_server.send(200, "text/plain", "OK");
}
} else {
http_server.send(404, "text/plain", "Effect not found.");
}
});
http_server.on("/delete", HTTP_GET, [&]() { http_server.on("/delete", HTTP_GET, [&]() {
LOGln("HTTP * GET /delete"); LOGln("HTTP * GET /delete");
if (http_server.args()==0) { if (http_server.args()==0) {

View File

@ -7,6 +7,8 @@ Settings settings;
Setting all_settings[] = { Setting all_settings[] = {
{"fps", &settings.fps, TYPE_UINT8}, {"fps", &settings.fps, TYPE_UINT8},
{"effects.big_clock.spacing", &settings.effects.big_clock.spacing, TYPE_UINT8},
{"effects.confetti.pixels_per_loop", &settings.effects.confetti.pixels_per_loop, 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.random", &settings.effects.cycle.random, TYPE_BOOL},
@ -43,11 +45,11 @@ Setting all_settings[] = {
{"effects.sines.count", &settings.effects.sines.count, TYPE_UINT8}, {"effects.sines.count", &settings.effects.sines.count, TYPE_UINT8},
{"effects.snake.direction_change", &settings.effects.snake.direction_change, TYPE_UINT8}, {"effects.snake.direction_change", &settings.effects.snake.direction_change, TYPE_UINT8},
{"effects.tv_static.black_bar_speed", &settings.effects.tv_static.black_bar_speed, TYPE_UINT16}, {"effects.tv_static.black_bar_speed", &settings.effects.tv_static.black_bar_speed, TYPE_UINT16},
}; };
const uint8_t all_settings_size = 29; const uint8_t all_settings_size = 30;
bool change_setting(const char* key, uint16_t new_value) { bool change_setting(const char* key, uint16_t new_value) {
LOGln("Settings * Setting %s to new value %d.", key, new_value); LOGln("Settings * Setting %s to new value %d.", key, new_value);
@ -93,13 +95,13 @@ bool save_settings() {
LOGln("Settings * Could not open SPIFFS for saving."); LOGln("Settings * Could not open SPIFFS for saving.");
return false; return false;
} }
File f = SPIFFS.open("/pitrix_settings.txt", "w"); File f = SPIFFS.open("/pitrix_settings.txt", "w");
if (!f) { if (!f) {
LOGln("Settings * Could not open /pitrix_settings.txt for writing."); LOGln("Settings * Could not open /pitrix_settings.txt for writing.");
return false; return false;
} }
Setting* s; Setting* s;
for (uint8_t i=0; i<all_settings_size; i++) { for (uint8_t i=0; i<all_settings_size; i++) {
s = &(all_settings[i]); s = &(all_settings[i]);
@ -112,7 +114,7 @@ bool save_settings() {
f.println(buf); f.println(buf);
} }
} }
f.close(); f.close();
return true; return true;
} }
@ -122,16 +124,16 @@ bool load_settings() {
LOGln("Settings * Could not open SPIFFS for loading."); LOGln("Settings * Could not open SPIFFS for loading.");
return false; return false;
} }
File f = SPIFFS.open("/pitrix_settings.txt", "r"); File f = SPIFFS.open("/pitrix_settings.txt", "r");
if (!f) { if (!f) {
LOGln("Settings * Could not open /pitrix_settings.txt for reading."); LOGln("Settings * Could not open /pitrix_settings.txt for reading.");
return false; return false;
} }
String s = f.readString(); String s = f.readString();
f.close(); f.close();
while (s.length() > 0) { while (s.length() > 0) {
int pos = s.lastIndexOf('\n'); int pos = s.lastIndexOf('\n');
String part = s.substring(pos + 1); String part = s.substring(pos + 1);