95 lines
No EOL
2.3 KiB
C
95 lines
No EOL
2.3 KiB
C
// 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);
|
|
} |