Revert PR #470 - implement automatic DST toggling

The DST code has not yet been fully tested, the upcoming movement
refactor is upon us and it will integrate with the micro timezone
library anyway. Revert it so that next can be merged into main.

This reverts commit ac5bf8cfce, reversing
changes made to 5a8a49a8c7.
This commit is contained in:
Matheus Afonso Martins Moreira
2024-09-17 17:08:32 -03:00
parent 683032219e
commit a9d503b807
32 changed files with 165 additions and 296 deletions

View File

@@ -30,19 +30,6 @@ ext_irq_cb_t btn_alarm_callback;
ext_irq_cb_t a2_callback;
ext_irq_cb_t a4_callback;
static bool dst_skip_rolling_back;
bool get_dst_skip_rolling_back(void) {
return dst_skip_rolling_back;
}
void set_dst_skip_rolling_back(void) {
dst_skip_rolling_back = true;
}
void clear_dst_skip_rolling_back(void) {
dst_skip_rolling_back = false;
}
bool _watch_rtc_is_enabled(void) {
return RTC->MODE2.CTRLA.bit.ENABLE;
}
@@ -73,7 +60,6 @@ void watch_rtc_set_date_time(watch_date_time date_time) {
_sync_rtc(); // Double sync as without it at high Hz faces setting time is unrealiable (specifically, set_time_hackwatch)
RTC->MODE2.CLOCK.reg = date_time.reg;
_sync_rtc();
clear_dst_skip_rolling_back();
}
watch_date_time watch_rtc_get_date_time(void) {

View File

@@ -157,11 +157,5 @@ void watch_rtc_enable(bool en);
*/
void watch_rtc_freqcorr_write(int16_t value, int16_t sign);
/** @brief Returns if we're currently at a point where the we rolled back for DST and need to ignore the next DST segment
*/
bool get_dst_skip_rolling_back(void);
void set_dst_skip_rolling_back(void);
void clear_dst_skip_rolling_back(void);
/// @}
#endif

View File

@@ -83,44 +83,6 @@ uint8_t is_leap(uint16_t y)
return !(y%4) && ((y%100) || !(y%400));
}
uint8_t get_dst_status(watch_date_time date_time) {
watch_date_time dst_start_time;
watch_date_time dst_end_time;
uint32_t unix_dst_start_time;
uint32_t unix_dst_end_time;
uint32_t unix_curr_time;
dst_start_time.unit.year = date_time.unit.year;
dst_start_time.unit.month = 3;
dst_start_time.unit.hour = 2;
dst_start_time.unit.minute = 0;
dst_start_time.unit.second = 0;
dst_start_time.unit.day = 15 - watch_utility_get_iso8601_weekday_number(dst_start_time.unit.year + WATCH_RTC_REFERENCE_YEAR, dst_start_time.unit.month, 1);
unix_dst_start_time = watch_utility_date_time_to_unix_time(dst_start_time, 0);
dst_end_time.unit.year = date_time.unit.year;
dst_end_time.unit.month = 11;
dst_end_time.unit.hour = 2;
dst_end_time.unit.minute = 0;
dst_end_time.unit.second = 0;
dst_end_time.unit.day = 15 - watch_utility_get_iso8601_weekday_number(dst_end_time.unit.year + WATCH_RTC_REFERENCE_YEAR, dst_end_time.unit.month, 1);
unix_dst_end_time = watch_utility_date_time_to_unix_time(dst_end_time, 0);
unix_curr_time = watch_utility_date_time_to_unix_time(date_time, 0);
unix_curr_time -= date_time.unit.second;
if (date_time.unit.second > 45) // In emu, it's been seen that we may trigger at 59sec rather than exactly 0 each time
unix_curr_time += 60;
if (unix_curr_time == unix_dst_start_time) return DST_STARTING;
if (unix_curr_time == unix_dst_end_time) return DST_ENDING;
if (unix_curr_time > unix_dst_end_time || unix_curr_time < unix_dst_start_time) return DST_ENDED;
return DST_OCCURRING;
}
bool dst_occurring(watch_date_time date_time) {
return get_dst_status(date_time) <= DST_OCCURRING;
}
uint16_t watch_utility_days_since_new_year(uint16_t year, uint8_t month, uint8_t day) {
uint16_t DAYS_SO_FAR[] = {
0, // Jan

View File

@@ -45,13 +45,6 @@ typedef struct {
uint32_t days; // 0-4294967295
} watch_duration_t;
typedef enum {
DST_STARTING,
DST_OCCURRING,
DST_ENDING,
DST_ENDED
} dst_t;
/** @brief Returns a two-letter weekday for the given timestamp, suitable for display
* in positions 0-1 of the watch face
* @param date_time The watch_date_time whose weekday you want.
@@ -85,17 +78,6 @@ uint16_t watch_utility_days_since_new_year(uint16_t year, uint8_t month, uint8_t
*/
uint8_t is_leap(uint16_t year);
/** @brief Returns off of dst_t based off if DST is occurring, srted, ended, or none of those.
* @param date_time The watch_date_time that you wish to convert.
* @return DST_OCCURRING, DST_HAPPENING, DST_ENDING, DST_ENDED
*/
uint8_t get_dst_status(watch_date_time date_time);
/** @brief Returns true if it's DST and false otherwise.
* @param date_time The watch_date_time that you wish to convert.
*/
bool dst_occurring(watch_date_time date_time);
/** @brief Returns the UNIX time (seconds since 1970) for a given date/time in UTC.
* @param date_time The watch_date_time that you wish to convert.
* @param year The year of the date you wish to convert.

View File

@@ -39,19 +39,6 @@ ext_irq_cb_t btn_alarm_callback;
ext_irq_cb_t a2_callback;
ext_irq_cb_t a4_callback;
static bool dst_skip_rolling_back;
bool get_dst_skip_rolling_back(void) {
return dst_skip_rolling_back;
}
void set_dst_skip_rolling_back(void) {
dst_skip_rolling_back = true;
}
void clear_dst_skip_rolling_back(void) {
dst_skip_rolling_back = false;
}
bool _watch_rtc_is_enabled(void) {
return true;
}
@@ -70,7 +57,6 @@ void watch_rtc_set_date_time(watch_date_time date_time) {
const date = new Date(year, month - 1, day, hour, minute, second);
return date - Date.now();
}, date_time.reg);
clear_dst_skip_rolling_back();
}
watch_date_time watch_rtc_get_date_time(void) {