Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hid app #524

Merged
merged 3 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 4 additions & 14 deletions applications/external/hid_app/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ static void hid_submenu_callback(void* context, uint32_t index) {
Hid* app = context;
if(index == HidSubmenuIndexKeynote) {
app->view_id = HidViewKeynote;
hid_keynote_set_orientation(app->hid_keynote, false);
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewKeynote);
} else if(index == HidSubmenuIndexKeynoteVertical) {
app->view_id = HidViewKeynoteVertical;
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewKeynoteVertical);
app->view_id = HidViewKeynote;
hid_keynote_set_orientation(app->hid_keynote, true);
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewKeynote);
} else if(index == HidSubmenuIndexKeyboard) {
app->view_id = HidViewKeyboard;
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewKeyboard);
Expand Down Expand Up @@ -62,7 +64,6 @@ static void bt_hid_connection_status_changed_callback(BtStatus status, void* con
}
}
hid_keynote_set_connected_status(hid->hid_keynote, connected);
hid_keynote_vertical_set_connected_status(hid->hid_keynote_vertical, connected);
hid_keyboard_set_connected_status(hid->hid_keyboard, connected);
hid_numpad_set_connected_status(hid->hid_numpad, connected);
hid_media_set_connected_status(hid->hid_media, connected);
Expand Down Expand Up @@ -177,15 +178,6 @@ Hid* hid_app_alloc_view(void* context) {
view_dispatcher_add_view(
app->view_dispatcher, HidViewKeynote, hid_keynote_get_view(app->hid_keynote));

// Keynote Vertical view
app->hid_keynote_vertical = hid_keynote_vertical_alloc(app);
view_set_previous_callback(
hid_keynote_vertical_get_view(app->hid_keynote_vertical), hid_exit_confirm_view);
view_dispatcher_add_view(
app->view_dispatcher,
HidViewKeynoteVertical,
hid_keynote_vertical_get_view(app->hid_keynote_vertical));

// Keyboard view
app->hid_keyboard = hid_keyboard_alloc(app);
view_set_previous_callback(hid_keyboard_get_view(app->hid_keyboard), hid_exit_confirm_view);
Expand Down Expand Up @@ -252,8 +244,6 @@ void hid_free(Hid* app) {
dialog_ex_free(app->dialog);
view_dispatcher_remove_view(app->view_dispatcher, HidViewKeynote);
hid_keynote_free(app->hid_keynote);
view_dispatcher_remove_view(app->view_dispatcher, HidViewKeynoteVertical);
hid_keynote_vertical_free(app->hid_keynote_vertical);
view_dispatcher_remove_view(app->view_dispatcher, HidViewKeyboard);
hid_keyboard_free(app->hid_keyboard);
view_dispatcher_remove_view(app->view_dispatcher, HidViewNumpad);
Expand Down
2 changes: 0 additions & 2 deletions applications/external/hid_app/hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <gui/modules/dialog_ex.h>
#include <gui/modules/popup.h>
#include "views/hid_keynote.h"
#include "views/hid_keynote_vertical.h"
#include "views/hid_keyboard.h"
#include "views/hid_numpad.h"
#include "views/hid_media.h"
Expand All @@ -43,7 +42,6 @@ struct Hid {
Submenu* device_type_submenu;
DialogEx* dialog;
HidKeynote* hid_keynote;
HidKeynoteVertical* hid_keynote_vertical;
HidKeyboard* hid_keyboard;
HidNumpad* hid_numpad;
HidMedia* hid_media;
Expand Down
1 change: 0 additions & 1 deletion applications/external/hid_app/views.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
typedef enum {
HidViewSubmenu,
HidViewKeynote,
HidViewKeynoteVertical,
HidViewKeyboard,
HidViewNumpad,
HidViewMedia,
Expand Down
98 changes: 98 additions & 0 deletions applications/external/hid_app/views/hid_keynote.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,91 @@ static void hid_keynote_draw_callback(Canvas* canvas, void* context) {
elements_multiline_text_aligned(canvas, 91, 57, AlignLeft, AlignBottom, "Back");
}

static void hid_keynote_draw_vertical_callback(Canvas* canvas, void* context) {
furi_assert(context);
HidKeynoteModel* model = context;

// Header
canvas_set_font(canvas, FontPrimary);
if(model->transport == HidTransportBle) {
if(model->connected) {
canvas_draw_icon(canvas, 0, 0, &I_Ble_connected_15x15);
} else {
canvas_draw_icon(canvas, 0, 0, &I_Ble_disconnected_15x15);
}

elements_multiline_text_aligned(canvas, 20, 3, AlignLeft, AlignTop, "Keynote");
} else {
elements_multiline_text_aligned(canvas, 12, 3, AlignLeft, AlignTop, "Keynote");
}

canvas_draw_icon(canvas, 2, 18, &I_Pin_back_arrow_10x8);
canvas_set_font(canvas, FontSecondary);
elements_multiline_text_aligned(canvas, 15, 19, AlignLeft, AlignTop, "Hold to exit");

const uint8_t x_2 = 23;
const uint8_t x_1 = 2;
const uint8_t x_3 = 44;

const uint8_t y_1 = 44;
const uint8_t y_2 = 65;

// Up
canvas_draw_icon(canvas, x_2, y_1, &I_Button_18x18);
if(model->up_pressed) {
elements_slightly_rounded_box(canvas, x_2 + 3, y_1 + 2, 13, 13);
canvas_set_color(canvas, ColorWhite);
}
hid_keynote_draw_arrow(canvas, x_2 + 9, y_1 + 6, CanvasDirectionBottomToTop);
canvas_set_color(canvas, ColorBlack);

// Down
canvas_draw_icon(canvas, x_2, y_2, &I_Button_18x18);
if(model->down_pressed) {
elements_slightly_rounded_box(canvas, x_2 + 3, y_2 + 2, 13, 13);
canvas_set_color(canvas, ColorWhite);
}
hid_keynote_draw_arrow(canvas, x_2 + 9, y_2 + 10, CanvasDirectionTopToBottom);
canvas_set_color(canvas, ColorBlack);

// Left
canvas_draw_icon(canvas, x_1, y_2, &I_Button_18x18);
if(model->left_pressed) {
elements_slightly_rounded_box(canvas, x_1 + 3, y_2 + 2, 13, 13);
canvas_set_color(canvas, ColorWhite);
}
hid_keynote_draw_arrow(canvas, x_1 + 7, y_2 + 8, CanvasDirectionRightToLeft);
canvas_set_color(canvas, ColorBlack);

// Right
canvas_draw_icon(canvas, x_3, y_2, &I_Button_18x18);
if(model->right_pressed) {
elements_slightly_rounded_box(canvas, x_3 + 3, y_2 + 2, 13, 13);
canvas_set_color(canvas, ColorWhite);
}
hid_keynote_draw_arrow(canvas, x_3 + 11, y_2 + 8, CanvasDirectionLeftToRight);
canvas_set_color(canvas, ColorBlack);

// Ok
canvas_draw_icon(canvas, 2, 86, &I_Space_60x18);
if(model->ok_pressed) {
elements_slightly_rounded_box(canvas, 5, 88, 55, 13);
canvas_set_color(canvas, ColorWhite);
}
canvas_draw_icon(canvas, 11, 90, &I_Ok_btn_9x9);
elements_multiline_text_aligned(canvas, 26, 98, AlignLeft, AlignBottom, "Space");
canvas_set_color(canvas, ColorBlack);

// Back
canvas_draw_icon(canvas, 2, 107, &I_Space_60x18);
if(model->back_pressed) {
elements_slightly_rounded_box(canvas, 5, 109, 55, 13);
canvas_set_color(canvas, ColorWhite);
}
canvas_draw_icon(canvas, 11, 111, &I_Pin_back_arrow_10x8);
elements_multiline_text_aligned(canvas, 26, 119, AlignLeft, AlignBottom, "Back");
}

static void hid_keynote_process(HidKeynote* hid_keynote, InputEvent* event) {
with_view_model(
hid_keynote->view,
Expand Down Expand Up @@ -212,3 +297,16 @@ void hid_keynote_set_connected_status(HidKeynote* hid_keynote, bool connected) {
with_view_model(
hid_keynote->view, HidKeynoteModel * model, { model->connected = connected; }, true);
}

void hid_keynote_set_orientation(HidKeynote* hid_keynote, bool vertical) {
furi_assert(hid_keynote);

if(vertical) {
view_set_draw_callback(hid_keynote->view, hid_keynote_draw_vertical_callback);
view_set_orientation(hid_keynote->view, ViewOrientationVerticalFlip);

} else {
view_set_draw_callback(hid_keynote->view, hid_keynote_draw_callback);
view_set_orientation(hid_keynote->view, ViewOrientationHorizontal);
}
}
2 changes: 2 additions & 0 deletions applications/external/hid_app/views/hid_keynote.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ void hid_keynote_free(HidKeynote* hid_keynote);
View* hid_keynote_get_view(HidKeynote* hid_keynote);

void hid_keynote_set_connected_status(HidKeynote* hid_keynote, bool connected);

void hid_keynote_set_orientation(HidKeynote* hid_keynote, bool vertical);
Loading