Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple fixes and improvements #380

Merged
merged 67 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
868fecd
add compile-time options for all preferences to movement_config
Oct 2, 2023
fc8c1fc
moon_phase_face: Make alarm long-press reset to current day.
WesleyAC Nov 3, 2023
1f6409a
sunrise_sunset_face: Fix use of uninitialized memory.
WesleyAC Nov 19, 2023
89e86fe
work around silicon erratum in TRNG
Dec 17, 2023
68f3865
work around silicon erratum in SUPC/VREG
Dec 17, 2023
93d7f38
fix simulator build by declaring Trng type as a void pointer
Dec 17, 2023
d10fa22
address SysTick erratum, which can hard-fault the chip
Dec 18, 2023
d96d6f9
make the HAL sleep function obey the chip documentation
Dec 18, 2023
de692e0
make any unknown interrupts/faults reset the microcontroller
Dec 18, 2023
5b762d0
USB Improvements
Hylian Oct 15, 2023
83a0e4e
annotate TRNG erratum, address review comment
Jan 22, 2024
2ae8f98
annotate SysTick erratum
Jan 22, 2024
af49d3c
annotate voltage regulation erratum
Jan 22, 2024
a2a60eb
annotate SLEEPCFG-register detail
Jan 22, 2024
3c6affb
Merge branch 'main' into preferences_in_config
madhogs Feb 14, 2024
67907e4
faces/totp: define TOTP data structure
matheusmoreira Feb 21, 2024
8a7d932
faces/totp: define TOTP struct initializer macro
matheusmoreira Feb 21, 2024
a99f6a7
faces/totp: update example data to new structure
matheusmoreira Feb 21, 2024
48e7fb1
faces/totp: define TOTP data array size function
matheusmoreira Feb 21, 2024
bbb920a
faces/totp: define current TOTP data function
matheusmoreira Feb 21, 2024
79cfe31
faces/totp: update watch face logic for new struct
matheusmoreira Feb 21, 2024
0ebd94c
faces/totp: delete unused structure field
matheusmoreira Feb 21, 2024
1c0050c
faces/totp: update copyright and license data
matheusmoreira Feb 21, 2024
ea47bf9
faces/pulsometer: implement advanced pulsometer
matheusmoreira Feb 21, 2024
4b67ef5
faces/pulsometer: document the advanced pulsometer
matheusmoreira Feb 21, 2024
4d77273
faces/pulsometer: update copyrights and credits
matheusmoreira Feb 21, 2024
30ebf47
faces/pulsometer: move structure definition
matheusmoreira Feb 24, 2024
8f04025
faces: rename simple_clock_face to clock_face
matheusmoreira Feb 24, 2024
01312c2
faces/clock: move structure definition
matheusmoreira Feb 24, 2024
e6d8b6a
faces/clock: define general indication function
matheusmoreira Feb 24, 2024
e2cba9f
faces/clock: simplify alarm indication function
matheusmoreira Feb 24, 2024
2132320
faces/clock: simplify signal indication function
matheusmoreira Feb 24, 2024
113b4bb
faces/clock: simplify 24h indication function
matheusmoreira Feb 24, 2024
9171339
faces/clock: simplify PM indication function
matheusmoreira Feb 24, 2024
0773439
faces/clock: refactor daily battery check
matheusmoreira Feb 25, 2024
e7052fe
faces/clock: simplify LAP indication function
matheusmoreira Feb 25, 2024
1d79930
faces/clock: refactor low power tick function
matheusmoreira Feb 25, 2024
76add5a
faces/clock: refactor tick tock animation code
matheusmoreira Feb 25, 2024
8f07192
faces/clock: refactor full time display code
matheusmoreira Feb 25, 2024
bf4d7a3
faces/clock: refactor partial time display code
matheusmoreira Feb 25, 2024
830200f
faces/clock: reorder periodic battery check
matheusmoreira Feb 25, 2024
1e2c23c
faces/clock: refactor clock display code
matheusmoreira Feb 25, 2024
2df6b28
faces/clock: refactor time signal toggling code
matheusmoreira Feb 25, 2024
5c376d9
faces/clock: indicate alarm only when necessary
matheusmoreira Feb 25, 2024
69639a5
faces/clock: indicate low power only when needed
matheusmoreira Feb 25, 2024
d705115
faces/totp: decode secrets when setting up
matheusmoreira Feb 26, 2024
46a4076
faces/totp: improve TOTP initializer labeling
matheusmoreira Feb 26, 2024
238709e
faces/totp: rename initializer macro to credential
matheusmoreira Feb 26, 2024
4633be0
faces/totp: delete leading underscores
matheusmoreira Feb 26, 2024
4cca3a0
faces/clock: update copyrights and credits
matheusmoreira Feb 24, 2024
4a66035
faces/clock: add 24h only feature
matheusmoreira Feb 25, 2024
26e1b7b
faces/totp: allow moving backwards through codes
maxz Jan 20, 2024
92baa22
faces/totp: update copyrights
matheusmoreira Mar 5, 2024
e1b1493
faces/pulsometer: remember pulsometer calibration
matheusmoreira Mar 5, 2024
fb3b96c
faces/pulsometer: remember pulsometer measurement
matheusmoreira Mar 5, 2024
6ca553e
movement: convert can_sleep an automatic variable
matheusmoreira Mar 6, 2024
b1adbd5
movement: fix unintended timeout short circuiting
matheusmoreira Mar 6, 2024
a4ee7dd
Merge 'fix-sunrise-sunset-uninitialized'
matheusmoreira Mar 5, 2024
592e18b
Merge branch 'silicon-errata' into advanced
matheusmoreira Mar 5, 2024
35c0a4b
Merge branch 'usb-improvements' into advanced
matheusmoreira Mar 5, 2024
f35cb84
Merge branch 'compile-time-preferences'
matheusmoreira Mar 5, 2024
7208df1
Merge branch 'moon-phase-face-long-press-reset'
matheusmoreira Mar 5, 2024
4b269c5
Merge branch 'advanced-clock+24h' into advanced
matheusmoreira Mar 5, 2024
6679680
Merge branch 'advanced-pulsometer' into advanced
matheusmoreira Mar 5, 2024
ca40d10
Merge branch 'structured-totp+maxz' into advanced
matheusmoreira Mar 5, 2024
8bf652f
Merge branch 'timeout-event-and-sleep-logic'
matheusmoreira Mar 6, 2024
955ac94
faces: restore simple_clock_face
matheusmoreira Mar 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions make.mk
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ SRCS += \
$(TOP)/watch-library/hardware/watch/watch_storage.c \
$(TOP)/watch-library/hardware/watch/watch_deepsleep.c \
$(TOP)/watch-library/hardware/watch/watch_private.c \
$(TOP)/watch-library/hardware/watch/watch_private_cdc.c \
$(TOP)/watch-library/hardware/watch/watch.c \
$(TOP)/watch-library/hardware/hal/src/hal_atomic.c \
$(TOP)/watch-library/hardware/hal/src/hal_delay.c \
Expand Down Expand Up @@ -229,3 +230,9 @@ endif
ifeq ($(BOARD), OSO-FEAL-A1-00)
CFLAGS += -DCRYSTALLESS
endif

