From 3630918a6f922fc21395ea2a3abf4630a8371352 Mon Sep 17 00:00:00 2001 From: lukas Date: Wed, 12 May 2021 21:20:32 +0200 Subject: [PATCH] set time to nightmode to 22o'clock night brightness=0 loadanimaiton step into new function and some coments --- src/Clock.cpp | 16 ++++++------ src/Clock.h | 4 +-- src/LoadAnimator.cpp | 60 +++++++++++++++++++++++--------------------- src/LoadAnimator.h | 14 +++++++++++ 4 files changed, 56 insertions(+), 38 deletions(-) diff --git a/src/Clock.cpp b/src/Clock.cpp index d77a08d..9ef75c9 100644 --- a/src/Clock.cpp +++ b/src/Clock.cpp @@ -30,8 +30,8 @@ void Clock::turnOn() { } void Clock::paintAlwaysOnLeds() { - printWord(types::es, Adafruit_NeoPixel::Color(150, 150, 0)); - printWord(types::ist, Adafruit_NeoPixel::Color(150, 0, 150)); + printWord(types::es, Adafruit_NeoPixel::Color(255, 255, 0)); + printWord(types::ist, Adafruit_NeoPixel::Color(255, 0, 255)); } void Clock::printWord(const std::vector& word, uint32_t color) { @@ -59,7 +59,7 @@ void Clock::refreshTime() { const uint8_t minute = loctime->tm_min; // enable night brighntess at 21' and disable it at 6' - if (hour >= 21 || hour <= 6) { + if (hour >= 22 || hour <= 6) { strip.setBrightness(NIGHTBRIGHTNESS); } else { strip.setBrightness(DAYBRIGHTNESS); @@ -98,14 +98,14 @@ void Clock::setTime(uint8_t hour, uint8_t minute, bool twentyAfterSyntax, bool a : hour == 0 || hour == 12 ? types::zwoelf : hourWord; - printWord(hourWord, Adafruit_NeoPixel::Color(0, 0, 150)); + printWord(hourWord, Adafruit_NeoPixel::Color(0, 255, 255)); // print the minute words and the corresponding after/before half words printMinutes(minuteselector, twentyAfterSyntax); // uhr if (minuteselector == 0 || alwaysClockWord) - printWord(types::uhr, Adafruit_NeoPixel::Color(150, 0, 0)); + printWord(types::uhr, Adafruit_NeoPixel::Color(255, 0, 0)); } void Clock::printMinutes(uint8_t minuteSelector, bool twentyAfterSyntax) { @@ -126,7 +126,7 @@ void Clock::printMinutes(uint8_t minuteSelector, bool twentyAfterSyntax) { else if (minuteSelector == 6) minuteWord = types::halb; - printWord(minuteWord, Adafruit_NeoPixel::Color(0, 150, 0)); + printWord(minuteWord, Adafruit_NeoPixel::Color(0, 255, 0)); // vor / nach std::vector vornachWord; @@ -142,13 +142,13 @@ void Clock::printMinutes(uint8_t minuteSelector, bool twentyAfterSyntax) { || minuteSelector == 10 || minuteSelector == 11 || ((minuteSelector == 8) && twentyAfterSyntax)) // check if twentyafter enabled if yess -- display vor vornachWord = types::vor; - printWord(vornachWord, Adafruit_NeoPixel::Color(150, 150, 150)); + printWord(vornachWord, Adafruit_NeoPixel::Color(255, 255, 255)); // halb if (minuteSelector >= 4 && minuteSelector <= 8) { // only 3 times if twentyafter syntax is on if (!twentyAfterSyntax || (minuteSelector >= 5 && minuteSelector <= 7)) - printWord(types::halb, Adafruit_NeoPixel::Color(150, 0, 0)); + printWord(types::halb, Adafruit_NeoPixel::Color(255, 0, 0)); } } diff --git a/src/Clock.h b/src/Clock.h index fbcfcaf..032bbcf 100644 --- a/src/Clock.h +++ b/src/Clock.h @@ -16,8 +16,8 @@ // define the esp pin the stip is attached to #define STRIPPIN D5 -#define DAYBRIGHTNESS 255 -#define NIGHTBRIGHTNESS 40 +#define DAYBRIGHTNESS 150 +#define NIGHTBRIGHTNESS 0 class Clock { private: diff --git a/src/LoadAnimator.cpp b/src/LoadAnimator.cpp index b131de4..956e145 100644 --- a/src/LoadAnimator.cpp +++ b/src/LoadAnimator.cpp @@ -6,37 +6,41 @@ #include "Types.h" void LoadAnimator::startLoadAnimation(Adafruit_NeoPixel* strip) { + this->strip = strip; + if (!timer.active()) - timer.attach_ms(100, [this, strip]() { - if (y == 0 && x < 7) { - x++; - } else if (x == 7 && y < 4) { - y++; - } else if (y == 4 && x > 0) { - x--; - } else if (x == 0 && y > 0) { - y--; - } - - uint8_t nr = types::convert(x + 2, y + 2); - strip->clear(); - strip->setPixelColor(nr, Adafruit_NeoPixel::Color(0, 0, 150)); - if (nro != 0) - strip->setPixelColor(nro, Adafruit_NeoPixel::Color(0, 0, 100)); - if (nroo != 0) - strip->setPixelColor(nroo, Adafruit_NeoPixel::Color(0, 0, 50)); - if (nrooo != 0) - strip->setPixelColor(nroo, Adafruit_NeoPixel::Color(0, 0, 25)); - strip->show(); - - nrooo = nroo; - nroo = nro; - nro = nr; - }); + timer.attach_ms(100, std::bind(&LoadAnimator::animationStep, this)); } void LoadAnimator::stopLoadAnimation() { timer.detach(); } -LoadAnimator::LoadAnimator() : timer(), x(0), y(0), nro(0), nroo(0), nrooo(0) { -} + +LoadAnimator::LoadAnimator() : timer(), x(0), y(0), nro(0), nroo(0), nrooo(0){}; + +void LoadAnimator::animationStep() { + if (y == 0 && x < 7) { + x++; + } else if (x == 7 && y < 4) { + y++; + } else if (y == 4 && x > 0) { + x--; + } else if (x == 0 && y > 0) { + y--; + } + + uint8_t nr = types::convert(x + 2, y + 2); + strip->clear(); + strip->setPixelColor(nr, Adafruit_NeoPixel::Color(0, 0, 150)); + if (nro != 0) + strip->setPixelColor(nro, Adafruit_NeoPixel::Color(0, 0, 100)); + if (nroo != 0) + strip->setPixelColor(nroo, Adafruit_NeoPixel::Color(0, 0, 50)); + if (nrooo != 0) + strip->setPixelColor(nroo, Adafruit_NeoPixel::Color(0, 0, 25)); + strip->show(); + + nrooo = nroo; + nroo = nro; + nro = nr; +} \ No newline at end of file diff --git a/src/LoadAnimator.h b/src/LoadAnimator.h index 15f20a6..1414dee 100644 --- a/src/LoadAnimator.h +++ b/src/LoadAnimator.h @@ -12,11 +12,25 @@ class LoadAnimator { private: Ticker timer; uint8_t x, y, nro, nroo, nrooo; + Adafruit_NeoPixel *strip; + + /** + * one animation step to process the animation + */ + void animationStep(); public: LoadAnimator(); + /** + * start the animation if not already runnint + * @param strip pointer to strip object + */ void startLoadAnimation(Adafruit_NeoPixel *strip); + + /** + * stop the animation + */ void stopLoadAnimation(); };