Precision watch update (#152)
* Intermediate changes * Databank working * Main commit for precision timing First version where all functions are supposed to be working * Fix math error in nanosec. File storage for location. * Remove obsolete comments * Missing page name on pages rotation - thanks to jeremy * Delete file.diff * Cleanup+tempchart 1) finetune must always reset last calibration time when doing non-0 time correction, even when you are not applying ppm correction. 2) Dithers over 31 periods not 10, more resolution with still no risk of overflow 3) Minute-boundery finetune fix. I also just got this 1-minute error after finetune... 4) Write frequency calibration value in 1 operation rather than 2. All RTC writes must be single operations to avoid partially correct data. 5) Some code cleanup 6) Tempchart face is added for temperature statistics * Update set_time_hackwatch_face.c * Math error in display code of finetune, allow to update correction time even without correction - by long alarm press * Increase reliability of stopping & starting RTC timer As it's quite dangerous operation * hackwatch - days adjust down fix by long alarm * unify style * More comments & last style change * Simulator support RTC operations (watch_rtc_enable and watch_rtc_freqcorr_write) are in common libs. * Unicode fix * Crystal aging is now adjustable (AA page in nanosec - annual aging, ppm/year) Aging is baked into fixed offset every time finetune is performed, as it relies on last adjustment time. * Blink on non-0 page every minute in finetune to measure clock error * Rolling back private changes * Cleanup * Cleanup * Quality of life changes in nanosec 1. Does not calculate & apply ppm correction if less than 6 hours passed since previous adjustment (as it gives very high correction values which are unrealistic and unhelpful) 2. Idle timeout resets to face 0 only if no correction was made * unify style * Fix low-power errors in nanosec infrastructure, faster display in finetune * Merge fix * unify style Co-authored-by: Jeremy O'Brien <neutral@fastmail.com> Co-authored-by: joeycastillo <joeycastillo@utexas.edu>
This commit is contained in:
committed by
GitHub
parent
fee6145e4d
commit
6b71711079
156
movement/watch_faces/complication/databank_face.c
Normal file
156
movement/watch_faces/complication/databank_face.c
Normal file
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2022 Mikhail Svarichevsky
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Displays some pre-defined data that you might want to remember. Math constants, birthdays, phone numbers...
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "databank_face.h"
|
||||
#include "watch.h"
|
||||
#include "watch_private_display.h"
|
||||
|
||||
const char *pi_data[] = {
|
||||
"PI", "314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442",
|
||||
"S ", "9192631770",
|
||||
"31", "2147483648",
|
||||
"32", "4294967296",
|
||||
"63", "9223372036854775808",
|
||||
"64", "18446744073709551616",
|
||||
};
|
||||
//we show 6 characters per screen
|
||||
|
||||
const int databank_num_pages = (sizeof(pi_data) / sizeof(char*) / 2);
|
||||
|
||||
struct {
|
||||
uint8_t current_word;
|
||||
uint8_t databank_page;
|
||||
bool animating;
|
||||
} databank_state;
|
||||
|
||||
void databank_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
|
||||
// These next two lines just silence the compiler warnings associated with unused parameters.
|
||||
// We have no use for the settings or the watch_face_index, so we make that explicit here.
|
||||
(void) settings;
|
||||
(void) context_ptr;
|
||||
(void) watch_face_index;
|
||||
// At boot, context_ptr will be NULL indicating that we don't have anyplace to store our context.
|
||||
}
|
||||
|
||||
void databank_face_activate(movement_settings_t *settings, void *context) {
|
||||
// same as above: silence the warning, we don't need to check the settings.
|
||||
(void) settings;
|
||||
(void) context;
|
||||
// we do however need to set some things in our context. Here we cast it to the correct type...
|
||||
databank_state.current_word = 0;
|
||||
databank_state.animating = true;
|
||||
}
|
||||
|
||||
static void display()
|
||||
{
|
||||
char buf[14];
|
||||
int page = databank_state.current_word;
|
||||
sprintf(buf, "%s%2d", pi_data[databank_state.databank_page * 2 + 0], page);
|
||||
watch_display_string(buf, 0);
|
||||
bool data_ended = false;
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if (pi_data[databank_state.databank_page * 2 + 1][page * 6 + i] == 0) {
|
||||
data_ended = true;
|
||||
}
|
||||
|
||||
if (!data_ended) {
|
||||
watch_display_character(pi_data[databank_state.databank_page * 2 + 1][page * 6 + i], 4 + i);
|
||||
} else {
|
||||
// only 6 digits per page
|
||||
watch_display_character(' ', 4 + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool databank_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
|
||||
(void) settings;
|
||||
(void) context;
|
||||
int max_words = (strlen(pi_data[databank_state.databank_page * 2 + 1]) - 1) / 6 + 1;
|
||||
|
||||
switch (event.event_type) {
|
||||
case EVENT_ACTIVATE:
|
||||
display();
|
||||
case EVENT_TICK:
|
||||
// on activate and tick, if we are animating,
|
||||
break;
|
||||
case EVENT_LIGHT_BUTTON_UP:
|
||||
// when the user presses 'light', we illuminate the LED. We could override this if
|
||||
// our UI needed an additional button for input, consuming the light button press
|
||||
// but not illuminating the LED.
|
||||
databank_state.current_word = (databank_state.current_word + max_words - 1) % max_words;
|
||||
display();
|
||||
break;
|
||||
case EVENT_LIGHT_LONG_PRESS:
|
||||
databank_state.databank_page = (databank_state.databank_page + databank_num_pages - 1) % databank_num_pages;
|
||||
databank_state.current_word = 0;
|
||||
display();
|
||||
break;
|
||||
case EVENT_MODE_BUTTON_UP:
|
||||
// when the user presses 'mode', we tell movement to move to the next watch face.
|
||||
// movement will call our resign function, clear the screen, and transfer control
|
||||
// to the next watch face in the list.
|
||||
movement_move_to_next_face();
|
||||
break;
|
||||
case EVENT_ALARM_LONG_PRESS:
|
||||
databank_state.databank_page = (databank_state.databank_page + 1) % databank_num_pages;
|
||||
databank_state.current_word = 0;
|
||||
display();
|
||||
break;
|
||||
case EVENT_ALARM_BUTTON_UP:
|
||||
// when the user presses 'alarm', we toggle the state of the animation. If animating,
|
||||
// we stop; if stopped, we resume.
|
||||
databank_state.current_word = (databank_state.current_word + 1) % max_words;
|
||||
display();
|
||||
break;
|
||||
case EVENT_LOW_ENERGY_UPDATE:
|
||||
// This low energy mode update occurs once a minute, if the watch face is in the
|
||||
// foreground when Movement enters low energy mode. We have the option of supporting
|
||||
// this mode, but since our watch face animates once a second, the "Hello there" face
|
||||
// isn't very useful in this mode. So we choose not to support it. (continued below)
|
||||
break;
|
||||
case EVENT_TIMEOUT:
|
||||
// ... Instead, we respond to the timeout event. This event happens after a configurable
|
||||
// interval on screen (1-30 minutes). The watch will give us this event as a chance to
|
||||
// resign control if we want to, and in this case, we do.
|
||||
// This function will return the watch to the first screen (usually a simple clock),
|
||||
// and it will do it long before the watch enters low energy mode. This ensures we
|
||||
// won't be on screen, and thus opts us out of getting the EVENT_LOW_ENERGY_UPDATE above.
|
||||
movement_move_to_face(0);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void databank_face_resign(movement_settings_t *settings, void *context) {
|
||||
// our watch face, like most watch faces, has nothing special to do when resigning.
|
||||
// watch faces that enable a peripheral or interact with a sensor may want to turn it off here.
|
||||
(void) settings;
|
||||
(void) context;
|
||||
}
|
||||
43
movement/watch_faces/complication/databank_face.h
Normal file
43
movement/watch_faces/complication/databank_face.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 DATABANK_FACE_H_
|
||||
#define DATABANK_FACE_H_
|
||||
|
||||
#include "movement.h"
|
||||
|
||||
void databank_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
|
||||
void databank_face_activate(movement_settings_t *settings, void *context);
|
||||
bool databank_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
|
||||
void databank_face_resign(movement_settings_t *settings, void *context);
|
||||
|
||||
#define databank_face ((const watch_face_t){ \
|
||||
databank_face_setup, \
|
||||
databank_face_activate, \
|
||||
databank_face_loop, \
|
||||
databank_face_resign, \
|
||||
NULL, \
|
||||
})
|
||||
|
||||
#endif // DATABANK_FACE_H_
|
||||
157
movement/watch_faces/complication/tempchart_face.c
Normal file
157
movement/watch_faces/complication/tempchart_face.c
Normal file
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2022 Mikhail Svarichevsky
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Gathers temperature statistics in a chart form. Statistics bins are per hour / per 0.5°C.
|
||||
* Saved to file every day at 00:00. Can help improve watch precision in the future.
|
||||
* If you can gather statistics over few months, and then send tempchart.ini to 3@14.by - it
|
||||
* will help future generations of precision quartz watches.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "tempchart_face.h"
|
||||
#include "watch.h"
|
||||
#include "watch_private_display.h"
|
||||
#include "filesystem.h"
|
||||
#include "thermistor_driver.h"
|
||||
|
||||
struct {
|
||||
uint8_t stat[24 * 70];
|
||||
uint16_t num_div;
|
||||
} tempchart_state;
|
||||
|
||||
static void tempchart_save(void) {
|
||||
filesystem_write_file("tempchart.ini", (char*)&tempchart_state, sizeof(tempchart_state));
|
||||
}
|
||||
|
||||
void tempchart_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
|
||||
// These next two lines just silence the compiler warnings associated with unused parameters.
|
||||
// We have no use for the settings or the watch_face_index, so we make that explicit here.
|
||||
(void) settings;
|
||||
(void) context_ptr;
|
||||
(void) watch_face_index;
|
||||
// At boot, context_ptr will be NULL indicating that we don't have anyplace to store our context.
|
||||
if (filesystem_get_file_size("tempchart.ini") != sizeof(tempchart_state)) {
|
||||
// No previous ini or old version of ini file - create new config file
|
||||
tempchart_state.num_div = 0;
|
||||
for (int i = 0; i < 24 * 70; i++)
|
||||
tempchart_state.stat[i] = 0;
|
||||
tempchart_save();
|
||||
} else
|
||||
filesystem_read_file("tempchart.ini", (char*)&tempchart_state, sizeof(tempchart_state));
|
||||
|
||||
}
|
||||
|
||||
void tempchart_face_activate(movement_settings_t *settings, void *context) {
|
||||
// same as above: silence the warning, we don't need to check the settings.
|
||||
(void) settings;
|
||||
(void) context;
|
||||
}
|
||||
|
||||
static void display(void) {
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 24 * 70; i++)
|
||||
sum += tempchart_state.stat[i];
|
||||
|
||||
char buf[24];
|
||||
sprintf(buf, "TS%2d%6d", tempchart_state.num_div, sum);
|
||||
watch_display_string(buf, 0);
|
||||
}
|
||||
|
||||
bool tempchart_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
|
||||
(void) settings;
|
||||
(void) context;
|
||||
|
||||
switch (event.event_type) {
|
||||
case EVENT_ACTIVATE:
|
||||
display();
|
||||
case EVENT_TICK:
|
||||
// on activate and tick, if we are animating,
|
||||
break;
|
||||
case EVENT_MODE_BUTTON_UP:
|
||||
// when the user presses 'mode', we tell movement to move to the next watch face.
|
||||
// movement will call our resign function, clear the screen, and transfer control
|
||||
// to the next watch face in the list.
|
||||
movement_move_to_next_face();
|
||||
break;
|
||||
case EVENT_LOW_ENERGY_UPDATE:
|
||||
// This low energy mode update occurs once a minute, if the watch face is in the
|
||||
// foreground when Movement enters low energy mode. We have the option of supporting
|
||||
// this mode, but since our watch face animates once a second, the "Hello there" face
|
||||
// isn't very useful in this mode. So we choose not to support it. (continued below)
|
||||
break;
|
||||
case EVENT_TIMEOUT:
|
||||
// ... Instead, we respond to the timeout event. This event happens after a configurable
|
||||
// interval on screen (1-30 minutes). The watch will give us this event as a chance to
|
||||
// resign control if we want to, and in this case, we do.
|
||||
// This function will return the watch to the first screen (usually a simple clock),
|
||||
// and it will do it long before the watch enters low energy mode. This ensures we
|
||||
// won't be on screen, and thus opts us out of getting the EVENT_LOW_ENERGY_UPDATE above.
|
||||
movement_move_to_face(0);
|
||||
break;
|
||||
case EVENT_BACKGROUND_TASK:
|
||||
// Here we measure temperature and do main frequency correction
|
||||
thermistor_driver_enable();
|
||||
float temperature_c = thermistor_driver_get_temperature();
|
||||
thermistor_driver_disable();
|
||||
watch_date_time date_time = watch_rtc_get_date_time();
|
||||
|
||||
int temp = round(temperature_c * 2);
|
||||
if ((temp < 0) || (temp >= 70)) break;
|
||||
|
||||
if (tempchart_state.stat[date_time.unit.hour + temp * 24] == 255) { // We've reached the limit
|
||||
tempchart_state.num_div++;
|
||||
for (int i = 0; i < 24 * 70; i++)
|
||||
tempchart_state.stat[i] = (tempchart_state.stat[i] + 1) >> 1; // So that we don't lose 1
|
||||
}
|
||||
tempchart_state.stat[date_time.unit.hour+temp*24]++;
|
||||
|
||||
if (date_time.unit.hour == 0 && date_time.unit.minute == 10)
|
||||
tempchart_save();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void tempchart_face_resign(movement_settings_t *settings, void *context) {
|
||||
// our watch face, like most watch faces, has nothing special to do when resigning.
|
||||
// watch faces that enable a peripheral or interact with a sensor may want to turn it off here.
|
||||
(void) settings;
|
||||
(void) context;
|
||||
}
|
||||
|
||||
//background freq correction
|
||||
bool tempchart_face_wants_background_task(movement_settings_t *settings, void *context) {
|
||||
(void) settings;
|
||||
(void) context;
|
||||
watch_date_time date_time = watch_rtc_get_date_time();
|
||||
|
||||
//Updating data every 5 minutes
|
||||
return date_time.unit.minute % 5 == 0;
|
||||
}
|
||||
45
movement/watch_faces/complication/tempchart_face.h
Normal file
45
movement/watch_faces/complication/tempchart_face.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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 TEMPCHART_FACE_H_
|
||||
#define TEMPCHART_FACE_H_
|
||||
|
||||
#include "movement.h"
|
||||
|
||||
void tempchart_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
|
||||
void tempchart_face_activate(movement_settings_t *settings, void *context);
|
||||
bool tempchart_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
|
||||
void tempchart_face_resign(movement_settings_t *settings, void *context);
|
||||
bool tempchart_face_wants_background_task(movement_settings_t *settings, void *context);
|
||||
|
||||
|
||||
#define tempchart_face ((const watch_face_t){ \
|
||||
tempchart_face_setup, \
|
||||
tempchart_face_activate, \
|
||||
tempchart_face_loop, \
|
||||
tempchart_face_resign, \
|
||||
tempchart_face_wants_background_task, \
|
||||
})
|
||||
|
||||
#endif // TEMPCHART_FACE_H_
|
||||
Reference in New Issue
Block a user