movement: add time zone conversion in sunrise/sunset face
This commit is contained in:
parent
3efdcd78a1
commit
68f17c8970
@ -46,6 +46,7 @@
|
|||||||
|
|
||||||
const watch_face_t watch_faces[] = {
|
const watch_face_t watch_faces[] = {
|
||||||
simple_clock_face,
|
simple_clock_face,
|
||||||
|
sunrise_sunset_face,
|
||||||
preferences_face,
|
preferences_face,
|
||||||
set_time_face,
|
set_time_face,
|
||||||
};
|
};
|
||||||
|
@ -33,12 +33,13 @@
|
|||||||
#include "watch_utility.h"
|
#include "watch_utility.h"
|
||||||
#include "sunriset.h"
|
#include "sunriset.h"
|
||||||
|
|
||||||
static void _sunrise_sunset_face_update() {
|
static void _sunrise_sunset_face_update(movement_settings_t *settings) {
|
||||||
char buf[14];
|
char buf[14];
|
||||||
double rise, set, minutes;
|
double rise, set, minutes;
|
||||||
// TODO: allow user to set location, using London for now.
|
// TODO: allow user to set location, using New York for now.
|
||||||
double lat = 51.509865;
|
double lat = 40.730610;
|
||||||
double lon = -0.118092;
|
double lon = -73.935242;
|
||||||
|
|
||||||
// TODO: account for time zone, currently only operates in GMT.
|
// TODO: account for time zone, currently only operates in GMT.
|
||||||
watch_date_time date_time = watch_rtc_get_date_time(); // the current date / time
|
watch_date_time date_time = watch_rtc_get_date_time(); // the current date / time
|
||||||
watch_date_time scratch_time; // scratchpad, contains different values at different times
|
watch_date_time scratch_time; // scratchpad, contains different values at different times
|
||||||
@ -67,6 +68,7 @@ static void _sunrise_sunset_face_update() {
|
|||||||
|
|
||||||
if (date_time.reg < scratch_time.reg) {
|
if (date_time.reg < scratch_time.reg) {
|
||||||
// display today's sunrise, it hasn't happened yet
|
// display today's sunrise, it hasn't happened yet
|
||||||
|
scratch_time = watch_utility_date_time_convert_zone(scratch_time, 0, movement_timezone_offsets[settings->bit.time_zone] * 60);
|
||||||
sprintf(buf, "rI%2d%2d%02d%02d", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute, scratch_time.unit.second);
|
sprintf(buf, "rI%2d%2d%02d%02d", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute, scratch_time.unit.second);
|
||||||
watch_display_string(buf, 0);
|
watch_display_string(buf, 0);
|
||||||
return;
|
return;
|
||||||
@ -79,6 +81,7 @@ static void _sunrise_sunset_face_update() {
|
|||||||
|
|
||||||
if (date_time.reg < scratch_time.reg) {
|
if (date_time.reg < scratch_time.reg) {
|
||||||
// display today's sunset, it hasn't happened yet
|
// display today's sunset, it hasn't happened yet
|
||||||
|
scratch_time = watch_utility_date_time_convert_zone(scratch_time, 0, movement_timezone_offsets[settings->bit.time_zone] * 60);
|
||||||
sprintf(buf, "SE%2d%02d%02d%02d", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute, scratch_time.unit.second);
|
sprintf(buf, "SE%2d%02d%02d%02d", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute, scratch_time.unit.second);
|
||||||
watch_display_string(buf, 0);
|
watch_display_string(buf, 0);
|
||||||
return;
|
return;
|
||||||
@ -114,7 +117,7 @@ bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *setti
|
|||||||
|
|
||||||
switch (event.event_type) {
|
switch (event.event_type) {
|
||||||
case EVENT_ACTIVATE:
|
case EVENT_ACTIVATE:
|
||||||
_sunrise_sunset_face_update();
|
_sunrise_sunset_face_update(settings);
|
||||||
break;
|
break;
|
||||||
case EVENT_LOW_ENERGY_UPDATE:
|
case EVENT_LOW_ENERGY_UPDATE:
|
||||||
case EVENT_TICK:
|
case EVENT_TICK:
|
||||||
|
@ -146,6 +146,11 @@ watch_date_time watch_utility_date_time_from_unix_time(uint32_t timestamp, uint3
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
watch_date_time watch_utility_date_time_convert_zone(watch_date_time date_time, uint32_t origin_utc_offset, uint32_t destination_utc_offset) {
|
||||||
|
uint32_t timestamp = watch_utility_date_time_to_unix_time(date_time, origin_utc_offset);
|
||||||
|
return watch_utility_date_time_from_unix_time(timestamp, destination_utc_offset);
|
||||||
|
}
|
||||||
|
|
||||||
float watch_utility_thermistor_temperature(uint16_t value, bool highside, float b_coefficient, float nominal_temperature, float nominal_resistance, float series_resistance) {
|
float watch_utility_thermistor_temperature(uint16_t value, bool highside, float b_coefficient, float nominal_temperature, float nominal_resistance, float series_resistance) {
|
||||||
float reading = (float)value;
|
float reading = (float)value;
|
||||||
|
|
||||||
|
@ -70,6 +70,17 @@ uint32_t watch_utility_date_time_to_unix_time(watch_date_time date_time, uint32_
|
|||||||
*/
|
*/
|
||||||
watch_date_time watch_utility_date_time_from_unix_time(uint32_t timestamp, uint32_t utc_offset);
|
watch_date_time watch_utility_date_time_from_unix_time(uint32_t timestamp, uint32_t utc_offset);
|
||||||
|
|
||||||
|
/** @brief Converts a time from a given time zone to another time zone.
|
||||||
|
* @param date_time The watch_date_time that you wish to convert
|
||||||
|
* @param origin_utc_offset The number of seconds from UTC in the origin time zone
|
||||||
|
* @param destination_utc_offset The number of seconds from UTC in the destination time zone
|
||||||
|
* @return A watch_date_time for the given UNIX timestamp and UTC offset, or if outside the range that
|
||||||
|
* watch_date_time can represent, a watch_date_time with all fields set to 0.
|
||||||
|
* @note Adapted from MIT-licensed code from musl, Copyright © 2005-2014 Rich Felker, et al.:
|
||||||
|
* https://github.com/esmil/musl/blob/1cc81f5cb0df2b66a795ff0c26d7bbc4d16e13c6/src/time/__secs_to_tm.c
|
||||||
|
*/
|
||||||
|
watch_date_time watch_utility_date_time_convert_zone(watch_date_time date_time, uint32_t origin_utc_offset, uint32_t destination_utc_offset);
|
||||||
|
|
||||||
/** @brief Returns a temperature in degrees Celsius for a given thermistor voltage divider circuit.
|
/** @brief Returns a temperature in degrees Celsius for a given thermistor voltage divider circuit.
|
||||||
* @param value The raw analog reading from the thermistor pin (0-65535)
|
* @param value The raw analog reading from the thermistor pin (0-65535)
|
||||||
* @param highside True if the thermistor is connected to VCC and the series resistor is connected
|
* @param highside True if the thermistor is connected to VCC and the series resistor is connected
|
||||||
|
Loading…
x
Reference in New Issue
Block a user