Compare commits
1 Commits
main
...
9668c246f9
| Author | SHA1 | Date | |
|---|---|---|---|
|
9668c246f9
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,2 @@
|
|||||||
klock4
|
klock4
|
||||||
!klock4/
|
|
||||||
html_out/
|
html_out/
|
||||||
|
|||||||
18
Makefile
18
Makefile
@ -1,18 +0,0 @@
|
|||||||
CC = clang
|
|
||||||
|
|
||||||
LIBS = -lm
|
|
||||||
|
|
||||||
x86:
|
|
||||||
$(CC) $(LIBS) klock4_x86.c -o klock4-x86
|
|
||||||
|
|
||||||
uc:
|
|
||||||
$(CC) $(LIBS) klock4_uc.c -o klock4-uc
|
|
||||||
|
|
||||||
wasm:
|
|
||||||
mkdir -p html_out
|
|
||||||
emcc klock4_wasm.c -s WASM=1 -o html_out/klock4.html --shell-file html_template/shell_minimal.html
|
|
||||||
|
|
||||||
all: x86 uc wasm
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -rf klock4-x86 klock4-uc html_out
|
|
||||||
@ -1,20 +1,15 @@
|
|||||||
#include <stdint.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#include <FastLED.h>
|
#include <FastLED.h>
|
||||||
#define DATA_PIN 13
|
#define DATA_PIN 13
|
||||||
|
|
||||||
#define SLEEP_DELAY 100
|
#include <stdint.h>
|
||||||
#include <DeepSleepScheduler.h>
|
#include <time.h>
|
||||||
|
#include <math.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})
|
||||||
@ -26,7 +21,6 @@ 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})
|
||||||
@ -37,14 +31,11 @@ typedef struct {uint8_t start; uint16_t len;} word_t;
|
|||||||
#define ZWOLF ((word_t) {.start= 94, .len=5})
|
#define ZWOLF ((word_t) {.start= 94, .len=5})
|
||||||
#define ZEHN_UHR ((word_t) {.start= 99, .len=4})
|
#define ZEHN_UHR ((word_t) {.start= 99, .len=4})
|
||||||
#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 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, EIN, ZWEI, DREI, VIER, FUNF_UHR,
|
ZWOLF, EINS, 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[] = {
|
||||||
@ -58,8 +49,6 @@ CRGB leds[ROWS*COLS];
|
|||||||
void set(word_t word) {
|
void set(word_t word) {
|
||||||
CRGB color = CRGB(255,255,255);
|
CRGB color = CRGB(255,255,255);
|
||||||
int dir = 1;
|
int dir = 1;
|
||||||
// because of the snaking LED layout, we need to reverse every second row
|
|
||||||
// i.e. flip the start on the other side and then count backwards
|
|
||||||
if (word.start % 22 >= 11) {
|
if (word.start % 22 >= 11) {
|
||||||
word.start = (word.start/11)*11 + 10 - (word.start % 11);
|
word.start = (word.start/11)*11 + 10 - (word.start % 11);
|
||||||
dir = -1;
|
dir = -1;
|
||||||
@ -87,10 +76,6 @@ 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) {
|
||||||
@ -117,64 +102,22 @@ 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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#define UPDATE_INTERVAL_S 5
|
|
||||||
|
|
||||||
time_t ts = 0L; // UTC
|
|
||||||
|
|
||||||
void clockUpdate() {
|
|
||||||
|
|
||||||
settime(ts);
|
|
||||||
|
|
||||||
FastLED.show();
|
|
||||||
|
|
||||||
ts += UPDATE_INTERVAL_S;
|
|
||||||
|
|
||||||
/* drift determined experimentally:
|
|
||||||
* ~3.5ms/cycle "calculation time"
|
|
||||||
* 60ms/cycle other drift (wakeup time?)
|
|
||||||
*/
|
|
||||||
#define DRIFT_MS 63
|
|
||||||
#define SCHEDULE_DELAY_MS ((1000 * UPDATE_INTERVAL_S) - DRIFT_MS)
|
|
||||||
scheduler.scheduleDelayed(clockUpdate, SCHEDULE_DELAY_MS);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
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(16);
|
FastLED.setBrightness(64);
|
||||||
|
|
||||||
scheduler.schedule(clockUpdate);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
/*
|
time_t ts = 1616970481; // UTC
|
||||||
set(ST);
|
|
||||||
set(EL);
|
while (1) {
|
||||||
set(LE);
|
settime(ts);
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
|
delay(200);
|
||||||
Serial.println(F("Please enter unix time stamp:"));
|
ts += 5 * 60;
|
||||||
while (Serial.available() == 0);
|
};
|
||||||
while (Serial.available() > 0) {
|
|
||||||
ts = Serial.parseInt();
|
|
||||||
if (Serial.read() == '\n')
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
ts = 1618651100L;
|
|
||||||
|
|
||||||
scheduler.execute();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -80,9 +80,7 @@ void settime(time_t ts) {
|
|||||||
float fminute = (float) minute + (float) second / 60;
|
float fminute = (float) minute + (float) second / 60;
|
||||||
minute = 5 * (unsigned int) roundf(fminute / 5);
|
minute = 5 * (unsigned int) roundf(fminute / 5);
|
||||||
|
|
||||||
unsigned int timezone = 1;
|
unsigned int hour = (ts / (60*60) + 1) % 12;
|
||||||
unsigned int daylight_savings = 1;
|
|
||||||
unsigned int hour = (ts / (60*60) + timezone + daylight_savings) % 12;
|
|
||||||
|
|
||||||
//printf("%02d:%02d\n", hour, minute);
|
//printf("%02d:%02d\n", hour, minute);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user