mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-06-15 20:01:54 -07:00
usb keyboard
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
BSD 2-Clause License
|
||||
|
||||
Copyright (c) 2022, Gabriel Cirlig
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -43,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
|
||||
@@ -136,21 +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) {
|
||||
@@ -232,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,
|
||||
@@ -363,11 +347,13 @@ 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; }, true);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -212,4 +212,4 @@ void usb_hid_mouse_free(UsbHidMouse* usb_hid_mouse) {
|
||||
View* usb_hid_mouse_get_view(UsbHidMouse* usb_hid_mouse) {
|
||||
furi_assert(usb_hid_mouse);
|
||||
return usb_hid_mouse->view;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user