mirror of
https://github.com/travisgoodspeed/goodwatch
synced 2024-11-21 23:58:31 +00:00
Allow setting timezone offset in beats app
This commit is contained in:
parent
720e96455b
commit
1675a3da79
@ -8,7 +8,12 @@
|
||||
#include "libs/beats.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int ticks;
|
||||
#define CURRENT_UTC_OFFSET 4
|
||||
|
||||
static int ticks;
|
||||
static int setting_offet=0;
|
||||
|
||||
static int16_t utc_offset = CURRENT_UTC_OFFSET;
|
||||
|
||||
//! Initialize the beats.
|
||||
void beats_init() {
|
||||
@ -20,17 +25,28 @@ int beats_exit() {
|
||||
return 0;
|
||||
};
|
||||
|
||||
//! Draw the beats.
|
||||
void beats_draw() {
|
||||
static void draw_setting_offset() {
|
||||
lcd_cleardigit(7);
|
||||
lcd_char(6, 'u');
|
||||
lcd_char(5, 't');
|
||||
lcd_char(4, 'c');
|
||||
lcd_cleardigit(3);
|
||||
lcd_char(2, utc_offset > -1 ? ' ' : '-');
|
||||
uint16_t unsigned_offset = utc_offset > 0 ? utc_offset : (0 - utc_offset);
|
||||
lcd_digit(1, (unsigned_offset / 10) % 10);
|
||||
lcd_digit(0, unsigned_offset % 10);
|
||||
}
|
||||
|
||||
static void draw_beats(int forced) {
|
||||
ticks++;
|
||||
// don't re-draw unless 30 seconds have passed
|
||||
// a "beat" is 86.4 seconds but I can't think of a good way to keep track
|
||||
// of how far along we are in a beat
|
||||
if (ticks < 4 * 30 && ticks != 0) {
|
||||
if (!forced && ticks < 4 * 30 && ticks != 0) {
|
||||
return;
|
||||
}
|
||||
ticks = 0;
|
||||
uint16_t beats = clock2beats(RTCHOUR, RTCMIN, RTCSEC);
|
||||
uint16_t beats = clock2beats(RTCHOUR, RTCMIN, RTCSEC, utc_offset);
|
||||
|
||||
lcd_digit(7, (beats / 100) % 10);
|
||||
lcd_digit(6,(beats / 10) % 10);
|
||||
@ -42,7 +58,34 @@ void beats_draw() {
|
||||
lcd_char(0, 's');
|
||||
};
|
||||
|
||||
//! Draw the beats.
|
||||
void beats_draw(int forced) {
|
||||
if(sidebutton_set()){
|
||||
setting_offet=!setting_offet;
|
||||
forced = 1;
|
||||
}
|
||||
|
||||
if (setting_offet) {
|
||||
draw_setting_offset();
|
||||
} else {
|
||||
draw_beats(forced);
|
||||
}
|
||||
}
|
||||
|
||||
//! A button has been pressed for the beats.
|
||||
int beats_keypress(char ch) {
|
||||
return 1;
|
||||
if(setting_offet) {
|
||||
switch(ch) {
|
||||
case '-':
|
||||
utc_offset--;
|
||||
return 1;
|
||||
case '+':
|
||||
utc_offset++;
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
};
|
@ -10,13 +10,11 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define UTC_OFFSET 4
|
||||
|
||||
uint16_t clock2beats(uint16_t hours, uint16_t minutes, uint16_t seconds) {
|
||||
uint16_t clock2beats(uint16_t hours, uint16_t minutes, uint16_t seconds, int16_t utc_offset) {
|
||||
uint32_t beats = seconds;
|
||||
beats += 60 * minutes;
|
||||
beats += (uint32_t)hours * 60 * 60; //explicit hour cast to work with 16-bit MSP430 arch
|
||||
beats += (UTC_OFFSET + 1) * 60 * 60; // offset from utc + 1 since beats in in UTC+1
|
||||
beats += (utc_offset + 1) * 60 * 60; // offset from utc + 1 since beats in in UTC+1
|
||||
|
||||
beats /= 86.4; // convert to beats
|
||||
beats %= 1000; // truncate to 3 digits for overflow
|
||||
@ -29,6 +27,8 @@ uint16_t clock2beats(uint16_t hours, uint16_t minutes, uint16_t seconds) {
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#define UTC_OFFSET 4
|
||||
|
||||
int main(void) {
|
||||
time_t rawtime;
|
||||
struct tm * timeinfo;
|
||||
@ -36,8 +36,7 @@ int main(void) {
|
||||
time(&rawtime);
|
||||
timeinfo = localtime(&rawtime);
|
||||
printf("Current local time and date: %s", asctime(timeinfo));
|
||||
printf("%u\n", timeinfo->tm_hour);
|
||||
uint16_t beats = clock2beats(timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
|
||||
uint16_t beats = clock2beats(timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, UTC_OFFSET);
|
||||
printf("@%u\n", beats);
|
||||
}
|
||||
|
||||
|
@ -8,4 +8,4 @@
|
||||
https://en.wikipedia.org/wiki/Swatch_Internet_Time
|
||||
*/
|
||||
|
||||
uint16_t clock2beats(uint16_t hours, uint16_t minutes, uint16_t seconds);
|
||||
uint16_t clock2beats(uint16_t hours, uint16_t minutes, uint16_t seconds, int16_t utc_offset);
|
Loading…
Reference in New Issue
Block a user