2021-03-06 22:06:09 +01:00
|
|
|
//
|
|
|
|
// Created by lukas on 06.03.21.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "Clock.h"
|
2021-03-06 23:42:48 +01:00
|
|
|
#include "Types.h"
|
2021-03-06 22:06:09 +01:00
|
|
|
|
2021-03-06 23:42:48 +01:00
|
|
|
Clock::Clock() : strip(NUMPIXELS, D5, NEO_GRB + NEO_KHZ800), animator(), refreshTicker() {
|
2021-03-06 22:06:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Clock::init() {
|
|
|
|
strip.begin();
|
|
|
|
strip.clear();
|
|
|
|
strip.show();
|
|
|
|
|
|
|
|
refreshTicker.attach(10, [this]() { this->refreshTime(); });
|
|
|
|
this->refreshTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clock::paintAllwaysOnLeds() {
|
|
|
|
printWord(types::es, Adafruit_NeoPixel::Color(150, 150, 0));
|
|
|
|
printWord(types::ist, Adafruit_NeoPixel::Color(150, 0, 150));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clock::printWord(std::vector<int> word, uint32_t color) {
|
|
|
|
for (const int i : word) {
|
|
|
|
strip.setPixelColor(i, color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clock::refreshTime() {
|
|
|
|
// grab the current instant in unix seconds
|
|
|
|
time_t now = time(nullptr);
|
|
|
|
if (now <= 604800) {
|
2021-03-06 23:42:48 +01:00
|
|
|
animator.startLoadAnimation(&strip);
|
2021-03-06 22:06:09 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-03-06 23:42:48 +01:00
|
|
|
animator.stopLoadAnimation();
|
|
|
|
strip.clear();
|
2021-03-06 22:06:09 +01:00
|
|
|
|
|
|
|
tm* loctime = localtime(&now);
|
|
|
|
|
|
|
|
const uint8_t hour = loctime->tm_hour;
|
|
|
|
const uint8_t minute = loctime->tm_min;
|
|
|
|
|
|
|
|
paintAllwaysOnLeds();
|
|
|
|
setTime(hour, minute);
|
|
|
|
strip.show();
|
|
|
|
|
|
|
|
Serial.print("time now: ");
|
|
|
|
Serial.print(hour);
|
|
|
|
Serial.print("h ");
|
|
|
|
Serial.print(minute);
|
|
|
|
Serial.println("M");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clock::setTime(uint8_t hour, uint8_t minute) {
|
|
|
|
const uint8_t minuteselector = minute / 5;
|
|
|
|
|
|
|
|
// if minuteselector >= 4 +1 to hour
|
|
|
|
if (minuteselector >= 4)
|
|
|
|
hour++;
|
|
|
|
|
|
|
|
// convert to 12h format
|
|
|
|
if (hour >= 12)
|
|
|
|
hour = hour - 12;
|
|
|
|
|
|
|
|
std::vector<int> hourWord;
|
|
|
|
|
2021-03-06 23:42:48 +01:00
|
|
|
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;
|
2021-03-06 22:06:09 +01:00
|
|
|
|
|
|
|
printWord(hourWord, Adafruit_NeoPixel::Color(0, 150, 0));
|
|
|
|
|
|
|
|
// fuenf / zehn / viertl word
|
|
|
|
std::vector<int> minuteWord;
|
|
|
|
if (minuteselector == 1 || minuteselector == 5 || minuteselector == 7 || minuteselector == 11)
|
|
|
|
minuteWord = types::fuenf;
|
|
|
|
else if (minuteselector == 2 || minuteselector == 4 || minuteselector == 8 || minuteselector == 10)
|
|
|
|
minuteWord = types::zehn;
|
|
|
|
else if (minuteselector == 3)
|
|
|
|
minuteWord = types::viertel;
|
|
|
|
else if (minuteselector == 9)
|
|
|
|
minuteWord = types::dreiviertel;
|
|
|
|
else if (minuteselector == 6)
|
|
|
|
minuteWord = types::halb;
|
|
|
|
|
|
|
|
printWord(minuteWord, Adafruit_NeoPixel::Color(0, 150, 0));
|
|
|
|
|
|
|
|
// vor / nach
|
|
|
|
std::vector<int> vornachWord;
|
|
|
|
if (minuteselector == 1 || minuteselector == 2 || minuteselector == 3 || minuteselector == 7 || minuteselector == 8)
|
|
|
|
vornachWord = types::nach;
|
|
|
|
else if (minuteselector == 4 || minuteselector == 5 || minuteselector == 10 || minuteselector == 11)
|
|
|
|
vornachWord = types::vor;
|
|
|
|
printWord(vornachWord, Adafruit_NeoPixel::Color(150, 150, 150));
|
|
|
|
|
|
|
|
// halb
|
|
|
|
if (minuteselector >= 4 && minuteselector <= 8)
|
|
|
|
printWord(types::halb, Adafruit_NeoPixel::Color(150, 0, 0));
|
|
|
|
|
2021-03-06 23:42:48 +01:00
|
|
|
// uhr
|
|
|
|
if (minuteselector == 0)
|
|
|
|
printWord(types::uhr, Adafruit_NeoPixel::Color(0, 0, 150));
|
|
|
|
}
|