mirror of
https://github.com/joeycastillo/second-movement.git
synced 2025-10-29 11:38:27 +00:00
Fix handling of longitude data > 100, including longitude data recovery in sunrise/sunset face
- Added functions to detect and recover from corrupted longitude data. - Updated the activation process to handle potential corruption by recovering and saving corrected longitude values. - Ensured that longitude values are reset to zero when exceeding valid limits.
This commit is contained in:
parent
e3101749c9
commit
39ca51eeaa
@ -200,6 +200,7 @@ static int16_t _sunrise_sunset_face_latlon_from_struct(sunrise_sunset_lat_lon_se
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
static sunrise_sunset_lat_lon_settings_t _sunrise_sunset_face_struct_from_latlon(int16_t val) {
|
||||
sunrise_sunset_lat_lon_settings_t retval;
|
||||
|
||||
@ -328,6 +329,8 @@ static void _sunrise_sunset_face_advance_digit(sunrise_sunset_state_t *state) {
|
||||
case 0:
|
||||
state->working_longitude.tens = (state->working_longitude.tens + 1) % 18;
|
||||
if (abs(_sunrise_sunset_face_latlon_from_struct(state->working_longitude)) > 18000) {
|
||||
state->working_longitude.hundreds = 0;
|
||||
state->working_longitude.tens = 0;
|
||||
state->working_longitude.ones = 0;
|
||||
state->working_longitude.tenths = 0;
|
||||
state->working_longitude.hundredths = 0;
|
||||
@ -422,6 +425,32 @@ static void _sunrise_sunset_face_advance_digit(sunrise_sunset_state_t *state) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool _sunrise_sunset_face_is_longitude_corrupted(sunrise_sunset_lat_lon_settings_t lon_struct) {
|
||||
int16_t lon_value = _sunrise_sunset_face_latlon_from_struct(lon_struct);
|
||||
return (lon_struct.tens > 9) || (abs(lon_value) > 18000);
|
||||
}
|
||||
|
||||
static sunrise_sunset_lat_lon_settings_t _sunrise_sunset_face_recover_longitude(sunrise_sunset_lat_lon_settings_t corrupted) {
|
||||
sunrise_sunset_lat_lon_settings_t recovered = {0};
|
||||
|
||||
if (corrupted.tens > 9) {
|
||||
recovered.hundreds = corrupted.tens / 10;
|
||||
recovered.tens = corrupted.tens % 10;
|
||||
recovered.ones = corrupted.ones;
|
||||
recovered.tenths = corrupted.tenths;
|
||||
recovered.hundredths = corrupted.hundredths;
|
||||
recovered.sign = corrupted.sign;
|
||||
|
||||
int16_t recovered_value = _sunrise_sunset_face_latlon_from_struct(recovered);
|
||||
if (abs(recovered_value) <= 18000) {
|
||||
return recovered;
|
||||
}
|
||||
}
|
||||
|
||||
memset(&recovered, 0, sizeof(recovered));
|
||||
return recovered;
|
||||
}
|
||||
|
||||
void sunrise_sunset_face_setup(uint8_t watch_face_index, void ** context_ptr) {
|
||||
(void) watch_face_index;
|
||||
if (*context_ptr == NULL) {
|
||||
@ -453,6 +482,16 @@ void sunrise_sunset_face_activate(void *context) {
|
||||
movement_location_t movement_location = load_location_from_filesystem();
|
||||
state->working_latitude = _sunrise_sunset_face_struct_from_latlon(movement_location.bit.latitude);
|
||||
state->working_longitude = _sunrise_sunset_face_struct_from_latlon(movement_location.bit.longitude);
|
||||
|
||||
// Detect and recover from corrupted longitude data
|
||||
if (_sunrise_sunset_face_is_longitude_corrupted(state->working_longitude)) {
|
||||
sunrise_sunset_lat_lon_settings_t recovered = _sunrise_sunset_face_recover_longitude(state->working_longitude);
|
||||
state->working_longitude = recovered;
|
||||
|
||||
// Save the corrected location immediately
|
||||
state->location_changed = true;
|
||||
_sunrise_sunset_face_update_location_register(state);
|
||||
}
|
||||
}
|
||||
|
||||
bool sunrise_sunset_face_loop(movement_event_t event, void *context) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user