diff --git a/application.fam b/application.fam index 460acb9..1e419f3 100644 --- a/application.fam +++ b/application.fam @@ -1,6 +1,6 @@ App( - appid="usb_keyboard", - name="USB Keyboard", + appid="USB_Keyboard", + name="USB Keyboard & Mouse", apptype=FlipperAppType.EXTERNAL, entry_point="usb_hid_app", stack_size=1 * 1024, @@ -10,5 +10,6 @@ App( ], order=60, fap_icon="usb_keyboard_10px.png", - fap_category="Tools", + fap_category="Misc", + fap_icon_assets="assets", ) diff --git a/assets/Arr_dwn_7x9.png b/assets/Arr_dwn_7x9.png new file mode 100644 index 0000000..d4034ef Binary files /dev/null and b/assets/Arr_dwn_7x9.png differ diff --git a/assets/Arr_up_7x9.png b/assets/Arr_up_7x9.png new file mode 100644 index 0000000..28b4236 Binary files /dev/null and b/assets/Arr_up_7x9.png differ diff --git a/assets/ButtonDown_7x4.png b/assets/ButtonDown_7x4.png new file mode 100644 index 0000000..2954bb6 Binary files /dev/null and b/assets/ButtonDown_7x4.png differ diff --git a/assets/ButtonLeft_4x7.png b/assets/ButtonLeft_4x7.png new file mode 100644 index 0000000..0b4655d Binary files /dev/null and b/assets/ButtonLeft_4x7.png differ diff --git a/assets/ButtonRight_4x7.png b/assets/ButtonRight_4x7.png new file mode 100644 index 0000000..8e1c74c Binary files /dev/null and b/assets/ButtonRight_4x7.png differ diff --git a/assets/ButtonUp_7x4.png b/assets/ButtonUp_7x4.png new file mode 100644 index 0000000..1be7932 Binary files /dev/null and b/assets/ButtonUp_7x4.png differ diff --git a/assets/Button_18x18.png b/assets/Button_18x18.png new file mode 100644 index 0000000..30a5b4f Binary files /dev/null and b/assets/Button_18x18.png differ diff --git a/assets/Circles_47x47.png b/assets/Circles_47x47.png new file mode 100644 index 0000000..6a16ebf Binary files /dev/null and b/assets/Circles_47x47.png differ diff --git a/assets/Left_mouse_icon_9x9.png b/assets/Left_mouse_icon_9x9.png new file mode 100644 index 0000000..c533d85 Binary files /dev/null and b/assets/Left_mouse_icon_9x9.png differ diff --git a/assets/Like_def_11x9.png b/assets/Like_def_11x9.png new file mode 100644 index 0000000..555bea3 Binary files /dev/null and b/assets/Like_def_11x9.png differ diff --git a/assets/Like_pressed_17x17.png b/assets/Like_pressed_17x17.png new file mode 100644 index 0000000..f5bf276 Binary files /dev/null and b/assets/Like_pressed_17x17.png differ diff --git a/assets/Ok_btn_9x9.png b/assets/Ok_btn_9x9.png new file mode 100644 index 0000000..9a1539d Binary files /dev/null and b/assets/Ok_btn_9x9.png differ diff --git a/assets/Ok_btn_pressed_13x13.png b/assets/Ok_btn_pressed_13x13.png new file mode 100644 index 0000000..6b46ba3 Binary files /dev/null and b/assets/Ok_btn_pressed_13x13.png differ diff --git a/assets/Pin_arrow_down_7x9.png b/assets/Pin_arrow_down_7x9.png new file mode 100644 index 0000000..9687397 Binary files /dev/null and b/assets/Pin_arrow_down_7x9.png differ diff --git a/assets/Pin_arrow_left_9x7.png b/assets/Pin_arrow_left_9x7.png new file mode 100644 index 0000000..fb4ded7 Binary files /dev/null and b/assets/Pin_arrow_left_9x7.png differ diff --git a/assets/Pin_arrow_right_9x7.png b/assets/Pin_arrow_right_9x7.png new file mode 100644 index 0000000..97648d1 Binary files /dev/null and b/assets/Pin_arrow_right_9x7.png differ diff --git a/assets/Pin_arrow_up_7x9.png b/assets/Pin_arrow_up_7x9.png new file mode 100644 index 0000000..a91a6fd Binary files /dev/null and b/assets/Pin_arrow_up_7x9.png differ diff --git a/assets/Pin_back_arrow_10x8.png b/assets/Pin_back_arrow_10x8.png new file mode 100644 index 0000000..3bafabd Binary files /dev/null and b/assets/Pin_back_arrow_10x8.png differ diff --git a/assets/Pressed_Button_13x13.png b/assets/Pressed_Button_13x13.png new file mode 100644 index 0000000..823926b Binary files /dev/null and b/assets/Pressed_Button_13x13.png differ diff --git a/assets/Right_mouse_icon_9x9.png b/assets/Right_mouse_icon_9x9.png new file mode 100644 index 0000000..446d717 Binary files /dev/null and b/assets/Right_mouse_icon_9x9.png differ diff --git a/assets/Space_65x18.png b/assets/Space_65x18.png new file mode 100644 index 0000000..b60ae50 Binary files /dev/null and b/assets/Space_65x18.png differ diff --git a/assets/Voldwn_6x6.png b/assets/Voldwn_6x6.png new file mode 100644 index 0000000..d7a82a2 Binary files /dev/null and b/assets/Voldwn_6x6.png differ diff --git a/assets/Volup_8x6.png b/assets/Volup_8x6.png new file mode 100644 index 0000000..4b7ec66 Binary files /dev/null and b/assets/Volup_8x6.png differ diff --git a/usb_hid.c b/usb_hid.c index c234456..60acb6e 100644 --- a/usb_hid.c +++ b/usb_hid.c @@ -72,8 +72,10 @@ UsbHid* usb_hid_app_alloc() { app->submenu, "Dirpad", UsbHidSubmenuIndexDirpad, usb_hid_submenu_callback, app); submenu_add_item( app->submenu, "Keyboard", UsbHidSubmenuIndexKeyboard, usb_hid_submenu_callback, app); - submenu_add_item(app->submenu, "Media", UsbHidSubmenuIndexMedia, usb_hid_submenu_callback, app); - submenu_add_item(app->submenu, "Mouse", UsbHidSubmenuIndexMouse, usb_hid_submenu_callback, app); + submenu_add_item( + app->submenu, "Media", UsbHidSubmenuIndexMedia, usb_hid_submenu_callback, app); + submenu_add_item( + app->submenu, "Mouse", UsbHidSubmenuIndexMouse, usb_hid_submenu_callback, app); view_set_previous_callback(submenu_get_view(app->submenu), usb_hid_exit); view_dispatcher_add_view( app->view_dispatcher, UsbHidViewSubmenu, submenu_get_view(app->submenu)); @@ -101,17 +103,21 @@ UsbHid* usb_hid_app_alloc() { view_set_previous_callback( usb_hid_keyboard_get_view(app->usb_hid_keyboard), usb_hid_exit_confirm_view); view_dispatcher_add_view( - app->view_dispatcher, UsbHidViewKeyboard, usb_hid_keyboard_get_view(app->usb_hid_keyboard)); + app->view_dispatcher, + UsbHidViewKeyboard, + usb_hid_keyboard_get_view(app->usb_hid_keyboard)); // Media view app->usb_hid_media = usb_hid_media_alloc(); - view_set_previous_callback(usb_hid_media_get_view(app->usb_hid_media), usb_hid_exit_confirm_view); + view_set_previous_callback( + usb_hid_media_get_view(app->usb_hid_media), usb_hid_exit_confirm_view); view_dispatcher_add_view( app->view_dispatcher, UsbHidViewMedia, usb_hid_media_get_view(app->usb_hid_media)); // Mouse view app->usb_hid_mouse = usb_hid_mouse_alloc(); - view_set_previous_callback(usb_hid_mouse_get_view(app->usb_hid_mouse), usb_hid_exit_confirm_view); + view_set_previous_callback( + usb_hid_mouse_get_view(app->usb_hid_mouse), usb_hid_exit_confirm_view); view_dispatcher_add_view( app->view_dispatcher, UsbHidViewMouse, usb_hid_mouse_get_view(app->usb_hid_mouse)); @@ -157,14 +163,14 @@ int32_t usb_hid_app(void* p) { // Switch profile to Hid UsbHid* app = usb_hid_app_alloc(); - FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config(); + FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config(); furi_hal_usb_unlock(); furi_check(furi_hal_usb_set_config(&usb_hid, NULL) == true); - view_dispatcher_run(app->view_dispatcher); - - // Change back profile - furi_hal_usb_set_config(usb_mode_prev, NULL); + view_dispatcher_run(app->view_dispatcher); + + // Change back profile + furi_hal_usb_set_config(usb_mode_prev, NULL); usb_hid_app_free(app); return 0; diff --git a/views/usb_hid_dirpad.c b/views/usb_hid_dirpad.c index 32e3d83..d6aec9e 100644 --- a/views/usb_hid_dirpad.c +++ b/views/usb_hid_dirpad.c @@ -2,6 +2,7 @@ #include #include #include +#include struct UsbHidDirpad { View* view; @@ -99,7 +100,9 @@ static void usb_hid_dirpad_draw_callback(Canvas* canvas, void* context) { static void usb_hid_dirpad_process(UsbHidDirpad* usb_hid_dirpad, InputEvent* event) { with_view_model( - usb_hid_dirpad->view, (UsbHidDirpadModel * model) { + usb_hid_dirpad->view, + UsbHidDirpadModel * model, + { if(event->type == InputTypePress) { if(event->key == InputKeyUp) { model->up_pressed = true; @@ -146,8 +149,8 @@ static void usb_hid_dirpad_process(UsbHidDirpad* usb_hid_dirpad, InputEvent* eve furi_hal_hid_consumer_key_release(HID_CONSUMER_AC_BACK); } } - return true; - }); + }, + true); } static bool usb_hid_dirpad_input_callback(InputEvent* event, void* context) { @@ -190,8 +193,5 @@ View* usb_hid_dirpad_get_view(UsbHidDirpad* usb_hid_dirpad) { void usb_hid_dirpad_set_connected_status(UsbHidDirpad* usb_hid_dirpad, bool connected) { furi_assert(usb_hid_dirpad); with_view_model( - usb_hid_dirpad->view, (UsbHidDirpadModel * model) { - model->connected = connected; - return true; - }); + usb_hid_dirpad->view, UsbHidDirpadModel * model, { model->connected = connected; }, true); } diff --git a/views/usb_hid_keyboard.c b/views/usb_hid_keyboard.c index fe07243..71438e1 100644 --- a/views/usb_hid_keyboard.c +++ b/views/usb_hid_keyboard.c @@ -3,6 +3,7 @@ #include #include #include +#include struct UsbHidKeyboard { View* view; @@ -42,7 +43,7 @@ typedef struct { #define KEY_WIDTH 9 #define KEY_HEIGHT 12 #define KEY_PADDING 1 -#define ROW_COUNT 7 +#define ROW_COUNT 6 #define COLUMN_COUNT 12 // 0 width items are not drawn, but there value is used @@ -135,20 +136,6 @@ const UsbHidKeyboardKey usb_hid_keyboard_keyset[ROW_COUNT][COLUMN_COUNT] = { {.width = 0, .icon = NULL, .value = HID_KEYBOARD_TAB}, {.width = 0, .icon = NULL, .value = HID_KEYBOARD_TAB}, }, - { - {.width = 1, .icon = NULL, .key = "1", .shift_key = "1", .value = HID_KEYBOARD_F1}, - {.width = 1, .icon = NULL, .key = "2", .shift_key = "2", .value = HID_KEYBOARD_F2}, - {.width = 1, .icon = NULL, .key = "3", .shift_key = "3", .value = HID_KEYBOARD_F3}, - {.width = 1, .icon = NULL, .key = "4", .shift_key = "4", .value = HID_KEYBOARD_F4}, - {.width = 1, .icon = NULL, .key = "5", .shift_key = "5", .value = HID_KEYBOARD_F5}, - {.width = 1, .icon = NULL, .key = "6", .shift_key = "6", .value = HID_KEYBOARD_F6}, - {.width = 1, .icon = NULL, .key = "7", .shift_key = "7", .value = HID_KEYBOARD_F7}, - {.width = 1, .icon = NULL, .key = "8", .shift_key = "8", .value = HID_KEYBOARD_F8}, - {.width = 1, .icon = NULL, .key = "9", .shift_key = "9", .value = HID_KEYBOARD_F9}, - {.width = 1, .icon = NULL, .key = "0", .shift_key = "0", .value = HID_KEYBOARD_F10}, - {.width = 1, .icon = NULL, .key = "1", .shift_key = "1", .value = HID_KEYBOARD_F11}, - {.width = 1, .icon = NULL, .key = "2", .shift_key = "2", .value = HID_KEYBOARD_F12}, - } }; static void usb_hid_keyboard_to_upper(char* str) { @@ -230,7 +217,6 @@ static void usb_hid_keyboard_draw_callback(Canvas* canvas, void* context) { // Select if back is clicked and its the backspace key // Deselect when the button clicked or not hovered bool keySelected = (x <= model->x && model->x < (x + key.width)) && y == model->y; - keySelected = y == ROW_COUNT - 1 ? !keySelected : keySelected; bool backSelected = model->back_pressed && key.value == HID_KEYBOARD_DELETE; usb_hid_keyboard_draw_key( canvas, @@ -256,7 +242,8 @@ static uint8_t usb_hid_keyboard_get_selected_key(UsbHidKeyboardModel* model) { return key.value; } -static void usb_hid_keyboard_get_select_key(UsbHidKeyboardModel* model, UsbHidKeyboardPoint delta) { +static void + usb_hid_keyboard_get_select_key(UsbHidKeyboardModel* model, UsbHidKeyboardPoint delta) { // Keep going until a valid spot is found, this allows for nulls and zero width keys in the map do { if(((int8_t)model->y) + delta.y < 0) @@ -276,7 +263,9 @@ static void usb_hid_keyboard_get_select_key(UsbHidKeyboardModel* model, UsbHidKe static void usb_hid_keyboard_process(UsbHidKeyboard* usb_hid_keyboard, InputEvent* event) { with_view_model( - usb_hid_keyboard->view, (UsbHidKeyboardModel * model) { + usb_hid_keyboard->view, + UsbHidKeyboardModel * model, + { if(event->key == InputKeyOk) { if(event->type == InputTypePress) { model->ok_pressed = true; @@ -337,8 +326,8 @@ static void usb_hid_keyboard_process(UsbHidKeyboard* usb_hid_keyboard, InputEven usb_hid_keyboard_get_select_key(model, (UsbHidKeyboardPoint){.x = 1, .y = 0}); } } - return true; - }); + }, + true); } static bool usb_hid_keyboard_input_callback(InputEvent* event, void* context) { @@ -358,18 +347,15 @@ static bool usb_hid_keyboard_input_callback(InputEvent* event, void* context) { UsbHidKeyboard* usb_hid_keyboard_alloc() { UsbHidKeyboard* usb_hid_keyboard = malloc(sizeof(UsbHidKeyboard)); - + usb_hid_keyboard->view = view_alloc(); view_set_context(usb_hid_keyboard->view, usb_hid_keyboard); view_allocate_model(usb_hid_keyboard->view, ViewModelTypeLocking, sizeof(UsbHidKeyboardModel)); view_set_draw_callback(usb_hid_keyboard->view, usb_hid_keyboard_draw_callback); view_set_input_callback(usb_hid_keyboard->view, usb_hid_keyboard_input_callback); - with_view_model( - usb_hid_keyboard->view, (UsbHidKeyboardModel * model) { - model->connected = true; - return true; - }); + with_view_model( + usb_hid_keyboard->view, UsbHidKeyboardModel * model, { model->connected = true; }, true); return usb_hid_keyboard; } @@ -383,4 +369,4 @@ void usb_hid_keyboard_free(UsbHidKeyboard* usb_hid_keyboard) { View* usb_hid_keyboard_get_view(UsbHidKeyboard* usb_hid_keyboard) { furi_assert(usb_hid_keyboard); return usb_hid_keyboard->view; -} +} \ No newline at end of file diff --git a/views/usb_hid_media.c b/views/usb_hid_media.c index 992ca17..8d21884 100644 --- a/views/usb_hid_media.c +++ b/views/usb_hid_media.c @@ -2,6 +2,7 @@ #include #include #include +#include struct UsbHidMedia { View* view; @@ -100,7 +101,9 @@ static void usb_hid_media_draw_callback(Canvas* canvas, void* context) { static void usb_hid_media_process_press(UsbHidMedia* usb_hid_media, InputEvent* event) { with_view_model( - usb_hid_media->view, (UsbHidMediaModel * model) { + usb_hid_media->view, + UsbHidMediaModel * model, + { if(event->key == InputKeyUp) { model->up_pressed = true; furi_hal_hid_consumer_key_press(HID_CONSUMER_VOLUME_INCREMENT); @@ -117,13 +120,15 @@ static void usb_hid_media_process_press(UsbHidMedia* usb_hid_media, InputEvent* model->ok_pressed = true; furi_hal_hid_consumer_key_press(HID_CONSUMER_PLAY_PAUSE); } - return true; - }); + }, + true); } static void hid_media_process_release(UsbHidMedia* usb_hid_media, InputEvent* event) { with_view_model( - usb_hid_media->view, (UsbHidMediaModel * model) { + usb_hid_media->view, + UsbHidMediaModel * model, + { if(event->key == InputKeyUp) { model->up_pressed = false; furi_hal_hid_consumer_key_release(HID_CONSUMER_VOLUME_INCREMENT); @@ -140,8 +145,8 @@ static void hid_media_process_release(UsbHidMedia* usb_hid_media, InputEvent* ev model->ok_pressed = false; furi_hal_hid_consumer_key_release(HID_CONSUMER_PLAY_PAUSE); } - return true; - }); + }, + true); } static bool usb_hid_media_input_callback(InputEvent* event, void* context) { @@ -172,11 +177,8 @@ UsbHidMedia* usb_hid_media_alloc() { view_set_draw_callback(usb_hid_media->view, usb_hid_media_draw_callback); view_set_input_callback(usb_hid_media->view, usb_hid_media_input_callback); - with_view_model( - usb_hid_media->view, (UsbHidMediaModel* model) { - model->connected = true; - return true; - }); + with_view_model( + usb_hid_media->view, UsbHidMediaModel * model, { model->connected = true; }, true); return usb_hid_media; } @@ -195,8 +197,5 @@ View* usb_hid_media_get_view(UsbHidMedia* usb_hid_media) { void usb_hid_media_set_connected_status(UsbHidMedia* usb_hid_media, bool connected) { furi_assert(usb_hid_media); with_view_model( - usb_hid_media->view, (UsbHidMediaModel * model) { - model->connected = connected; - return true; - }); + usb_hid_media->view, UsbHidMediaModel * model, { model->connected = connected; }, true); } diff --git a/views/usb_hid_mouse.c b/views/usb_hid_mouse.c index cd8ae61..27f2ac1 100644 --- a/views/usb_hid_mouse.c +++ b/views/usb_hid_mouse.c @@ -2,6 +2,7 @@ #include #include #include +#include struct UsbHidMouse { View* view; @@ -25,11 +26,11 @@ static void usb_hid_mouse_draw_callback(Canvas* canvas, void* context) { UsbHidMouseModel* model = context; // Header - if(model->connected) { + /*if(model->connected) { canvas_draw_icon(canvas, 0, 0, &I_Ble_connected_15x15); } else { canvas_draw_icon(canvas, 0, 0, &I_Ble_disconnected_15x15); - } + }*/ canvas_set_font(canvas, FontPrimary); elements_multiline_text_aligned(canvas, 17, 3, AlignLeft, AlignTop, "Mouse"); canvas_set_font(canvas, FontSecondary); @@ -102,7 +103,9 @@ static void usb_hid_mouse_draw_callback(Canvas* canvas, void* context) { static void usb_hid_mouse_process(UsbHidMouse* usb_hid_mouse, InputEvent* event) { with_view_model( - usb_hid_mouse->view, (UsbHidMouseModel * model) { + usb_hid_mouse->view, + UsbHidMouseModel * model, + { if(event->key == InputKeyBack) { if(event->type == InputTypeShort) { furi_hal_hid_mouse_press(HID_MOUSE_BTN_RIGHT); @@ -166,8 +169,8 @@ static void usb_hid_mouse_process(UsbHidMouse* usb_hid_mouse, InputEvent* event) model->up_pressed = false; } } - return true; - }); + }, + true); } static bool usb_hid_mouse_input_callback(InputEvent* event, void* context) { @@ -176,8 +179,8 @@ static bool usb_hid_mouse_input_callback(InputEvent* event, void* context) { bool consumed = false; if(event->type == InputTypeLong && event->key == InputKeyBack) { - furi_hal_hid_mouse_release(HID_MOUSE_BTN_LEFT); - furi_hal_hid_mouse_release(HID_MOUSE_BTN_RIGHT); + furi_hal_hid_mouse_release(HID_MOUSE_BTN_LEFT); + furi_hal_hid_mouse_release(HID_MOUSE_BTN_RIGHT); } else { usb_hid_mouse_process(usb_hid_mouse, event); consumed = true; @@ -193,12 +196,9 @@ UsbHidMouse* usb_hid_mouse_alloc() { view_allocate_model(usb_hid_mouse->view, ViewModelTypeLocking, sizeof(UsbHidMouseModel)); view_set_draw_callback(usb_hid_mouse->view, usb_hid_mouse_draw_callback); view_set_input_callback(usb_hid_mouse->view, usb_hid_mouse_input_callback); - - with_view_model( - usb_hid_mouse->view, (UsbHidMouseModel* model) { - model->connected = true; - return true; - }); + + with_view_model( + usb_hid_mouse->view, UsbHidMouseModel * model, { model->connected = true; }, true); return usb_hid_mouse; } @@ -213,4 +213,3 @@ View* usb_hid_mouse_get_view(UsbHidMouse* usb_hid_mouse) { furi_assert(usb_hid_mouse); return usb_hid_mouse->view; } -