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/
|
||||
html_out/
|
||||
|
|
|
@ -1,15 +1,20 @@
|
|||
#include <FastLED.h>
|
||||
#define DATA_PIN 13
|
||||
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <FastLED.h>
|
||||
#define DATA_PIN 13
|
||||
|
||||
#define SLEEP_DELAY 100
|
||||
#include <DeepSleepScheduler.h>
|
||||
|
||||
#define ROWS 10
|
||||
#define COLS 11
|
||||
|
||||
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 IST ((word_t) {.start= 3, .len=3})
|
||||
#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 ELF ((word_t) {.start= 49, .len=3})
|
||||
#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 ZWEI ((word_t) {.start= 62, .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 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[] = {
|
||||
ZWOLF, EINS, ZWEI, DREI, VIER, FUNF_UHR,
|
||||
ZWOLF, EIN, ZWEI, DREI, VIER, FUNF_UHR,
|
||||
SECHS, SIEBEN, ACHT, NEUN, ZEHN_UHR, ELF
|
||||
};
|
||||
word_t PARTS[] = {
|
||||
|
@ -77,6 +87,10 @@ void settime(time_t ts) {
|
|||
unsigned int daylight_savings = 1;
|
||||
unsigned int hour = (ts / (60*60) + timezone + daylight_savings) % 12;
|
||||
|
||||
Serial.print(hour);
|
||||
Serial.print(F(":"));
|
||||
Serial.println(minute);
|
||||
|
||||
int before = 0;
|
||||
|
||||
if (minute >= 25) {
|
||||
|
@ -103,23 +117,64 @@ void settime(time_t ts) {
|
|||
if (minute/5 == 5)
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
#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.setBrightness(64);
|
||||
FastLED.setBrightness(16);
|
||||
|
||||
scheduler.schedule(clockUpdate);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// TODO: Get actual time from somewhere
|
||||
time_t ts = 1616970481; // UTC
|
||||
|
||||
while (1) {
|
||||
settime(ts);
|
||||
/*
|
||||
set(ST);
|
||||
set(EL);
|
||||
set(LE);
|
||||
FastLED.show();
|
||||
delay(200);
|
||||
ts += 5 * 60;
|
||||
};
|
||||
|
||||
Serial.println(F("Please enter unix time stamp:"));
|
||||
while (Serial.available() == 0);
|
||||
while (Serial.available() > 0) {
|
||||
ts = Serial.parseInt();
|
||||
if (Serial.read() == '\n')
|
||||
break;
|
||||
}
|
||||
*/
|
||||
ts = 1618048100L;
|
||||
|
||||
scheduler.execute();
|
||||
|
||||
}
|
Loading…
Reference in New Issue