Skip to content
Snippets Groups Projects
Commit 1c239c5a authored by q3k's avatar q3k
Browse files

splitflap: use timezone

This is based on time_get_timezone_offset from pycardium, which really
should be available as part of the epicardium API to l0dables. For now
we copy-paste this.
parent ba6cfb03
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,8 @@
#include "tmr_utils.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "render.h"
#include "splitflap.h"
......@@ -26,6 +28,36 @@ void SysTick_Handler() {
tick++;
}
static uint32_t get_timezone_offset(void) {
static uint32_t offset = INT32_MAX;
/* Only read the timezone setting once after starting
* the interpeter to not impact performance */
if (offset == INT32_MAX) {
offset = 3600;
char buf[128];
int ret = epic_config_get_string("timezone", buf, sizeof(buf));
/* Understands formats like +0100, 0100, 100, -0800 */
if (ret == 0 && strlen(buf) > 0) {
errno = 0;
long int timezone = strtol(buf, NULL, 10);
int sign = 1;
if (timezone < 0) {
sign = -1;
timezone = -timezone;
}
if (errno == 0) {
offset = (timezone / 100) * 3600;
offset += (timezone % 100) * 60;
offset *= sign;
}
}
}
return offset;
}
static void sample_rtc(uint32_t *ticks, uint32_t *rtc) {
*rtc = epic_rtc_get_seconds();
*ticks = tick;
......@@ -68,7 +100,7 @@ int main(void) {
// operate in UTC+2. Compensate and show UTC+2 time, even if the user is
// not in this timezone.
// TODO(q3k): file a bug
seconds += 7200;
seconds += get_timezone_offset();
SplitFlap_Draw(theta(), seconds);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment