diff options
author | Max Zettlmeißl <max@zettlmeissl.de> | 2024-01-21 00:15:01 +0100 |
---|---|---|
committer | Matheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com> | 2024-03-05 03:58:09 -0300 |
commit | 26e1b7bdc4ae4c76ce6e424091bf573d6d61059a (patch) | |
tree | 44fbf7171d187ff181afdb0d851b12492d444e78 | |
parent | 4633be0845aab21603f0f09e1ab026c74e7fc547 (diff) | |
download | Sensor-Watch-26e1b7bdc4ae4c76ce6e424091bf573d6d61059a.tar.gz Sensor-Watch-26e1b7bdc4ae4c76ce6e424091bf573d6d61059a.tar.bz2 Sensor-Watch-26e1b7bdc4ae4c76ce6e424091bf573d6d61059a.zip |
faces/totp: allow moving backwards through codes
Adds the ability to cycle back to the previous credential with LIGHT.
Long pressing LIGHT activates the LED.
Co-authored-by: Matheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com>
-rw-r--r-- | movement/watch_faces/complication/totp_face.c | 18 | ||||
-rw-r--r-- | movement/watch_faces/complication/totp_face.h | 2 | ||||
-rw-r--r-- | movement/watch_faces/complication/totp_face_lfs.c | 15 | ||||
-rw-r--r-- | movement/watch_faces/complication/totp_face_lfs.h | 2 |
4 files changed, 35 insertions, 2 deletions
diff --git a/movement/watch_faces/complication/totp_face.c b/movement/watch_faces/complication/totp_face.c index 35e435c6..b0a4f5c5 100644 --- a/movement/watch_faces/complication/totp_face.c +++ b/movement/watch_faces/complication/totp_face.c @@ -130,6 +130,7 @@ void totp_face_activate(movement_settings_t *settings, void *context) { bool totp_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { (void) settings; totp_state_t *totp_state = (totp_state_t *)context; + totp_t *totp; switch (event.event_type) { case EVENT_TICK: @@ -148,12 +149,27 @@ bool totp_face_loop(movement_event_t event, movement_settings_t *settings, void // wrap around to first key totp_state->current_index = 0; } - totp_t *totp = totp_current(totp_state); + totp = totp_current(totp_state); + TOTP(totp->key, totp->key_length, totp->period, totp->algorithm); + totp_display(totp_state); + break; + case EVENT_LIGHT_BUTTON_UP: + if (totp_state->current_index == 0) { + // Wrap around to the last credential. + totp_state->current_index = totp_total() - 1; + } else { + totp_state->current_index--; + } + totp = totp_current(totp_state); TOTP(totp->key, totp->key_length, totp->period, totp->algorithm); totp_display(totp_state); break; case EVENT_ALARM_BUTTON_DOWN: case EVENT_ALARM_LONG_PRESS: + case EVENT_LIGHT_BUTTON_DOWN: + break; + case EVENT_LIGHT_LONG_PRESS: + movement_illuminate_led(); break; default: movement_default_loop_handler(event, settings); diff --git a/movement/watch_faces/complication/totp_face.h b/movement/watch_faces/complication/totp_face.h index 9332435c..8bde4713 100644 --- a/movement/watch_faces/complication/totp_face.h +++ b/movement/watch_faces/complication/totp_face.h @@ -58,6 +58,8 @@ * o Once finished, remove the two provided examples. * * If you have more than one secret key, press ALARM to cycle through them. + * Press LIGHT to cycle in the other direction or keep it pressed longer to + * activate the light. */ #include "movement.h" diff --git a/movement/watch_faces/complication/totp_face_lfs.c b/movement/watch_faces/complication/totp_face_lfs.c index 4066ac48..820ad52e 100644 --- a/movement/watch_faces/complication/totp_face_lfs.c +++ b/movement/watch_faces/complication/totp_face_lfs.c @@ -163,7 +163,7 @@ static void totp_face_lfs_read_file(char *filename) { continue; } - // If we found a probably valid TOTP record, keep it. + // If we found a probably valid TOTP record, keep it. if (totp_records[num_totp_records].secret_size) { num_totp_records += 1; } else { @@ -255,8 +255,21 @@ bool totp_face_lfs_loop(movement_event_t event, movement_settings_t *settings, v totp_face_set_record(totp_state, (totp_state->current_index + 1) % num_totp_records); totp_face_display(totp_state); break; + case EVENT_LIGHT_BUTTON_UP: + if (totp_state->current_index - 1 >= 0) { + totp_face_set_record(totp_state, totp_state->current_index - 1); + } else { + // Wrap around to the last record. + totp_face_set_record(totp_state, num_totp_records - 1); + } + totp_face_display(totp_state); + break; case EVENT_ALARM_BUTTON_DOWN: case EVENT_ALARM_LONG_PRESS: + case EVENT_LIGHT_BUTTON_DOWN: + break; + case EVENT_LIGHT_LONG_PRESS: + movement_illuminate_led(); break; default: movement_default_loop_handler(event, settings); diff --git a/movement/watch_faces/complication/totp_face_lfs.h b/movement/watch_faces/complication/totp_face_lfs.h index 64c6ce15..72ae2460 100644 --- a/movement/watch_faces/complication/totp_face_lfs.h +++ b/movement/watch_faces/complication/totp_face_lfs.h @@ -47,6 +47,8 @@ * to modify the URI. * * If you have more than one secret key, press ALARM to cycle through them. + * Press LIGHT to cycle in the other direction or keep it pressed longer to + * activate the light. */ #include "movement.h" |