diff --git a/project/flippypass.c b/project/flippypass.c index aaa08c1..2d29283 100644 --- a/project/flippypass.c +++ b/project/flippypass.c @@ -1,6 +1,7 @@ // Libraries +/* Main */ #include - +/* Backends */ #include "ui/ui.h" // Entry Point diff --git a/project/ui/app.h b/project/ui/app.h index f132f03..db9f620 100644 --- a/project/ui/app.h +++ b/project/ui/app.h @@ -53,6 +53,7 @@ typedef struct { TextBox* textbox; Popup* popup; + void* usb_prev_mode; Manager* manager; char* keyboard; int selection; diff --git a/project/ui/scenes/send.c b/project/ui/scenes/send.c index 3602962..c23294c 100644 --- a/project/ui/scenes/send.c +++ b/project/ui/scenes/send.c @@ -1,6 +1,9 @@ // Header #include "send.h" +// Libraries +#include "../../workers/sender.h" + // Functions void FP_Scene_Callback_Send(DialogExResult result, void* context) { // Setting context @@ -16,6 +19,10 @@ void FP_Scene_Enter_Send(void* context) { // Reset view dialog_ex_reset(app->dialog); + // Sender worker + FuriHalUsbInterface* usb_mode_prev = sender_init(); + app->usb_prev_mode = usb_mode_prev; + // Adding dialog content dialog_ex_set_header( app->dialog, @@ -33,11 +40,15 @@ void FP_Scene_Enter_Send(void* context) { ); dialog_ex_set_left_button_text( app->dialog, - "Username" + "User" + ); + dialog_ex_set_center_button_text( + app->dialog, + "Enter" ); dialog_ex_set_right_button_text( app->dialog, - "Password" + "Pass" ); // Setting context and callback @@ -51,6 +62,13 @@ void FP_Scene_Exit_Send(void* context) { // Setting context FP_App* app = context; + // Exit + FuriHalUsbInterface* usb_mode_prev = app->usb_prev_mode; + sender_free(usb_mode_prev); + + // Free reference + free(usb_mode_prev); + // Reset menu submenu_reset(app->submenu); } @@ -68,6 +86,15 @@ bool FP_Scene_Event_Send(void* context, SceneManagerEvent event) { // What to do? switch (event.event) { + case DialogExResultLeft: // Username + sender_execute(app->manager->current->user); + break; + case DialogExResultCenter: + sender_return(); + break; + case DialogExResultRight: // Password + sender_execute(app->manager->current->phrase); + break; default: break; } diff --git a/project/workers/sender.c b/project/workers/sender.c new file mode 100644 index 0000000..46ebe63 --- /dev/null +++ b/project/workers/sender.c @@ -0,0 +1,95 @@ +// Header +#include "sender.h" + +// Structures + +// Functions +bool send_string(char* buffer) { + // DEBUG + FURI_LOG_D(TAG, "Sending: %s", buffer); + + // Going through all characters + while (*buffer) { + // Turning buffer into keycode + uint16_t keycode = HID_ASCII_TO_KEY(*buffer); + + // None? + if (keycode != HID_KEYBOARD_NONE) { + // Sending it over to the client + furi_hal_hid_kb_press(keycode); + furi_hal_hid_kb_release(keycode); + } + + // Incriment through string + buffer++; + } + + // Done! + return true; +} +int32_t send_thread(void* context) { + // Starting a Mutex + FuriMutex* mutex = furi_mutex_alloc(FuriMutexTypeNormal); + + // Setting context + char* buffer = context; + + // Sending string + send_string(buffer); + + // Free mutex + furi_mutex_release(mutex); + furi_mutex_free(mutex); + + // Exit + return 0; +} +int32_t send_return() { + // Starting a Mutex + FuriMutex* mutex = furi_mutex_alloc(FuriMutexTypeNormal); + + // Sending string + uint16_t keycode = HID_ASCII_TO_KEY('\n'); + furi_hal_hid_kb_press(keycode); + furi_hal_hid_kb_release(keycode); + + // Free mutex + furi_mutex_release(mutex); + furi_mutex_free(mutex); + + // Exit + return 0; +} + +FuriHalUsbInterface* sender_init() { + // Getting ready to have USB used for keyboard + FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config(); + furi_hal_usb_unlock(); + furi_check(furi_hal_usb_set_config(&usb_hid, NULL) == true); + + return usb_mode_prev; +} +void sender_free(FuriHalUsbInterface* usb_mode_prev) { + // Return to normal + furi_hal_usb_set_config(usb_mode_prev, NULL); +} + +void sender_execute(char* buffer) { + // DEBUG + FURI_LOG_D(TAG, "Sending %s", buffer); + + FuriThread* thread = furi_thread_alloc(); + furi_thread_set_name(thread, "FPBadUSBWorker"); + furi_thread_set_stack_size(thread, 1024); + furi_thread_set_context(thread, buffer); + furi_thread_set_callback(thread, send_thread); + furi_thread_start(thread); +} +void sender_return() { + FuriThread* thread = furi_thread_alloc(); + furi_thread_set_name(thread, "FPBadUSBWorker"); + furi_thread_set_stack_size(thread, 1024); + furi_thread_set_context(thread, NULL); + furi_thread_set_callback(thread, send_return); + furi_thread_start(thread); +} \ No newline at end of file diff --git a/project/workers/sender.h b/project/workers/sender.h new file mode 100644 index 0000000..4042db6 --- /dev/null +++ b/project/workers/sender.h @@ -0,0 +1,20 @@ +// Define once +#ifndef H_SENDER +#define H_SENDER + +// Libraries +#include +#include + +#include +#include + +#include "../backend/base.h" + +// Functions +FuriHalUsbInterface* sender_init(); +void sender_free(FuriHalUsbInterface* usb_mode_prev); +void sender_execute(char* buffer); +void sender_return(); + +#endif \ No newline at end of file