Skip to content

Commit

Permalink
synced with unleashed version
Browse files Browse the repository at this point in the history
  • Loading branch information
huuck committed Dec 5, 2022
1 parent 690a806 commit 17f347c
Show file tree
Hide file tree
Showing 29 changed files with 67 additions and 76 deletions.
7 changes: 4 additions & 3 deletions application.fam
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -10,5 +10,6 @@ App(
],
order=60,
fap_icon="usb_keyboard_10px.png",
fap_category="Tools",
fap_category="Misc",
fap_icon_assets="assets",
)
Binary file added assets/Arr_dwn_7x9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Arr_up_7x9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ButtonDown_7x4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ButtonLeft_4x7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ButtonRight_4x7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ButtonUp_7x4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Button_18x18.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Circles_47x47.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Left_mouse_icon_9x9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Like_def_11x9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Like_pressed_17x17.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Ok_btn_9x9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Ok_btn_pressed_13x13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Pin_arrow_down_7x9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Pin_arrow_left_9x7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Pin_arrow_right_9x7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Pin_arrow_up_7x9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Pin_back_arrow_10x8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Pressed_Button_13x13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Right_mouse_icon_9x9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Space_65x18.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Voldwn_6x6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Volup_8x6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 16 additions & 10 deletions usb_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions views/usb_hid_dirpad.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <furi.h>
#include <furi_hal_usb_hid.h>
#include <gui/elements.h>
#include <USB_Keyboard_icons.h>

struct UsbHidDirpad {
View* view;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
40 changes: 13 additions & 27 deletions views/usb_hid_keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <furi_hal_usb_hid.h>
#include <gui/elements.h>
#include <gui/icon_i.h>
#include <USB_Keyboard_icons.h>

struct UsbHidKeyboard {
View* view;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand All @@ -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;
}
}
29 changes: 14 additions & 15 deletions views/usb_hid_media.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <furi.h>
#include <furi_hal_usb_hid.h>
#include <gui/elements.h>
#include <USB_Keyboard_icons.h>

struct UsbHidMedia {
View* view;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}
27 changes: 13 additions & 14 deletions views/usb_hid_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <furi.h>
#include <furi_hal_usb_hid.h>
#include <gui/elements.h>
#include <USB_Keyboard_icons.h>

struct UsbHidMouse {
View* view;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -213,4 +213,3 @@ View* usb_hid_mouse_get_view(UsbHidMouse* usb_hid_mouse) {
furi_assert(usb_hid_mouse);
return usb_hid_mouse->view;
}

0 comments on commit 17f347c

Please sign in to comment.