summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoey Castillo <joeycastillo@utexas.edu>2022-02-12 22:52:26 -0500
committerJoey Castillo <joeycastillo@utexas.edu>2022-02-13 11:25:28 -0500
commitee95229e19ea56680828bb57e366729e6f95d079 (patch)
tree0dbbaeb9a49cea5523d7020e4b4fa1e11c6f1b2b
parent0bb267c702be08f420efffc7dd66782c7563e130 (diff)
downloadSensor-Watch-ee95229e19ea56680828bb57e366729e6f95d079.tar.gz
Sensor-Watch-ee95229e19ea56680828bb57e366729e6f95d079.tar.bz2
Sensor-Watch-ee95229e19ea56680828bb57e366729e6f95d079.zip
world clock: store settings in backup register if possible
-rw-r--r--movement/watch_faces/clock/world_clock_face.c47
-rw-r--r--movement/watch_faces/clock/world_clock_face.h13
2 files changed, 34 insertions, 26 deletions
diff --git a/movement/watch_faces/clock/world_clock_face.c b/movement/watch_faces/clock/world_clock_face.c
index de4eeaff..f0f7e954 100644
--- a/movement/watch_faces/clock/world_clock_face.c
+++ b/movement/watch_faces/clock/world_clock_face.c
@@ -33,10 +33,13 @@ void world_clock_face_setup(movement_settings_t *settings, uint8_t watch_face_in
(void) watch_face_index;
if (*context_ptr == NULL) {
*context_ptr = malloc(sizeof(world_clock_state_t));
- world_clock_state_t *state = (world_clock_state_t *)*context_ptr;
- state->settings.char_0 = 0;
- state->settings.char_1 = 0;
- state->settings.timezone_index = 0; // start at UTC
+ memset(*context_ptr, 0, sizeof(world_clock_state_t));
+ uint8_t backup_register = movement_claim_backup_register();
+ if (backup_register) {
+ world_clock_state_t *state = (world_clock_state_t *)*context_ptr;
+ state->settings.reg = watch_get_backup_data(backup_register);
+ state->backup_register = backup_register;
+ }
}
}
@@ -64,7 +67,7 @@ static bool world_clock_face_do_display_mode(movement_event_t event, movement_se
case EVENT_LOW_ENERGY_UPDATE:
date_time = watch_rtc_get_date_time();
timestamp = watch_utility_date_time_to_unix_time(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60);
- date_time = watch_utility_date_time_from_unix_time(timestamp, movement_timezone_offsets[state->settings.timezone_index] * 60);
+ date_time = watch_utility_date_time_from_unix_time(timestamp, movement_timezone_offsets[state->settings.bit.timezone_index] * 60);
previous_date_time = state->previous_date_time;
state->previous_date_time = date_time.reg;
@@ -92,15 +95,15 @@ static bool world_clock_face_do_display_mode(movement_event_t event, movement_se
if (event.event_type == EVENT_LOW_ENERGY_UPDATE) {
if (!watch_tick_animation_is_running()) watch_start_tick_animation(500);
sprintf(buf, "%c%c%2d%2d%02d ",
- movement_valid_position_0_chars[state->settings.char_0],
- movement_valid_position_1_chars[state->settings.char_1],
+ movement_valid_position_0_chars[state->settings.bit.char_0],
+ movement_valid_position_1_chars[state->settings.bit.char_1],
date_time.unit.day,
date_time.unit.hour,
date_time.unit.minute);
} else {
sprintf(buf, "%c%c%2d%2d%02d%02d",
- movement_valid_position_0_chars[state->settings.char_0],
- movement_valid_position_1_chars[state->settings.char_1],
+ movement_valid_position_0_chars[state->settings.bit.char_0],
+ movement_valid_position_1_chars[state->settings.bit.char_1],
date_time.unit.day,
date_time.unit.hour,
date_time.unit.minute,
@@ -129,6 +132,7 @@ static bool world_clock_face_do_display_mode(movement_event_t event, movement_se
static bool _world_clock_face_do_settings_mode(movement_event_t event, movement_settings_t *settings, world_clock_state_t *state) {
switch (event.event_type) {
case EVENT_MODE_BUTTON_UP:
+ if (state->backup_register) watch_store_backup_data(state->settings.reg, state->backup_register);
movement_move_to_next_face();
return false;
case EVENT_LIGHT_BUTTON_DOWN:
@@ -137,26 +141,27 @@ static bool _world_clock_face_do_settings_mode(movement_event_t event, movement_
movement_request_tick_frequency(1);
state->current_screen = 0;
state->previous_date_time = 0xFFFFFFFF;
+ if (state->backup_register) watch_store_backup_data(state->settings.reg, state->backup_register);
world_clock_face_do_display_mode(event, settings, state);
}
break;
case EVENT_ALARM_BUTTON_DOWN:
switch (state->current_screen) {
case 1:
- state->settings.char_0++;
- if (state->settings.char_0 >= strlen(movement_valid_position_0_chars)) {
- state->settings.char_0 = 0;
+ state->settings.bit.char_0++;
+ if (state->settings.bit.char_0 >= strlen(movement_valid_position_0_chars)) {
+ state->settings.bit.char_0 = 0;
}
break;
case 2:
- state->settings.char_1++;
- if (state->settings.char_1 >= strlen(movement_valid_position_1_chars)) {
- state->settings.char_1 = 0;
+ state->settings.bit.char_1++;
+ if (state->settings.bit.char_1 >= strlen(movement_valid_position_1_chars)) {
+ state->settings.bit.char_1 = 0;
}
break;
case 3:
- state->settings.timezone_index++;
- if (state->settings.timezone_index > 40) state->settings.timezone_index = 0;
+ state->settings.bit.timezone_index++;
+ if (state->settings.bit.timezone_index > 40) state->settings.bit.timezone_index = 0;
break;
}
break;
@@ -169,10 +174,10 @@ static bool _world_clock_face_do_settings_mode(movement_event_t event, movement_
char buf[13];
sprintf(buf, "%c%c %3d%02d ",
- movement_valid_position_0_chars[state->settings.char_0],
- movement_valid_position_1_chars[state->settings.char_1],
- (int8_t) (movement_timezone_offsets[state->settings.timezone_index] / 60),
- (int8_t) (movement_timezone_offsets[state->settings.timezone_index] % 60) * (movement_timezone_offsets[state->settings.timezone_index] < 0 ? -1 : 1));
+ movement_valid_position_0_chars[state->settings.bit.char_0],
+ movement_valid_position_1_chars[state->settings.bit.char_1],
+ (int8_t) (movement_timezone_offsets[state->settings.bit.timezone_index] / 60),
+ (int8_t) (movement_timezone_offsets[state->settings.bit.timezone_index] % 60) * (movement_timezone_offsets[state->settings.bit.timezone_index] < 0 ? -1 : 1));
watch_set_colon();
watch_clear_indicator(WATCH_INDICATOR_PM);
diff --git a/movement/watch_faces/clock/world_clock_face.h b/movement/watch_faces/clock/world_clock_face.h
index 36960f53..669dcaa8 100644
--- a/movement/watch_faces/clock/world_clock_face.h
+++ b/movement/watch_faces/clock/world_clock_face.h
@@ -26,15 +26,18 @@
#define WORLD_CLOCK_FACE_H_
#include "movement.h"
-
-typedef struct {
- uint8_t char_0;
- uint8_t char_1;
- uint8_t timezone_index;
+typedef union {
+ struct {
+ uint8_t char_0;
+ uint8_t char_1;
+ uint8_t timezone_index;
+ } bit;
+ uint32_t reg;
} world_clock_settings_t;
typedef struct {
world_clock_settings_t settings;
+ uint8_t backup_register;
uint8_t current_screen;
uint32_t previous_date_time;
} world_clock_state_t;
href='#n499'>499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
```
yosys -- Yosys Open SYnthesis Suite

Copyright (C) 2012 - 2020  Claire Xenia Wolf <claire@yosyshq.com>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
```


yosys – Yosys Open SYnthesis Suite
===================================

This is a framework for RTL synthesis tools. It currently has
extensive Verilog-2005 support and provides a basic set of
synthesis algorithms for various application domains.

Yosys can be adapted to perform any synthesis job by combining
the existing passes (algorithms) using synthesis scripts and
adding additional passes as needed by extending the yosys C++
code base.

Yosys is free software licensed under the ISC license (a GPL
compatible license that is similar in terms to the MIT license
or the 2-clause BSD license).


Web Site and Other Resources
============================

More information and documentation can be found on the Yosys web site:
- https://yosyshq.net/yosys/

The "Documentation" page on the web site contains links to more resources,
including a manual that even describes some of the Yosys internals:
- https://yosyshq.net/yosys/documentation.html

The directory `guidelines` contains additional information
for people interested in using the Yosys C++ APIs.

Users interested in formal verification might want to use the formal verification
front-end for Yosys, SymbiYosys:
- https://symbiyosys.readthedocs.io/en/latest/
- https://github.com/YosysHQ/SymbiYosys


Setup
======

You need a C++ compiler with C++11 support (up-to-date CLANG or GCC is
recommended) and some standard tools such as GNU Flex, GNU Bison, and GNU Make.
TCL, readline and libffi are optional (see ``ENABLE_*`` settings in Makefile).
Xdot (graphviz) is used by the ``show`` command in yosys to display schematics.

For example on Ubuntu Linux 16.04 LTS the following commands will install all
prerequisites for building yosys:

	$ sudo apt-get install build-essential clang bison flex \
		libreadline-dev gawk tcl-dev libffi-dev git \