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>
This commit is contained in:
Max Zettlmeißl
2024-01-21 00:15:01 +01:00
committed by Matheus Afonso Martins Moreira
parent 4633be0845
commit 26e1b7bdc4
4 changed files with 35 additions and 2 deletions

View File

@@ -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);