From 6e37e7fb5e05b28bf687618c854c0269a87157b7 Mon Sep 17 00:00:00 2001 From: Merlin Schumacher Date: Wed, 27 May 2020 16:45:53 +0200 Subject: [PATCH] code cleanup --- platformio.ini | 4 ---- src/color.h | 7 ++++++- src/main.cpp | 56 ++++++++++++++++++++++++++++---------------------- 3 files changed, 38 insertions(+), 29 deletions(-) diff --git a/platformio.ini b/platformio.ini index 6ce2090..c90afa4 100644 --- a/platformio.ini +++ b/platformio.ini @@ -26,7 +26,6 @@ lib_deps = ArduinoJson@6.15.1 ezTime@0.8.3 NeoPixelBus@2.5.7 - PubSubClient@2.8 extra_scripts = pre:build_data.py [env:esp12e] @@ -45,7 +44,6 @@ lib_deps = ArduinoJson@6.15.1 ezTime@0.8.3 NeoPixelBus@2.5.7 - PubSubClient@2.8 extra_scripts = pre:build_data.py [env:lolin32-devel] @@ -60,7 +58,6 @@ lib_deps = ArduinoJson@6.15.1 ezTime@0.8.3 NeoPixelBus@2.5.7 - PubSubClient@2.8 extra_scripts = pre:build_data.py [env:lolin32] @@ -75,5 +72,4 @@ lib_deps = ArduinoJson@6.15.1 ezTime@0.8.3 NeoPixelBus@2.5.7 - PubSubClient@2.8 extra_scripts = pre:build_data.py \ No newline at end of file diff --git a/src/color.h b/src/color.h index 7efd9ab..6cb7c96 100644 --- a/src/color.h +++ b/src/color.h @@ -50,13 +50,18 @@ RgbColor Alarm(uint8_t WheelPos) } } -void alarmAnimation() +void alarmAnimation(bool isNight = false) { for (uint16_t i = 0; i < config.config.ledCount; i++) { animationPos++; animationColor = Alarm(animationPos); + + if (isNight) + { + animationColor = DimColor(90, animationColor); + } uint8_t pixelPos = (i + second()) % 60; strip->SetPixelColor(pixelPos, animationColor); } diff --git a/src/main.cpp b/src/main.cpp index 3d7b2f0..96c56c3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -57,22 +57,8 @@ uint8_t calculateHourHand() return hourHand; } -void showClockElements() +void renderHourDots() { - - webserver.currentTime = localTime.dateTime(); - strip->ClearTo(off); - - uint8_t hour12 = localTime.hour() % 12; - uint8_t segmentLength = floor((float)config.config.ledCount / 12); - uint8_t segmentStart = floor((float)config.config.ledCount / 12 * hour12); - segmentStart = (segmentStart + config.config.ledRoot) % config.config.ledCount; - for (size_t i = 0; i < segmentLength; i++) - { - strip->SetPixelColor(segmentStart + i, segment); - } - - // calculate hour dots float step = (float)config.config.ledCount / 12; for (size_t i = 0; i < 12; i++) { @@ -87,12 +73,23 @@ void showClockElements() strip->SetPixelColor(dotPos, dot); } } +} + +void renderHourSegment() +{ - setPixel(calculateHourHand(), hourColor, config.config.blendColors); - setPixel(calculateMinuteHand(), minuteColor, config.config.blendColors); - renderSecondHand(); + uint8_t hour12 = localTime.hour() % 12; + uint8_t segmentLength = floor((float)config.config.ledCount / 12); + uint8_t segmentStart = floor((float)config.config.ledCount / 12 * hour12); + segmentStart = (segmentStart + config.config.ledRoot) % config.config.ledCount; + for (size_t i = 0; i < segmentLength; i++) + { + strip->SetPixelColor(segmentStart + i, segment); + } +} - strip->Show(); +void showClockElements() +{ } void setup() @@ -140,24 +137,35 @@ void loop() uint8_t sec = second(); + strip->ClearTo(off); if (currentSecond != sec) { currentMinute = minute(); + currentSecond = sec; updateColors(isNight()); + webserver.currentTime = localTime.dateTime(); } if (isAlarm() && tick()) { - alarmAnimation(); + alarmAnimation(isNight()); } else if (config.config.hourLight && currentMinute == 0 && !isAlarm() && tick()) { - hourRainbow(); + hourRainbow(isNight()); } - else if (!isAlarm() && currentMinute != 0) + else if (!isAlarm() && currentMinute != 0 && tick()) { - currentSecond = second(); - showClockElements(); + currentSecond = sec; + renderHourDots(); + renderHourSegment(); + + setPixel(calculateHourHand(), hourColor, config.config.blendColors); + setPixel(calculateMinuteHand(), minuteColor, config.config.blendColors); + renderSecondHand(); + + strip->Show(); animationPos = 0; } + yield(); }