}
void app_setup() {
- struct calendar_date_time date_time;
- watch_get_date_time(&date_time);
- if (date_time.date.year < 2020) {
- date_time.date.year = 2020;
- watch_set_date_time(date_time);
- }
-
watch_enable_external_interrupts();
watch_register_interrupt_callback(BTN_MODE, cb_mode_pressed, INTERRUPT_TRIGGER_RISING);
watch_register_interrupt_callback(BTN_LIGHT, cb_light_pressed, INTERRUPT_TRIGGER_RISING);
watch_enable_display();
- watch_register_tick_callback(cb_tick);
+ watch_rtc_register_tick_callback(cb_tick);
}
/**
}
void log_data() {
- struct calendar_date_time date_time;
- watch_get_date_time(&date_time);
- uint8_t hour = date_time.time.hour;
+ watch_date_time date_time = watch_rtc_get_date_time();
+ uint8_t hour = date_time.unit.hour;
int8_t temperature = read_temperature(NULL);
for(int i = 0; i < MAX_DATA_POINTS - 1; i++) {
}
void do_clock_mode() {
- struct calendar_date_time date_time;
+ watch_date_time date_time = watch_rtc_get_date_time();
const char months[12][3] = {"JA", "FE", "MR", "AR", "MA", "JN", "JL", "AU", "SE", "OC", "NO", "dE"};
- watch_get_date_time(&date_time);
- watch_display_string((char *)months[date_time.date.month - 1], 0);
- sprintf(buf, "%2d%2d%02d%02d", date_time.date.day, date_time.time.hour, date_time.time.min, date_time.time.sec);
+ watch_display_string((char *)months[date_time.unit.month - 1], 0);
+ sprintf(buf, "%2d%2d%02d%02d", date_time.unit.day, date_time.unit.hour, date_time.unit.minute, date_time.unit.second);
watch_display_string(buf, 2);
watch_set_colon();
}
}
void do_set_time_mode() {
- struct calendar_date_time date_time;
+ watch_date_time date_time = watch_rtc_get_date_time();
- watch_get_date_time(&date_time);
watch_display_string(" ", 0);
switch (application_state.page) {
case 0: // hour
- sprintf(buf, "ST t%2d", date_time.time.hour);
+ sprintf(buf, "ST t%2d", date_time.unit.hour);
break;
case 1: // minute
- sprintf(buf, "ST t %02d", date_time.time.min);
+ sprintf(buf, "ST t %02d", date_time.unit.minute);
break;
case 2: // second
- sprintf(buf, "ST t %02d", date_time.time.sec);
+ sprintf(buf, "ST t %02d", date_time.unit.second);
break;
case 3: // year
- sprintf(buf, "ST d%2d", date_time.date.year - 2000);
+ sprintf(buf, "ST d%2d", date_time.unit.year + 20);
break;
case 4: // month
- sprintf(buf, "ST d %02d", date_time.date.month);
+ sprintf(buf, "ST d %02d", date_time.unit.month);
break;
case 5: // day
- sprintf(buf, "ST d %02d", date_time.date.day);
+ sprintf(buf, "ST d %02d", date_time.unit.day);
break;
}
watch_display_string(buf, 0);
}
void set_time_mode_handle_secondary_button() {
- struct calendar_date_time date_time;
- watch_get_date_time(&date_time);
+ watch_date_time date_time = watch_rtc_get_date_time();
const uint8_t days_in_month[12] = {31, 28, 31, 30, 31, 30, 30, 31, 30, 31, 30, 31};
switch (application_state.page) {
case 0: // hour
- date_time.time.hour = (date_time.time.hour + 1) % 24;
+ date_time.unit.hour = (date_time.unit.hour + 1) % 24;
break;
case 1: // minute
- date_time.time.min = (date_time.time.min + 1) % 60;
+ date_time.unit.minute = (date_time.unit.minute + 1) % 60;
break;
case 2: // second
- date_time.time.sec = 0;
+ date_time.unit.second = 0;
break;
case 3: // year
// only allow 2021-2030. fix this sometime next decade
- date_time.date.year = ((date_time.date.year % 10) + 1) + 2020;
+ date_time.unit.year = ((date_time.unit.year % 10) + 1);
break;
case 4: // month
- date_time.date.month = ((date_time.date.month + 1) % 12);
+ date_time.unit.month = ((date_time.unit.month + 1) % 12);
break;
case 5: // day
- date_time.date.day = date_time.date.day + 1;
+ date_time.unit.day = date_time.unit.day + 1;
// can't set to the 29th on a leap year. if it's february 29, set to 11:59 on the 28th.
// and it should roll over.
- if (date_time.date.day > days_in_month[date_time.date.month - 1]) {
- date_time.date.day = 1;
+ if (date_time.unit.day > days_in_month[date_time.unit.month - 1]) {
+ date_time.unit.day = 1;
}
break;
}
- watch_set_date_time(date_time);
+ watch_rtc_set_date_time(date_time);
}
void cb_mode_pressed() {
void cb_tick() {
// TODO: use alarm interrupt to trigger data acquisition.
- struct calendar_date_time date_time;
- watch_get_date_time(&date_time);
- if (date_time.time.min == 0 && date_time.time.sec == 0) {
+ watch_date_time date_time = watch_rtc_get_date_time();
+ if (date_time.unit.minute == 0 && date_time.unit.second == 0) {
log_data();
}
}
void app_setup() {
- struct calendar_date_time date_time;
- watch_get_date_time(&date_time);
- if (date_time.date.year < 2020) {
- date_time.date.year = 2020;
- watch_set_date_time(date_time);
- }
-
watch_enable_external_interrupts();
watch_register_interrupt_callback(BTN_MODE, cb_mode_pressed, INTERRUPT_TRIGGER_RISING);
watch_register_interrupt_callback(BTN_LIGHT, cb_light_pressed, INTERRUPT_TRIGGER_RISING);
watch_enable_leds();
watch_enable_display();
- watch_register_tick_callback(cb_tick);
+ watch_rtc_register_tick_callback(cb_tick);
}
void app_prepare_for_sleep() {
}
void do_clock_mode() {
- struct calendar_date_time date_time;
+ watch_date_time date_time = watch_rtc_get_date_time();
const char months[12][3] = {"JA", "FE", "MR", "AR", "MA", "JN", "JL", "AU", "SE", "OC", "NO", "dE"};
- watch_get_date_time(&date_time);
- watch_display_string((char *)months[date_time.date.month - 1], 0);
- sprintf(buf, "%2d%2d%02d%02d", date_time.date.day, date_time.time.hour, date_time.time.min, date_time.time.sec);
+ watch_display_string((char *)months[date_time.unit.month - 1], 0);
+ sprintf(buf, "%2d%2d%02d%02d", date_time.unit.day, date_time.unit.hour, date_time.unit.minute, date_time.unit.second);
watch_display_string(buf, 2);
watch_set_colon();
+
}
void do_beats_mode() {
watch_clear_colon();
- struct calendar_date_time date_time;
-
- watch_get_date_time(&date_time);
-
- uint16_t beats = clock2beats(date_time.time.hour, date_time.time.min, date_time.time.sec, UTC_OFFSET);
+ watch_date_time date_time = watch_rtc_get_date_time();
+ uint16_t beats = clock2beats(date_time.unit.hour, date_time.unit.minute, date_time.unit.second, UTC_OFFSET);
sprintf(buf, "bt %04d ", beats);
watch_display_string(buf, 0);
}
void do_set_time_mode() {
- struct calendar_date_time date_time;
+ watch_date_time date_time = watch_rtc_get_date_time();
- watch_get_date_time(&date_time);
watch_display_string(" ", 0);
switch (application_state.page) {
case 0: // hour
- sprintf(buf, "ST t%2d", date_time.time.hour);
+ sprintf(buf, "ST t%2d", date_time.unit.hour);
break;
case 1: // minute
- sprintf(buf, "ST t %02d", date_time.time.min);
+ sprintf(buf, "ST t %02d", date_time.unit.minute);
break;
case 2: // second
- sprintf(buf, "ST t %02d", date_time.time.sec);
+ sprintf(buf, "ST t %02d", date_time.unit.second);
break;
case 3: // year
- sprintf(buf, "ST d%2d", date_time.date.year - 2000);
+ sprintf(buf, "ST d%2d", date_time.unit.year + 20);
break;
case 4: // month
- sprintf(buf, "ST d %02d", date_time.date.month);
+ sprintf(buf, "ST d %02d", date_time.unit.month);
break;
case 5: // day
- sprintf(buf, "ST d %02d", date_time.date.day);
+ sprintf(buf, "ST d %02d", date_time.unit.day);
break;
}
watch_display_string(buf, 0);
}
void set_time_mode_handle_secondary_button() {
- struct calendar_date_time date_time;
- watch_get_date_time(&date_time);
+ watch_date_time date_time = watch_rtc_get_date_time();
const uint8_t days_in_month[12] = {31, 28, 31, 30, 31, 30, 30, 31, 30, 31, 30, 31};
switch (application_state.page) {
case 0: // hour
- date_time.time.hour = (date_time.time.hour + 1) % 24;
+ date_time.unit.hour = (date_time.unit.hour + 1) % 24;
break;
case 1: // minute
- date_time.time.min = (date_time.time.min + 1) % 60;
+ date_time.unit.minute = (date_time.unit.minute + 1) % 60;
break;
case 2: // second
- date_time.time.sec = 0;
+ date_time.unit.second = 0;
break;
case 3: // year
// only allow 2021-2030. fix this sometime next decade
- date_time.date.year = ((date_time.date.year % 10) + 1) + 2020;
+ date_time.unit.year = ((date_time.unit.year % 10) + 1);
break;
case 4: // month
- date_time.date.month = ((date_time.date.month + 1) % 12);
+ date_time.unit.month = ((date_time.unit.month + 1) % 12);
break;
case 5: // day
- date_time.date.day = date_time.date.day + 1;
+ date_time.unit.day = date_time.unit.day + 1;
// can't set to the 29th on a leap year. if it's february 29, set to 11:59 on the 28th.
// and it should roll over.
- if (date_time.date.day > days_in_month[date_time.date.month - 1]) {
- date_time.date.day = 1;
+ if (date_time.unit.day > days_in_month[date_time.unit.month - 1]) {
+ date_time.unit.day = 1;
}
break;
}
- watch_set_date_time(date_time);
+ watch_rtc_set_date_time(date_time);
}
void cb_mode_pressed() {