NewYear FIX + Firework draw FIX
This commit is contained in:
parent
9fe739f5c1
commit
01dd357009
@ -1,33 +0,0 @@
|
|||||||
# !!! WARNING !!! AUTO-GENERATED FILE, PLEASE DO NOT MODIFY IT AND USE
|
|
||||||
# https://docs.platformio.org/page/projectconf/section_env_build.html#build-flags
|
|
||||||
#
|
|
||||||
# If you need to override existing CMake configuration or add extra,
|
|
||||||
# please create `CMakeListsUser.txt` in the root of project.
|
|
||||||
# The `CMakeListsUser.txt` will not be overwritten by PlatformIO.
|
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.13)
|
|
||||||
set(CMAKE_SYSTEM_NAME Generic)
|
|
||||||
set(CMAKE_C_COMPILER_WORKS 1)
|
|
||||||
set(CMAKE_CXX_COMPILER_WORKS 1)
|
|
||||||
|
|
||||||
project("MediaTable" C CXX)
|
|
||||||
|
|
||||||
include(CMakeListsPrivate.txt)
|
|
||||||
|
|
||||||
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/CMakeListsUser.txt)
|
|
||||||
include(CMakeListsUser.txt)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
add_custom_target(
|
|
||||||
Production ALL
|
|
||||||
COMMAND platformio -c clion run "$<$<NOT:$<CONFIG:All>>:-e${CMAKE_BUILD_TYPE}>"
|
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
add_custom_target(
|
|
||||||
Debug ALL
|
|
||||||
COMMAND platformio -c clion debug "$<$<NOT:$<CONFIG:All>>:-e${CMAKE_BUILD_TYPE}>"
|
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(Z_DUMMY_TARGET ${SRC_LIST})
|
|
||||||
@ -14,10 +14,10 @@ board = esp32dev
|
|||||||
framework = arduino
|
framework = arduino
|
||||||
lib_deps = https://github.com/adafruit/Adafruit_NeoPixel
|
lib_deps = https://github.com/adafruit/Adafruit_NeoPixel
|
||||||
build_flags =
|
build_flags =
|
||||||
upload_port = 10.0.0.153
|
;upload_port = 10.0.0.153
|
||||||
upload_protocol = espota
|
;upload_protocol = espota
|
||||||
;upload_port = /dev/ttyUSB0
|
upload_port = /dev/ttyUSB0
|
||||||
;upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_port = /dev/ttyUSB0
|
monitor_port = /dev/ttyUSB0
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
monitor_filters = esp32_exception_decoder
|
monitor_filters = esp32_exception_decoder
|
||||||
|
|||||||
@ -4,6 +4,11 @@
|
|||||||
#include "BASICS.h"
|
#include "BASICS.h"
|
||||||
#include "display/Display.h"
|
#include "display/Display.h"
|
||||||
|
|
||||||
|
#define FAKE_DAYS 0
|
||||||
|
#define FAKE_HOURS 0
|
||||||
|
#define FAKE_MINUTES 0
|
||||||
|
#define FAKE_SECONDS 0
|
||||||
|
|
||||||
enum ModeId {
|
enum ModeId {
|
||||||
NONE,
|
NONE,
|
||||||
BORDER,
|
BORDER,
|
||||||
@ -108,6 +113,7 @@ private:
|
|||||||
void realtimeUpdate() {
|
void realtimeUpdate() {
|
||||||
time_t tmp;
|
time_t tmp;
|
||||||
time(&tmp);
|
time(&tmp);
|
||||||
|
tmp += ((FAKE_DAYS * 24 + FAKE_HOURS) * 60 + FAKE_MINUTES) * 60 + FAKE_SECONDS;
|
||||||
realtimeOK = tmp > 1600000000;
|
realtimeOK = tmp > 1600000000;
|
||||||
if (realtimeOK) {
|
if (realtimeOK) {
|
||||||
realtimeChanged = epoch != tmp;
|
realtimeChanged = epoch != tmp;
|
||||||
|
|||||||
@ -5,6 +5,9 @@
|
|||||||
#include "display/Vector.h"
|
#include "display/Vector.h"
|
||||||
#include "display/Display.h"
|
#include "display/Display.h"
|
||||||
|
|
||||||
|
#define DARKER_FACTOR 0.75
|
||||||
|
#define SLOWER_DIVISOR 1
|
||||||
|
|
||||||
class Firework {
|
class Firework {
|
||||||
|
|
||||||
enum State {
|
enum State {
|
||||||
@ -52,55 +55,42 @@ public:
|
|||||||
sparkle = 0.0;
|
sparkle = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool launch() {
|
|
||||||
if (state != INITIAL) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
state = RISE;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void step(microseconds_t microseconds) {
|
void step(microseconds_t microseconds) {
|
||||||
|
microseconds = microseconds / SLOWER_DIVISOR;
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case INITIAL:
|
case INITIAL:
|
||||||
|
state = RISE;
|
||||||
break;
|
break;
|
||||||
case RISE:
|
case RISE:
|
||||||
if (position.y <= destinationHeight) {
|
if (position.y > destinationHeight) {
|
||||||
|
position.y = doStep(position.y, 0.0, height, 1000, -microseconds);
|
||||||
|
} else {
|
||||||
state = EXPLODE;
|
state = EXPLODE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EXPLODE:
|
case EXPLODE:
|
||||||
if (explosion >= explosionRadius) {
|
if (explosion < explosionRadius) {
|
||||||
|
explosion = doStep(explosion, 0.0, explosionRadius, 500, +microseconds);
|
||||||
|
} else {
|
||||||
state = SPARKLE;
|
state = SPARKLE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SPARKLE:
|
case SPARKLE:
|
||||||
if (sparkle >= sparkleMax) {
|
if (sparkle < sparkleMax) {
|
||||||
|
sparkle = doStep(sparkle, 0.0, sparkleMax, 1000, +microseconds);
|
||||||
|
} else {
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch (state) {
|
|
||||||
case INITIAL:
|
|
||||||
break;
|
|
||||||
case RISE:
|
|
||||||
position.y = doStep(position.y, 0.0, height, 1000, -microseconds);
|
|
||||||
break;
|
|
||||||
case EXPLODE:
|
|
||||||
explosion = doStep(explosion, 0.0, explosionRadius, 500, +microseconds);
|
|
||||||
break;
|
|
||||||
case SPARKLE:
|
|
||||||
sparkle = doStep(sparkle, 0.0, sparkleMax, 1000, +microseconds);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw(Display display) {
|
void draw(Display &display) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case INITIAL:
|
case INITIAL:
|
||||||
break;
|
break;
|
||||||
case RISE:
|
case RISE:
|
||||||
display.set(position, YELLOW);
|
display.set(position, factor(YELLOW, DARKER_FACTOR));
|
||||||
break;
|
break;
|
||||||
case EXPLODE:
|
case EXPLODE:
|
||||||
drawParticle(display, +0.0, +1.0);
|
drawParticle(display, +0.0, +1.0);
|
||||||
@ -125,10 +115,32 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *getStateName() const {
|
||||||
|
switch (state) {
|
||||||
|
case INITIAL:
|
||||||
|
return "INITIAL";
|
||||||
|
case RISE:
|
||||||
|
return "RISE";
|
||||||
|
case EXPLODE:
|
||||||
|
return "EXPLODE";
|
||||||
|
case SPARKLE:
|
||||||
|
return "SPARKLE";
|
||||||
|
}
|
||||||
|
return "[???]";
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void drawParticle(Display display, double x, double y) {
|
static Color factor(Color color, double factor) {
|
||||||
display.set(position.plus(x * explosion, y * explosion), color);
|
return {
|
||||||
|
(uint8_t) round(color.r * factor),
|
||||||
|
(uint8_t) round(color.g * factor),
|
||||||
|
(uint8_t) round(color.b * factor),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawParticle(Display &display, double x, double y) {
|
||||||
|
display.set(position.plus(x * explosion, y * explosion), factor(color, DARKER_FACTOR));
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#ifndef MODE_NEW_YEAR_H
|
#ifndef MODE_NEW_YEAR_H
|
||||||
#define MODE_NEW_YEAR_H
|
#define MODE_NEW_YEAR_H
|
||||||
|
|
||||||
#define MAX_FIREWORKS 10
|
#define MAX_FIREWORKS 5
|
||||||
|
|
||||||
#include "mode/Mode.h"
|
#include "mode/Mode.h"
|
||||||
#include "Firework.h"
|
#include "Firework.h"
|
||||||
@ -20,7 +20,6 @@ public:
|
|||||||
|
|
||||||
explicit NewYear(Display &display) :
|
explicit NewYear(Display &display) :
|
||||||
Mode(display) {
|
Mode(display) {
|
||||||
timer(0, 500);
|
|
||||||
for (auto &firework: fireworks) {
|
for (auto &firework: fireworks) {
|
||||||
firework.init(display);
|
firework.init(display);
|
||||||
}
|
}
|
||||||
@ -48,6 +47,7 @@ protected:
|
|||||||
for (auto &firework: fireworks) {
|
for (auto &firework: fireworks) {
|
||||||
firework.step(microseconds);
|
firework.step(microseconds);
|
||||||
}
|
}
|
||||||
|
markDirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,17 +65,15 @@ protected:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tick(uint8_t index, microseconds_t microseconds) override {
|
|
||||||
launch();
|
|
||||||
}
|
|
||||||
|
|
||||||
void draw(Display &display) override {
|
void draw(Display &display) override {
|
||||||
display.clear();
|
display.clear();
|
||||||
if (!realtimeOK) {
|
if (!realtimeOK) {
|
||||||
drawNoTime(display);
|
drawNoTime(display);
|
||||||
} else if (now.tm_mon == 1 && now.tm_mday == 1 && now.tm_hour == 0) {
|
} else if (now.tm_mon == 1 && now.tm_mday == 1 && now.tm_hour == 0) {
|
||||||
drawYear(display, now.tm_year + 1900);
|
for (auto &firework: fireworks) {
|
||||||
drawFirework(display);
|
firework.draw(display);
|
||||||
|
}
|
||||||
|
drawYear(display, now.tm_year);
|
||||||
} else {
|
} else {
|
||||||
drawCountdown(display, now);
|
drawCountdown(display, now);
|
||||||
}
|
}
|
||||||
@ -94,23 +92,10 @@ private:
|
|||||||
void setMode(State state) {
|
void setMode(State state) {
|
||||||
if (_state != state) {
|
if (_state != state) {
|
||||||
_state = state;
|
_state = state;
|
||||||
if (state == FIREWORK) {
|
|
||||||
timer(0, 500);
|
|
||||||
} else {
|
|
||||||
timer(0, 0);
|
|
||||||
}
|
|
||||||
markDirty();
|
markDirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void launch() {
|
|
||||||
for (auto &firework: fireworks) {
|
|
||||||
if (firework.launch()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void drawCountdown(Display &display, const tm &now) {
|
void drawCountdown(Display &display, const tm &now) {
|
||||||
uint8_t hours = (24 - now.tm_hour - (now.tm_min > 0 || now.tm_sec > 0 ? 1 : 0));
|
uint8_t hours = (24 - now.tm_hour - (now.tm_min > 0 || now.tm_sec > 0 ? 1 : 0));
|
||||||
uint8_t minutes = (60 - now.tm_min - (now.tm_sec > 0 ? 1 : 0)) % 60;
|
uint8_t minutes = (60 - now.tm_min - (now.tm_sec > 0 ? 1 : 0)) % 60;
|
||||||
@ -221,12 +206,6 @@ private:
|
|||||||
x += display.print(x, 1, year / 1 % 10, WHITE);
|
x += display.print(x, 1, year / 1 % 10, WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawFirework(Display &display) {
|
|
||||||
for (auto &firework: fireworks) {
|
|
||||||
firework.draw(display);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -69,7 +69,7 @@ void ntp_setup() {
|
|||||||
calculateGateway(calculatedGateway, sizeof(calculatedGateway));
|
calculateGateway(calculatedGateway, sizeof(calculatedGateway));
|
||||||
sntp_set_time_sync_notification_cb(timeSyncCallback);
|
sntp_set_time_sync_notification_cb(timeSyncCallback);
|
||||||
Serial.printf("configTime(%s / %s / %s)\n", WiFi.gatewayIP().toString().c_str(), calculatedGateway, "pool.ntp.org");
|
Serial.printf("configTime(%s / %s / %s)\n", WiFi.gatewayIP().toString().c_str(), calculatedGateway, "pool.ntp.org");
|
||||||
configTime(3600, 3600, WiFi.gatewayIP().toString().c_str(), calculatedGateway, "pool.ntp.org");
|
configTime(3600, 3600, "pool.ntp.org", WiFi.gatewayIP().toString().c_str(), calculatedGateway);
|
||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user