# Build options to customize movement and faces

ifdef CLOCK_FACE_24H_ONLY
CFLAGS += -DCLOCK_FACE_24H_ONLY
endif
121 changes: 61 additions & 60 deletions movement/filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static int filesystem_ls(lfs_t *lfs, const char *path) {

printf("%4ld bytes ", info.size);

printf("%s\n", info.name);
printf("%s\r\n", info.name);
}

err = lfs_dir_close(lfs, &dir);
Expand All @@ -117,11 +117,11 @@ bool filesystem_init(void) {
// reformat if we can't mount the filesystem
// this should only happen on the first boot
if (err < 0) {
printf("Ignore that error! Formatting filesystem...\n");
printf("Ignore that error! Formatting filesystem...\r\n");
err = lfs_format(&lfs, &cfg);
if (err < 0) return false;
err = lfs_mount(&lfs, &cfg) == LFS_ERR_OK;
printf("Filesystem mounted with %ld bytes free.\n", filesystem_get_free_space());
printf("Filesystem mounted with %ld bytes free.\r\n", filesystem_get_free_space());
}

return err == LFS_ERR_OK;
Expand All @@ -139,7 +139,7 @@ bool filesystem_rm(char *filename) {
if (filesystem_file_exists(filename)) {
return lfs_remove(&lfs, filename) == LFS_ERR_OK;
} else {
printf("rm: %s: No such file\n", filename);
printf("rm: %s: No such file\r\n", filename);
return false;
}
}
Expand Down Expand Up @@ -197,13 +197,13 @@ static void filesystem_cat(char *filename) {
char *buf = malloc(info.size + 1);
filesystem_read_file(filename, buf, info.size);
buf[info.size] = '\0';
printf("%s\n", buf);
printf("%s\r\n", buf);
free(buf);
} else {
printf("\n");
printf("\r\n");
}
} else {
printf("cat: %s: No such file\n", filename);
printf("cat: %s: No such file\r\n", filename);
}
}

