add version info, add gitlab build job, outsource types in sperate files, new animator while connecting to network
This commit is contained in:
parent
7dbef0b498
commit
d18b62595b
23
.gitlab-ci.yml
Normal file
23
.gitlab-ci.yml
Normal file
@ -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
|
@ -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
|
||||
|
@ -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<int> word, uint32_t color) {
|
||||
@ -29,14 +29,14 @@ void Clock::printWord(std::vector<int> 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);
|
||||
|
||||
@ -78,7 +78,7 @@ void Clock::setTime(uint8_t hour, uint8_t minute) {
|
||||
: hour == 9 ? types::neun
|
||||
: hour == 10 ? types::zehn2
|
||||
: hour == 11 ? types::elf
|
||||
: hour == 0 ? types::zwoelf
|
||||
: 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<int> types::es = calcPixels(0, 0, 2);
|
||||
const std::vector<int> types::ist = calcPixels(3, 0, 3);
|
||||
const std::vector<int> types::fuenf = calcPixels(8, 0, 4);
|
||||
const std::vector<int> types::zehn = calcPixels(0, 1, 4);
|
||||
const std::vector<int> types::zwanzig = calcPixels(5, 1, 7);
|
||||
const std::vector<int> types::drei = calcPixels(1, 2, 3);
|
||||
const std::vector<int> types::viertel = calcPixels(5, 2, 7);
|
||||
const std::vector<int> types::dreiviertel = calcPixels(1, 2, 11);
|
||||
const std::vector<int> types::vor = calcPixels(0, 3, 3);
|
||||
const std::vector<int> types::nach = calcPixels(3, 3, 4);
|
||||
const std::vector<int> types::halb = calcPixels(8, 3, 4);
|
||||
const std::vector<int> types::zwoelf = calcPixels(0, 4, 5);
|
||||
const std::vector<int> types::sieben = calcPixels(6, 4, 6);
|
||||
const std::vector<int> types::ein = calcPixels(0, 5, 3);
|
||||
const std::vector<int> types::eins = calcPixels(0, 5, 4);
|
||||
const std::vector<int> types::vier = calcPixels(4, 5, 4);
|
||||
const std::vector<int> types::acht = calcPixels(8, 5, 4);
|
||||
const std::vector<int> types::sechs = calcPixels(0, 6, 5);
|
||||
const std::vector<int> types::zwei = calcPixels(6, 6, 5);
|
||||
const std::vector<int> types::fuenf2 = calcPixels(1, 7, 5);
|
||||
const std::vector<int> types::elf = calcPixels(5, 7, 3);
|
||||
const std::vector<int> types::zehn2 = calcPixels(8, 7, 4);
|
||||
const std::vector<int> types::neun = calcPixels(0, 8, 4);
|
||||
const std::vector<int> types::drei2 = calcPixels(4, 8, 4);
|
||||
const std::vector<int> types::ein2 = calcPixels(6, 8, 3);
|
||||
const std::vector<int> 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<int> types::calcPixels(uint8_t x, uint8_t y, uint8_t nrPixels) {
|
||||
std::vector<int> 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));
|
||||
}
|
18
src/Clock.h
18
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<int> word, uint32_t color);
|
||||
@ -27,22 +29,6 @@ class Clock {
|
||||
|
||||
Ticker refreshTicker;
|
||||
};
|
||||
struct types {
|
||||
static const std::vector<int>
|
||||
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<int> calcPixels(uint8_t x, uint8_t y, uint8_t nrPixels);
|
||||
};
|
||||
|
||||
|
||||
#endif // LEDSTRIPINTERFACE_CLOCK_H
|
||||
|
42
src/LoadAnimator.cpp
Normal file
42
src/LoadAnimator.cpp
Normal file
@ -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) {
|
||||
}
|
23
src/LoadAnimator.h
Normal file
23
src/LoadAnimator.h
Normal file
@ -0,0 +1,23 @@
|
||||
//
|
||||
// Created by lukas on 06.03.21.
|
||||
//
|
||||
|
||||
#ifndef LEDSTRIPINTERFACE_LOADANIMATOR_H
|
||||
#define LEDSTRIPINTERFACE_LOADANIMATOR_H
|
||||
|
||||
#include <Ticker.h>
|
||||
#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
|
52
src/Types.cpp
Normal file
52
src/Types.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
//
|
||||
// Created by lukas on 06.03.21.
|
||||
//
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
const std::vector<int> types::es = calcPixels(0, 0, 2);
|
||||
const std::vector<int> types::ist = calcPixels(3, 0, 3);
|
||||
const std::vector<int> types::fuenf = calcPixels(8, 0, 4);
|
||||
const std::vector<int> types::zehn = calcPixels(0, 1, 4);
|
||||
const std::vector<int> types::zwanzig = calcPixels(5, 1, 7);
|
||||
const std::vector<int> types::drei = calcPixels(1, 2, 3);
|
||||
const std::vector<int> types::viertel = calcPixels(5, 2, 7);
|
||||
const std::vector<int> types::dreiviertel = calcPixels(1, 2, 11);
|
||||
const std::vector<int> types::vor = calcPixels(0, 3, 3);
|
||||
const std::vector<int> types::nach = calcPixels(3, 3, 4);
|
||||
const std::vector<int> types::halb = calcPixels(8, 3, 4);
|
||||
const std::vector<int> types::zwoelf = calcPixels(0, 4, 5);
|
||||
const std::vector<int> types::sieben = calcPixels(6, 4, 6);
|
||||
const std::vector<int> types::ein = calcPixels(0, 5, 3);
|
||||
const std::vector<int> types::eins = calcPixels(0, 5, 4);
|
||||
const std::vector<int> types::vier = calcPixels(4, 5, 4);
|
||||
const std::vector<int> types::acht = calcPixels(8, 5, 4);
|
||||
const std::vector<int> types::sechs = calcPixels(0, 6, 5);
|
||||
const std::vector<int> types::zwei = calcPixels(6, 6, 5);
|
||||
const std::vector<int> types::fuenf2 = calcPixels(1, 7, 5);
|
||||
const std::vector<int> types::elf = calcPixels(5, 7, 3);
|
||||
const std::vector<int> types::zehn2 = calcPixels(8, 7, 4);
|
||||
const std::vector<int> types::neun = calcPixels(0, 8, 4);
|
||||
const std::vector<int> types::drei2 = calcPixels(4, 8, 4);
|
||||
const std::vector<int> types::ein2 = calcPixels(6, 8, 3);
|
||||
const std::vector<int> 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<int> types::calcPixels(uint8_t x, uint8_t y, uint8_t nrPixels) {
|
||||
std::vector<int> vec;
|
||||
for (uint8_t i = 0; i < nrPixels; i++) {
|
||||
vec.push_back(convert(x + i, y));
|
||||
}
|
||||
|
||||
return vec;
|
||||
}
|
27
src/Types.h
Normal file
27
src/Types.h
Normal file
@ -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<int>
|
||||
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<int> calcPixels(uint8_t x, uint8_t y, uint8_t nrPixels);
|
||||
};
|
||||
|
||||
#endif // LEDSTRIPINTERFACE_TYPES_H
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user