xremote_general_view.c 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*!
  2. * @file flipper-xremote/views/xremote_general_view.c
  3. @license This project is released under the GNU GPLv3 License
  4. * @copyright (c) 2023 Sandro Kalatozishvili (s.kalatoz@gmail.com)
  5. *
  6. * @brief General remote buttons section UI and view functionality.
  7. */
  8. #include "xremote_general_view.h"
  9. static void xremote_general_view_draw_callback(Canvas* canvas, void* context)
  10. {
  11. furi_assert(context);
  12. XRemoteViewModel* model = context;
  13. xremote_canvas_draw_header(canvas, "General");
  14. xremote_canvas_draw_button_wide(canvas, model->ok_pressed, 0, 27, "Power", XRemoteIconEnter);
  15. xremote_canvas_draw_button_wide(canvas, model->up_pressed, 0, 45, "Input", XRemoteIconArrowUp);
  16. xremote_canvas_draw_button_wide(canvas, model->down_pressed, 0, 63, "Setup", XRemoteIconArrowDown);
  17. xremote_canvas_draw_button_wide(canvas, model->left_pressed, 0, 81, "Menu", XRemoteIconArrowLeft);
  18. xremote_canvas_draw_button_wide(canvas, model->right_pressed, 0, 99, "List", XRemoteIconArrowRight);
  19. xremote_canvas_draw_exit_footer(canvas, "Press to exit");
  20. }
  21. static void xremote_general_view_process(XRemoteView* view, InputEvent* event)
  22. {
  23. with_view_model(
  24. xremote_view_get_view(view),
  25. XRemoteViewModel* model,
  26. {
  27. if (event->type == InputTypePress)
  28. {
  29. if (event->key == InputKeyOk)
  30. {
  31. model->ok_pressed = true;
  32. xremote_view_send_ir(view, XREMOTE_COMMAND_POWER);
  33. }
  34. else if (event->key == InputKeyUp)
  35. {
  36. model->up_pressed = true;
  37. xremote_view_send_ir(view, XREMOTE_COMMAND_INPUT);
  38. }
  39. else if (event->key == InputKeyDown)
  40. {
  41. model->down_pressed = true;
  42. xremote_view_send_ir(view, XREMOTE_COMMAND_SETUP);
  43. }
  44. else if (event->key == InputKeyLeft)
  45. {
  46. model->left_pressed = true;
  47. xremote_view_send_ir(view, XREMOTE_COMMAND_MENU);
  48. }
  49. else if (event->key == InputKeyRight)
  50. {
  51. model->right_pressed = true;
  52. xremote_view_send_ir(view, XREMOTE_COMMAND_LIST);
  53. }
  54. }
  55. else if (event->type == InputTypeRelease)
  56. {
  57. if (event->key == InputKeyOk) model->ok_pressed = false;
  58. else if (event->key == InputKeyUp) model->up_pressed = false;
  59. else if (event->key == InputKeyDown) model->down_pressed = false;
  60. else if (event->key == InputKeyLeft) model->left_pressed = false;
  61. else if (event->key == InputKeyRight) model->right_pressed = false;
  62. }
  63. },
  64. true);
  65. }
  66. static bool xremote_general_view_input_callback(InputEvent* event, void* context)
  67. {
  68. furi_assert(context);
  69. XRemoteView* view = (XRemoteView*)context;
  70. if (event->key == InputKeyBack) return false;
  71. xremote_general_view_process(view, event);
  72. return true;
  73. }
  74. XRemoteView* xremote_general_view_alloc(NotificationApp* notifications)
  75. {
  76. return xremote_view_alloc(notifications,
  77. xremote_general_view_input_callback,
  78. xremote_general_view_draw_callback);
  79. }