From 01dd3570094536dd1a9ec4d8622e544e0e2bfe08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Sat, 30 Dec 2023 10:48:32 +0100 Subject: [PATCH] NewYear FIX + Firework draw FIX --- CMakeLists.txt | 33 ------------------ platformio.ini | 8 ++--- src/mode/Mode.h | 6 ++++ src/mode/NewYear/Firework.h | 68 ++++++++++++++++++++++--------------- src/mode/NewYear/NewYear.h | 33 ++++-------------- src/wifi.cpp | 2 +- 6 files changed, 57 insertions(+), 93 deletions(-) delete mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 8414fc7..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -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 "$<$>:-e${CMAKE_BUILD_TYPE}>" - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -) - -add_custom_target( - Debug ALL - COMMAND platformio -c clion debug "$<$>:-e${CMAKE_BUILD_TYPE}>" - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -) - -add_executable(Z_DUMMY_TARGET ${SRC_LIST}) diff --git a/platformio.ini b/platformio.ini index c63c4b4..0c43c40 100644 --- a/platformio.ini +++ b/platformio.ini @@ -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 diff --git a/src/mode/Mode.h b/src/mode/Mode.h index e5c98ef..6ae9f55 100644 --- a/src/mode/Mode.h +++ b/src/mode/Mode.h @@ -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; diff --git a/src/mode/NewYear/Firework.h b/src/mode/NewYear/Firework.h index ab07895..b20c55b 100644 --- a/src/mode/NewYear/Firework.h +++ b/src/mode/NewYear/Firework.h @@ -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)); } }; diff --git a/src/mode/NewYear/NewYear.h b/src/mode/NewYear/NewYear.h index a37b1fd..9c221a7 100644 --- a/src/mode/NewYear/NewYear.h +++ b/src/mode/NewYear/NewYear.h @@ -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 diff --git a/src/wifi.cpp b/src/wifi.cpp index 19b7542..6f7708a 100644 --- a/src/wifi.cpp +++ b/src/wifi.cpp @@ -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(); }