Expand All @@ -223,59 +223,60 @@ bool filesystem_append_file(char *filename, char *text, int32_t length) {
return lfs_file_close(&lfs, &file) == LFS_ERR_OK;
}

void filesystem_process_command(char *line) {
printf("$ %s", line);
char *command = strtok(line, " \n");

if (strcmp(command, "ls") == 0) {
char *directory = strtok(NULL, " \n");
if (directory == NULL) {
filesystem_ls(&lfs, "/");
} else {
printf("usage: ls\n");
}
} else if (strcmp(command, "cat") == 0) {
char *filename = strtok(NULL, " \n");
if (filename == NULL) {
printf("usage: cat file\n");
} else {
filesystem_cat(filename);
}
} else if (strcmp(command, "df") == 0) {
printf("free space: %ld bytes\n", filesystem_get_free_space());
} else if (strcmp(command, "rm") == 0) {
char *filename = strtok(NULL, " \n");
if (filename == NULL) {
printf("usage: rm file\n");
} else {
filesystem_rm(filename);
}
} else if (strcmp(command, "echo") == 0) {
char *text = malloc(248);
memset(text, 0, 248);
size_t pos = 0;
char *word = strtok(NULL, " \n");
while (strcmp(word, ">") && strcmp(word, ">>")) {
sprintf(text + pos, "%s ", word);
pos += strlen(word) + 1;
word = strtok(NULL, " \n");
if (word == NULL) break;
}
text[strlen(text) - 1] = 0;
char *filename = strtok(NULL, " \n");
if (filename == NULL) {
printf("usage: echo text > file\n");
} else if (strchr(filename, '/') || strchr(filename, '\\')) {
printf("subdirectories are not supported\n");
} else if (!strcmp(word, ">")) {
filesystem_write_file(filename, text, strlen(text));
filesystem_append_file(filename, "\n", 1);
} else if (!strcmp(word, ">>")) {
filesystem_append_file(filename, text, strlen(text));
filesystem_append_file(filename, "\n", 1);
}
free(text);
int filesystem_cmd_ls(int argc, char *argv[]) {
if (argc >= 2) {
filesystem_ls(&lfs, argv[1]);
} else {
printf("%s: command not found\n", command);
filesystem_ls(&lfs, "/");
}
return 0;
}

int filesystem_cmd_cat(int argc, char *argv[]) {
(void) argc;
filesystem_cat(argv[1]);
return 0;
}

int filesystem_cmd_df(int argc, char *argv[]) {
(void) argc;
(void) argv;
printf("free space: %ld bytes\r\n", filesystem_get_free_space());
return 0;
}

int filesystem_cmd_rm(int argc, char *argv[]) {
(void) argc;
filesystem_rm(argv[1]);
return 0;
}

int filesystem_cmd_echo(int argc, char *argv[]) {
(void) argc;

char *line = argv[1];
size_t line_len = strlen(line);
if (line[0] == '"' || line[0] == '\'') {
line++;
line_len -= 2;
line[line_len] = '\0';
}

if (strchr(argv[3], '/')) {
printf("subdirectories are not supported\r\n");
return -2;
}

if (!strcmp(argv[2], ">")) {
filesystem_write_file(argv[3], line, line_len);
filesystem_append_file(argv[3], "\n", 1);
} else if (!strcmp(argv[2], ">>")) {
filesystem_append_file(argv[3], line, line_len);
filesystem_append_file(argv[3], "\n", 1);
} else {
return -2;
}

return 0;
}

9 changes: 5 additions & 4 deletions movement/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ bool filesystem_write_file(char *filename, char *text, int32_t length);
*/
bool filesystem_append_file(char *filename, char *text, int32_t length);

/** @brief Handles the interactive file browser when Movement is plugged in to USB.
* @param line The command that the user typed into the serial console.
*/
void filesystem_process_command(char *line);
int filesystem_cmd_ls(int argc, char *argv[]);
int filesystem_cmd_cat(int argc, char *argv[]);
int filesystem_cmd_df(int argc, char *argv[]);
int filesystem_cmd_rm(int argc, char *argv[]);
int filesystem_cmd_echo(int argc, char *argv[]);

#endif // FILESYSTEM_H_
3 changes: 3 additions & 0 deletions movement/make/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ SRCS += \
../../littlefs/lfs_util.c \
../movement.c \
../filesystem.c \
../shell.c \
../shell_cmd_list.c \
../watch_faces/clock/simple_clock_face.c \
../watch_faces/clock/clock_face.c \
../watch_faces/clock/world_clock_face.c \
../watch_faces/clock/beats_face.c \
../watch_faces/clock/weeknumber_clock_face.c \
Expand Down
64 changes: 36 additions & 28 deletions movement/movement.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "watch.h"
#include "filesystem.h"
#include "movement.h"
#include "shell.h"

#ifndef MOVEMENT_FIRMWARE
#include "movement_config.h"
Expand Down Expand Up @@ -69,6 +70,31 @@
#define MOVEMENT_DEFAULT_GREEN_COLOR 0xF
#endif

// Default to 12h mode
#ifndef MOVEMENT_DEFAULT_24H_MODE
#define MOVEMENT_DEFAULT_24H_MODE false
#endif

// Default to mode button sounding on press
#ifndef MOVEMENT_DEFAULT_BUTTON_SOUND
#define MOVEMENT_DEFAULT_BUTTON_SOUND true
#endif

// Default to switch back to main watch face after 60 seconds
#ifndef MOVEMENT_DEFAULT_TIMEOUT_INTERVAL
#define MOVEMENT_DEFAULT_TIMEOUT_INTERVAL 0
#endif

// Default to switch to low energy mode after 2 hours
#ifndef MOVEMENT_DEFAULT_LOW_ENERGY_INTERVAL
#define MOVEMENT_DEFAULT_LOW_ENERGY_INTERVAL 2
#endif

// Default to 1 second led duration
#ifndef MOVEMENT_DEFAULT_LED_DURATION
#define MOVEMENT_DEFAULT_LED_DURATION 1
#endif

#if __EMSCRIPTEN__
#include <emscripten.h>
#endif
Expand Down Expand Up @@ -351,11 +377,13 @@ void app_init(void) {

memset(&movement_state, 0, sizeof(movement_state));

movement_state.settings.bit.clock_mode_24h = MOVEMENT_DEFAULT_24H_MODE;
movement_state.settings.bit.led_red_color = MOVEMENT_DEFAULT_RED_COLOR;
movement_state.settings.bit.led_green_color = MOVEMENT_DEFAULT_GREEN_COLOR;
movement_state.settings.bit.button_should_sound = true;
movement_state.settings.bit.le_interval = 2;
movement_state.settings.bit.led_duration = 1;
movement_state.settings.bit.button_should_sound = MOVEMENT_DEFAULT_BUTTON_SOUND;
movement_state.settings.bit.to_interval = MOVEMENT_DEFAULT_TIMEOUT_INTERVAL;
movement_state.settings.bit.le_interval = MOVEMENT_DEFAULT_LOW_ENERGY_INTERVAL;
movement_state.settings.bit.led_duration = MOVEMENT_DEFAULT_LED_DURATION;
movement_state.light_ticks = -1;
movement_state.alarm_ticks = -1;
movement_state.next_available_backup_register = 4;
Expand Down Expand Up @@ -509,7 +537,7 @@ bool app_loop(void) {
}

// default to being allowed to sleep by the face.
static bool can_sleep = true;
bool can_sleep = true;

if (event.event_type) {
event.subsecond = movement_state.subsecond;
Expand All @@ -533,7 +561,8 @@ bool app_loop(void) {
// first trip | can sleep | cannot sleep | can sleep | cannot sleep
// second trip | can sleep | cannot sleep | cannot sleep | can sleep
// && | can sleep | cannot sleep | cannot sleep | cannot sleep
can_sleep = can_sleep && wf->loop(event, &movement_state.settings, watch_face_contexts[movement_state.current_face_idx]);
bool can_sleep2 = wf->loop(event, &movement_state.settings, watch_face_contexts[movement_state.current_face_idx]);
can_sleep = can_sleep && can_sleep2;
event.event_type = EVENT_NONE;
if (movement_state.settings.bit.to_always && movement_state.current_face_idx != 0) {
// ...but if the user has "timeout always" set, give it the boot.
Expand Down Expand Up @@ -561,30 +590,9 @@ bool app_loop(void) {
}
}

// if we are plugged into USB, handle the file browser tasks
// if we are plugged into USB, handle the serial shell
if (watch_is_usb_enabled()) {
char line[256] = {0};
#if __EMSCRIPTEN__
// This is a terrible hack; ideally this should be handled deeper in the watch library.
// Alas, emscripten treats read() as something that should pop up an input box, so I
// wasn't able to implement this over there. I sense that this relates to read() being
// the wrong way to read data from USB (like we should be using fgets or something), but
// until I untangle that, this will have to do.
char *received_data = (char*)EM_ASM_INT({
var len = lengthBytesUTF8(tx) + 1;
var s = _malloc(len);
stringToUTF8(tx, s, len);
return s;
});
memcpy(line, received_data, min(255, strlen(received_data)));
free(received_data);
EM_ASM({
tx = "";
});
#else
read(0, line, 256);
#endif
if (strlen(line)) filesystem_process_command(line);
shell_task();
}

event.subsecond = 0;
Expand Down
43 changes: 43 additions & 0 deletions movement/movement_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,47 @@ const watch_face_t watch_faces[] = {
/* Custom hourly chime tune. Check movement_custom_signal_tunes.h for options. */
#define SIGNAL_TUNE_DEFAULT

/* Determines the intensity of the led colors
* Set a hex value 0-15 with 0x0 being off and 0xF being max intensity
*/
#define MOVEMENT_DEFAULT_GREEN_COLOR 0xF
#define MOVEMENT_DEFAULT_RED_COLOR 0x0

/* Set to true for 24h mode or false for 12h mode */
#define MOVEMENT_DEFAULT_24H_MODE false

/* Enable or disable the sound on mode button press */
#define MOVEMENT_DEFAULT_BUTTON_SOUND true

/* Set the timeout before switching back to the main watch face
* Valid values are:
* 0: 60 seconds
* 1: 2 minutes
* 2: 5 minutes
* 3: 30 minutes
*/
#define MOVEMENT_DEFAULT_TIMEOUT_INTERVAL 0

/* Set the timeout before switching to low energy mode
* Valid values are:
* 0: Never
* 1: 1 hour
* 2: 2 hours
* 3: 6 hours
* 4: 12 hours
* 5: 1 day
* 6: 2 days
* 7: 7 days
*/
#define MOVEMENT_DEFAULT_LOW_ENERGY_INTERVAL 1

/* Set the led duration
* Valid values are:
* 0: No LED
* 1: 1 second
* 2: 3 seconds
* 3: 5 seconds
*/
#define MOVEMENT_DEFAULT_LED_DURATION 1

#endif // MOVEMENT_CONFIG_H_
1 change: 1 addition & 0 deletions movement/movement_faces.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define MOVEMENT_FACES_H_

#include "simple_clock_face.h"
#include "clock_face.h"
#include "world_clock_face.h"
#include "preferences_face.h"
#include "set_time_face.h"
Expand Down
Loading
Loading