Skip to content

Commit

Permalink
Allow to cycle backwards through the credentials.
Browse files Browse the repository at this point in the history
It is helpful to be able to go back to the previous credential by
pressing the light button.
Pressing the light button longer (for more than half a second)
activates the LED.
  • Loading branch information
maxz committed Jan 20, 2024
1 parent 82660b4 commit 055d9c9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
24 changes: 24 additions & 0 deletions movement/watch_faces/complication/totp_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ static uint8_t keys[] = {

#define NUMBER_OF_CREDENTIALS (sizeof(credentials) / sizeof(totp_parameters_t))

static uint16_t key_offset(uint8_t credential_index) {
uint16_t offset = 0;
for (uint8_t i = 0; i < credential_index; ++i) {
offset += credentials[i].key_size;
}
return offset;
}

static void _update_display(totp_state_t *totp_state) {
char buf[14];
div_t result;
Expand Down Expand Up @@ -126,8 +134,24 @@ bool totp_face_loop(movement_event_t event, movement_settings_t *settings, void
TOTP(keys + totp_state->current_key_offset, credentials[totp_state->current_index].key_size, credentials[totp_state->current_index].time_step, credentials[totp_state->current_index].algorithm);
_update_display(totp_state);
break;
case EVENT_LIGHT_BUTTON_UP:
if (totp_state->current_index - 1 >= 0) {
totp_state->current_key_offset -= credentials[totp_state->current_index].key_size;
totp_state->current_index--;
} else {
// Wrap around to the last credential.
totp_state->current_index = NUMBER_OF_CREDENTIALS - 1;
totp_state->current_key_offset = key_offset(totp_state->current_index);
}
TOTP(keys + totp_state->current_key_offset, credentials[totp_state->current_index].key_size, credentials[totp_state->current_index].time_step, credentials[totp_state->current_index].algorithm);
_update_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);
Expand Down
2 changes: 2 additions & 0 deletions movement/watch_faces/complication/totp_face.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
* o Once finished, remove the five 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"
Expand Down
15 changes: 14 additions & 1 deletion movement/watch_faces/complication/totp_face_lfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions movement/watch_faces/complication/totp_face_lfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 055d9c9

Please sign in to comment.