2022-11-28 19:27:16 +03:00
|
|
|
#include "hid_keynote.h"
|
2021-12-15 20:39:06 +03:00
|
|
|
#include <gui/elements.h>
|
2022-11-28 19:27:16 +03:00
|
|
|
#include "../hid.h"
|
2021-12-15 20:39:06 +03:00
|
|
|
|
2022-11-28 19:27:16 +03:00
|
|
|
#include "hid_icons.h"
|
2022-10-12 18:48:13 +03:00
|
|
|
|
2022-11-28 19:27:16 +03:00
|
|
|
#define TAG "HidKeynote"
|
|
|
|
|
|
|
|
struct HidKeynote {
|
2021-12-15 20:39:06 +03:00
|
|
|
View* view;
|
2022-11-28 19:27:16 +03:00
|
|
|
Hid* hid;
|
2021-12-15 20:39:06 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
bool left_pressed;
|
|
|
|
bool up_pressed;
|
|
|
|
bool right_pressed;
|
|
|
|
bool down_pressed;
|
|
|
|
bool ok_pressed;
|
2022-07-08 15:36:34 +03:00
|
|
|
bool back_pressed;
|
2021-12-15 20:39:06 +03:00
|
|
|
bool connected;
|
2022-11-28 19:27:16 +03:00
|
|
|
} HidKeynoteModel;
|
2021-12-15 20:39:06 +03:00
|
|
|
|
2022-11-28 19:27:16 +03:00
|
|
|
static void hid_keynote_draw_arrow(Canvas* canvas, uint8_t x, uint8_t y, CanvasDirection dir) {
|
2021-12-15 20:39:06 +03:00
|
|
|
canvas_draw_triangle(canvas, x, y, 5, 3, dir);
|
|
|
|
if(dir == CanvasDirectionBottomToTop) {
|
|
|
|
canvas_draw_line(canvas, x, y + 6, x, y - 1);
|
|
|
|
} else if(dir == CanvasDirectionTopToBottom) {
|
|
|
|
canvas_draw_line(canvas, x, y - 6, x, y + 1);
|
|
|
|
} else if(dir == CanvasDirectionRightToLeft) {
|
|
|
|
canvas_draw_line(canvas, x + 6, y, x - 1, y);
|
|
|
|
} else if(dir == CanvasDirectionLeftToRight) {
|
|
|
|
canvas_draw_line(canvas, x - 6, y, x + 1, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-28 19:27:16 +03:00
|
|
|
static void hid_keynote_draw_callback(Canvas* canvas, void* context) {
|
2021-12-15 20:39:06 +03:00
|
|
|
furi_assert(context);
|
2022-11-28 19:27:16 +03:00
|
|
|
HidKeynoteModel* model = context;
|
2021-12-15 20:39:06 +03:00
|
|
|
|
|
|
|
// Header
|
|
|
|
if(model->connected) {
|
2022-07-08 15:36:34 +03:00
|
|
|
canvas_draw_icon(canvas, 0, 0, &I_Ble_connected_15x15);
|
2021-12-15 20:39:06 +03:00
|
|
|
} else {
|
2022-07-08 15:36:34 +03:00
|
|
|
canvas_draw_icon(canvas, 0, 0, &I_Ble_disconnected_15x15);
|
2021-12-15 20:39:06 +03:00
|
|
|
}
|
2022-07-08 15:36:34 +03:00
|
|
|
canvas_set_font(canvas, FontPrimary);
|
|
|
|
elements_multiline_text_aligned(canvas, 17, 3, AlignLeft, AlignTop, "Keynote");
|
2022-08-22 19:41:41 +03:00
|
|
|
|
|
|
|
canvas_draw_icon(canvas, 68, 2, &I_Pin_back_arrow_10x8);
|
2022-07-08 15:36:34 +03:00
|
|
|
canvas_set_font(canvas, FontSecondary);
|
2022-08-22 19:41:41 +03:00
|
|
|
elements_multiline_text_aligned(canvas, 127, 3, AlignRight, AlignTop, "Hold to exit");
|
2021-12-15 20:39:06 +03:00
|
|
|
|
|
|
|
// Up
|
2022-07-08 15:36:34 +03:00
|
|
|
canvas_draw_icon(canvas, 21, 24, &I_Button_18x18);
|
2021-12-15 20:39:06 +03:00
|
|
|
if(model->up_pressed) {
|
2022-07-08 15:36:34 +03:00
|
|
|
elements_slightly_rounded_box(canvas, 24, 26, 13, 13);
|
2021-12-15 20:39:06 +03:00
|
|
|
canvas_set_color(canvas, ColorWhite);
|
|
|
|
}
|
2022-11-28 19:27:16 +03:00
|
|
|
hid_keynote_draw_arrow(canvas, 30, 30, CanvasDirectionBottomToTop);
|
2021-12-15 20:39:06 +03:00
|
|
|
canvas_set_color(canvas, ColorBlack);
|
|
|
|
|
|
|
|
// Down
|
2022-07-08 15:36:34 +03:00
|
|
|
canvas_draw_icon(canvas, 21, 45, &I_Button_18x18);
|
2021-12-15 20:39:06 +03:00
|
|
|
if(model->down_pressed) {
|
2022-07-08 15:36:34 +03:00
|
|
|
elements_slightly_rounded_box(canvas, 24, 47, 13, 13);
|
2021-12-15 20:39:06 +03:00
|
|
|
canvas_set_color(canvas, ColorWhite);
|
|
|
|
}
|
2022-11-28 19:27:16 +03:00
|
|
|
hid_keynote_draw_arrow(canvas, 30, 55, CanvasDirectionTopToBottom);
|
2021-12-15 20:39:06 +03:00
|
|
|
canvas_set_color(canvas, ColorBlack);
|
|
|
|
|
|
|
|
// Left
|
2022-07-08 15:36:34 +03:00
|
|
|
canvas_draw_icon(canvas, 0, 45, &I_Button_18x18);
|
2021-12-15 20:39:06 +03:00
|
|
|
if(model->left_pressed) {
|
2022-07-08 15:36:34 +03:00
|
|
|
elements_slightly_rounded_box(canvas, 3, 47, 13, 13);
|
2021-12-15 20:39:06 +03:00
|
|
|
canvas_set_color(canvas, ColorWhite);
|
|
|
|
}
|
2022-11-28 19:27:16 +03:00
|
|
|
hid_keynote_draw_arrow(canvas, 7, 53, CanvasDirectionRightToLeft);
|
2021-12-15 20:39:06 +03:00
|
|
|
canvas_set_color(canvas, ColorBlack);
|
|
|
|
|
|
|
|
// Right
|
2022-07-08 15:36:34 +03:00
|
|
|
canvas_draw_icon(canvas, 42, 45, &I_Button_18x18);
|
2021-12-15 20:39:06 +03:00
|
|
|
if(model->right_pressed) {
|
2022-07-08 15:36:34 +03:00
|
|
|
elements_slightly_rounded_box(canvas, 45, 47, 13, 13);
|
2021-12-15 20:39:06 +03:00
|
|
|
canvas_set_color(canvas, ColorWhite);
|
|
|
|
}
|
2022-11-28 19:27:16 +03:00
|
|
|
hid_keynote_draw_arrow(canvas, 53, 53, CanvasDirectionLeftToRight);
|
2021-12-15 20:39:06 +03:00
|
|
|
canvas_set_color(canvas, ColorBlack);
|
|
|
|
|
|
|
|
// Ok
|
2022-07-08 15:36:34 +03:00
|
|
|
canvas_draw_icon(canvas, 63, 25, &I_Space_65x18);
|
2021-12-15 20:39:06 +03:00
|
|
|
if(model->ok_pressed) {
|
2022-07-08 15:36:34 +03:00
|
|
|
elements_slightly_rounded_box(canvas, 66, 27, 60, 13);
|
2021-12-15 20:39:06 +03:00
|
|
|
canvas_set_color(canvas, ColorWhite);
|
|
|
|
}
|
2022-07-08 15:36:34 +03:00
|
|
|
canvas_draw_icon(canvas, 74, 29, &I_Ok_btn_9x9);
|
|
|
|
elements_multiline_text_aligned(canvas, 91, 36, AlignLeft, AlignBottom, "Space");
|
|
|
|
canvas_set_color(canvas, ColorBlack);
|
2021-12-15 20:39:06 +03:00
|
|
|
|
2022-07-08 15:36:34 +03:00
|
|
|
// Back
|
|
|
|
canvas_draw_icon(canvas, 63, 45, &I_Space_65x18);
|
|
|
|
if(model->back_pressed) {
|
|
|
|
elements_slightly_rounded_box(canvas, 66, 47, 60, 13);
|
|
|
|
canvas_set_color(canvas, ColorWhite);
|
|
|
|
}
|
2022-08-22 19:41:41 +03:00
|
|
|
canvas_draw_icon(canvas, 74, 49, &I_Pin_back_arrow_10x8);
|
|
|
|
elements_multiline_text_aligned(canvas, 91, 57, AlignLeft, AlignBottom, "Back");
|
2021-12-15 20:39:06 +03:00
|
|
|
}
|
|
|
|
|
2022-11-28 19:27:16 +03:00
|
|
|
static void hid_keynote_process(HidKeynote* hid_keynote, InputEvent* event) {
|
2021-12-15 20:39:06 +03:00
|
|
|
with_view_model(
|
2022-11-28 19:27:16 +03:00
|
|
|
hid_keynote->view,
|
|
|
|
HidKeynoteModel * model,
|
2022-10-08 20:38:29 +03:00
|
|
|
{
|
2022-07-08 15:36:34 +03:00
|
|
|
if(event->type == InputTypePress) {
|
|
|
|
if(event->key == InputKeyUp) {
|
|
|
|
model->up_pressed = true;
|
2022-11-28 19:27:16 +03:00
|
|
|
hid_hal_keyboard_press(hid_keynote->hid, HID_KEYBOARD_UP_ARROW);
|
2022-07-08 15:36:34 +03:00
|
|
|
} else if(event->key == InputKeyDown) {
|
|
|
|
model->down_pressed = true;
|
2022-11-28 19:27:16 +03:00
|
|
|
hid_hal_keyboard_press(hid_keynote->hid, HID_KEYBOARD_DOWN_ARROW);
|
2022-07-08 15:36:34 +03:00
|
|
|
} else if(event->key == InputKeyLeft) {
|
|
|
|
model->left_pressed = true;
|
2022-11-28 19:27:16 +03:00
|
|
|
hid_hal_keyboard_press(hid_keynote->hid, HID_KEYBOARD_LEFT_ARROW);
|
2022-07-08 15:36:34 +03:00
|
|
|
} else if(event->key == InputKeyRight) {
|
|
|
|
model->right_pressed = true;
|
2022-11-28 19:27:16 +03:00
|
|
|
hid_hal_keyboard_press(hid_keynote->hid, HID_KEYBOARD_RIGHT_ARROW);
|
2022-07-08 15:36:34 +03:00
|
|
|
} else if(event->key == InputKeyOk) {
|
|
|
|
model->ok_pressed = true;
|
2022-11-28 19:27:16 +03:00
|
|
|
hid_hal_keyboard_press(hid_keynote->hid, HID_KEYBOARD_SPACEBAR);
|
2022-07-08 15:36:34 +03:00
|
|
|
} else if(event->key == InputKeyBack) {
|
|
|
|
model->back_pressed = true;
|
|
|
|
}
|
|
|
|
} else if(event->type == InputTypeRelease) {
|
|
|
|
if(event->key == InputKeyUp) {
|
|
|
|
model->up_pressed = false;
|
2022-11-28 19:27:16 +03:00
|
|
|
hid_hal_keyboard_release(hid_keynote->hid, HID_KEYBOARD_UP_ARROW);
|
2022-07-08 15:36:34 +03:00
|
|
|
} else if(event->key == InputKeyDown) {
|
|
|
|
model->down_pressed = false;
|
2022-11-28 19:27:16 +03:00
|
|
|
hid_hal_keyboard_release(hid_keynote->hid, HID_KEYBOARD_DOWN_ARROW);
|
2022-07-08 15:36:34 +03:00
|
|
|
} else if(event->key == InputKeyLeft) {
|
|
|
|
model->left_pressed = false;
|
2022-11-28 19:27:16 +03:00
|
|
|
hid_hal_keyboard_release(hid_keynote->hid, HID_KEYBOARD_LEFT_ARROW);
|
2022-07-08 15:36:34 +03:00
|
|
|
} else if(event->key == InputKeyRight) {
|
|
|
|
model->right_pressed = false;
|
2022-11-28 19:27:16 +03:00
|
|
|
hid_hal_keyboard_release(hid_keynote->hid, HID_KEYBOARD_RIGHT_ARROW);
|
2022-07-08 15:36:34 +03:00
|
|
|
} else if(event->key == InputKeyOk) {
|
|
|
|
model->ok_pressed = false;
|
2022-11-28 19:27:16 +03:00
|
|
|
hid_hal_keyboard_release(hid_keynote->hid, HID_KEYBOARD_SPACEBAR);
|
2022-07-08 15:36:34 +03:00
|
|
|
} else if(event->key == InputKeyBack) {
|
|
|
|
model->back_pressed = false;
|
|
|
|
}
|
|
|
|
} else if(event->type == InputTypeShort) {
|
|
|
|
if(event->key == InputKeyBack) {
|
2022-11-28 19:27:16 +03:00
|
|
|
hid_hal_keyboard_press(hid_keynote->hid, HID_KEYBOARD_DELETE);
|
|
|
|
hid_hal_keyboard_release(hid_keynote->hid, HID_KEYBOARD_DELETE);
|
|
|
|
hid_hal_consumer_key_press(hid_keynote->hid, HID_CONSUMER_AC_BACK);
|
|
|
|
hid_hal_consumer_key_release(hid_keynote->hid, HID_CONSUMER_AC_BACK);
|
2022-07-08 15:36:34 +03:00
|
|
|
}
|
2021-12-15 20:39:06 +03:00
|
|
|
}
|
2022-10-08 20:38:29 +03:00
|
|
|
},
|
|
|
|
true);
|
2021-12-15 20:39:06 +03:00
|
|
|
}
|
|
|
|
|
2022-11-28 19:27:16 +03:00
|
|
|
static bool hid_keynote_input_callback(InputEvent* event, void* context) {
|
2021-12-15 20:39:06 +03:00
|
|
|
furi_assert(context);
|
2022-11-28 19:27:16 +03:00
|
|
|
HidKeynote* hid_keynote = context;
|
2021-12-15 20:39:06 +03:00
|
|
|
bool consumed = false;
|
|
|
|
|
2022-07-08 15:36:34 +03:00
|
|
|
if(event->type == InputTypeLong && event->key == InputKeyBack) {
|
2022-11-28 19:27:16 +03:00
|
|
|
hid_hal_keyboard_release_all(hid_keynote->hid);
|
2022-07-08 15:36:34 +03:00
|
|
|
} else {
|
2022-11-28 19:27:16 +03:00
|
|
|
hid_keynote_process(hid_keynote, event);
|
2021-12-15 20:39:06 +03:00
|
|
|
consumed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
2022-11-28 19:27:16 +03:00
|
|
|
HidKeynote* hid_keynote_alloc(Hid* hid) {
|
|
|
|
HidKeynote* hid_keynote = malloc(sizeof(HidKeynote));
|
|
|
|
hid_keynote->view = view_alloc();
|
|
|
|
hid_keynote->hid = hid;
|
|
|
|
view_set_context(hid_keynote->view, hid_keynote);
|
|
|
|
view_allocate_model(hid_keynote->view, ViewModelTypeLocking, sizeof(HidKeynoteModel));
|
|
|
|
view_set_draw_callback(hid_keynote->view, hid_keynote_draw_callback);
|
|
|
|
view_set_input_callback(hid_keynote->view, hid_keynote_input_callback);
|
2021-12-15 20:39:06 +03:00
|
|
|
|
2022-11-28 19:27:16 +03:00
|
|
|
return hid_keynote;
|
2021-12-15 20:39:06 +03:00
|
|
|
}
|
|
|
|
|
2022-11-28 19:27:16 +03:00
|
|
|
void hid_keynote_free(HidKeynote* hid_keynote) {
|
|
|
|
furi_assert(hid_keynote);
|
|
|
|
view_free(hid_keynote->view);
|
|
|
|
free(hid_keynote);
|
2021-12-15 20:39:06 +03:00
|
|
|
}
|
|
|
|
|
2022-11-28 19:27:16 +03:00
|
|
|
View* hid_keynote_get_view(HidKeynote* hid_keynote) {
|
|
|
|
furi_assert(hid_keynote);
|
|
|
|
return hid_keynote->view;
|
2021-12-15 20:39:06 +03:00
|
|
|
}
|
|
|
|
|
2022-11-28 19:27:16 +03:00
|
|
|
void hid_keynote_set_connected_status(HidKeynote* hid_keynote, bool connected) {
|
|
|
|
furi_assert(hid_keynote);
|
2021-12-15 20:39:06 +03:00
|
|
|
with_view_model(
|
2022-11-28 19:27:16 +03:00
|
|
|
hid_keynote->view, HidKeynoteModel * model, { model->connected = connected; }, true);
|
2021-12-15 20:39:06 +03:00
|
|
|
}
|