diff --git a/examples/device/hid_cdc_passkey/src/main.c b/examples/device/hid_cdc_passkey/src/main.c index 6f0e480d2..c971527ce 100644 --- a/examples/device/hid_cdc_passkey/src/main.c +++ b/examples/device/hid_cdc_passkey/src/main.c @@ -435,6 +435,26 @@ void hid_task(void) } } +static void past_credentials(bool user) +{ + if (!credentials || 0 == strlen(username) || 0 == strlen(password)) { + printf("no credentials to paste\r\n"); + return; + } + + user_paste = 0; + pass_paste = 0; + pasted_when = board_millis(); + + if (user) { + send_hid_report(username[user_paste++]); + printf("pasting username and password\r\n"); + } else { + send_hid_report(password[pass_paste++]); + printf("pasting password\r\n"); + } +} + void button_task(void) { static uint32_t button1_ms = 0; // when the button has been pressed (in ms) @@ -485,25 +505,9 @@ void button_task(void) printf("clearing credentials\r\n"); } } else if (!button1_pressed && button1_ok && !button2_ok) { // button 1 released - if (!credentials) { - printf("no credentials saved\r\n"); - } else { - user_paste = 0; - pass_paste = 0; - pasted_when = board_millis(); - send_hid_report(username[user_paste++]); - printf("pasting username and password\r\n"); - } + past_credentials(!config.button_swap); } else if (!button2_pressed && !button1_ok && button2_ok) { // button 2 released - if (!credentials) { - printf("no credentials saved\r\n"); - } else { - user_paste = 0; - pass_paste = 0; - pasted_when = board_millis(); - send_hid_report(password[pass_paste++]); - printf("pasting password\r\n"); - } + past_credentials(config.button_swap); } // clear button state