]> git.earman.xyz Git - sensor-watch.git/commitdiff
Merge PR #268 - add daylight savings time toggle
authorMatheus Afonso Martins Moreira <matheus@matheusmoreira.com>
Sun, 8 Sep 2024 14:09:10 +0000 (11:09 -0300)
committerMatheus Afonso Martins Moreira <matheus@matheusmoreira.com>
Sun, 8 Sep 2024 14:09:10 +0000 (11:09 -0300)
Adds a toggle in the preferences face that allows the user
to enable or disable the daylight savings time.

Should help produce the correct results with the sunrise/sunset presets.

A proper solution would be to integrate the tzinfo database
but it's too big for the watch at the time of this writing.
Can't be done unless it can be shrunk down into a subset
the user would be interested. Even then it's a stopgap
since the database is likely to keep growing over time.

Reviewed-by: Matheus Afonso Martins Moreira <matheus@matheusmoreira.com>
GitHub-Pull-Request: https://github.com/joeycastillo/Sensor-Watch/pull/268

1  2 
movement/movement.c
movement/movement.h
movement/watch_faces/settings/set_time_face.c

Simple merge
index 2158b7dd45454d900190d59c0b8fbceae7de851e,d61d510662177735d280437148bf187773725737..929552f1faf08beb8ba225aad6d11b6d7caaef45
@@@ -60,10 -60,10 +60,11 @@@ typedef union 
          // time-oriented complication like a sunrise/sunset timer, and a simple locale preference could tell an
          // altimeter to display feet or meters as easily as it tells a thermometer to display degrees in F or C.
          bool clock_mode_24h : 1;            // indicates whether clock should use 12 or 24 hour mode.
 +        bool clock_24h_leading_zero : 1;    // indicates whether clock should leading zero to indicate 24 hour mode.
          bool use_imperial_units : 1;        // indicates whether to use metric units (the default) or imperial.
          bool alarm_enabled : 1;             // indicates whether there is at least one alarm enabled.
-         uint8_t reserved : 5;               // room for more preferences if needed.
+         bool dst_active : 1;                // indicates whether daylight savings time is active
 -        uint8_t reserved : 5;               // room for more preferences if needed.
++        uint8_t reserved : 4;               // room for more preferences if needed.
      } bit;
      uint32_t reg;
  } movement_settings_t;
index 605849f5e9d531705fcf10ef278fa3ab90d3d9db,fb0c80640872167e8d695fdb1df867187d91af31..d50d24be01c11da0671cc41493dee77baecbb713
  #include <stdlib.h>
  #include "set_time_face.h"
  #include "watch.h"
 +#include "watch_utility.h"
  
- #define SET_TIME_FACE_NUM_SETTINGS (7)
- const char set_time_face_titles[SET_TIME_FACE_NUM_SETTINGS][3] = {"HR", "M1", "SE", "YR", "MO", "DA", "ZO"};
+ #define SET_TIME_FACE_NUM_SETTINGS (8)
+ const char set_time_face_titles[SET_TIME_FACE_NUM_SETTINGS][3] = {"HR", "M1", "SE", "YR", "MO", "DA", "ZO", "DS"};
  
  static bool _quick_ticks_running;
  
@@@ -59,9 -66,17 +59,19 @@@ static void _handle_alarm_button(moveme
              settings->bit.time_zone++;
              if (settings->bit.time_zone > 40) settings->bit.time_zone = 0;
              break;
+         case 7: // daylight savings time
+             if (settings->bit.dst_active) {  // deactivate DST
+                 date_time.unit.hour = (date_time.unit.hour + 24 - 1) % 24;
+                 settings->bit.time_zone = movement_dst_inverse_jump_table[settings->bit.time_zone];
+             } else {  // activate DST
+                 date_time.unit.hour = (date_time.unit.hour + 1) % 24;
+                 settings->bit.time_zone = movement_dst_jump_table[settings->bit.time_zone];
+             }
+             settings->bit.dst_active = !settings->bit.dst_active;
+             break;
      }
 +    if (date_time.unit.day > days_in_month(date_time.unit.month, date_time.unit.year + WATCH_RTC_REFERENCE_YEAR))
 +        date_time.unit.day = 1;
      watch_rtc_set_date_time(date_time);
  }