Compare commits
3 Commits
b5c1f350d2
...
359b7a7826
Author | SHA1 | Date | |
---|---|---|---|
359b7a7826 | |||
416ab46f9b | |||
b4aa711940 |
12
include/effect_tv_static.h
Normal file
12
include/effect_tv_static.h
Normal file
@ -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"; }
|
||||||
|
};
|
@ -73,6 +73,10 @@ 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 */ {
|
||||||
|
uint16_t black_bar_speed = 3500;
|
||||||
|
} tv_static;
|
||||||
} effects;
|
} effects;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -81,3 +85,6 @@ extern Setting all_settings[];
|
|||||||
extern const uint8_t all_settings_size;
|
extern const uint8_t all_settings_size;
|
||||||
|
|
||||||
bool change_setting(const char* key, uint16_t new_value);
|
bool change_setting(const char* key, uint16_t new_value);
|
||||||
|
uint16_t setting_default(Setting* s);
|
||||||
|
bool save_settings();
|
||||||
|
bool load_settings();
|
||||||
|
@ -21,7 +21,7 @@ lib_deps =
|
|||||||
ESPAsyncTCP
|
ESPAsyncTCP
|
||||||
|
|
||||||
[env:ota]
|
[env:ota]
|
||||||
upload_port = 10.10.2.78
|
upload_port = 10.10.2.80
|
||||||
upload_protocol = espota
|
upload_protocol = espota
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
board = esp07
|
board = esp07
|
||||||
|
@ -29,15 +29,8 @@ void BigClockEffect::_draw_seconds() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint16_t millis = ntpClient.getEpochMillis() % 1000;
|
uint16_t millis = ntpClient.getEpochMillis() % 1000;
|
||||||
/*
|
uint8_t offset = 5 - (millis / 200);
|
||||||
// Enable this to have the next pixel move smoothly to its position
|
uint8_t part = 255 - ((millis % 200) * 256 / 200);
|
||||||
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 number_to_show = (60 - seconds - offset) / 5 + 1;
|
uint8_t number_to_show = (60 - seconds - offset) / 5 + 1;
|
||||||
for(uint8_t i = 0; i<number_to_show; i++) {
|
for(uint8_t i = 0; i<number_to_show; i++) {
|
||||||
uint8_t pos = seconds + offset + i*5;
|
uint8_t pos = seconds + offset + i*5;
|
||||||
@ -46,26 +39,6 @@ void BigClockEffect::_draw_seconds() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BigClockEffect::_draw_border_pixel(uint8_t i, uint8_t part, CRGB* color) {
|
void BigClockEffect::_draw_border_pixel(uint8_t i, uint8_t part, CRGB* color) {
|
||||||
/*uint8_t x, y;
|
|
||||||
if (i<=8) {
|
|
||||||
x = 7 + i;
|
|
||||||
y = 0;
|
|
||||||
} else if (i<=23) {
|
|
||||||
x = 15;
|
|
||||||
y = i - 8;
|
|
||||||
} else if (i<= 38) {
|
|
||||||
x = 15 - i + 23;
|
|
||||||
y = 15;
|
|
||||||
} else if (i <= 53) {
|
|
||||||
x = 0;
|
|
||||||
y = 15 - i + 38;
|
|
||||||
} else if (i <= 60) {
|
|
||||||
x = i - 53;
|
|
||||||
y = 0;
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
window->setPixel(x, y, color);*/
|
|
||||||
accum88 x, y;
|
accum88 x, y;
|
||||||
if (i<=8) {
|
if (i<=8) {
|
||||||
x = ((7+i)<<8) + part;
|
x = ((7+i)<<8) + part;
|
||||||
|
27
src/effect_tv_static.cpp
Normal file
27
src/effect_tv_static.cpp
Normal file
@ -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;
|
||||||
|
}
|
@ -22,6 +22,7 @@
|
|||||||
#include "effect_sines.h"
|
#include "effect_sines.h"
|
||||||
#include "effect_marquee.h"
|
#include "effect_marquee.h"
|
||||||
#include "effect_blur2d.h"
|
#include "effect_blur2d.h"
|
||||||
|
#include "effect_tv_static.h"
|
||||||
|
|
||||||
Effect* current_effect;
|
Effect* current_effect;
|
||||||
|
|
||||||
@ -52,9 +53,10 @@ const EffectEntry effects[] = {
|
|||||||
/* 21 */ {"sines", true, [](){ return new SinesEffect(); }},
|
/* 21 */ {"sines", true, [](){ return new SinesEffect(); }},
|
||||||
/* 22 */ {"blur2d", true, [](){ return new Blur2DEffect(); }},
|
/* 22 */ {"blur2d", true, [](){ return new Blur2DEffect(); }},
|
||||||
/* 23 */ {"marquee", 0, [](){ return new MarqueeEffect(); }},
|
/* 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) {
|
Effect* select_effect(const char* name) {
|
||||||
|
@ -22,7 +22,7 @@ const uint8_t font_numbers3x5_blocky_data[] PROGMEM = {
|
|||||||
B10111, B10101, B11101, // 2
|
B10111, B10101, B11101, // 2
|
||||||
B10001, B10101, B11111, // 3
|
B10001, B10101, B11111, // 3
|
||||||
B11100, B00100, B11111, // 4
|
B11100, B00100, B11111, // 4
|
||||||
B11101, B10101, B11111, // 5
|
B11101, B10101, B10111, // 5
|
||||||
B11111, B10101, B10111, // 6
|
B11111, B10101, B10111, // 6
|
||||||
B10000, B10000, B11111, // 7
|
B10000, B10000, B11111, // 7
|
||||||
B11111, B10101, B11111, // 8
|
B11111, B10101, B11111, // 8
|
||||||
|
@ -58,13 +58,53 @@ void http_server_setup() {
|
|||||||
http_server.send(200, "text/html", message);
|
http_server.send(200, "text/html", message);
|
||||||
});
|
});
|
||||||
http_server.on("/settings", HTTP_GET, [&]() {
|
http_server.on("/settings", HTTP_GET, [&]() {
|
||||||
String message = "<html><head><title>Pitrix settings</title></head><body><h1>Pitrix settings</h1><a href='/'>Back to main page</a><table>";
|
String message = "<html><head><title>Pitrix settings</title></head><body><h1>Pitrix settings</h1><a href='/'>Back to main page</a><table>\n";
|
||||||
for (int i=0; i<all_settings_size; i++) {
|
for (int i=0; i<all_settings_size; i++) {
|
||||||
|
Setting s = all_settings[i];
|
||||||
|
uint16_t default_value = setting_default(&s);
|
||||||
|
uint16_t value = *(s.value);
|
||||||
|
|
||||||
message += "<tr><td>";
|
message += "<tr><td>";
|
||||||
message += all_settings[i].name;
|
if (default_value != value) {
|
||||||
|
message += "<strong>";
|
||||||
|
}
|
||||||
|
message += s.name;
|
||||||
|
if (default_value != value) {
|
||||||
|
message += "<strong>";
|
||||||
|
}
|
||||||
message += "</td><td>";
|
message += "</td><td>";
|
||||||
message += *all_settings[i].value;
|
message += value;
|
||||||
message += "</td></tr>";
|
if (default_value != value) {
|
||||||
|
message += " (";
|
||||||
|
message += default_value;
|
||||||
|
message += ")";
|
||||||
|
}
|
||||||
|
message += "</td><td><form method='POST' action='/settings?redir=1'><input type='hidden' name='key' value='";
|
||||||
|
message += s.name;
|
||||||
|
message += "'/>";
|
||||||
|
if (s.type==TYPE_UINT8 || s.type==TYPE_UINT16) {
|
||||||
|
message += "<input type='number' name='value' value='";
|
||||||
|
message += value;
|
||||||
|
message += "' min='0' max='";
|
||||||
|
if (s.type==TYPE_UINT8) {
|
||||||
|
message += "255";
|
||||||
|
} else {
|
||||||
|
message += "65535";
|
||||||
|
}
|
||||||
|
message += "' />";
|
||||||
|
} else if (s.type==TYPE_BOOL) {
|
||||||
|
message += "<input type='radio' name='value' value='0'";
|
||||||
|
if (value==0) {
|
||||||
|
message += " checked='checked'";
|
||||||
|
}
|
||||||
|
message += "> Off / <input type='radio' name='value' value='1'";
|
||||||
|
if (value==1) {
|
||||||
|
message += " checked='checked'";
|
||||||
|
}
|
||||||
|
message += "> On";
|
||||||
|
}
|
||||||
|
message += "<input type='submit' value='Save' />";
|
||||||
|
message += "</form></td></tr>\n";
|
||||||
}
|
}
|
||||||
message += "</table></body></html>";
|
message += "</table></body></html>";
|
||||||
http_server.send(200, "text/html", message);
|
http_server.send(200, "text/html", message);
|
||||||
@ -78,11 +118,38 @@ void http_server_setup() {
|
|||||||
uint16_t value = http_server.arg("value").toInt();
|
uint16_t value = http_server.arg("value").toInt();
|
||||||
|
|
||||||
if (change_setting(name.c_str(), value)) {
|
if (change_setting(name.c_str(), value)) {
|
||||||
http_server.send(200, "text/plain", "OK");
|
if (http_server.hasArg("redir")) {
|
||||||
|
http_server.sendHeader("Location", "/settings");
|
||||||
|
http_server.send(301);
|
||||||
|
} else {
|
||||||
|
http_server.send(200, "text/plain", "OK");
|
||||||
|
}
|
||||||
|
save_settings();
|
||||||
} else {
|
} else {
|
||||||
http_server.send(400, "text/plain", "Could not change setting.");
|
http_server.send(400, "text/plain", "Could not change setting.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
http_server.on("/settings/load", HTTP_POST, [&]() {
|
||||||
|
load_settings();
|
||||||
|
http_server.send(200, "text/plain", "OK");
|
||||||
|
});
|
||||||
|
http_server.on("/settings/save", HTTP_POST, [&]() {
|
||||||
|
save_settings();
|
||||||
|
http_server.send(200, "text/plain", "OK");
|
||||||
|
});
|
||||||
|
http_server.on("/settings.txt", HTTP_GET, [&]() {
|
||||||
|
File f;
|
||||||
|
if (SPIFFS.begin()) {
|
||||||
|
f=SPIFFS.open("/pitrix_settings.txt", "r");
|
||||||
|
if (f) {
|
||||||
|
String s = f.readString();
|
||||||
|
f.close();
|
||||||
|
http_server.send(200, "text/plain", s);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
http_server.send(500, "text/plain", "Could not read settings.");
|
||||||
|
});
|
||||||
http_server.on("/effects", HTTP_GET, [&]() {
|
http_server.on("/effects", HTTP_GET, [&]() {
|
||||||
String message = "<html><head><title>Pitrix effects</title></head><body><h1>Pitrix settings</h1><a href='/'>Back to main page</a><table>";
|
String message = "<html><head><title>Pitrix effects</title></head><body><h1>Pitrix settings</h1><a href='/'>Back to main page</a><table>";
|
||||||
for (int i=0; i<effects_size; i++) {
|
for (int i=0; i<effects_size; i++) {
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "effects.h"
|
#include "effects.h"
|
||||||
#include "http_server.h"
|
#include "http_server.h"
|
||||||
#include "recorder.h"
|
#include "recorder.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
uint8_t starting_up = OTA_STARTUP_DELAY;
|
uint8_t starting_up = OTA_STARTUP_DELAY;
|
||||||
int loop_timeouts = 0;
|
int loop_timeouts = 0;
|
||||||
@ -53,6 +54,7 @@ void setup() {
|
|||||||
recorder = new Recorder();
|
recorder = new Recorder();
|
||||||
#endif
|
#endif
|
||||||
SPIFFS.begin();
|
SPIFFS.begin();
|
||||||
|
load_settings();
|
||||||
LOGln("Core * Setup complete");
|
LOGln("Core * Setup complete");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include <FS.h>
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
|
||||||
@ -39,13 +40,15 @@ 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},
|
||||||
};
|
};
|
||||||
|
|
||||||
const uint8_t all_settings_size = 25;
|
const uint8_t all_settings_size = 26;
|
||||||
|
|
||||||
bool change_setting(const char* key, uint16_t new_value) {
|
bool change_setting(const char* key, uint16_t new_value) {
|
||||||
LOGln("Settings * Trying to set setting %s to new value %d...", key, new_value);
|
LOGln("Settings * Setting %s to new value %d.", key, new_value);
|
||||||
Setting* s = NULL;
|
Setting* s = NULL;
|
||||||
for (uint8_t i=0; i<all_settings_size; i++) {
|
for (uint8_t i=0; i<all_settings_size; i++) {
|
||||||
if (strcmp(key, all_settings[i].name)==0) {
|
if (strcmp(key, all_settings[i].name)==0) {
|
||||||
@ -69,6 +72,72 @@ bool change_setting(const char* key, uint16_t new_value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
*(s->value) = new_value;
|
*(s->value) = new_value;
|
||||||
LOGln("Settings * Success. New value for %s is %d.", key, new_value);
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t setting_default(Setting* s) {
|
||||||
|
Settings defaults;
|
||||||
|
auto p_settings = std::addressof(settings);
|
||||||
|
auto p_defaults = std::addressof(defaults);
|
||||||
|
uint16_t* p_this = s->value;
|
||||||
|
uint16_t diff = p_this - (uint16_t*)p_settings;
|
||||||
|
uint16_t default_value = *((uint16_t*)p_defaults + diff);
|
||||||
|
return default_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool save_settings() {
|
||||||
|
if (!SPIFFS.begin()) {
|
||||||
|
LOGln("Settings * Could not open SPIFFS for saving.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
File f = SPIFFS.open("/pitrix_settings.txt", "w");
|
||||||
|
if (!f) {
|
||||||
|
LOGln("Settings * Could not open /pitrix_settings.txt for writing.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i=0; i<all_settings_size; i++) {
|
||||||
|
Setting s = all_settings[i];
|
||||||
|
uint16_t value = *(s.value);
|
||||||
|
uint16_t default_value = setting_default(&s);
|
||||||
|
if (default_value != value) {
|
||||||
|
char buf[50];
|
||||||
|
snprintf(buf, 50, "%s=%d", s.name, value);
|
||||||
|
LOGln("Saving: %s", buf);
|
||||||
|
f.println(buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
f.close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool load_settings() {
|
||||||
|
if (!SPIFFS.begin()) {
|
||||||
|
LOGln("Settings * Could not open SPIFFS for loading.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
File f = SPIFFS.open("/pitrix_settings.txt", "r");
|
||||||
|
if (!f) {
|
||||||
|
LOGln("Settings * Could not open /pitrix_settings.txt for reading.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String s = f.readString();
|
||||||
|
f.close();
|
||||||
|
|
||||||
|
while (s.length() > 0) {
|
||||||
|
int pos = s.lastIndexOf('\n');
|
||||||
|
String part = s.substring(pos + 1);
|
||||||
|
if (pos==-1) pos=0;
|
||||||
|
s.remove(pos);
|
||||||
|
pos = part.indexOf('=');
|
||||||
|
if (pos < 1) continue;
|
||||||
|
String key = part.substring(0, pos);
|
||||||
|
uint16_t value = part.substring(pos + 1).toInt();
|
||||||
|
change_setting(key.c_str(), value);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user