Optimize finetune and nanosec faces to work with rtc-counter32

This commit is contained in:
Alessandro Genova
2025-08-02 23:06:45 -04:00
parent 6e23421df4
commit e2d13e076e
5 changed files with 28 additions and 33 deletions

View File

@ -535,8 +535,22 @@ watch_date_time_t movement_get_local_date_time(void) {
return watch_utility_date_time_from_unix_time(timestamp, movement_get_current_timezone_offset()); return watch_utility_date_time_from_unix_time(timestamp, movement_get_current_timezone_offset());
} }
uint32_t movement_get_utc_timestamp(void) {
return watch_rtc_get_unix_time();
}
void movement_set_utc_date_time(watch_date_time_t date_time) { void movement_set_utc_date_time(watch_date_time_t date_time) {
watch_rtc_set_date_time(date_time); movement_set_utc_timestamp(watch_utility_date_time_to_unix_time(date_time, 0));
}
void movement_set_local_date_time(watch_date_time_t date_time) {
int32_t current_offset = movement_get_current_timezone_offset();
watch_date_time_t utc_date_time = watch_utility_date_time_convert_zone(date_time, current_offset, 0);
movement_set_utc_date_time(utc_date_time);
}
void movement_set_utc_timestamp(uint32_t timestamp) {
watch_rtc_set_unix_time(timestamp);
// If the time was changed, the top of the minute alarm needs to be reset accordingly // If the time was changed, the top of the minute alarm needs to be reset accordingly
_movement_set_top_of_minute_alarm(); _movement_set_top_of_minute_alarm();
@ -547,11 +561,6 @@ void movement_set_utc_date_time(watch_date_time_t date_time) {
_movement_update_dst_offset_cache(); _movement_update_dst_offset_cache();
} }
void movement_set_local_date_time(watch_date_time_t date_time) {
int32_t current_offset = movement_get_current_timezone_offset();
watch_date_time_t utc_date_time = watch_utility_date_time_convert_zone(date_time, current_offset, 0);
movement_set_utc_date_time(utc_date_time);
}
bool movement_button_should_sound(void) { bool movement_button_should_sound(void) {
return movement_state.settings.bit.button_should_sound; return movement_state.settings.bit.button_should_sound;

View File

@ -331,9 +331,11 @@ void movement_set_timezone_index(uint8_t value);
watch_date_time_t movement_get_utc_date_time(void); watch_date_time_t movement_get_utc_date_time(void);
watch_date_time_t movement_get_local_date_time(void); watch_date_time_t movement_get_local_date_time(void);
watch_date_time_t movement_get_date_time_in_zone(uint8_t zone_index); watch_date_time_t movement_get_date_time_in_zone(uint8_t zone_index);
uint32_t movement_get_utc_timestamp(void);
void movement_set_utc_date_time(watch_date_time_t date_time); void movement_set_utc_date_time(watch_date_time_t date_time);
void movement_set_local_date_time(watch_date_time_t date_time); void movement_set_local_date_time(watch_date_time_t date_time);
void movement_set_utc_timestamp(uint32_t timestamp);
bool movement_button_should_sound(void); bool movement_button_should_sound(void);
void movement_set_button_should_sound(bool value); void movement_set_button_should_sound(bool value);

View File

@ -27,7 +27,6 @@
#include <math.h> #include <math.h>
#include "finetune_face.h" #include "finetune_face.h"
#include "nanosec_face.h" #include "nanosec_face.h"
#include "watch_utility.h"
#include "delay.h" #include "delay.h"
extern nanosec_state_t nanosec_state; extern nanosec_state_t nanosec_state;
@ -51,7 +50,7 @@ void finetune_face_activate(void *context) {
} }
static float finetune_get_hours_passed(void) { static float finetune_get_hours_passed(void) {
uint32_t current_time = watch_utility_date_time_to_unix_time(watch_rtc_get_date_time(), 0); uint32_t current_time = movement_get_utc_timestamp();
return (current_time - nanosec_state.last_correction_time) / 3600.0f; return (current_time - nanosec_state.last_correction_time) / 3600.0f;
} }
@ -64,7 +63,7 @@ static void finetune_update_display(void) {
if (finetune_page == 0) { if (finetune_page == 0) {
watch_display_text_with_fallback(WATCH_POSITION_TOP_LEFT, "FTU", "FT"); watch_display_text_with_fallback(WATCH_POSITION_TOP_LEFT, "FTU", "FT");
watch_date_time_t date_time = watch_rtc_get_date_time(); watch_date_time_t date_time = movement_get_utc_date_time();
sprintf(buf, "%04d%02d", abs(total_adjustment), date_time.unit.second); sprintf(buf, "%04d%02d", abs(total_adjustment), date_time.unit.second);
watch_display_text(WATCH_POSITION_BOTTOM, buf); watch_display_text(WATCH_POSITION_BOTTOM, buf);
@ -106,17 +105,9 @@ static void finetune_adjust_subseconds(int delta) {
watch_rtc_enable(false); watch_rtc_enable(false);
delay_ms(delta); delay_ms(delta);
if (delta > 500) { if (delta > 500) {
watch_date_time_t date_time = movement_get_utc_date_time(); uint32_t timestamp = movement_get_utc_timestamp();
date_time.unit.second = (date_time.unit.second + 1) % 60; timestamp += 1;
if (date_time.unit.second == 0) { // Overflow movement_set_utc_timestamp(timestamp);
date_time.unit.minute = (date_time.unit.minute + 1) % 60;
if (date_time.unit.minute == 0) { // Overflow
date_time.unit.hour = (date_time.unit.hour + 1) % 24;
if (date_time.unit.hour == 0) // Overflow
date_time.unit.day++;
}
}
movement_set_utc_date_time(date_time);
} }
watch_rtc_enable(true); watch_rtc_enable(true);
} }
@ -126,7 +117,7 @@ static void finetune_update_correction_time(void) {
nanosec_state.freq_correction += roundf(nanosec_get_aging() * 100); nanosec_state.freq_correction += roundf(nanosec_get_aging() * 100);
// Remember when we last corrected time // Remember when we last corrected time
nanosec_state.last_correction_time = watch_utility_date_time_to_unix_time(watch_rtc_get_date_time(), 0); nanosec_state.last_correction_time = movement_get_utc_timestamp();
nanosec_save(); nanosec_save();
movement_move_to_face(0); // Go to main face after saving settings movement_move_to_face(0); // Go to main face after saving settings
} }
@ -146,7 +137,7 @@ bool finetune_face_loop(movement_event_t event, void *context) {
// We flash green LED once per minute to measure clock error, when we are not on first screen // We flash green LED once per minute to measure clock error, when we are not on first screen
if (finetune_page!=0) { if (finetune_page!=0) {
watch_date_time_t date_time; watch_date_time_t date_time;
date_time = watch_rtc_get_date_time(); date_time = movement_get_utc_date_time();
if (date_time.unit.second == 0) { if (date_time.unit.second == 0) {
watch_set_led_green(); watch_set_led_green();
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__

View File

@ -44,11 +44,6 @@
* worry about aging only on second/third years of watch calibration (if you * worry about aging only on second/third years of watch calibration (if you
* are really looking at less than 10 seconds per year of error). * are really looking at less than 10 seconds per year of error).
* *
* Warning, do not use at the first second of a month, as you might stay at
* the same month and it will surprise you. Just wait 1 second...We are not
* fully replicating RTC timer behavior when RTC is off.
* Simulating months and years is... too much complexity.
*
* For full usage instructions, please refer to the wiki: * For full usage instructions, please refer to the wiki:
* https://www.sensorwatch.net/docs/watchfaces/nanosec/ * https://www.sensorwatch.net/docs/watchfaces/nanosec/
*/ */

View File

@ -27,7 +27,6 @@
#include <math.h> #include <math.h>
#include "nanosec_face.h" #include "nanosec_face.h"
#include "filesystem.h" #include "filesystem.h"
#include "watch_utility.h"
int16_t freq_correction_residual = 0; // Dithering 0.1ppm correction, does not need to be configured. int16_t freq_correction_residual = 0; // Dithering 0.1ppm correction, does not need to be configured.
int16_t freq_correction_previous = -30000; int16_t freq_correction_previous = -30000;
@ -44,8 +43,7 @@ const float voltage_coefficient = 0.241666667 * dithering; // 10 * ppm/V. Nomina
static void nanosec_init_profile(void) { static void nanosec_init_profile(void) {
nanosec_changed = true; nanosec_changed = true;
nanosec_state.correction_cadence = 10; nanosec_state.correction_cadence = 10;
watch_date_time_t date_time = watch_rtc_get_date_time(); nanosec_state.last_correction_time = movement_get_utc_timestamp();
nanosec_state.last_correction_time = watch_utility_date_time_to_unix_time(date_time, 0);
// init data after changing profile - do that once per profile selection // init data after changing profile - do that once per profile selection
switch (nanosec_state.correction_profile) { switch (nanosec_state.correction_profile) {
@ -265,8 +263,8 @@ static void nanosec_next_edit_screen(void) {
float nanosec_get_aging() // Returns aging correction in ppm float nanosec_get_aging() // Returns aging correction in ppm
{ {
watch_date_time_t date_time = watch_rtc_get_date_time(); uint32_t timestamp = movement_get_utc_timestamp();
float years = (watch_utility_date_time_to_unix_time(date_time, 0) - nanosec_state.last_correction_time) / 31536000.0f; // Years passed since finetune float years = (timestamp - nanosec_state.last_correction_time) / 31536000.0f; // Years passed since finetune
return years*nanosec_state.aging_ppm_pa/100.0f; return years*nanosec_state.aging_ppm_pa/100.0f;
} }
@ -377,7 +375,7 @@ movement_watch_face_advisory_t nanosec_face_advise(void *context) {
// No need for background correction if we are on profile 0 - static hardware correction. // No need for background correction if we are on profile 0 - static hardware correction.
if (nanosec_state.correction_profile != 0) { if (nanosec_state.correction_profile != 0) {
watch_date_time_t date_time = watch_rtc_get_date_time(); watch_date_time_t date_time = movement_get_utc_date_time();
retval.wants_background_task = date_time.unit.minute % nanosec_state.correction_cadence == 0; retval.wants_background_task = date_time.unit.minute % nanosec_state.correction_cadence == 0;
} }