have close enough to update less and clean up code
This commit is contained in:
parent
fa35b8bb77
commit
53f11cbd1e
@ -24,42 +24,27 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
#include "close_enough_clock_face.h"
|
#include "close_enough_clock_face.h"
|
||||||
#include "watch.h"
|
#include "watch.h"
|
||||||
#include "watch_utility.h"
|
#include "watch_utility.h"
|
||||||
#include "watch_private_display.h"
|
|
||||||
|
|
||||||
static const char first_words[12][3] = {
|
const char *words[12][2] = {
|
||||||
" ", // "HH OC",
|
{" ", "OC"}, // "HH OC",
|
||||||
" 5", // " 5 past HH",
|
{" 5", " P"}, // " 5 past HH",
|
||||||
"10", // "10 past HH",
|
{"10", " P"}, // "10 past HH",
|
||||||
"15", // "15 past HH",
|
{"15", " P"}, // "15 past HH",
|
||||||
"20", // "20 past HH",
|
{"20", " P"}, // "20 past HH",
|
||||||
"25", // "25 past HH",
|
{"25", " P"}, // "25 past HH",
|
||||||
"30", // "30 past HH",
|
{"30", " P"}, // "30 past HH",
|
||||||
"35", // "35 past HH",
|
{"35", " P"}, // "35 past HH",
|
||||||
"40", // "20 two HH+1",
|
{"40", " P"}, // "40 past HH",
|
||||||
"15", // "15 two HH+1",
|
{"15", " 2"}, // "15 two HH+1",
|
||||||
"10", // "10 two HH+1",
|
{"10", " 2"}, // "10 two HH+1",
|
||||||
" 5" // " 5 two HH+1"
|
{" 5", " 2"}, // " 5 two HH+1",
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char second_words[12][3] = {
|
static const int hour_switch_index = 9;
|
||||||
"OC", // "HH OC",
|
|
||||||
" P", // " 5 past HH",
|
|
||||||
" P", // "10 past HH",
|
|
||||||
" P", // "15 past HH",
|
|
||||||
" P", // "20 past HH",
|
|
||||||
" P", // "25 past HH",
|
|
||||||
" P", // "30 past HH",
|
|
||||||
" P", // "35 past HH",
|
|
||||||
" 2", // "20 two HH+1",
|
|
||||||
" 2", // "15 two HH+1",
|
|
||||||
" 2", // "10 two HH+1",
|
|
||||||
" 2" // " 5 two HH+1"
|
|
||||||
};
|
|
||||||
|
|
||||||
static const int hour_switch_index = 8;
|
|
||||||
|
|
||||||
static void _update_alarm_indicator(bool settings_alarm_enabled, close_enough_clock_state_t *state) {
|
static void _update_alarm_indicator(bool settings_alarm_enabled, close_enough_clock_state_t *state) {
|
||||||
state->alarm_enabled = settings_alarm_enabled;
|
state->alarm_enabled = settings_alarm_enabled;
|
||||||
@ -95,20 +80,26 @@ void close_enough_clock_face_activate(movement_settings_t *settings, void *conte
|
|||||||
|
|
||||||
// this ensures that none of the five_minute_periods will match, so we always rerender when the face activates
|
// this ensures that none of the five_minute_periods will match, so we always rerender when the face activates
|
||||||
state->prev_five_minute_period = -1;
|
state->prev_five_minute_period = -1;
|
||||||
|
state->prev_min_checked = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool close_enough_clock_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
|
bool close_enough_clock_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
|
||||||
close_enough_clock_state_t *state = (close_enough_clock_state_t *)context;
|
close_enough_clock_state_t *state = (close_enough_clock_state_t *)context;
|
||||||
char buf[11];
|
|
||||||
|
|
||||||
|
char buf[11];
|
||||||
watch_date_time date_time;
|
watch_date_time date_time;
|
||||||
|
bool show_next_hour = false;
|
||||||
int prev_five_minute_period;
|
int prev_five_minute_period;
|
||||||
|
int prev_min_checked;
|
||||||
|
int close_enough_hour;
|
||||||
|
|
||||||
switch (event.event_type) {
|
switch (event.event_type) {
|
||||||
case EVENT_ACTIVATE:
|
case EVENT_ACTIVATE:
|
||||||
case EVENT_TICK:
|
case EVENT_TICK:
|
||||||
case EVENT_LOW_ENERGY_UPDATE:
|
case EVENT_LOW_ENERGY_UPDATE:
|
||||||
date_time = watch_rtc_get_date_time();
|
date_time = watch_rtc_get_date_time();
|
||||||
prev_five_minute_period = state->prev_five_minute_period;
|
prev_five_minute_period = state->prev_five_minute_period;
|
||||||
|
prev_min_checked = state->prev_min_checked;
|
||||||
|
|
||||||
// check the battery voltage once a day...
|
// check the battery voltage once a day...
|
||||||
if (date_time.unit.day != state->last_battery_check) {
|
if (date_time.unit.day != state->last_battery_check) {
|
||||||
@ -126,27 +117,51 @@ bool close_enough_clock_face_loop(movement_event_t event, movement_settings_t *s
|
|||||||
watch_set_indicator(WATCH_INDICATOR_LAP);
|
watch_set_indicator(WATCH_INDICATOR_LAP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// same minute, skip update
|
||||||
|
if (date_time.unit.minute == prev_min_checked) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
state->prev_min_checked = date_time.unit.minute;
|
||||||
|
}
|
||||||
|
|
||||||
int five_minute_period = (date_time.unit.minute / 5) % 12;
|
int five_minute_period = (date_time.unit.minute / 5) % 12;
|
||||||
|
|
||||||
|
// If we are 60% to the next 5 interval, move up to the next period
|
||||||
|
if (fmodf(date_time.unit.minute / 5.0f, 1.0f) > 0.5f) {
|
||||||
|
// If we are on the last 5 interval and moving to the next period we need to display the next hour because we are wrapping around
|
||||||
|
if (five_minute_period == 11) {
|
||||||
|
show_next_hour = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
five_minute_period = (five_minute_period + 1) % 12;
|
||||||
|
}
|
||||||
|
|
||||||
// same five_minute_period, skip update
|
// same five_minute_period, skip update
|
||||||
if (five_minute_period == prev_five_minute_period) {
|
if (five_minute_period == prev_five_minute_period) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// move from "x mins past y" to "x mins to y+1"
|
// we don't want to modify date_time.unit.hour just in case other watch faces use it
|
||||||
if (five_minute_period >= hour_switch_index) {
|
close_enough_hour = date_time.unit.hour;
|
||||||
date_time.unit.hour += 1;
|
|
||||||
date_time.unit.hour %= 24;
|
// move from "MM(mins) P HH" to "MM(mins) 2 HH+1"
|
||||||
|
if (five_minute_period >= hour_switch_index || show_next_hour) {
|
||||||
|
close_enough_hour = (close_enough_hour + 1) % 24;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!settings->bit.clock_mode_24h) {
|
if (!settings->bit.clock_mode_24h) {
|
||||||
// if we are in 12 hour mode, do some cleanup.
|
// if we are in 12 hour mode, do some cleanup.
|
||||||
if (date_time.unit.hour < 12) {
|
if (close_enough_hour < 12) {
|
||||||
watch_clear_indicator(WATCH_INDICATOR_PM);
|
watch_clear_indicator(WATCH_INDICATOR_PM);
|
||||||
} else {
|
} else {
|
||||||
watch_set_indicator(WATCH_INDICATOR_PM);
|
watch_set_indicator(WATCH_INDICATOR_PM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close_enough_hour %= 12;
|
||||||
|
if (close_enough_hour == 0) {
|
||||||
|
close_enough_hour = 12;
|
||||||
|
}
|
||||||
|
|
||||||
date_time.unit.hour %= 12;
|
date_time.unit.hour %= 12;
|
||||||
if (date_time.unit.hour == 0) {
|
if (date_time.unit.hour == 0) {
|
||||||
date_time.unit.hour = 12;
|
date_time.unit.hour = 12;
|
||||||
@ -156,14 +171,14 @@ bool close_enough_clock_face_loop(movement_event_t event, movement_settings_t *s
|
|||||||
char first_word[3];
|
char first_word[3];
|
||||||
char second_word[3];
|
char second_word[3];
|
||||||
char third_word[3];
|
char third_word[3];
|
||||||
if (five_minute_period == 0) {
|
if (five_minute_period == 0) { // "HH OC",
|
||||||
sprintf(first_word, "%2d", date_time.unit.hour);
|
sprintf(first_word, "%2d", close_enough_hour);
|
||||||
strncpy(second_word, first_words[five_minute_period], 3);
|
strncpy(second_word, words[five_minute_period][0], 3);
|
||||||
strncpy(third_word, second_words[five_minute_period], 3);
|
strncpy(third_word, words[five_minute_period][1], 3);
|
||||||
} else {
|
} else {
|
||||||
strncpy(first_word, first_words[five_minute_period], 3);
|
strncpy(first_word, words[five_minute_period][0], 3);
|
||||||
strncpy(second_word, second_words[five_minute_period], 3);
|
strncpy(second_word, words[five_minute_period][1], 3);
|
||||||
sprintf(third_word, "%2d", date_time.unit.hour);
|
sprintf(third_word, "%2d", close_enough_hour);
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(
|
sprintf(
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int prev_five_minute_period;
|
int prev_five_minute_period;
|
||||||
|
int prev_min_checked;
|
||||||
uint8_t last_battery_check;
|
uint8_t last_battery_check;
|
||||||
bool battery_low;
|
bool battery_low;
|
||||||
bool alarm_enabled;
|
bool alarm_enabled;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user