xremote_control_view.c 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*!
  2. * @file flipper-xremote/views/xremote_control_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 UI and view functionality for the IR control page.
  7. */
  8. #include "xremote_control_view.h"
  9. static void xremote_control_view_draw_callback(Canvas* canvas, void* context)
  10. {
  11. furi_assert(context);
  12. XRemoteViewModel* model = context;
  13. xremote_canvas_draw_header(canvas, "Control");
  14. xremote_canvas_draw_frame(canvas, model->up_pressed, 17, 30, 31, "VOL +");
  15. xremote_canvas_draw_frame(canvas, model->left_pressed, 4, 50, 23, "< CH");
  16. xremote_canvas_draw_frame(canvas, model->right_pressed, 37, 50, 23, "CH >");
  17. xremote_canvas_draw_frame(canvas, model->down_pressed, 17, 70, 31, "VOL -");
  18. xremote_canvas_draw_button_wide(canvas, model->ok_pressed, 0, 95, "Mute", XRemoteIconEnter);
  19. xremote_canvas_draw_exit_footer(canvas, "Press to exit");
  20. }
  21. static void xremote_control_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_MUTE);
  33. }
  34. else if (event->key == InputKeyUp)
  35. {
  36. model->up_pressed = true;
  37. xremote_view_send_ir(view, XREMOTE_COMMAND_VOL_UP);
  38. }
  39. else if (event->key == InputKeyDown)
  40. {
  41. model->down_pressed = true;
  42. xremote_view_send_ir(view, XREMOTE_COMMAND_VOL_DOWN);
  43. }
  44. else if (event->key == InputKeyLeft)
  45. {
  46. model->left_pressed = true;
  47. xremote_view_send_ir(view, XREMOTE_COMMAND_PREV_CHAN);
  48. }
  49. else if (event->key == InputKeyRight)
  50. {
  51. model->right_pressed = true;
  52. xremote_view_send_ir(view, XREMOTE_COMMAND_NEXT_CHAN);
  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_control_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_control_view_process(view, event);
  72. return true;
  73. }
  74. XRemoteView* xremote_control_view_alloc(NotificationApp* notifications)
  75. {
  76. return xremote_view_alloc(notifications,
  77. xremote_control_view_input_callback,
  78. xremote_control_view_draw_callback);
  79. }