diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..cd81d48 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,23 @@ +image: nikolaik/python-nodejs:python3.9-nodejs15-slim + +stages: + - build + +cache: + paths: + - "~/.platformio" + - ./interface/node_modules + +before_script: + - "pip install -U platformio" + - "platformio update" + +build: + stage: build + script: + - "platformio run -e esp12e" + - vers=$(grep -Po '[0-9]*\.[0-9]*\.[0-9]*(?=\")' ./src/main.cpp) + - mv .pio/build/esp12e/*.bin WordClock-${vers}.bin + artifacts: + paths: + - ./*.bin diff --git a/features.ini b/features.ini index ffb890d..edf0db6 100644 --- a/features.ini +++ b/features.ini @@ -2,7 +2,7 @@ build_flags = -D FT_PROJECT=1 -D FT_SECURITY=1 - -D FT_MQTT=1 + -D FT_MQTT=0 -D FT_NTP=1 -D FT_OTA=1 -D FT_UPLOAD_FIRMWARE=1 diff --git a/src/Clock.cpp b/src/Clock.cpp index cda0e5b..0f498f8 100644 --- a/src/Clock.cpp +++ b/src/Clock.cpp @@ -3,8 +3,9 @@ // #include "Clock.h" +#include "Types.h" -Clock::Clock() : strip(NUMPIXELS, D5, NEO_GRB + NEO_KHZ800), refreshTicker() { +Clock::Clock() : strip(NUMPIXELS, D5, NEO_GRB + NEO_KHZ800), animator(), refreshTicker() { } void Clock::init() { @@ -19,7 +20,6 @@ void Clock::init() { void Clock::paintAllwaysOnLeds() { printWord(types::es, Adafruit_NeoPixel::Color(150, 150, 0)); printWord(types::ist, Adafruit_NeoPixel::Color(150, 0, 150)); - printWord(types::uhr, Adafruit_NeoPixel::Color(0, 0, 150)); } void Clock::printWord(std::vector word, uint32_t color) { @@ -29,14 +29,14 @@ void Clock::printWord(std::vector word, uint32_t color) { } void Clock::refreshTime() { - strip.clear(); - // grab the current instant in unix seconds time_t now = time(nullptr); if (now <= 604800) { - strip.show(); + animator.startLoadAnimation(&strip); return; } + animator.stopLoadAnimation(); + strip.clear(); tm* loctime = localtime(&now); @@ -67,19 +67,19 @@ void Clock::setTime(uint8_t hour, uint8_t minute) { std::vector hourWord; - hourWord = hour == 1 ? types::ein - : hour == 2 ? types::zwei - : hour == 3 ? types::drei - : hour == 4 ? types::vier - : hour == 5 ? types::fuenf2 - : hour == 6 ? types::sechs - : hour == 7 ? types::sieben - : hour == 8 ? types::acht - : hour == 9 ? types::neun - : hour == 10 ? types::zehn2 - : hour == 11 ? types::elf - : hour == 0 ? types::zwoelf - : hourWord; + hourWord = hour == 1 ? types::ein + : hour == 2 ? types::zwei + : hour == 3 ? types::drei + : hour == 4 ? types::vier + : hour == 5 ? types::fuenf2 + : hour == 6 ? types::sechs + : hour == 7 ? types::sieben + : hour == 8 ? types::acht + : hour == 9 ? types::neun + : hour == 10 ? types::zehn2 + : hour == 11 ? types::elf + : hour == 0 || hour == 12 ? types::zwoelf + : hourWord; printWord(hourWord, Adafruit_NeoPixel::Color(0, 150, 0)); @@ -109,51 +109,8 @@ void Clock::setTime(uint8_t hour, uint8_t minute) { // halb if (minuteselector >= 4 && minuteselector <= 8) printWord(types::halb, Adafruit_NeoPixel::Color(150, 0, 0)); -} -const std::vector types::es = calcPixels(0, 0, 2); -const std::vector types::ist = calcPixels(3, 0, 3); -const std::vector types::fuenf = calcPixels(8, 0, 4); -const std::vector types::zehn = calcPixels(0, 1, 4); -const std::vector types::zwanzig = calcPixels(5, 1, 7); -const std::vector types::drei = calcPixels(1, 2, 3); -const std::vector types::viertel = calcPixels(5, 2, 7); -const std::vector types::dreiviertel = calcPixels(1, 2, 11); -const std::vector types::vor = calcPixels(0, 3, 3); -const std::vector types::nach = calcPixels(3, 3, 4); -const std::vector types::halb = calcPixels(8, 3, 4); -const std::vector types::zwoelf = calcPixels(0, 4, 5); -const std::vector types::sieben = calcPixels(6, 4, 6); -const std::vector types::ein = calcPixels(0, 5, 3); -const std::vector types::eins = calcPixels(0, 5, 4); -const std::vector types::vier = calcPixels(4, 5, 4); -const std::vector types::acht = calcPixels(8, 5, 4); -const std::vector types::sechs = calcPixels(0, 6, 5); -const std::vector types::zwei = calcPixels(6, 6, 5); -const std::vector types::fuenf2 = calcPixels(1, 7, 5); -const std::vector types::elf = calcPixels(5, 7, 3); -const std::vector types::zehn2 = calcPixels(8, 7, 4); -const std::vector types::neun = calcPixels(0, 8, 4); -const std::vector types::drei2 = calcPixels(4, 8, 4); -const std::vector types::ein2 = calcPixels(6, 8, 3); -const std::vector types::uhr = calcPixels(9, 8, 3); - -uint8_t types::convert(uint8_t x, uint8_t y) { - const bool upRow = (x % 2) == 0; - - int val = x * 9 + y; - // if its a row upwards we need to calculate the additional down and up pixels - if (upRow) - // we need to go the rest down (9 -y) and up (*2) and subtract the too many added 10 - val += ((9 - y) * 2) - 10; - return val; -} - -std::vector types::calcPixels(uint8_t x, uint8_t y, uint8_t nrPixels) { - std::vector vec; - for (uint8_t i = 0; i < nrPixels; i++) { - vec.push_back(convert(x + i, y)); - } - - return vec; -} + // uhr + if (minuteselector == 0) + printWord(types::uhr, Adafruit_NeoPixel::Color(0, 0, 150)); +} \ No newline at end of file diff --git a/src/Clock.h b/src/Clock.h index 7befcec..024cffe 100644 --- a/src/Clock.h +++ b/src/Clock.h @@ -9,12 +9,14 @@ #include "Adafruit_NeoPixel.h" #include "Arduino.h" #include "../.pio/libdeps/node32s/Adafruit NeoPixel/Adafruit_NeoPixel.h" +#include "LoadAnimator.h" #define NUMPIXELS 108 // Popular NeoPixel ring size class Clock { private: Adafruit_NeoPixel strip{}; + LoadAnimator animator; void paintAllwaysOnLeds(); void printWord(std::vector word, uint32_t color); @@ -27,22 +29,6 @@ class Clock { Ticker refreshTicker; }; -struct types { - static const std::vector - es, ist, fuenf, - zehn, zwanzig, drei, - viertel, dreiviertel, vor, - nach, halb, zwoelf, - sieben, ein, eins, - vier, acht, sechs, - zwei, fuenf2, elf, - zehn2, neun, drei2, - ein2, uhr; - - static uint8_t convert(uint8_t x, uint8_t y); - - static std::vector calcPixels(uint8_t x, uint8_t y, uint8_t nrPixels); -}; #endif // LEDSTRIPINTERFACE_CLOCK_H diff --git a/src/LoadAnimator.cpp b/src/LoadAnimator.cpp new file mode 100644 index 0000000..b131de4 --- /dev/null +++ b/src/LoadAnimator.cpp @@ -0,0 +1,42 @@ +// +// Created by lukas on 06.03.21. +// + +#include "LoadAnimator.h" +#include "Types.h" + +void LoadAnimator::startLoadAnimation(Adafruit_NeoPixel* 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; + }); +} + +void LoadAnimator::stopLoadAnimation() { + timer.detach(); +} +LoadAnimator::LoadAnimator() : timer(), x(0), y(0), nro(0), nroo(0), nrooo(0) { +} diff --git a/src/LoadAnimator.h b/src/LoadAnimator.h new file mode 100644 index 0000000..913fb91 --- /dev/null +++ b/src/LoadAnimator.h @@ -0,0 +1,23 @@ +// +// Created by lukas on 06.03.21. +// + +#ifndef LEDSTRIPINTERFACE_LOADANIMATOR_H +#define LEDSTRIPINTERFACE_LOADANIMATOR_H + +#include +#include "../.pio/libdeps/esp12e/Adafruit NeoPixel/Adafruit_NeoPixel.h" + +class LoadAnimator { + private: + Ticker timer; + uint8_t x, y, nro, nroo, nrooo; + + public: + LoadAnimator(); + + void startLoadAnimation(Adafruit_NeoPixel *strip); + void stopLoadAnimation(); +}; + +#endif // LEDSTRIPINTERFACE_LOADANIMATOR_H diff --git a/src/Types.cpp b/src/Types.cpp new file mode 100644 index 0000000..b2f3613 --- /dev/null +++ b/src/Types.cpp @@ -0,0 +1,52 @@ +// +// Created by lukas on 06.03.21. +// + +#include "Types.h" + +const std::vector types::es = calcPixels(0, 0, 2); +const std::vector types::ist = calcPixels(3, 0, 3); +const std::vector types::fuenf = calcPixels(8, 0, 4); +const std::vector types::zehn = calcPixels(0, 1, 4); +const std::vector types::zwanzig = calcPixels(5, 1, 7); +const std::vector types::drei = calcPixels(1, 2, 3); +const std::vector types::viertel = calcPixels(5, 2, 7); +const std::vector types::dreiviertel = calcPixels(1, 2, 11); +const std::vector types::vor = calcPixels(0, 3, 3); +const std::vector types::nach = calcPixels(3, 3, 4); +const std::vector types::halb = calcPixels(8, 3, 4); +const std::vector types::zwoelf = calcPixels(0, 4, 5); +const std::vector types::sieben = calcPixels(6, 4, 6); +const std::vector types::ein = calcPixels(0, 5, 3); +const std::vector types::eins = calcPixels(0, 5, 4); +const std::vector types::vier = calcPixels(4, 5, 4); +const std::vector types::acht = calcPixels(8, 5, 4); +const std::vector types::sechs = calcPixels(0, 6, 5); +const std::vector types::zwei = calcPixels(6, 6, 5); +const std::vector types::fuenf2 = calcPixels(1, 7, 5); +const std::vector types::elf = calcPixels(5, 7, 3); +const std::vector types::zehn2 = calcPixels(8, 7, 4); +const std::vector types::neun = calcPixels(0, 8, 4); +const std::vector types::drei2 = calcPixels(4, 8, 4); +const std::vector types::ein2 = calcPixels(6, 8, 3); +const std::vector types::uhr = calcPixels(9, 8, 3); + +uint8_t types::convert(uint8_t x, uint8_t y) { + const bool upRow = (x % 2) == 0; + + int val = x * 9 + y; + // if its a row upwards we need to calculate the additional down and up pixels + if (upRow) + // we need to go the rest down (9 -y) and up (*2) and subtract the too many added 10 + val += ((9 - y) * 2) - 10; + return val; +} + +std::vector types::calcPixels(uint8_t x, uint8_t y, uint8_t nrPixels) { + std::vector vec; + for (uint8_t i = 0; i < nrPixels; i++) { + vec.push_back(convert(x + i, y)); + } + + return vec; +} \ No newline at end of file diff --git a/src/Types.h b/src/Types.h new file mode 100644 index 0000000..2587d2e --- /dev/null +++ b/src/Types.h @@ -0,0 +1,27 @@ +// +// Created by lukas on 06.03.21. +// + +#ifndef LEDSTRIPINTERFACE_TYPES_H +#define LEDSTRIPINTERFACE_TYPES_H + +#include "Arduino.h" + +struct types { + static const std::vector + es, ist, fuenf, + zehn, zwanzig, drei, + viertel, dreiviertel, vor, + nach, halb, zwoelf, + sieben, ein, eins, + vier, acht, sechs, + zwei, fuenf2, elf, + zehn2, neun, drei2, + ein2, uhr; + + static uint8_t convert(uint8_t x, uint8_t y); + + static std::vector calcPixels(uint8_t x, uint8_t y, uint8_t nrPixels); +}; + +#endif // LEDSTRIPINTERFACE_TYPES_H diff --git a/src/main.cpp b/src/main.cpp index 90af6c0..c1d063f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,6 +3,9 @@ #define SERIAL_BAUD_RATE 115200 +// version info +#define VERSION "v0.1.0" + AsyncWebServer server(80); ESP8266React esp8266React(&server); @@ -11,6 +14,8 @@ ClockService cservice = ClockService(&server, esp8266React.getSecurityManager()) void setup() { // start serial and filesystem Serial.begin(SERIAL_BAUD_RATE); + Serial.print("Starting WordClock "); + Serial.println(VERSION); // start the framework and demo project esp8266React.begin();