This commit is contained in:
Alex
2021-03-08 15:27:42 +03:00
parent b2c68a6015
commit c93604a59d
9 changed files with 43 additions and 21 deletions

View File

@@ -68,7 +68,7 @@ void drawDots(int X, int Y, CRGB color) {
}
void drawClock(byte Y, byte speed, CRGB color) {
if (cfg.deviceType == 1 || cfg.width < 16) return; // лента или мелкая матрица - на выход
if (cfg.deviceType == 1) return; // лента - на выход
byte h1, h2, m1, m2;
if (gotNTP || gotTime) {
h1 = now.hour / 10;

View File

@@ -1,4 +1,10 @@
/*
Версия 0.22b
Чуть переделан смерч
Исправлены глюки когда есть вайфай но нет интернета
Добавлено свечение после завершения рассвета, время настраивается
Обновлены бинарники, прошлая версия могла быть с ошибкой
Версия 0.21b
Выбор палитры для частиц и конфетти
Счётчик количества ламп онлайн в приложении
@@ -115,10 +121,10 @@ const char AP_NameChar[] = "GyverLamp2";
const char WiFiPassword[] = "12345678";
// ------------ Прочее -------------
#define GL_VERSION 21 // код версии прошивки
#define GL_VERSION 22 // код версии прошивки
#define EE_TOUT 30000 // таймаут сохранения епром после изменения, мс
//#define DEBUG_SERIAL // закомментируй чтобы выключить отладку (скорость 115200)
#define EE_KEY 55 // ключ сброса WiFi (измени для сброса всех настроек)
#define EE_KEY 56 // ключ сброса eeprom
#define NTP_UPD_PRD 5 // период обновления времени с NTP сервера, минут
//#define SKIP_WIFI // пропустить подключение к вафле (для отладки)
@@ -178,7 +184,7 @@ CRGB leds[MAX_LEDS];
Time now;
Button btn(BTN_PIN);
timerMillis EEtmr(EE_TOUT), turnoffTmr, connTmr(120000ul), dawnTmr, holdPresTmr(30000ul), blinkTmr(300);
timerMillis effTmr(30, true), onlineTmr(500, true);
timerMillis effTmr(30, true), onlineTmr(500, true), postDawn(10 * 60000ul);
TimeRandom trnd;
VolAnalyzer vol(A0), low, high;
FastFilter phot;

View File

@@ -81,7 +81,7 @@ struct Config {
int16_t length = 16; // длина ленты
int16_t width = 16; // ширина матрицы
byte GMT = 3; // часовой пояс +13
byte GMT = 16; // часовой пояс +13
uint32_t cityID = 1; // city ID
bool mqtt = 0; // mqtt
char mqttID[32]; //
@@ -122,13 +122,14 @@ struct Preset {
byte fromPal = 0; // из палитры (0/1)
};
#define DAWN_SIZE 23
#define DAWN_SIZE 24
struct Dawn {
byte state[7] = {0, 0, 0, 0, 0, 0, 0}; // (1/0)
byte hour[7] = {0, 0, 0, 0, 0, 0, 0}; // (0.. 59)
byte minute[7] = {0, 0, 0, 0, 0, 0, 0}; // (0.. 59)
byte bright = 100; // (0.. 255)
byte time = 1; // (5,10,15,20..)
byte post = 1; // (5,10,15,20..)
};
/*

View File

@@ -26,6 +26,11 @@ void EE_startup() {
DEBUGLN(sizeof(cfg) + sizeof(dawn) + sizeof(pal) + sizeof(preset) + 1);
// запускаем всё
if (cfg.deviceType == GL_TYPE_STRIP) {
if (cfg.length > MAX_LEDS) cfg.length = MAX_LEDS;
cfg.width = 1;
}
if (cfg.length * cfg.width > MAX_LEDS) cfg.width = MAX_LEDS / cfg.length;
FastLED.setMaxPowerInVoltsAndMilliamps(STRIP_VOLT, cfg.maxCur * 100);
updPal();
}

View File

@@ -2,12 +2,19 @@ void effectsRoutine() {
static byte prevEff = 255;
if (!effTmr.isReady()) return;
if (dawnTmr.running()) {
fill_solid(leds, MAX_LEDS, ColorFromPalette(HeatColors_p, dawnTmr.getLength8(), scaleFF(dawnTmr.getLength8(), dawn.bright), LINEARBLEND));
if (dawnTmr.running() || postDawn.running()) {
byte thisColor = dawnTmr.getLength8();
if (postDawn.running()) thisColor = 255;
fill_solid(leds, MAX_LEDS, ColorFromPalette(HeatColors_p, thisColor, scaleFF(thisColor, dawn.bright), LINEARBLEND));
drawClock(cfg.length / 2 - 4, 100, 0);
FastLED.show();
if (dawnTmr.isReady()) {
dawnTmr.stop();
postDawn.setInterval(dawn.post * 60000ul);
postDawn.restart();
}
if (postDawn.isReady()) {
postDawn.stop();
FastLED.clear();
FastLED.show();
}
@@ -234,12 +241,11 @@ void effectsRoutine() {
FOR_k(0, (thisScale >> 5) + 1) {
FOR_i(0, cfg.length) {
//byte thisPos = inoise8(i * 10 - (now.weekMs >> 1) * CUR_PRES.speed / 255, k * 10000);
byte thisPos = inoise8(i * 10 + k * 10000, (now.weekMs >> 1) * CUR_PRES.speed / 255);
byte thisPos = inoise8(i * 10 + (now.weekMs >> 3) * CUR_PRES.speed / 255 + k * 10000, (now.weekMs >> 1) * CUR_PRES.speed / 255);
thisPos = map(thisPos, 50, 200, 0, cfg.width);
byte scale = 3;
byte scale = 4;
FOR_j(0, scale) {
CRGB color = ColorFromPalette(paletteArr[CUR_PRES.palette - 1], scalePal(j * 255 / scale), 255, LINEARBLEND);
color.fadeToBlackBy(j * 255 / scale);
CRGB color = ColorFromPalette(paletteArr[CUR_PRES.palette - 1], scalePal(j * 255 / scale), (255 - j * 255 / (scale - 1)), LINEARBLEND);
if (j == 0) {
setPixOverlap(thisPos, i, color);
} else {

View File

@@ -1,5 +1,7 @@
// TODO
// защита от переполнения
#ifndef mString_h
#define mString_h
#include <Arduino.h>
char* mUtoa(uint32_t value, char *buffer, bool clear = 1);
char* mLtoa(int32_t value, char *buffer, bool clear = 1);
@@ -356,5 +358,5 @@ class mString {
}
}
private:
};
#endif

View File

@@ -42,8 +42,9 @@ void controlHandler(bool state) {
DEBUGLN("stop off timer");
return;
}
if (dawnTmr.running()) {
if (dawnTmr.running() || postDawn.running()) {
dawnTmr.stop();
postDawn.stop();
delay(50);
FastLED.clear();
FastLED.show();

View File

@@ -1,6 +1,6 @@
void setupTime() {
ntp.setUpdateInterval(NTP_UPD_PRD * 60000ul);
ntp.setTimeOffset((cfg.GMT - 13) * 3600);
ntp.setUpdateInterval(NTP_UPD_PRD * 60000ul / 2); // ставим меньше, так как апдейт вручную
ntp.setTimeOffset((cfg.GMT - 13) * 3600l);
ntp.setPoolServerName(NTPserver);
if (cfg.WiFimode && !connTmr.running()) { // если успешно подключились к WiFi
ntp.begin();
@@ -18,8 +18,8 @@ void timeTicker() {
now.hour = ntp.getHours();
now.day = ntp.getDay(); // вс 0, сб 6
now.weekMs = now.getWeekS() * 1000ul + ntp.getMillis();
now.setMs(ntp.getMillis());
if (ntp.update()) gotNTP = true;
now.setMs(ntp.getMillis());
if (now.sec == 0 && now.min % NTP_UPD_PRD == 0 && ntp.update()) gotNTP = true;
} else { // если вайфай не подключен
now.tick(); // тикаем своим счётчиком
}
@@ -75,6 +75,7 @@ void checkWorkTime() {
byte curState = isWorkTime(now.hour, cfg.workFrom, cfg.workTo);
if (prevState != curState) { // переключение расписания
prevState = curState;
// todo: проверить пересечение с рассветом
if (curState && !cfg.state && !cfg.manualOff) fade(1); // нужно включить, а лампа выключена и не выключалась вручную
if (!curState && cfg.state) fade(0); // нужно выключить, а лампа включена
}

View File

@@ -38,7 +38,7 @@ class timerMillis {
return _active;
}
byte getLength8() {
return (_active) ? ((millis() - _tmr) * 255ul / _interval) : 0;
return (_active) ? ((min(uint32_t(millis() - _tmr), _interval)) * 255ul / _interval) : 0;
}
private: