'movement' -> 'legacy' to signal things we still need to bring in
This commit is contained in:
242
legacy/watch_faces/settings/finetune_face.c
Normal file
242
legacy/watch_faces/settings/finetune_face.c
Normal file
@@ -0,0 +1,242 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2022 Mikhail Svarichevsky https://3.14.by/
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "finetune_face.h"
|
||||
#include "nanosec_face.h"
|
||||
#include "watch_utility.h"
|
||||
|
||||
extern nanosec_state_t nanosec_state;
|
||||
|
||||
int total_adjustment;
|
||||
int8_t finetune_page;
|
||||
|
||||
void finetune_face_setup(uint8_t watch_face_index, void ** context_ptr) {
|
||||
(void) watch_face_index;
|
||||
(void) context_ptr;
|
||||
// Do any pin or peripheral setup here; this will be called whenever the watch wakes from deep sleep.
|
||||
}
|
||||
|
||||
void finetune_face_activate(void *context) {
|
||||
(void) context;
|
||||
|
||||
// Handle any tasks related to your watch face coming on screen.
|
||||
watch_display_string("FT", 0);
|
||||
total_adjustment = 0;
|
||||
finetune_page = 0;
|
||||
}
|
||||
|
||||
static float finetune_get_hours_passed(void) {
|
||||
uint32_t current_time = watch_utility_date_time_to_unix_time(watch_rtc_get_date_time(), 0);
|
||||
return (current_time - nanosec_state.last_correction_time) / 3600.0f;
|
||||
}
|
||||
|
||||
static float finetune_get_correction(void) {
|
||||
return total_adjustment / (finetune_get_hours_passed() * 3600.0f) * 1000.0f;
|
||||
}
|
||||
|
||||
static void finetune_update_display(void) {
|
||||
char buf[25];
|
||||
|
||||
if (finetune_page == 0) {
|
||||
watch_display_string("FT", 0);
|
||||
watch_date_time_t date_time = watch_rtc_get_date_time();
|
||||
sprintf(buf, "%02d", date_time.unit.second);
|
||||
watch_display_string(buf, 8);
|
||||
|
||||
sprintf(buf, "%04d", abs(total_adjustment));
|
||||
watch_display_string(buf, 4);
|
||||
|
||||
if (total_adjustment < 0) {
|
||||
watch_display_string("--", 2);
|
||||
} else {
|
||||
watch_display_string(" ", 2);
|
||||
}
|
||||
} else if (finetune_page == 1) {
|
||||
float hours = finetune_get_hours_passed();
|
||||
|
||||
sprintf(buf, "DT %4d%02d", (int)hours, (int)(fmodf(hours, 1.) * 100));
|
||||
watch_display_string(buf, 0);
|
||||
} else if (finetune_page == 2) {
|
||||
if (finetune_get_hours_passed() < 6) {
|
||||
sprintf(buf, " F 6HR ");
|
||||
watch_display_string(buf, 0);
|
||||
} else {
|
||||
float correction = finetune_get_correction();
|
||||
sprintf(buf, " F%s%2d%04d", (total_adjustment < 0) ? " -" : " ", (int)fabsf(correction), (int)(remainderf(fabsf(correction), 1.) * 10000));
|
||||
watch_display_string(buf, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void finetune_adjust_subseconds(int delta) {
|
||||
// Update display first ot make it appear faster for the user
|
||||
if (delta > 500)
|
||||
total_adjustment += (delta - 1000);
|
||||
else
|
||||
total_adjustment += delta;
|
||||
finetune_update_display();
|
||||
|
||||
// Then delay clock
|
||||
watch_rtc_enable(false);
|
||||
delay_ms(delta);
|
||||
if (delta > 500) {
|
||||
watch_date_time_t date_time = watch_rtc_get_date_time();
|
||||
date_time.unit.second = (date_time.unit.second + 1) % 60;
|
||||
if (date_time.unit.second == 0) { // Overflow
|
||||
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++;
|
||||
}
|
||||
}
|
||||
watch_rtc_set_date_time(date_time);
|
||||
}
|
||||
watch_rtc_enable(true);
|
||||
}
|
||||
|
||||
static void finetune_update_correction_time(void) {
|
||||
// Update aging, as we update correciton time - we must bake accrued aging into static offset
|
||||
nanosec_state.freq_correction += roundf(nanosec_get_aging() * 100);
|
||||
|
||||
// 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_save();
|
||||
movement_move_to_face(0); // Go to main face after saving settings
|
||||
}
|
||||
|
||||
bool finetune_face_loop(movement_event_t event, void *context) {
|
||||
|
||||
(void) context;
|
||||
|
||||
switch (event.event_type) {
|
||||
case EVENT_ACTIVATE:
|
||||
// Show your initial UI here.
|
||||
finetune_update_display();
|
||||
break;
|
||||
|
||||
case EVENT_TICK:
|
||||
// If needed, update your display here, at canonical 0.5sec position.
|
||||
// We flash green LED once per minute to measure clock error, when we are not on first screen
|
||||
if (finetune_page!=0) {
|
||||
watch_date_time_t date_time;
|
||||
date_time = watch_rtc_get_date_time();
|
||||
if (date_time.unit.second == 0) {
|
||||
watch_set_led_green();
|
||||
#ifndef __EMSCRIPTEN__
|
||||
delay_us(500);
|
||||
#endif
|
||||
watch_set_led_off();
|
||||
}
|
||||
}
|
||||
|
||||
finetune_update_display();
|
||||
break;
|
||||
|
||||
case EVENT_MODE_BUTTON_UP:
|
||||
// Only allow for fast exit when correction is 0!!!
|
||||
if (finetune_page == 0 && total_adjustment == 0) {
|
||||
movement_move_to_next_face();
|
||||
} else {
|
||||
finetune_page = (finetune_page + 1) % 3;
|
||||
finetune_update_display();
|
||||
}
|
||||
break;
|
||||
|
||||
case EVENT_MODE_LONG_PRESS:
|
||||
// You shouldn't need to change this case; Mode almost always moves to the next watch face.
|
||||
finetune_page = (finetune_page + 1) % 3;
|
||||
finetune_update_display();
|
||||
break;
|
||||
|
||||
case EVENT_LIGHT_LONG_PRESS:
|
||||
// We are making it slower by 250ms
|
||||
if (finetune_page == 0) {
|
||||
finetune_adjust_subseconds(250);
|
||||
} else if (finetune_page == 2 && finetune_get_hours_passed() >= 6) {
|
||||
// Applying ppm correction, only if >6 hours passed
|
||||
nanosec_state.freq_correction += (int)round(finetune_get_correction() * 100);
|
||||
finetune_update_correction_time();
|
||||
}
|
||||
break;
|
||||
|
||||
case EVENT_LIGHT_BUTTON_UP:
|
||||
// We are making it slower by 25ms
|
||||
if (finetune_page == 0) {
|
||||
finetune_adjust_subseconds(25);
|
||||
}
|
||||
break;
|
||||
|
||||
case EVENT_ALARM_LONG_PRESS:
|
||||
if (finetune_page == 0) {
|
||||
finetune_adjust_subseconds(750);
|
||||
} else if (finetune_page == 2) {
|
||||
// Exit without applying correction to ppm, but update correction time
|
||||
finetune_update_correction_time();
|
||||
}
|
||||
break;
|
||||
|
||||
case EVENT_ALARM_BUTTON_UP:
|
||||
if (finetune_page == 0) {
|
||||
finetune_adjust_subseconds(975);
|
||||
}
|
||||
break;
|
||||
|
||||
case EVENT_TIMEOUT:
|
||||
// Your watch face will receive this event after a period of inactivity. If it makes sense to resign,
|
||||
// you may uncomment this line to move back to the first watch face in the list:
|
||||
if (total_adjustment == 0) // Timeout only works if no adjustment was made
|
||||
movement_move_to_face(0);
|
||||
break;
|
||||
|
||||
case EVENT_LOW_ENERGY_UPDATE:
|
||||
// If you did not resign in EVENT_TIMEOUT, you can use this event to update the display once a minute.
|
||||
// Avoid displaying fast-updating values like seconds, since the display won't update again for 60 seconds.
|
||||
// You should also consider starting the tick animation, to show the wearer that this is sleep mode:
|
||||
// watch_start_sleep_animation(500);
|
||||
break;
|
||||
|
||||
case EVENT_LIGHT_BUTTON_DOWN:
|
||||
// don't light up every time light is hit
|
||||
break;
|
||||
default:
|
||||
movement_default_loop_handler(event);
|
||||
break;
|
||||
}
|
||||
|
||||
// return true if the watch can enter standby mode. If you are PWM'ing an LED or buzzing the buzzer here,
|
||||
// you should return false since the PWM driver does not operate in standby mode.
|
||||
return true;
|
||||
}
|
||||
|
||||
void finetune_face_resign(void *context) {
|
||||
(void) context;
|
||||
|
||||
if (total_adjustment != 0) {
|
||||
finetune_update_correction_time();
|
||||
}
|
||||
}
|
||||
77
legacy/watch_faces/settings/finetune_face.h
Normal file
77
legacy/watch_faces/settings/finetune_face.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2022 Mikhail Svarichevsky https://3.14.by/
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef FINETUNE_FACE_H_
|
||||
#define FINETUNE_FACE_H_
|
||||
|
||||
/*
|
||||
* FINETUNE face
|
||||
*
|
||||
* FineTune face allows to align watch with sub-second precision in 25/250ms
|
||||
* accuracy. Counts time since previous finetune, and allows to calculate &
|
||||
* apply ppm correction for nanosec.
|
||||
*
|
||||
* Best used in conjunction with the NANOSEC face.
|
||||
*
|
||||
* Main screen - adjust delay (light/alarm)
|
||||
* Long MODE press - show hours since previous finetune
|
||||
* Long MODE press - show calculated ppm correction.
|
||||
* You can apply it with long LIGHT, or just reset finetune timer with long ALARM.
|
||||
*
|
||||
* Finetune will apply crystal aging correction on every finetune save
|
||||
* (as aging is calculated since "last finetune" timestamp); but you should
|
||||
* 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).
|
||||
*
|
||||
* 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:
|
||||
* https://www.sensorwatch.net/docs/watchfaces/nanosec/
|
||||
*/
|
||||
|
||||
#include "movement.h"
|
||||
|
||||
typedef struct {
|
||||
// Anything you need to keep track of, put it here!
|
||||
uint8_t unused;
|
||||
} finetune_state_t;
|
||||
|
||||
void finetune_face_setup(uint8_t watch_face_index, void ** context_ptr);
|
||||
void finetune_face_activate(void *context);
|
||||
bool finetune_face_loop(movement_event_t event, void *context);
|
||||
void finetune_face_resign(void *context);
|
||||
|
||||
#define finetune_face ((const watch_face_t){ \
|
||||
finetune_face_setup, \
|
||||
finetune_face_activate, \
|
||||
finetune_face_loop, \
|
||||
finetune_face_resign, \
|
||||
NULL, \
|
||||
})
|
||||
|
||||
#endif // FINETUNE_FACE_H_
|
||||
|
||||
375
legacy/watch_faces/settings/nanosec_face.c
Normal file
375
legacy/watch_faces/settings/nanosec_face.c
Normal file
@@ -0,0 +1,375 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2022 Mikhail Svarichevsky https://3.14.by/
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "thermistor_driver.h"
|
||||
#include "nanosec_face.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_previous = -30000;
|
||||
#define dithering 31
|
||||
|
||||
nanosec_state_t nanosec_state;
|
||||
|
||||
#define nanosec_max_screen 7
|
||||
int8_t nanosec_screen = 0;
|
||||
bool nanosec_changed = false; // We try to avoid saving settings when no changes were made, for example when just browsing through face
|
||||
|
||||
const float voltage_coefficient = 0.241666667 * dithering; // 10 * ppm/V. Nominal frequency is at 3V.
|
||||
|
||||
static void nanosec_init_profile(void) {
|
||||
nanosec_changed = true;
|
||||
nanosec_state.correction_cadence = 10;
|
||||
watch_date_time_t date_time = watch_rtc_get_date_time();
|
||||
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
|
||||
switch (nanosec_state.correction_profile) {
|
||||
case 0: // No tempco, no dithering
|
||||
nanosec_state.freq_correction = 0;
|
||||
nanosec_state.center_temperature = 2500;
|
||||
nanosec_state.quadratic_tempco = 0;
|
||||
nanosec_state.cubic_tempco = 0;
|
||||
nanosec_state.aging_ppm_pa = 0;
|
||||
break;
|
||||
case 1: // No tempco, with dithering
|
||||
nanosec_state.freq_correction = 0;
|
||||
nanosec_state.center_temperature = 2500;
|
||||
nanosec_state.quadratic_tempco = 0;
|
||||
nanosec_state.cubic_tempco = 0;
|
||||
nanosec_state.aging_ppm_pa = 0;
|
||||
break;
|
||||
case 2: // Datasheet correction
|
||||
nanosec_state.freq_correction = 0;
|
||||
nanosec_state.center_temperature = 2500;
|
||||
nanosec_state.quadratic_tempco = 3400;
|
||||
nanosec_state.cubic_tempco = 0;
|
||||
nanosec_state.aging_ppm_pa = 0;
|
||||
break;
|
||||
case 3: // Datasheet correction + cubic coefficient
|
||||
nanosec_state.freq_correction = 0;
|
||||
nanosec_state.center_temperature = 2500;
|
||||
nanosec_state.quadratic_tempco = 3400;
|
||||
nanosec_state.cubic_tempco = 1360;
|
||||
nanosec_state.aging_ppm_pa = 0;
|
||||
break;
|
||||
case 4: // Full custom
|
||||
nanosec_state.freq_correction = 1768;
|
||||
nanosec_state.center_temperature = 2653;
|
||||
nanosec_state.quadratic_tempco = 4091;
|
||||
nanosec_state.cubic_tempco = 1359;
|
||||
nanosec_state.aging_ppm_pa = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void nanosec_internal_write_RTC_correction(int16_t value, int16_t sign) {
|
||||
if (sign == 0) {
|
||||
if (value == freq_correction_previous)
|
||||
return; // Do not write same correction value twice
|
||||
freq_correction_previous = value;
|
||||
} else {
|
||||
if (value == -freq_correction_previous)
|
||||
return; // Do not write same correction value twice
|
||||
freq_correction_previous = -value;
|
||||
}
|
||||
|
||||
watch_rtc_freqcorr_write(value, sign);
|
||||
}
|
||||
|
||||
// Receives clock correction, already corrected for temperature and battery voltage, multiplied by "dithering"
|
||||
static void apply_RTC_correction(int16_t correction) {
|
||||
correction += freq_correction_residual;
|
||||
int32_t correction_lr = (int32_t)correction * 2 / dithering; // int division
|
||||
if (correction_lr & 1) {
|
||||
if (correction_lr > 0) {
|
||||
correction_lr++;
|
||||
} else {
|
||||
correction_lr--;
|
||||
}
|
||||
}
|
||||
correction_lr >>= 1;
|
||||
freq_correction_residual = correction - correction_lr * dithering;
|
||||
|
||||
// Warning! Freqcorr is not signed int8!!
|
||||
// First we clamp it to 8-bit range
|
||||
if (correction_lr > 127) {
|
||||
nanosec_internal_write_RTC_correction(127, 0);
|
||||
} else if (correction_lr < -127) {
|
||||
nanosec_internal_write_RTC_correction(127, 1);
|
||||
} else if (correction_lr < 0) {
|
||||
nanosec_internal_write_RTC_correction(abs(correction_lr), 1);
|
||||
} else { // correction
|
||||
nanosec_internal_write_RTC_correction(correction_lr, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// User-related saves
|
||||
void nanosec_ui_save(void) {
|
||||
if (nanosec_changed)
|
||||
nanosec_save();
|
||||
}
|
||||
|
||||
// This is low-level save function, that can be used by other faces
|
||||
void nanosec_save(void) {
|
||||
if (nanosec_state.correction_profile == 0) {
|
||||
freq_correction_residual = 0;
|
||||
apply_RTC_correction(nanosec_state.freq_correction * 1.0f * dithering / 100); // Will be divided by dithering inside, final resolution is mere 1ppm
|
||||
}
|
||||
|
||||
filesystem_write_file("nanosec.ini", (char*)&nanosec_state, sizeof(nanosec_state));
|
||||
nanosec_changed = false;
|
||||
}
|
||||
|
||||
void nanosec_face_setup(uint8_t watch_face_index, void ** context_ptr) {
|
||||
(void) watch_face_index;
|
||||
|
||||
if (*context_ptr == NULL) {
|
||||
if (filesystem_get_file_size("nanosec.ini") != sizeof(nanosec_state)) {
|
||||
// No previous ini or old version of ini file - create new config file
|
||||
nanosec_state.correction_profile = 3;
|
||||
nanosec_init_profile();
|
||||
nanosec_ui_save();
|
||||
} else {
|
||||
filesystem_read_file("nanosec.ini", (char*)&nanosec_state, sizeof(nanosec_state));
|
||||
}
|
||||
|
||||
freq_correction_residual = 0;
|
||||
nanosec_screen = 0;
|
||||
|
||||
*context_ptr = (void *)1; // No need to re-read from filesystem when exiting low power mode
|
||||
}
|
||||
}
|
||||
|
||||
void nanosec_face_activate(void *context) {
|
||||
(void) context;
|
||||
|
||||
// Handle any tasks related to your watch face coming on screen.
|
||||
nanosec_changed = false;
|
||||
}
|
||||
|
||||
static void nanosec_update_display() {
|
||||
char buf[14];
|
||||
|
||||
switch (nanosec_screen) {
|
||||
case 0:
|
||||
sprintf(buf, "FC %6d", nanosec_state.freq_correction);
|
||||
break;
|
||||
case 1:
|
||||
sprintf(buf, "T0 %6d", nanosec_state.center_temperature);
|
||||
break;
|
||||
case 2:
|
||||
sprintf(buf, "2C %6d", nanosec_state.quadratic_tempco);
|
||||
break;
|
||||
case 3:
|
||||
sprintf(buf, "3C %6d", nanosec_state.cubic_tempco);
|
||||
break;
|
||||
case 4: // Profile
|
||||
sprintf(buf, "PR P%1d", nanosec_state.correction_profile);
|
||||
break;
|
||||
case 5: // Cadence
|
||||
sprintf(buf, "CD %2d", nanosec_state.correction_cadence);
|
||||
break;
|
||||
case 6: // Aging
|
||||
sprintf(buf, "AA %6d", nanosec_state.aging_ppm_pa);
|
||||
break;
|
||||
}
|
||||
watch_display_string(buf, 0);
|
||||
}
|
||||
|
||||
static void value_increase(int16_t delta) {
|
||||
nanosec_changed = true;
|
||||
|
||||
switch (nanosec_screen) {
|
||||
case 0:
|
||||
nanosec_state.freq_correction += delta;
|
||||
break;
|
||||
case 1:
|
||||
nanosec_state.center_temperature += delta;
|
||||
break;
|
||||
case 2:
|
||||
nanosec_state.quadratic_tempco += delta;
|
||||
break;
|
||||
case 3:
|
||||
nanosec_state.cubic_tempco += delta;
|
||||
break;
|
||||
case 4: // Profile
|
||||
nanosec_state.correction_profile = (nanosec_state.correction_profile + delta) % nanosec_profile_count;
|
||||
// if ALARM decreases profile below 0, roll back around
|
||||
if (nanosec_state.correction_profile < 0) {
|
||||
nanosec_state.correction_profile += nanosec_profile_count;
|
||||
}
|
||||
break;
|
||||
case 5: // Cadence
|
||||
switch (nanosec_state.correction_cadence) {
|
||||
case 1:
|
||||
nanosec_state.correction_cadence = (delta > 0) ? 5 : 60;
|
||||
break;
|
||||
case 5:
|
||||
nanosec_state.correction_cadence = (delta > 0) ? 10 : 1;
|
||||
break;
|
||||
case 10:
|
||||
nanosec_state.correction_cadence = (delta > 0) ? 20 : 5;
|
||||
break;
|
||||
case 20:
|
||||
nanosec_state.correction_cadence = (delta > 0) ? 60 : 10;
|
||||
break;
|
||||
case 60:
|
||||
nanosec_state.correction_cadence = (delta > 0) ? 1 : 20;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 6: // Aging
|
||||
nanosec_state.aging_ppm_pa += delta;
|
||||
break;
|
||||
}
|
||||
|
||||
nanosec_update_display();
|
||||
}
|
||||
|
||||
static void nanosec_next_edit_screen(void) {
|
||||
nanosec_screen = (nanosec_screen + 1) % nanosec_max_screen;
|
||||
nanosec_update_display();
|
||||
}
|
||||
|
||||
float nanosec_get_aging() // Returns aging correction in ppm
|
||||
{
|
||||
watch_date_time_t date_time = watch_rtc_get_date_time();
|
||||
float years = (watch_utility_date_time_to_unix_time(date_time, 0) - nanosec_state.last_correction_time) / 31536000.0f; // Years passed since finetune
|
||||
return years*nanosec_state.aging_ppm_pa/100.0f;
|
||||
}
|
||||
|
||||
|
||||
bool nanosec_face_loop(movement_event_t event, void *context) {
|
||||
(void) context;
|
||||
|
||||
switch (event.event_type) {
|
||||
case EVENT_ACTIVATE:
|
||||
// Show your initial UI here.
|
||||
nanosec_screen = 0; // Start at page 0
|
||||
nanosec_update_display();
|
||||
break;
|
||||
case EVENT_TICK:
|
||||
break;
|
||||
case EVENT_MODE_BUTTON_UP:
|
||||
if (nanosec_screen == 0) { // we can exit face only on the 0th page
|
||||
nanosec_ui_save();
|
||||
movement_move_to_next_face();
|
||||
} else {
|
||||
nanosec_next_edit_screen();
|
||||
}
|
||||
break;
|
||||
case EVENT_MODE_LONG_PRESS:
|
||||
nanosec_next_edit_screen();
|
||||
break;
|
||||
case EVENT_LIGHT_BUTTON_UP:
|
||||
value_increase(1);
|
||||
break;
|
||||
case EVENT_LIGHT_LONG_PRESS:
|
||||
if (nanosec_screen == 4) { // If we are in profile - apply profiles
|
||||
nanosec_init_profile();
|
||||
nanosec_screen = 0;
|
||||
nanosec_update_display();
|
||||
} else {
|
||||
value_increase(50);
|
||||
}
|
||||
break;
|
||||
case EVENT_ALARM_BUTTON_UP:
|
||||
value_increase(-1);
|
||||
break;
|
||||
case EVENT_ALARM_LONG_PRESS:
|
||||
if (nanosec_screen == 4) { // If we are in profile - still decrease by 1
|
||||
value_increase(-1);
|
||||
} else {
|
||||
value_increase(-50);
|
||||
}
|
||||
break;
|
||||
case EVENT_TIMEOUT:
|
||||
// Your watch face will receive this event after a period of inactivity. If it makes sense to resign,
|
||||
// you may uncomment this line to move back to the first watch face in the list:
|
||||
// movement_move_to_face(0);
|
||||
break;
|
||||
case EVENT_LOW_ENERGY_UPDATE:
|
||||
// If you did not resign in EVENT_TIMEOUT, you can use this event to update the display once a minute.
|
||||
// Avoid displaying fast-updating values like seconds, since the display won't update again for 60 seconds.
|
||||
// You should also consider starting the tick animation, to show the wearer that this is sleep mode:
|
||||
// watch_start_sleep_animation(500);
|
||||
break;
|
||||
case EVENT_BACKGROUND_TASK:
|
||||
// Here we measure temperature and do main frequency correction
|
||||
thermistor_driver_enable();
|
||||
float temperature_c = thermistor_driver_get_temperature();
|
||||
float voltage = (float)watch_get_vcc_voltage() / 1000.0;
|
||||
thermistor_driver_disable();
|
||||
// L22 correction scaling is 0.95367ppm per 1 in FREQCORR
|
||||
// At wrong temperature crystall starting to run slow, negative correction will speed up frequency to correct
|
||||
// Default 32kHz correciton factor is -0.034, centered around 25°C
|
||||
float dt = temperature_c - nanosec_state.center_temperature / 100.0;
|
||||
|
||||
int16_t correction = round((
|
||||
nanosec_state.freq_correction / 100.0f * dithering +
|
||||
(-nanosec_state.quadratic_tempco / 100000.0 * dithering) * dt * dt +
|
||||
(nanosec_state.cubic_tempco / 10000000.0 * dithering) * dt * dt * dt +
|
||||
(voltage - 3.0) * voltage_coefficient +
|
||||
nanosec_get_aging() * dithering
|
||||
) / 0.95367); // 1 correction unit is 0.095367ppm.
|
||||
|
||||
apply_RTC_correction(correction);
|
||||
break;
|
||||
case EVENT_LIGHT_BUTTON_DOWN:
|
||||
// don't light up every time light is hit
|
||||
break;
|
||||
default:
|
||||
movement_default_loop_handler(event);
|
||||
break;
|
||||
}
|
||||
|
||||
// return true if the watch can enter standby mode. If you are PWM'ing an LED or buzzing the buzzer here,
|
||||
// you should return false since the PWM driver does not operate in standby mode.
|
||||
return true;
|
||||
}
|
||||
|
||||
void nanosec_face_resign(void *context) {
|
||||
(void) context;
|
||||
|
||||
nanosec_ui_save();
|
||||
}
|
||||
|
||||
// Background freq correction
|
||||
movement_watch_face_advisory_t nanosec_face_advise(void *context) {
|
||||
(void) context;
|
||||
movement_watch_face_advisory_t retval = { 0 };
|
||||
|
||||
// No need for background correction if we are on profile 0 - static hardware correction.
|
||||
if (nanosec_state.correction_profile != 0) {
|
||||
watch_date_time_t date_time = watch_rtc_get_date_time();
|
||||
retval.wants_background_task = date_time.unit.minute % nanosec_state.correction_cadence == 0;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
108
legacy/watch_faces/settings/nanosec_face.h
Normal file
108
legacy/watch_faces/settings/nanosec_face.h
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2022 Mikhail Svarichevsky https://3.14.by/
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef NANOSEC_FACE_H_
|
||||
#define NANOSEC_FACE_H_
|
||||
|
||||
/*
|
||||
* NANOSEC face
|
||||
*
|
||||
* The goal of nanosec face is dramatic improvement of SensorWatch accuracy.
|
||||
* Minimum goal is <60 seconds of error per year. Full success is if we can
|
||||
* reach <15 seconds per year (<0.47ppm error).
|
||||
*
|
||||
* Best used in conjunction with the FINETUNE face.
|
||||
*
|
||||
* It implements temperature correction using tempco from datasheet (and
|
||||
* allows to adjust these) and allows to introduce offset fix. Therefore
|
||||
* requires temperature sensor board.
|
||||
*
|
||||
* Most users will need to apply profile 3 ("default") or 2 ("conservative
|
||||
* datasheet"), and tune first parameter "static offset" (as it's different
|
||||
* for every crystal sample).
|
||||
*
|
||||
* Frequency correction is dithered over 31 correction intervals (31x10
|
||||
* minutes or ~5 hours), to allow <0.1ppm correction resolution.
|
||||
* * 1ppm is 0.0864 sec per day.
|
||||
* * 0.1ppm is 0.00864 sec per day.
|
||||
*
|
||||
* To stay under 1ppm error you would need calibration of your specific
|
||||
* instance of quartz crystal after some "burn-in" (ideally 1 year).
|
||||
*
|
||||
* Should improve TOTP experience.
|
||||
*
|
||||
* Default funing fork tempco: -0.034 ppm/°C², centered around 25°C
|
||||
* We add optional cubic coefficient, which was measured in practice on my sample.
|
||||
*
|
||||
* Cadence (CD) - how many minutes between corrections. Default 10 minutes.
|
||||
* Every minute might be too much. Every hour - slightly less power
|
||||
* consumption but also less precision.
|
||||
*
|
||||
* Can compensate crystal aging (ppm/year) - but you really should be worrying
|
||||
* about it on second/third years of watch calibration.
|
||||
*
|
||||
* For full usage instructions, please refer to the wiki:
|
||||
* https://www.sensorwatch.net/docs/watchfaces/nanosec/
|
||||
*/
|
||||
|
||||
#include "movement.h"
|
||||
|
||||
#define nanosec_profile_count 5
|
||||
typedef struct {
|
||||
// Correction profiles:
|
||||
// 0 - static hardware correction.
|
||||
// 1 - static correction with dithering.
|
||||
// 2 - datasheet quadratic correction (universal).
|
||||
// 3 - cubic correction conservative (likely universal).
|
||||
// 4 - cubic correction finetuned (sample-specific).
|
||||
int8_t correction_profile;
|
||||
int16_t freq_correction; // Static correction - multiplied by 100
|
||||
int16_t center_temperature; // Multiplied by 100, +25.0 -> +2500
|
||||
int16_t quadratic_tempco; // 0.034 -> 3400, multiplied by 100000. Stored positive, used as negative.
|
||||
int16_t cubic_tempco; // default 0, 0.000136 -> 1360, multiplied by 10000000. Stored positive, used positive.
|
||||
int8_t correction_cadence;
|
||||
uint32_t last_correction_time; // Not used at the moment - but will in the future
|
||||
int16_t aging_ppm_pa; // multiplied by 100. Aging per year.
|
||||
} nanosec_state_t;
|
||||
|
||||
void nanosec_face_setup(uint8_t watch_face_index, void ** context_ptr);
|
||||
void nanosec_face_activate(void *context);
|
||||
bool nanosec_face_loop(movement_event_t event, void *context);
|
||||
void nanosec_face_resign(void *context);
|
||||
movement_watch_face_advisory_t nanosec_face_advise(void *context);
|
||||
void nanosec_ui_save(void);
|
||||
void nanosec_save(void);
|
||||
float nanosec_get_aging(void);
|
||||
|
||||
|
||||
#define nanosec_face ((const watch_face_t) { \
|
||||
nanosec_face_setup, \
|
||||
nanosec_face_activate, \
|
||||
nanosec_face_loop, \
|
||||
nanosec_face_resign, \
|
||||
nanosec_face_advise, \
|
||||
})
|
||||
|
||||
#endif // NANOSEC_FACE_H_
|
||||
|
||||
231
legacy/watch_faces/settings/place_face.h
Normal file
231
legacy/watch_faces/settings/place_face.h
Normal file
@@ -0,0 +1,231 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Tobias Raayoni Last / @randogoth
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef place_FACE_H_
|
||||
#define place_FACE_H_
|
||||
|
||||
#include "movement.h"
|
||||
|
||||
/*
|
||||
* PLACE FACE
|
||||
* ==========
|
||||
*
|
||||
* Based on and expanded from the Sunrise/Sunset face. Outsourced the location setting functionality to
|
||||
* its own face. Also serves as a converter between different coordinate notation formats.
|
||||
*
|
||||
* With the LIGHT button each place coordinate can be shown and edited in 4 different display modes:
|
||||
*
|
||||
* 1) Decimal Latitude and Longitude (WGS84) up to 5 decimal points
|
||||
* 2) Latitude and Longitude (WGS84) in traditional DD°MM'SS" notation
|
||||
* 3) Ten digit Open Location Code (aka. PlusCode) format
|
||||
* 4) Ten digit Geohash format
|
||||
*
|
||||
* Using the ALARM button the user can flip through 2 pages of coordinate info to see the first and
|
||||
* second sets of digits.
|
||||
*
|
||||
* (please also refer to the notes on precision below)
|
||||
*
|
||||
* Editing Mode
|
||||
* ============
|
||||
*
|
||||
* A LONG PRESS of the LIGHT button toggles editing mode for each of the selected notations.
|
||||
*
|
||||
* In this mode LIGHT moves the cursor and ALARM changes the letter cycling through the available
|
||||
* alphabet or numbers.
|
||||
*
|
||||
* When OLC or Geohash display are edited, Digit Info mode is activated. It serves as a workaround
|
||||
* for the limitation of how ambiguously alphanumeric characters are displayed on the main seven segment
|
||||
* digits of the watch face ( S or 5, I or 1, U or W?).
|
||||
*
|
||||
* The selected letter is also shown in the much easier to read alphanumeric 8 segment weekday digit above.
|
||||
* In addition the '24H' indicator is active when the selected digit represents a number and the 'PM'
|
||||
* indicator for a letter.
|
||||
*
|
||||
* A LONG PRESS of LIGHT saves the changes.
|
||||
*
|
||||
* Coordinates are read or stored to both the traditional internal location register and a file on
|
||||
* the LFS file system ("place.loc"). By default the Watch Face loads the coordinates from file
|
||||
* when activated. If no file is present, the coordinates are loaded from the register.
|
||||
* (please also see the notes on precision below)
|
||||
*
|
||||
* Auxiliary Mode: Digit Info
|
||||
* ==========================
|
||||
*
|
||||
* A LONG PRESS of the ALARM button toggles Digit Info mode when OLC or Geohash display is active.
|
||||
* (LAP indicator is on) It is a means of being able to see the detailed Digit Info as described above
|
||||
* but without the risk of accidentally editing any of digits.
|
||||
*
|
||||
* Both ALARM and LIGHT buttons can be used to flip through the letters.
|
||||
*
|
||||
* Notes on Coordinate Precision
|
||||
* =============================
|
||||
*
|
||||
* The common WGS84 Latitude and Longitude degrees naturally do not represent meters in distance
|
||||
* on the ground. 1° Longitude on the equatorial line equals a width of 111.32 kilometers, but
|
||||
* at 40° latitude further North or South it is approximately 85 kilometers wide. The closer to
|
||||
* the poles the narrower (and more precise) the latitude degrees get.
|
||||
*
|
||||
* The Sensor Watch's traditional 16bit location register only stores latitudes and longitudes
|
||||
* with two decimal points. That equals a longitudal precision of 36 arc seconds, or ~1111 meters
|
||||
* at the equator - precise enough for astronomical calculations, but not if you want to store the
|
||||
* location of let's say a building.
|
||||
*
|
||||
* Hence we propose the <place.loc> file that serves the same purpose, but with a precision of
|
||||
* five decimal digits. That equals 0.04 arc seconds or 1.11 meters at the equator.
|
||||
*
|
||||
* Please also note that the different notations of this watch face also have varying magnitudes
|
||||
* of precision:
|
||||
*
|
||||
* | Format | Notation | Precision at Equator | Precision at 67° N/S |
|
||||
* | ------------------ | ---------------------- | -------------------- | -------------------- |
|
||||
* | 2d. Decimal LatLon | 29.98, 31.13 | 1111.320 m | 435.125 m |
|
||||
* | 5d. Decimal LatLon | 29.97916, 31.13417 | 1.111 m | 0.435 m |
|
||||
* | DMS LatLon | N 29°58′45″, E 31°8′3″ | 30.833 m | 12.083 m |
|
||||
* | Open Location Code | 7GXHX4HM+MM | 13.875 m | 13.875 m |
|
||||
* | Geohash | stq4s3x1qu | 1.189 m | 0.596 m |
|
||||
*
|
||||
* Since all notations are internally converted into degrees with 5 decimal points, expect some
|
||||
* rounding errors when editing or loading the coordinates in other notation formats.
|
||||
*
|
||||
*/
|
||||
|
||||
static const char olc_alphabet[20] = "23456789CFGHJMPQRUWX";
|
||||
static const char geohash_alphabet[32] = "0123456789bCdEfGhjkmnpqrstuVwxyz";
|
||||
|
||||
typedef struct {
|
||||
uint8_t sign: 1; // 0-1
|
||||
uint8_t hundreds: 1; // 0-1
|
||||
uint8_t tens: 4; // 0-9
|
||||
uint8_t ones: 4; // 0-9
|
||||
uint8_t d01: 4; // 0-9
|
||||
uint8_t d02: 4; // 0-9
|
||||
uint8_t d03: 4; // 0-9
|
||||
uint8_t d04: 4; // 0-9
|
||||
uint8_t d05: 4; // 0-9
|
||||
} place_format_decimal_latlon_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t sign: 1; // 0-1
|
||||
uint8_t hundreds: 1; // 0-1
|
||||
uint8_t tens: 4; // 0-9
|
||||
uint8_t ones: 4; // 0-9
|
||||
uint8_t mins_tens: 3; // 0-5
|
||||
uint8_t mins_ones: 4; // 0-9
|
||||
uint8_t secs_tens: 3; // 0-5
|
||||
uint8_t secs_ones: 4; // 0-9
|
||||
} place_format_dms_latlon_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t lat1: 5; // 2-X
|
||||
uint8_t lon1: 5; // 2-X
|
||||
uint8_t lat2: 5; // 2-X
|
||||
uint8_t lon2: 5; // 2-X
|
||||
uint8_t lat3: 5; // 2-X
|
||||
uint8_t lon3: 5; // 2-X
|
||||
uint8_t lat4: 5; // 2-X
|
||||
uint8_t lon4: 5; // 2-X
|
||||
uint8_t lat5: 5; // 2-X
|
||||
uint8_t lon5: 5; // 2-X
|
||||
} place_format_olc_t;
|
||||
|
||||
typedef struct {
|
||||
int32_t latitude : 25;
|
||||
int32_t longitude : 26;
|
||||
} coordinate_t;
|
||||
|
||||
typedef struct {
|
||||
place_format_decimal_latlon_t latitude;
|
||||
place_format_decimal_latlon_t longitude;
|
||||
} place_coordinate_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t d01: 6; // 0-z
|
||||
uint8_t d02: 6; // 0-z
|
||||
uint8_t d03: 6; // 0-z
|
||||
uint8_t d04: 6; // 0-z
|
||||
uint8_t d05: 6; // 0-z
|
||||
uint8_t d06: 6; // 0-z
|
||||
uint8_t d07: 6; // 0-z
|
||||
uint8_t d08: 6; // 0-z
|
||||
uint8_t d09: 6; // 0-z
|
||||
uint8_t d10: 6; // 0-z
|
||||
} place_format_geohash_t;
|
||||
|
||||
typedef struct {
|
||||
double max;
|
||||
double min;
|
||||
} place_format_geohash_interval;
|
||||
|
||||
typedef struct {
|
||||
uint8_t min_digit : 1;
|
||||
uint8_t max_digit : 3;
|
||||
} place_mode_schema_page_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t max_page : 3;
|
||||
place_mode_schema_page_t page[4];
|
||||
} place_mode_schema_mode_t;
|
||||
|
||||
enum place_modes_e {
|
||||
MODE_DECIMAL = 0,
|
||||
MODE_DMS,
|
||||
MODE_OLC,
|
||||
MODE_GEOHASH
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
enum place_modes_e mode;
|
||||
uint8_t page : 3;
|
||||
int8_t active_digit: 4;
|
||||
bool edit;
|
||||
bool digit_info;
|
||||
place_format_decimal_latlon_t working_latitude;
|
||||
place_format_decimal_latlon_t working_longitude;
|
||||
place_format_dms_latlon_t working_dms_latitude;
|
||||
place_format_dms_latlon_t working_dms_longitude;
|
||||
place_format_olc_t working_pluscode;
|
||||
place_format_geohash_t working_geohash;
|
||||
place_mode_schema_mode_t modes[4];
|
||||
} place_state_t;
|
||||
|
||||
// PUBLIC WATCH FACE FUNCTIONS ////////////////////////////////////////////////
|
||||
|
||||
void place_face_setup(uint8_t watch_face_index, void ** context_ptr);
|
||||
void place_face_activate(void *context);
|
||||
bool place_face_loop(movement_event_t event, void *context);
|
||||
void place_face_resign(void *context);
|
||||
|
||||
void place_latlon_to_olc(char *pluscode, double latitude, double longitude);
|
||||
void place_latlon_to_geohash(char *geohash, double latitude, double longitude);
|
||||
|
||||
#define place_face ((const watch_face_t){ \
|
||||
place_face_setup, \
|
||||
place_face_activate, \
|
||||
place_face_loop, \
|
||||
place_face_resign, \
|
||||
NULL, \
|
||||
})
|
||||
|
||||
#endif // place_FACE_H_
|
||||
|
||||
148
legacy/watch_faces/settings/save_load_face.c
Normal file
148
legacy/watch_faces/settings/save_load_face.c
Normal file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Wesley Aptekar-Cassels
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "save_load_face.h"
|
||||
#include "filesystem.h"
|
||||
|
||||
static void save(save_load_state_t *state) {
|
||||
savefile_t savefile = {
|
||||
1,
|
||||
watch_get_backup_data(0),
|
||||
watch_get_backup_data(1),
|
||||
watch_get_backup_data(2),
|
||||
watch_get_backup_data(3),
|
||||
watch_get_backup_data(4),
|
||||
watch_get_backup_data(5),
|
||||
watch_get_backup_data(6),
|
||||
watch_get_backup_data(7),
|
||||
watch_rtc_get_date_time(),
|
||||
};
|
||||
state->slot[state->index] = savefile;
|
||||
char filename[23];
|
||||
sprintf(filename, "save_load_face_%d.bin", state->index);
|
||||
filesystem_write_file(filename, (char*)&savefile, sizeof(savefile_t));
|
||||
}
|
||||
|
||||
static void load(save_load_state_t *state) {
|
||||
watch_store_backup_data(state->slot[state->index].b0, 0);
|
||||
watch_store_backup_data(state->slot[state->index].b1, 1);
|
||||
watch_store_backup_data(state->slot[state->index].b2, 2);
|
||||
watch_store_backup_data(state->slot[state->index].b3, 3);
|
||||
watch_store_backup_data(state->slot[state->index].b4, 4);
|
||||
watch_store_backup_data(state->slot[state->index].b5, 5);
|
||||
watch_store_backup_data(state->slot[state->index].b6, 6);
|
||||
watch_store_backup_data(state->slot[state->index].b7, 7);
|
||||
}
|
||||
|
||||
static void load_saves_to_state(save_load_state_t *state) {
|
||||
for (uint8_t i = 0; i < SAVE_LOAD_SLOTS; i++) {
|
||||
char filename[23];
|
||||
sprintf(filename, "save_load_face_%d.bin", i);
|
||||
if (filesystem_get_file_size(filename) != sizeof(savefile_t)) {
|
||||
state->slot[i].version = 0;
|
||||
continue;
|
||||
}
|
||||
filesystem_read_file(filename, (char*)&state->slot[i], sizeof(savefile_t));
|
||||
if (state->slot[i].version != 1) {
|
||||
state->slot[i].version = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void save_load_face_setup(uint8_t watch_face_index, void ** context_ptr) {
|
||||
(void) watch_face_index;
|
||||
if (*context_ptr == NULL) {
|
||||
*context_ptr = malloc(sizeof(save_load_state_t));
|
||||
memset(*context_ptr, 0, sizeof(save_load_state_t));
|
||||
}
|
||||
}
|
||||
|
||||
void save_load_face_activate(void *context) {
|
||||
save_load_state_t *state = (save_load_state_t *)context;
|
||||
state->index = 0;
|
||||
state->update_timeout = 0;
|
||||
load_saves_to_state(state);
|
||||
}
|
||||
|
||||
static void update_display(save_load_state_t *state) {
|
||||
char buf[11];
|
||||
sprintf(buf, "SL %1d", state->index);
|
||||
watch_display_string(buf, 0);
|
||||
|
||||
if (state->slot[state->index].version) {
|
||||
sprintf(buf, "%02d%02d%02d", state->slot[state->index].rtc.unit.year + 20, state->slot[state->index].rtc.unit.month, state->slot[state->index].rtc.unit.day);
|
||||
watch_display_string(buf, 4);
|
||||
} else {
|
||||
watch_display_string("no dat", 4);
|
||||
}
|
||||
}
|
||||
|
||||
bool save_load_face_loop(movement_event_t event, void *context) {
|
||||
save_load_state_t *state = (save_load_state_t *)context;
|
||||
|
||||
switch (event.event_type) {
|
||||
case EVENT_ACTIVATE:
|
||||
update_display(state);
|
||||
break;
|
||||
case EVENT_TICK:
|
||||
if (state->update_timeout) {
|
||||
if (!--state->update_timeout) {
|
||||
update_display(state);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case EVENT_ALARM_BUTTON_UP:
|
||||
state->index = (state->index + 1) % SAVE_LOAD_SLOTS;
|
||||
update_display(state);
|
||||
break;
|
||||
case EVENT_LIGHT_LONG_PRESS:
|
||||
save(state);
|
||||
watch_display_string("Saved ", 4);
|
||||
state->update_timeout = 3;
|
||||
break;
|
||||
case EVENT_ALARM_LONG_PRESS:
|
||||
if (state->slot[state->index].version) {
|
||||
load(state);
|
||||
watch_display_string("Loaded", 4);
|
||||
state->update_timeout = 3;
|
||||
}
|
||||
break;
|
||||
case EVENT_TIMEOUT:
|
||||
movement_move_to_face(0);
|
||||
break;
|
||||
default:
|
||||
return movement_default_loop_handler(event);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void save_load_face_resign(void *context) {
|
||||
(void) context;
|
||||
|
||||
// handle any cleanup before your watch face goes off-screen.
|
||||
}
|
||||
|
||||
82
legacy/watch_faces/settings/save_load_face.h
Normal file
82
legacy/watch_faces/settings/save_load_face.h
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Wesley Aptekar-Cassels
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef SAVE_LOAD_FACE_H_
|
||||
#define SAVE_LOAD_FACE_H_
|
||||
|
||||
#include "movement.h"
|
||||
#include "watch_rtc.h"
|
||||
|
||||
/*
|
||||
* Save/Load face
|
||||
*
|
||||
* This allows you to save your settings (including location, birthday, etc) to
|
||||
* LFS, which is not wiped when firmware is updated, and then load them again.
|
||||
* It provides multiple save slots (four by default).
|
||||
*
|
||||
* Press ALARM to cycle through save slots. Long press LIGHT to save to the
|
||||
* current slot. Long press ALARM to load from the current slot. The date that
|
||||
* a save was taken is shown in YYMMDD format , or "no dat" if the slot is
|
||||
* empty. The index of the current slot is displayed in the upper right corner.
|
||||
*
|
||||
* While the time that a save was taken is recorded, it is not currently
|
||||
* restored.
|
||||
*/
|
||||
|
||||
typedef struct savefile {
|
||||
uint8_t version;
|
||||
uint32_t b0;
|
||||
uint32_t b1;
|
||||
uint32_t b2;
|
||||
uint32_t b3;
|
||||
uint32_t b4;
|
||||
uint32_t b5;
|
||||
uint32_t b6;
|
||||
uint32_t b7;
|
||||
watch_date_time_t rtc;
|
||||
} savefile_t;
|
||||
|
||||
#define SAVE_LOAD_SLOTS 4
|
||||
|
||||
typedef struct {
|
||||
uint8_t index;
|
||||
uint8_t update_timeout;
|
||||
savefile_t slot[SAVE_LOAD_SLOTS];
|
||||
} save_load_state_t;
|
||||
|
||||
void save_load_face_setup(uint8_t watch_face_index, void ** context_ptr);
|
||||
void save_load_face_activate(void *context);
|
||||
bool save_load_face_loop(movement_event_t event, void *context);
|
||||
void save_load_face_resign(void *context);
|
||||
|
||||
#define save_load_face ((const watch_face_t){ \
|
||||
save_load_face_setup, \
|
||||
save_load_face_activate, \
|
||||
save_load_face_loop, \
|
||||
save_load_face_resign, \
|
||||
NULL, \
|
||||
})
|
||||
|
||||
#endif // SAVE_LOAD_FACE_H_
|
||||
|
||||
266
legacy/watch_faces/settings/set_time_hackwatch_face.c
Normal file
266
legacy/watch_faces/settings/set_time_hackwatch_face.c
Normal file
@@ -0,0 +1,266 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2022 Joey Castillo
|
||||
* Copyright (c) 2022 Mikhail Svarichevsky https://3.14.by/
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "set_time_hackwatch_face.h"
|
||||
#include "watch.h"
|
||||
#include "watch_utility.h"
|
||||
#include "zones.h"
|
||||
|
||||
char set_time_hackwatch_face_titles[][3] = {"HR", "M1", "SE", "YR", "MO", "DA", "ZO"};
|
||||
#define set_time_hackwatch_face_NUM_SETTINGS (sizeof(set_time_hackwatch_face_titles) / sizeof(*set_time_hackwatch_face_titles))
|
||||
|
||||
watch_date_time_t date_time_settings;
|
||||
|
||||
void set_time_hackwatch_face_setup(uint8_t watch_face_index, void ** context_ptr) {
|
||||
(void) watch_face_index;
|
||||
if (*context_ptr == NULL) *context_ptr = malloc(sizeof(uint8_t));
|
||||
}
|
||||
|
||||
void set_time_hackwatch_face_activate(void *context) {
|
||||
*((uint8_t *)context) = 3;
|
||||
movement_request_tick_frequency(32);
|
||||
date_time_settings = watch_rtc_get_date_time();
|
||||
}
|
||||
|
||||
bool set_time_hackwatch_face_loop(movement_event_t event, void *context) {
|
||||
uint8_t current_page = *((uint8_t *)context);
|
||||
|
||||
if (event.subsecond == 15) // Delay displayed time update by ~0.5 seconds, to align phase exactly to main clock at 1Hz
|
||||
date_time_settings = watch_rtc_get_date_time();
|
||||
|
||||
static int8_t seconds_reset_sequence;
|
||||
|
||||
switch (event.event_type) {
|
||||
case EVENT_MODE_BUTTON_UP:
|
||||
if (current_page == 2)
|
||||
watch_rtc_enable(true);
|
||||
movement_move_to_next_face();
|
||||
return false;
|
||||
case EVENT_LIGHT_LONG_PRESS:
|
||||
current_page = (current_page + set_time_hackwatch_face_NUM_SETTINGS - 1) % set_time_hackwatch_face_NUM_SETTINGS;
|
||||
if (current_page == 2)
|
||||
seconds_reset_sequence = 0;
|
||||
|
||||
*((uint8_t *)context) = current_page;
|
||||
break;
|
||||
case EVENT_LIGHT_BUTTON_UP:
|
||||
if (current_page == 2)
|
||||
watch_rtc_enable(true);
|
||||
|
||||
current_page = (current_page + 1) % set_time_hackwatch_face_NUM_SETTINGS;
|
||||
if (current_page == 2)
|
||||
seconds_reset_sequence = 0;
|
||||
|
||||
*((uint8_t *)context) = current_page;
|
||||
break;
|
||||
case EVENT_TICK:
|
||||
// We use it to wait for "middle" subsecond position
|
||||
if (current_page == 2 && seconds_reset_sequence == 1 && event.subsecond == 15) { // wait ~0.5sec - until we reach half second point
|
||||
watch_rtc_enable(false);
|
||||
seconds_reset_sequence = 2;
|
||||
|
||||
// Set new time while RTC is off, to get perfect start
|
||||
if (date_time_settings.unit.second > 30) {
|
||||
date_time_settings.unit.minute = (date_time_settings.unit.minute + 1) % 60; // Roll to next minute if we are almost there
|
||||
if (date_time_settings.unit.minute == 0) { // Overflow
|
||||
date_time_settings.unit.hour = (date_time_settings.unit.hour + 1) % 24;
|
||||
if (date_time_settings.unit.hour == 0) // Overflow
|
||||
date_time_settings.unit.day++;
|
||||
}
|
||||
}
|
||||
date_time_settings.unit.second = 0;
|
||||
watch_rtc_set_date_time(date_time_settings);
|
||||
}
|
||||
break;
|
||||
case EVENT_ALARM_BUTTON_DOWN:
|
||||
if (current_page == 2) {
|
||||
watch_rtc_enable(true); // If it is disabled accidentally - re-enable it
|
||||
seconds_reset_sequence = 1; // Waiting for whole second
|
||||
}
|
||||
break;
|
||||
case EVENT_ALARM_LONG_PRESS:
|
||||
switch (current_page) {
|
||||
case 0: // hour
|
||||
date_time_settings.unit.hour = (date_time_settings.unit.hour + 24 -1) % 24;
|
||||
break;
|
||||
case 1: // minute
|
||||
date_time_settings.unit.minute = (date_time_settings.unit.minute + 60 - 1) % 60;
|
||||
break;
|
||||
case 3: // year
|
||||
// only allow 2021-2061. fix this sometime later
|
||||
date_time_settings.unit.year = (date_time_settings.unit.year + 50 - 1) % 50;
|
||||
break;
|
||||
case 4: // month
|
||||
date_time_settings.unit.month = (date_time_settings.unit.month + 12 - 2) % 12 + 1;
|
||||
break;
|
||||
case 5: // day
|
||||
date_time_settings.unit.day = date_time_settings.unit.day - 2;
|
||||
if (date_time_settings.unit.day == 0) {
|
||||
date_time_settings.unit.day = days_in_month(date_time_settings.unit.month, date_time_settings.unit.year + WATCH_RTC_REFERENCE_YEAR);
|
||||
} else
|
||||
date_time_settings.unit.day++;
|
||||
break;
|
||||
case 6: // time zone
|
||||
if (movement_get_timezone_index() > 0) {
|
||||
movement_set_timezone_index(movement_get_timezone_index() - 1);
|
||||
} else {
|
||||
movement_set_timezone_index(NUM_ZONE_NAMES - 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (current_page != 2) // Do not set time when we are at seconds, it was already set previously
|
||||
watch_rtc_set_date_time(date_time_settings);
|
||||
break;
|
||||
|
||||
case EVENT_ALARM_LONG_UP://Setting seconds on long release
|
||||
switch (current_page) {
|
||||
case 2: // second
|
||||
seconds_reset_sequence = 0;
|
||||
watch_rtc_enable(true);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case EVENT_ALARM_BUTTON_UP:
|
||||
switch (current_page) {
|
||||
case 0: // hour
|
||||
date_time_settings.unit.hour = (date_time_settings.unit.hour + 1) % 24;
|
||||
break;
|
||||
case 1: // minute
|
||||
date_time_settings.unit.minute = (date_time_settings.unit.minute + 1) % 60;
|
||||
break;
|
||||
case 2: // second
|
||||
seconds_reset_sequence = 0;
|
||||
watch_rtc_enable(true);
|
||||
break;
|
||||
case 3: // year
|
||||
// only allow 2021-2061. fix this sometime later
|
||||
date_time_settings.unit.year = ((date_time_settings.unit.year % 50) + 1);
|
||||
break;
|
||||
case 4: // month
|
||||
date_time_settings.unit.month = (date_time_settings.unit.month % 12) + 1;
|
||||
break;
|
||||
case 5: // day
|
||||
date_time_settings.unit.day = (date_time_settings.unit.day % watch_utility_days_in_month(date_time_settings.unit.month, date_time_settings.unit.year + WATCH_RTC_REFERENCE_YEAR)) + 1;
|
||||
break;
|
||||
case 6: // time zone
|
||||
movement_set_timezone_index(movement_get_timezone_index() + 1);
|
||||
if (movement_get_timezone_index() >= NUM_ZONE_NAMES) movement_set_timezone_index(0);
|
||||
break;
|
||||
}
|
||||
if (current_page != 2) // Do not set time when we are at seconds, it was already set previously
|
||||
watch_rtc_set_date_time(date_time_settings);
|
||||
//TODO: Do not update whole RTC, just what we are changing
|
||||
break;
|
||||
case EVENT_TIMEOUT:
|
||||
movement_move_to_face(0);
|
||||
break;
|
||||
case EVENT_LIGHT_BUTTON_DOWN:
|
||||
// don't light up every time light is hit
|
||||
break;
|
||||
default:
|
||||
movement_default_loop_handler(event);
|
||||
break;
|
||||
}
|
||||
|
||||
char buf[11];
|
||||
if (current_page < 3) {
|
||||
watch_set_colon();
|
||||
if (movement_clock_mode_24h()) {
|
||||
watch_set_indicator(WATCH_INDICATOR_24H);
|
||||
sprintf(buf,
|
||||
"%s %2d%02d%02d",
|
||||
set_time_hackwatch_face_titles[current_page],
|
||||
date_time_settings.unit.hour,
|
||||
date_time_settings.unit.minute,
|
||||
date_time_settings.unit.second);
|
||||
} else {
|
||||
sprintf(buf,
|
||||
"%s %2d%02d%02d",
|
||||
set_time_hackwatch_face_titles[current_page],
|
||||
(date_time_settings.unit.hour % 12) ? (date_time_settings.unit.hour % 12) : 12,
|
||||
date_time_settings.unit.minute,
|
||||
date_time_settings.unit.second);
|
||||
if (date_time_settings.unit.hour < 12) {
|
||||
watch_clear_indicator(WATCH_INDICATOR_PM);
|
||||
} else {
|
||||
watch_set_indicator(WATCH_INDICATOR_PM);
|
||||
}
|
||||
}
|
||||
} else if (current_page < 6) {
|
||||
watch_clear_colon();
|
||||
watch_clear_indicator(WATCH_INDICATOR_24H);
|
||||
watch_clear_indicator(WATCH_INDICATOR_PM);
|
||||
sprintf(buf,
|
||||
"%s %2d%02d%02d",
|
||||
set_time_hackwatch_face_titles[current_page],
|
||||
date_time_settings.unit.year + 20,
|
||||
date_time_settings.unit.month,
|
||||
date_time_settings.unit.day);
|
||||
} else {
|
||||
if ((event.subsecond / 8 ) % 2) {
|
||||
watch_clear_colon();
|
||||
sprintf(buf, "%s ", set_time_hackwatch_face_titles[current_page]);
|
||||
} else {
|
||||
watch_set_colon();
|
||||
sprintf(buf,
|
||||
"%s %3d%02d ",
|
||||
set_time_hackwatch_face_titles[current_page],
|
||||
(int8_t)(movement_get_current_timezone_offset() / 3600),
|
||||
(int8_t)(movement_get_current_timezone_offset() % 3600) * (movement_get_current_timezone_offset() < 0 ? -1 : 1));
|
||||
}
|
||||
}
|
||||
|
||||
// blink up the parameter we're setting
|
||||
if ( (event.subsecond / 8) % 2) {
|
||||
switch (current_page) {
|
||||
case 0:
|
||||
case 3:
|
||||
buf[4] = buf[5] = ' ';
|
||||
break;
|
||||
case 1:
|
||||
case 4:
|
||||
buf[6] = buf[7] = ' ';
|
||||
break;
|
||||
case 2:
|
||||
// Only blink first number when setting seconds, to make it easier to see subsecond error
|
||||
buf[8] = ' ';
|
||||
break;
|
||||
case 5:
|
||||
buf[8] = buf[9] = ' ';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
watch_display_string(buf, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void set_time_hackwatch_face_resign(void *context) {
|
||||
(void) context;
|
||||
watch_set_led_off();
|
||||
movement_store_settings();
|
||||
}
|
||||
66
legacy/watch_faces/settings/set_time_hackwatch_face.h
Normal file
66
legacy/watch_faces/settings/set_time_hackwatch_face.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2022 Joey Castillo
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef SET_TIME_HACKWATCH_FACE_H_
|
||||
#define SET_TIME_HACKWATCH_FACE_H_
|
||||
|
||||
/*
|
||||
* SET TIME HACKWATCH
|
||||
*
|
||||
* This is an extended version of set_time face which allow setting seconds
|
||||
* precisely. To achieve that - press and hold alarm button few seconds before
|
||||
* 00 and release exaclty as reference clock turns 00.
|
||||
*
|
||||
* All settings can go up, or down (long alarm press).
|
||||
*
|
||||
* The challenge is that SensorWatch display is delayed 0.5 seconds vs hardware
|
||||
* RTC clock. It is caused by interrupts being generated by raising edge of
|
||||
* counter. It means there is no way to precisely trigger at 0.5s, as events
|
||||
* at different frequencies slightly mismatch. This watch face achieves this
|
||||
* approximately by triggering at 15th out of 32Hz events.
|
||||
*
|
||||
* If you are <30 seconds when setting seconds - you will stay in the same
|
||||
* minute. Otherwise - you will go to next minute.
|
||||
*
|
||||
* Note that changing anything will slightly delay subseconds counter. This
|
||||
* is why this face sets seconds last to achiveve best precision. Still,
|
||||
* best possible precision is achieved with finetune face.
|
||||
*/
|
||||
|
||||
#include "movement.h"
|
||||
|
||||
void set_time_hackwatch_face_setup(uint8_t watch_face_index, void ** context_ptr);
|
||||
void set_time_hackwatch_face_activate(void *context);
|
||||
bool set_time_hackwatch_face_loop(movement_event_t event, void *context);
|
||||
void set_time_hackwatch_face_resign(void *context);
|
||||
|
||||
#define set_time_hackwatch_face ((const watch_face_t){ \
|
||||
set_time_hackwatch_face_setup, \
|
||||
set_time_hackwatch_face_activate, \
|
||||
set_time_hackwatch_face_loop, \
|
||||
set_time_hackwatch_face_resign, \
|
||||
NULL, \
|
||||
})
|
||||
|
||||
#endif // SET_TIME_HACKWATCH_FACE_H_
|
||||
Reference in New Issue
Block a user