xremote_infoscreen.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include "xremote_infoscreen.h"
  2. #include "../xremote.h"
  3. struct XRemoteInfoscreen {
  4. View* view;
  5. XRemoteInfoscreenCallback callback;
  6. void* context;
  7. };
  8. typedef struct {
  9. int some_value;
  10. } XRemoteInfoscreenModel;
  11. void xremote_infoscreen_set_callback(
  12. XRemoteInfoscreen* instance,
  13. XRemoteInfoscreenCallback callback,
  14. void* context) {
  15. furi_assert(instance);
  16. furi_assert(callback);
  17. instance->callback = callback;
  18. instance->context = context;
  19. }
  20. void xremote_infoscreen_draw(Canvas* canvas, XRemoteInfoscreenModel* model) {
  21. UNUSED(model);
  22. canvas_clear(canvas);
  23. canvas_set_color(canvas, ColorBlack);
  24. canvas_set_font(canvas, FontPrimary);
  25. canvas_draw_str_aligned(canvas, 64, 10, AlignCenter, AlignTop, "Cross Remote");
  26. canvas_set_font(canvas, FontSecondary);
  27. canvas_draw_str_aligned(canvas, 64, 22, AlignCenter, AlignTop, "Chain IR and SubGhz");
  28. canvas_draw_str_aligned(canvas, 64, 32, AlignCenter, AlignTop, "Commands");
  29. elements_button_center(canvas, "Back");
  30. }
  31. static void xremote_infoscreen_model_init(XRemoteInfoscreenModel* const model) {
  32. model->some_value = 1;
  33. }
  34. bool xremote_infoscreen_input(InputEvent* event, void* context) {
  35. furi_assert(context);
  36. XRemoteInfoscreen* instance = context;
  37. if (event->type == InputTypeRelease) {
  38. switch(event->key) {
  39. case InputKeyBack:
  40. with_view_model(
  41. instance->view,
  42. XRemoteInfoscreenModel * model,
  43. {
  44. UNUSED(model);
  45. instance->callback(XRemoteCustomEventInfoscreenBack, instance->context);
  46. },
  47. true);
  48. break;
  49. case InputKeyLeft:
  50. case InputKeyRight:
  51. case InputKeyUp:
  52. case InputKeyDown:
  53. case InputKeyOk:
  54. with_view_model(
  55. instance->view,
  56. XRemoteInfoscreenModel* model,
  57. {
  58. UNUSED(model);
  59. instance->callback(XRemoteCustomEventInfoscreenOk, instance->context);
  60. },
  61. true);
  62. break;
  63. case InputKeyMAX:
  64. break;
  65. }
  66. }
  67. return true;
  68. }
  69. void xremote_infoscreen_exit(void* context) {
  70. furi_assert(context);
  71. }
  72. void xremote_infoscreen_enter(void* context) {
  73. furi_assert(context);
  74. XRemoteInfoscreen* instance = (XRemoteInfoscreen*)context;
  75. with_view_model(
  76. instance->view,
  77. XRemoteInfoscreenModel * model,
  78. {
  79. xremote_infoscreen_model_init(model);
  80. },
  81. true
  82. );
  83. }
  84. XRemoteInfoscreen* xremote_infoscreen_alloc() {
  85. XRemoteInfoscreen* instance = malloc(sizeof(XRemoteInfoscreen));
  86. instance->view = view_alloc();
  87. view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(XRemoteInfoscreenModel));
  88. view_set_context(instance->view, instance); // furi_assert crashes in events without this
  89. view_set_draw_callback(instance->view, (ViewDrawCallback)xremote_infoscreen_draw);
  90. view_set_input_callback(instance->view, xremote_infoscreen_input);
  91. //view_set_enter_callback(instance->view, xremote_infoscreen_enter);
  92. //view_set_exit_callback(instance->view, xremote_infoscreen_exit);
  93. with_view_model(
  94. instance->view,
  95. XRemoteInfoscreenModel * model,
  96. {
  97. xremote_infoscreen_model_init(model);
  98. },
  99. true
  100. );
  101. return instance;
  102. }
  103. void xremote_infoscreen_free(XRemoteInfoscreen* instance) {
  104. furi_assert(instance);
  105. with_view_model(
  106. instance->view,
  107. XRemoteInfoscreenModel * model,
  108. {
  109. UNUSED(model);
  110. },
  111. true);
  112. view_free(instance->view);
  113. free(instance);
  114. }
  115. View* xremote_infoscreen_get_view(XRemoteInfoscreen* instance) {
  116. furi_assert(instance);
  117. return instance->view;
  118. }