xremote_infoscreen.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. { xremote_infoscreen_model_init(model); },
  79. true);
  80. }
  81. XRemoteInfoscreen* xremote_infoscreen_alloc() {
  82. XRemoteInfoscreen* instance = malloc(sizeof(XRemoteInfoscreen));
  83. instance->view = view_alloc();
  84. view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(XRemoteInfoscreenModel));
  85. view_set_context(instance->view, instance); // furi_assert crashes in events without this
  86. view_set_draw_callback(instance->view, (ViewDrawCallback)xremote_infoscreen_draw);
  87. view_set_input_callback(instance->view, xremote_infoscreen_input);
  88. //view_set_enter_callback(instance->view, xremote_infoscreen_enter);
  89. //view_set_exit_callback(instance->view, xremote_infoscreen_exit);
  90. with_view_model(
  91. instance->view,
  92. XRemoteInfoscreenModel * model,
  93. { xremote_infoscreen_model_init(model); },
  94. true);
  95. return instance;
  96. }
  97. void xremote_infoscreen_free(XRemoteInfoscreen* instance) {
  98. furi_assert(instance);
  99. with_view_model(
  100. instance->view, XRemoteInfoscreenModel * model, { UNUSED(model); }, true);
  101. view_free(instance->view);
  102. free(instance);
  103. }
  104. View* xremote_infoscreen_get_view(XRemoteInfoscreen* instance) {
  105. furi_assert(instance);
  106. return instance->view;
  107. }