NewYear FIX + Firework draw FIX

This commit is contained in:
Patrick Haßel 2023-12-30 10:48:32 +01:00
parent 9fe739f5c1
commit 01dd357009
6 changed files with 57 additions and 93 deletions

View File

@ -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})

View File

@ -14,10 +14,10 @@ board = esp32dev
framework = arduino
lib_deps = https://github.com/adafruit/Adafruit_NeoPixel
build_flags =
upload_port = 10.0.0.153
upload_protocol = espota
;upload_port = /dev/ttyUSB0
;upload_speed = 921600
;upload_port = 10.0.0.153
;upload_protocol = espota
upload_port = /dev/ttyUSB0
upload_speed = 921600
monitor_port = /dev/ttyUSB0
monitor_speed = 115200
monitor_filters = esp32_exception_decoder

View File

@ -4,6 +4,11 @@
#include "BASICS.h"
#include "display/Display.h"
#define FAKE_DAYS 0
#define FAKE_HOURS 0
#define FAKE_MINUTES 0
#define FAKE_SECONDS 0
enum ModeId {
NONE,
BORDER,
@ -108,6 +113,7 @@ private:
void realtimeUpdate() {
time_t tmp;
time(&tmp);
tmp += ((FAKE_DAYS * 24 + FAKE_HOURS) * 60 + FAKE_MINUTES) * 60 + FAKE_SECONDS;
realtimeOK = tmp > 1600000000;
if (realtimeOK) {
realtimeChanged = epoch != tmp;

View File

@ -5,6 +5,9 @@
#include "display/Vector.h"
#include "display/Display.h"
#define DARKER_FACTOR 0.75
#define SLOWER_DIVISOR 1
class Firework {
enum State {
@ -52,55 +55,42 @@ public:
sparkle = 0.0;
}
bool launch() {
if (state != INITIAL) {
return false;
}
state = RISE;
return true;
}
void step(microseconds_t microseconds) {
microseconds = microseconds / SLOWER_DIVISOR;
switch (state) {
case INITIAL:
state = RISE;
break;
case RISE:
if (position.y <= destinationHeight) {
if (position.y > destinationHeight) {
position.y = doStep(position.y, 0.0, height, 1000, -microseconds);
} else {
state = EXPLODE;
}
break;
case EXPLODE:
if (explosion >= explosionRadius) {
if (explosion < explosionRadius) {
explosion = doStep(explosion, 0.0, explosionRadius, 500, +microseconds);
} else {
state = SPARKLE;
}
break;
case SPARKLE:
if (sparkle >= sparkleMax) {
if (sparkle < sparkleMax) {
sparkle = doStep(sparkle, 0.0, sparkleMax, 1000, +microseconds);
} else {
reset();
}
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) {
case INITIAL:
break;
case RISE:
display.set(position, YELLOW);
display.set(position, factor(YELLOW, DARKER_FACTOR));
break;
case EXPLODE:
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:
void drawParticle(Display display, double x, double y) {
display.set(position.plus(x * explosion, y * explosion), color);
static Color factor(Color color, double factor) {
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));
}
};

View File

@ -1,7 +1,7 @@
#ifndef MODE_NEW_YEAR_H
#define MODE_NEW_YEAR_H
#define MAX_FIREWORKS 10
#define MAX_FIREWORKS 5
#include "mode/Mode.h"
#include "Firework.h"
@ -20,7 +20,6 @@ public:
explicit NewYear(Display &display) :
Mode(display) {
timer(0, 500);
for (auto &firework: fireworks) {
firework.init(display);
}
@ -48,6 +47,7 @@ protected:
for (auto &firework: fireworks) {
firework.step(microseconds);
}
markDirty();
}
}
@ -65,17 +65,15 @@ protected:
}
}
void tick(uint8_t index, microseconds_t microseconds) override {
launch();
}
void draw(Display &display) override {
display.clear();
if (!realtimeOK) {
drawNoTime(display);
} else if (now.tm_mon == 1 && now.tm_mday == 1 && now.tm_hour == 0) {
drawYear(display, now.tm_year + 1900);
drawFirework(display);
for (auto &firework: fireworks) {
firework.draw(display);
}
drawYear(display, now.tm_year);
} else {
drawCountdown(display, now);
}
@ -94,23 +92,10 @@ private:
void setMode(State state) {
if (_state != state) {
_state = state;
if (state == FIREWORK) {
timer(0, 500);
} else {
timer(0, 0);
}
markDirty();
}
}
void launch() {
for (auto &firework: fireworks) {
if (firework.launch()) {
return;
}
}
}
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 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);
}
void drawFirework(Display &display) {
for (auto &firework: fireworks) {
firework.draw(display);
}
}
};
#endif

View File

@ -69,7 +69,7 @@ void ntp_setup() {
calculateGateway(calculatedGateway, sizeof(calculatedGateway));
sntp_set_time_sync_notification_cb(timeSyncCallback);
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();
}