Skip to content

Commit 9dcb6cb

Browse files
authored
Fixed #24 (#25)
* Fixed #24 * Small improvement to the USB mode restore code
1 parent 766a3d6 commit 9dcb6cb

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

services/hid_worker/hid_worker.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,23 @@ const uint8_t hid_number_keys[10] = {
1212
HID_KEYBOARD_8,
1313
HID_KEYBOARD_9};
1414

15+
static void totp_hid_worker_restore_usb_mode(TotpHidWorkerTypeContext* context) {
16+
if(context->usb_mode_prev != NULL) {
17+
furi_hal_usb_set_config(context->usb_mode_prev, NULL);
18+
context->usb_mode_prev = NULL;
19+
}
20+
}
21+
1522
static void totp_hid_worker_type_code(TotpHidWorkerTypeContext* context) {
16-
FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config();
23+
context->usb_mode_prev = furi_hal_usb_get_config();
1724
furi_hal_usb_unlock();
1825
furi_check(furi_hal_usb_set_config(&usb_hid, NULL) == true);
1926
uint8_t i = 0;
2027
do {
2128
furi_delay_ms(500);
2229
i++;
23-
} while(!furi_hal_hid_is_connected() && i < 100);
30+
} while(!furi_hal_hid_is_connected() && i < 50);
31+
furi_delay_ms(500);
2432

2533
if(furi_hal_hid_is_connected() &&
2634
furi_mutex_acquire(context->string_sync, 500) == FuriStatusOk) {
@@ -37,14 +45,10 @@ static void totp_hid_worker_type_code(TotpHidWorkerTypeContext* context) {
3745

3846
furi_mutex_release(context->string_sync);
3947

40-
furi_hal_hid_kb_press(HID_KEYBOARD_RETURN);
41-
furi_delay_ms(30);
42-
furi_hal_hid_kb_release(HID_KEYBOARD_RETURN);
43-
4448
furi_delay_ms(100);
4549
}
4650

47-
furi_hal_usb_set_config(usb_mode_prev, NULL);
51+
totp_hid_worker_restore_usb_mode(context);
4852
}
4953

5054
static int32_t totp_hid_worker_callback(void* context) {
@@ -77,6 +81,7 @@ TotpHidWorkerTypeContext* totp_hid_worker_start() {
7781
furi_check(context != NULL);
7882
context->string_sync = furi_mutex_alloc(FuriMutexTypeNormal);
7983
context->thread = furi_thread_alloc();
84+
context->usb_mode_prev = NULL;
8085
furi_thread_set_name(context->thread, "TOTPHidWorker");
8186
furi_thread_set_stack_size(context->thread, 1024);
8287
furi_thread_set_context(context->thread, context);
@@ -91,6 +96,7 @@ void totp_hid_worker_stop(TotpHidWorkerTypeContext* context) {
9196
furi_thread_join(context->thread);
9297
furi_thread_free(context->thread);
9398
furi_mutex_free(context->string_sync);
99+
totp_hid_worker_restore_usb_mode(context);
94100
free(context);
95101
}
96102

services/hid_worker/hid_worker.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ typedef struct {
99
uint8_t string_length;
1010
FuriThread* thread;
1111
FuriMutex* string_sync;
12+
FuriHalUsbInterface* usb_mode_prev;
1213
} TotpHidWorkerTypeContext;
1314

1415
typedef enum {

0 commit comments

Comments
 (0)