155 lines
3.1 KiB
C
155 lines
3.1 KiB
C
|
#include <stdint.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <unistd.h>
|
||
|
#include <string.h>
|
||
|
#include <stdio.h>
|
||
|
#include <time.h>
|
||
|
#include <math.h>
|
||
|
|
||
|
#define ROWS 10
|
||
|
#define COLS 11
|
||
|
|
||
|
const unsigned char TEXT[] = "\
|
||
|
ESXISTXFUNF\
|
||
|
ZEHNZWANZIG\
|
||
|
DREIVIERTEL\
|
||
|
VORGESTNACH\
|
||
|
HALBXELFUNF\
|
||
|
EINSXLEZWEI\
|
||
|
DREIXTXVIER\
|
||
|
SECHSXXACHT\
|
||
|
SIEBENZWOLF\
|
||
|
ZEHNEUNXUHR";
|
||
|
|
||
|
typedef struct {uint8_t start; uint16_t len;} word_t;
|
||
|
|
||
|
#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})
|
||
|
#define ZEHN_PRE ((word_t) {.start= 11, .len=4})
|
||
|
#define ZWANZIG ((word_t) {.start= 15, .len=7})
|
||
|
#define VIERTEL ((word_t) {.start= 26, .len=7})
|
||
|
#define VOR ((word_t) {.start= 33, .len=3})
|
||
|
#define NACH ((word_t) {.start= 40, .len=4})
|
||
|
#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 EINS ((word_t) {.start= 55, .len=4})
|
||
|
#define ZWEI ((word_t) {.start= 62, .len=4})
|
||
|
#define DREI ((word_t) {.start= 66, .len=4})
|
||
|
#define VIER ((word_t) {.start= 73, .len=4})
|
||
|
#define SECHS ((word_t) {.start= 77, .len=5})
|
||
|
#define ACHT ((word_t) {.start= 84, .len=4})
|
||
|
#define SIEBEN ((word_t) {.start= 88, .len=6})
|
||
|
#define ZWOLF ((word_t) {.start= 94, .len=5})
|
||
|
#define ZEHN_UHR ((word_t) {.start= 99, .len=4})
|
||
|
#define NEUN ((word_t) {.start=102, .len=4})
|
||
|
#define UHR ((word_t) {.start=107, .len=3})
|
||
|
|
||
|
word_t HOURS[] = {
|
||
|
ZWOLF, EINS, ZWEI, DREI, VIER, FUNF_UHR,
|
||
|
SECHS, SIEBEN, ACHT, NEUN, ZEHN_UHR, ELF
|
||
|
};
|
||
|
word_t PARTS[] = {
|
||
|
UHR, FUNF_PRE, ZEHN_PRE, VIERTEL,
|
||
|
ZWANZIG, FUNF_PRE, HALB
|
||
|
};
|
||
|
|
||
|
|
||
|
uint8_t active[ROWS*COLS] = {0};
|
||
|
|
||
|
void set(word_t word) {
|
||
|
for (unsigned int i = word.start; i < word.start + word.len; i++)
|
||
|
active[i] = 1;
|
||
|
}
|
||
|
|
||
|
void reset(void) {
|
||
|
memset(&active, 0, sizeof(active));
|
||
|
set(ES);
|
||
|
set(IST);
|
||
|
}
|
||
|
|
||
|
|
||
|
void settime(time_t ts) {
|
||
|
|
||
|
unsigned int second = ts % 60;
|
||
|
|
||
|
unsigned int minute = (ts / 60) % 60;
|
||
|
float fminute = (float) minute + (float) second / 60;
|
||
|
minute = 5 * (unsigned int) roundf(fminute / 5);
|
||
|
|
||
|
unsigned int daylight_savings = 1;
|
||
|
unsigned int hour = (ts / (60*60) + 1 + daylight_savings) % 12;
|
||
|
|
||
|
//printf("%02d:%02d\n", hour, minute);
|
||
|
|
||
|
int before = 0;
|
||
|
|
||
|
if (minute >= 25) {
|
||
|
hour = (hour+1) % 12;
|
||
|
before = 1;
|
||
|
minute = 60-minute;
|
||
|
if (minute == 35) {
|
||
|
minute = 25;
|
||
|
before = 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//printf("%02d %s %02d\n", minute, before ? "vor" : "nach", hour);
|
||
|
|
||
|
if (minute == 25)
|
||
|
before = !before;
|
||
|
|
||
|
reset();
|
||
|
|
||
|
if (minute != 0 && minute != 30)
|
||
|
set(before ? VOR : NACH);
|
||
|
|
||
|
set(HOURS[hour]);
|
||
|
set(PARTS[minute/5]);
|
||
|
|
||
|
if (minute/5 == 5)
|
||
|
set(HALB); // '5 before half' requires additional set
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
void dump() {
|
||
|
|
||
|
const char WHITE[] = "\033[1;37m";
|
||
|
const char GRAY[] = "\033[0;30m";
|
||
|
|
||
|
for (int i = 0; i < ROWS*COLS; i++) {
|
||
|
|
||
|
int col = i % COLS;
|
||
|
if (col == 0)
|
||
|
printf("\n ");
|
||
|
|
||
|
const char* color = active[i] ? WHITE : GRAY;
|
||
|
|
||
|
printf(" %s%c", color, TEXT[i]);
|
||
|
|
||
|
}
|
||
|
|
||
|
#define RESET_COLORS "\033[0m"
|
||
|
printf(RESET_COLORS "\n");
|
||
|
|
||
|
}
|
||
|
|
||
|
int main() {
|
||
|
|
||
|
time_t ts = time(NULL);
|
||
|
|
||
|
while (1) {
|
||
|
printf("\033c");
|
||
|
ts = time(NULL);
|
||
|
settime(ts);
|
||
|
dump();
|
||
|
|
||
|
sleep(5);
|
||
|
};
|
||
|
|
||
|
return 0;
|
||
|
|
||
|
}
|