Move ino file to own directory, minor fixes and updates, fixed scheduling
This commit is contained in:
parent
cda493de2c
commit
858ebac086
|
@ -1,2 +1,3 @@
|
||||||
klock4
|
klock4
|
||||||
|
!klock4/
|
||||||
html_out/
|
html_out/
|
||||||
|
|
|
@ -1,15 +1,20 @@
|
||||||
#include <FastLED.h>
|
|
||||||
#define DATA_PIN 13
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
#include <FastLED.h>
|
||||||
|
#define DATA_PIN 13
|
||||||
|
|
||||||
|
#define SLEEP_DELAY 100
|
||||||
|
#include <DeepSleepScheduler.h>
|
||||||
|
|
||||||
#define ROWS 10
|
#define ROWS 10
|
||||||
#define COLS 11
|
#define COLS 11
|
||||||
|
|
||||||
typedef struct {uint8_t start; uint16_t len;} word_t;
|
typedef struct {uint8_t start; uint16_t len;} word_t;
|
||||||
|
|
||||||
|
#define _ALL ((word_t) {.start= 0, .len=110})
|
||||||
|
|
||||||
#define ES ((word_t) {.start= 0, .len=2})
|
#define ES ((word_t) {.start= 0, .len=2})
|
||||||
#define IST ((word_t) {.start= 3, .len=3})
|
#define IST ((word_t) {.start= 3, .len=3})
|
||||||
#define FUNF_PRE ((word_t) {.start= 7, .len=4})
|
#define FUNF_PRE ((word_t) {.start= 7, .len=4})
|
||||||
|
@ -21,6 +26,7 @@ typedef struct {uint8_t start; uint16_t len;} word_t;
|
||||||
#define HALB ((word_t) {.start= 44, .len=4})
|
#define HALB ((word_t) {.start= 44, .len=4})
|
||||||
#define ELF ((word_t) {.start= 49, .len=3})
|
#define ELF ((word_t) {.start= 49, .len=3})
|
||||||
#define FUNF_UHR ((word_t) {.start= 51, .len=4})
|
#define FUNF_UHR ((word_t) {.start= 51, .len=4})
|
||||||
|
#define EIN ((word_t) {.start= 55, .len=3})
|
||||||
#define EINS ((word_t) {.start= 55, .len=4})
|
#define EINS ((word_t) {.start= 55, .len=4})
|
||||||
#define ZWEI ((word_t) {.start= 62, .len=4})
|
#define ZWEI ((word_t) {.start= 62, .len=4})
|
||||||
#define DREI ((word_t) {.start= 66, .len=4})
|
#define DREI ((word_t) {.start= 66, .len=4})
|
||||||
|
@ -33,8 +39,12 @@ typedef struct {uint8_t start; uint16_t len;} word_t;
|
||||||
#define NEUN ((word_t) {.start=102, .len=4})
|
#define NEUN ((word_t) {.start=102, .len=4})
|
||||||
#define UHR ((word_t) {.start=107, .len=3})
|
#define UHR ((word_t) {.start=107, .len=3})
|
||||||
|
|
||||||
|
#define ST ((word_t) {.start= 38, .len=2})
|
||||||
|
#define EL ((word_t) {.start= 49, .len=2})
|
||||||
|
#define LE ((word_t) {.start= 60, .len=2})
|
||||||
|
|
||||||
word_t HOURS[] = {
|
word_t HOURS[] = {
|
||||||
ZWOLF, EINS, ZWEI, DREI, VIER, FUNF_UHR,
|
ZWOLF, EIN, ZWEI, DREI, VIER, FUNF_UHR,
|
||||||
SECHS, SIEBEN, ACHT, NEUN, ZEHN_UHR, ELF
|
SECHS, SIEBEN, ACHT, NEUN, ZEHN_UHR, ELF
|
||||||
};
|
};
|
||||||
word_t PARTS[] = {
|
word_t PARTS[] = {
|
||||||
|
@ -77,6 +87,10 @@ void settime(time_t ts) {
|
||||||
unsigned int daylight_savings = 1;
|
unsigned int daylight_savings = 1;
|
||||||
unsigned int hour = (ts / (60*60) + timezone + daylight_savings) % 12;
|
unsigned int hour = (ts / (60*60) + timezone + daylight_savings) % 12;
|
||||||
|
|
||||||
|
Serial.print(hour);
|
||||||
|
Serial.print(F(":"));
|
||||||
|
Serial.println(minute);
|
||||||
|
|
||||||
int before = 0;
|
int before = 0;
|
||||||
|
|
||||||
if (minute >= 25) {
|
if (minute >= 25) {
|
||||||
|
@ -103,23 +117,64 @@ void settime(time_t ts) {
|
||||||
if (minute/5 == 5)
|
if (minute/5 == 5)
|
||||||
set(HALB); // '5 before half' requires additional set
|
set(HALB); // '5 before half' requires additional set
|
||||||
|
|
||||||
|
// minute 0 -> "EIN Uhr"
|
||||||
|
// minute N -> "N vor/nach EINS"
|
||||||
|
if(hour == 1 && minute != 0)
|
||||||
|
set(EINS);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
#define UPDATE_INTERVAL_S 5
|
||||||
|
|
||||||
|
time_t ts = 0L; // UTC
|
||||||
|
|
||||||
|
void clockUpdate() {
|
||||||
|
|
||||||
|
settime(ts);
|
||||||
|
|
||||||
|
FastLED.show();
|
||||||
|
|
||||||
|
ts += UPDATE_INTERVAL_S;
|
||||||
|
|
||||||
|
/* drift determined experimentally:
|
||||||
|
* ~3.5 ms "calculation time" per cycle
|
||||||
|
* ~12.6ms/s aka 63.6ms/cycle other drift (wakeup time?)
|
||||||
|
*/
|
||||||
|
#define DRIFT_MS 65
|
||||||
|
#define SCHEDULE_DELAY_MS ((1000 * UPDATE_INTERVAL_S) - DRIFT_MS)
|
||||||
|
scheduler.scheduleDelayed(clockUpdate, SCHEDULE_DELAY_MS);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
Serial.begin(57600);
|
||||||
|
|
||||||
FastLED.addLeds<WS2812,DATA_PIN,GRB>(leds, ROWS*COLS);
|
FastLED.addLeds<WS2812,DATA_PIN,GRB>(leds, ROWS*COLS);
|
||||||
FastLED.setBrightness(64);
|
FastLED.setBrightness(16);
|
||||||
|
|
||||||
|
scheduler.schedule(clockUpdate);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
// TODO: Get actual time from somewhere
|
/*
|
||||||
time_t ts = 1616970481; // UTC
|
set(ST);
|
||||||
|
set(EL);
|
||||||
|
set(LE);
|
||||||
|
FastLED.show();
|
||||||
|
|
||||||
while (1) {
|
Serial.println(F("Please enter unix time stamp:"));
|
||||||
settime(ts);
|
while (Serial.available() == 0);
|
||||||
FastLED.show();
|
while (Serial.available() > 0) {
|
||||||
delay(200);
|
ts = Serial.parseInt();
|
||||||
ts += 5 * 60;
|
if (Serial.read() == '\n')
|
||||||
};
|
break;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
ts = 1618048100L;
|
||||||
|
|
||||||
|
scheduler.execute();
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue