mirror of
https://github.com/joeycastillo/second-movement.git
synced 2025-10-29 19:47:40 +00:00
Set time on make (#35)
* Time can get set from makefile * Added setting make time into simulator * Added Hash in settings * Added default location * Cuts the Githash to 6 characters in the settings in case the makefile didn't do that already * bump gossamer commit * remove automatic timezone setting * automatic time set: rename MAKEFILE_ to BUILD_ to match gossamer * Revert "Added default location" This reverts commit c24f69450fd40472c4f6cebb790a56c3f0d69cb6. * silence warning * watch_get_init_date_time: explicitly initialize all fields to 0 --------- Co-authored-by: Joey Castillo <joeycastillo@utexas.edu>
This commit is contained in:
parent
7a6f7147ae
commit
154bd54510
2
gossamer
2
gossamer
@ -1 +1 @@
|
||||
Subproject commit dd9e89b9a096d58f9d4a8c0ad2b51884be66e3d7
|
||||
Subproject commit 8c9b7a5326023b2ee215cf48168c0f708cc33dc5
|
||||
11
movement.c
11
movement.c
@ -664,20 +664,17 @@ void app_init(void) {
|
||||
movement_store_settings();
|
||||
}
|
||||
|
||||
// populate the DST offset cache
|
||||
_movement_update_dst_offset_cache();
|
||||
|
||||
watch_date_time_t date_time = watch_rtc_get_date_time();
|
||||
if (date_time.reg == 0) {
|
||||
// at first boot, set year to 2025
|
||||
date_time.unit.year = 2025 - WATCH_RTC_REFERENCE_YEAR;
|
||||
date_time.unit.month = 1;
|
||||
date_time.unit.day = 1;
|
||||
date_time = watch_get_init_date_time();
|
||||
// but convert from local time to UTC
|
||||
date_time = watch_utility_date_time_convert_zone(date_time, movement_get_current_timezone_offset(), 0);
|
||||
watch_rtc_set_date_time(date_time);
|
||||
}
|
||||
|
||||
// populate the DST offset cache
|
||||
_movement_update_dst_offset_cache();
|
||||
|
||||
if (movement_state.accelerometer_motion_threshold == 0) movement_state.accelerometer_motion_threshold = 32;
|
||||
|
||||
movement_state.light_ticks = -1;
|
||||
|
||||
@ -215,6 +215,19 @@ static void blue_led_setting_advance(void) {
|
||||
movement_set_backlight_color(color);
|
||||
}
|
||||
|
||||
static void git_hash_setting_display(uint8_t subsecond) {
|
||||
(void) subsecond;
|
||||
char buf[8];
|
||||
// BUILD_GIT_HASH will already be truncated to 6 characters in the makefile, but this is to be safe.
|
||||
sprintf(buf, "%.6s", BUILD_GIT_HASH);
|
||||
watch_display_text_with_fallback(WATCH_POSITION_TOP_LEFT, "GH ", "GH");
|
||||
watch_display_text(WATCH_POSITION_BOTTOM, buf);
|
||||
}
|
||||
|
||||
static void git_hash_setting_advance(void) {
|
||||
return;
|
||||
}
|
||||
|
||||
void settings_face_setup(uint8_t watch_face_index, void ** context_ptr) {
|
||||
(void) watch_face_index;
|
||||
if (*context_ptr == NULL) {
|
||||
@ -223,6 +236,9 @@ void settings_face_setup(uint8_t watch_face_index, void ** context_ptr) {
|
||||
int8_t current_setting = 0;
|
||||
|
||||
state->num_settings = 5; // baseline, without LED settings
|
||||
#ifdef BUILD_GIT_HASH
|
||||
state->num_settings++;
|
||||
#endif
|
||||
#ifdef WATCH_RED_TCC_CHANNEL
|
||||
state->num_settings++;
|
||||
#endif
|
||||
@ -247,6 +263,11 @@ void settings_face_setup(uint8_t watch_face_index, void ** context_ptr) {
|
||||
state->settings_screens[current_setting].display = low_energy_setting_display;
|
||||
state->settings_screens[current_setting].advance = low_energy_setting_advance;
|
||||
current_setting++;
|
||||
#endif
|
||||
#ifdef BUILD_GIT_HASH
|
||||
state->settings_screens[current_setting].display = git_hash_setting_display;
|
||||
state->settings_screens[current_setting].advance = git_hash_setting_advance;
|
||||
current_setting++;
|
||||
#endif
|
||||
state->settings_screens[current_setting].display = led_duration_setting_display;
|
||||
state->settings_screens[current_setting].advance = led_duration_setting_advance;
|
||||
|
||||
@ -56,6 +56,32 @@ rtc_date_time_t watch_rtc_get_date_time(void) {
|
||||
return rtc_get_date_time();
|
||||
}
|
||||
|
||||
rtc_date_time_t watch_get_init_date_time(void) {
|
||||
rtc_date_time_t date_time;
|
||||
#ifdef BUILD_YEAR
|
||||
date_time.unit.year = BUILD_YEAR;
|
||||
#else
|
||||
date_time.unit.year = 5;
|
||||
#endif
|
||||
#ifdef BUILD_MONTH
|
||||
date_time.unit.month = BUILD_MONTH;
|
||||
#else
|
||||
date_time.unit.month = 1;
|
||||
#endif
|
||||
#ifdef BUILD_DAY
|
||||
date_time.unit.day = BUILD_DAY;
|
||||
#else
|
||||
date_time.unit.day = 1;
|
||||
#endif
|
||||
#ifdef BUILD_HOUR
|
||||
date_time.unit.hour = BUILD_HOUR;
|
||||
#endif
|
||||
#ifdef BUILD_MINUTE
|
||||
date_time.unit.minute = BUILD_MINUTE;
|
||||
#endif
|
||||
return date_time;
|
||||
}
|
||||
|
||||
void watch_rtc_register_tick_callback(watch_cb_t callback) {
|
||||
watch_rtc_register_periodic_callback(callback, 1);
|
||||
}
|
||||
|
||||
@ -68,6 +68,11 @@ void watch_rtc_set_date_time(rtc_date_time_t date_time);
|
||||
*/
|
||||
rtc_date_time_t watch_rtc_get_date_time(void);
|
||||
|
||||
/** @brief Returns the date and time that the watch defaults to when power cycled. Often comes from the Makefile flags.
|
||||
* @return A rtc_date_time_t with the current date and time, with a year value from 0-63 representing 2020-2083.
|
||||
*/
|
||||
rtc_date_time_t watch_get_init_date_time(void);
|
||||
|
||||
/** @brief Registers an alarm callback that will be called when the RTC time matches the target time, as masked
|
||||
* by the provided mask.
|
||||
* @param callback The function you wish to have called when the alarm fires. If this value is NULL, the alarm
|
||||
|
||||
@ -45,11 +45,17 @@ bool _watch_rtc_is_enabled(void) {
|
||||
}
|
||||
|
||||
void _watch_rtc_init(void) {
|
||||
#if EMSCRIPTEN
|
||||
// Shifts the timezone so our local time is converted to UTC and set
|
||||
int32_t time_zone_offset = EM_ASM_INT({
|
||||
return -new Date().getTimezoneOffset() * 60;
|
||||
});
|
||||
#endif
|
||||
#ifdef BUILD_YEAR
|
||||
watch_date_time_t date_time = watch_get_init_date_time();
|
||||
#else
|
||||
watch_date_time_t date_time = watch_rtc_get_date_time();
|
||||
#endif
|
||||
watch_rtc_set_date_time(watch_utility_date_time_convert_zone(date_time, time_zone_offset, 0));
|
||||
}
|
||||
|
||||
@ -80,6 +86,34 @@ watch_date_time_t watch_rtc_get_date_time(void) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
rtc_date_time_t watch_get_init_date_time(void) {
|
||||
rtc_date_time_t date_time = {0};
|
||||
|
||||
#ifdef BUILD_YEAR
|
||||
date_time.unit.year = BUILD_YEAR;
|
||||
#else
|
||||
date_time.unit.year = 5;
|
||||
#endif
|
||||
#ifdef BUILD_MONTH
|
||||
date_time.unit.month = BUILD_MONTH;
|
||||
#else
|
||||
date_time.unit.month = 1;
|
||||
#endif
|
||||
#ifdef BUILD_DAY
|
||||
date_time.unit.day = BUILD_DAY;
|
||||
#else
|
||||
date_time.unit.day = 1;
|
||||
#endif
|
||||
#ifdef BUILD_HOUR
|
||||
date_time.unit.hour = BUILD_HOUR;
|
||||
#endif
|
||||
#ifdef BUILD_MINUTE
|
||||
date_time.unit.minute = BUILD_MINUTE;
|
||||
#endif
|
||||
|
||||
return date_time;
|
||||
}
|
||||
|
||||
void watch_rtc_register_tick_callback(watch_cb_t callback) {
|
||||
watch_rtc_register_periodic_callback(callback, 1);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user