]> git.earman.xyz Git - sensor-watch.git/commitdiff
Set time on make (#35)
authorvoloved <36523934+voloved@users.noreply.github.com>
Sun, 6 Jul 2025 14:56:27 +0000 (10:56 -0400)
committerGitHub <noreply@github.com>
Sun, 6 Jul 2025 14:56:27 +0000 (10:56 -0400)
* 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>
gossamer
movement.c
watch-faces/settings/settings_face.c
watch-library/hardware/watch/watch_rtc.c
watch-library/shared/watch/watch_rtc.h
watch-library/simulator/watch/watch_rtc.c

index dd9e89b9a096d58f9d4a8c0ad2b51884be66e3d7..8c9b7a5326023b2ee215cf48168c0f708cc33dc5 160000 (submodule)
--- a/gossamer
+++ b/gossamer
@@ -1 +1 @@
-Subproject commit dd9e89b9a096d58f9d4a8c0ad2b51884be66e3d7
+Subproject commit 8c9b7a5326023b2ee215cf48168c0f708cc33dc5
index 46ca4179c7dee17f8906b6d2c9ef80062d0e817d..8e2c5031f5f9dab9681cee6519093348e6db7f03 100644 (file)
@@ -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;
index 0a17985aacdffa9c7e16d4533bfe4da8350e0ebe..cbadbd56b9759a940fe40ffde764b5cc665392c3 100644 (file)
@@ -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;
index 820a48f3486ea276c7fa56238e8df6b991156fc7..babae30d901b6e0f714d6a22a48d36a794f24481 100644 (file)
@@ -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);
 }
index c590040cec1fd7c522c161d198792563d491bb23..a51fc826331bd2cf9774ecc10b7873ee2b51ebd9 100644 (file)
@@ -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
index 3fdc0d400feaeb9511170b91872c81d0f084f656..40487dc693f37a5347ced27fe02382a0162f834c 100644 (file)
@@ -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);
 }