]> git.earman.xyz Git - sensor-watch.git/commitdiff
movement: have beats and TOTP face use new time zone setting
authorJoey Castillo <joeycastillo@utexas.edu>
Thu, 25 Nov 2021 15:47:59 +0000 (10:47 -0500)
committerJoey Castillo <joeycastillo@utexas.edu>
Thu, 25 Nov 2021 15:47:59 +0000 (10:47 -0500)
movement/watch_faces/complications/beats_face.c
movement/watch_faces/complications/totp_face.c

index 95a9aaefa81f5777be59bb713e366a31d879978d..119ddd50e507a8d68d19fd60c62f1c8a2d7ed9f2 100644 (file)
@@ -3,7 +3,6 @@
 #include "beats_face.h"
 #include "watch.h"
 
-const uint8_t UTC_OFFSET = 4; // set to your current UTC offset to see correct beats time
 const uint8_t BEAT_REFRESH_FREQUENCY = 8;
 
 void beats_face_setup(movement_settings_t *settings, void ** context_ptr) {
@@ -29,7 +28,7 @@ bool beats_face_loop(movement_event_t event, movement_settings_t *settings, void
         case EVENT_ACTIVATE:
         case EVENT_TICK:
             date_time = watch_rtc_get_date_time();
-            beats = clock2beats(date_time.unit.hour, date_time.unit.minute, date_time.unit.second, event.subsecond, UTC_OFFSET);
+            beats = clock2beats(date_time.unit.hour, date_time.unit.minute, date_time.unit.second, event.subsecond, movement_timezone_offsets[settings->bit.time_zone]);
             sprintf(buf, "bt  %6.0f", beats * 100);
 
             watch_display_string(buf, 0);
@@ -37,7 +36,7 @@ bool beats_face_loop(movement_event_t event, movement_settings_t *settings, void
         case EVENT_LOW_ENERGY_UPDATE:
             if (!watch_tick_animation_is_running()) watch_start_tick_animation(432);
             date_time = watch_rtc_get_date_time();
-            beats = clock2beats(date_time.unit.hour, date_time.unit.minute, date_time.unit.second, event.subsecond, UTC_OFFSET);
+            beats = clock2beats(date_time.unit.hour, date_time.unit.minute, date_time.unit.second, event.subsecond, movement_timezone_offsets[settings->bit.time_zone]);
             sprintf(buf, "bt  %4d  ", (int)beats);
 
             watch_display_string(buf, 0);
@@ -68,7 +67,7 @@ float clock2beats(uint16_t hours, uint16_t minutes, uint16_t seconds, uint16_t s
     float beats = seconds + ((float)subseconds / (float)BEAT_REFRESH_FREQUENCY);
     beats += 60 * minutes;
     beats += (float)hours * 60 * 60;
-    beats += (utc_offset + 1) * 60 * 60; // offset from utc + 1 since beats in in UTC+1
+    beats -= (utc_offset - 60) * 60; // offset from utc + 1 since beats in in UTC+1
 
     beats /= 86.4; // convert to beats
     while(beats > 1000) beats -= 1000; // beats %= 1000 but for a float
index 4aa1382a6d2d6e59c780b3c89ce5b8e9b7e0d562..4a34d7ad5089ac1e53cb454e36e459a56454ff96 100644 (file)
@@ -1,6 +1,5 @@
 /**
  * TODO:
- * - Add support for UTC offset in settings?
  * - Support for multiple codes
  */
 #include <stdlib.h>
@@ -16,7 +15,6 @@
 static uint8_t hmacKey[] = {0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x21, 0xde, 0xad, 0xbe, 0xef}; // Secret key
 
 
-static const uint8_t UTC_OFFSET = 5; // set to your current UTC offset
 static const uint32_t TIMESTEP = 30;
 
 void totp_face_setup(movement_settings_t *settings, void ** context_ptr) {
@@ -29,7 +27,7 @@ void totp_face_activate(movement_settings_t *settings, void *context) {
     (void) settings;
     memset(context, 0, sizeof(totp_state_t));
     totp_state_t *totp_state = (totp_state_t *)context;
-    totp_state->timestamp = watch_utility_date_time_to_unix_time(watch_rtc_get_date_time(), UTC_OFFSET);
+    totp_state->timestamp = watch_utility_date_time_to_unix_time(watch_rtc_get_date_time(), movement_timezone_offsets[settings->bit.time_zone] * 60);
     totp_state->current_code = getCodeFromTimestamp(totp_state->timestamp);
 }