xremote_infoscreen.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. char buffer[64];
  23. canvas_clear(canvas);
  24. canvas_set_color(canvas, ColorBlack);
  25. canvas_set_font(canvas, FontPrimary);
  26. canvas_draw_str_aligned(canvas, 64, 10, AlignCenter, AlignTop, "Cross Remote");
  27. canvas_set_font(canvas, FontSecondary);
  28. canvas_draw_str_aligned(canvas, 64, 22, AlignCenter, AlignTop, "Chain IR and SubGhz");
  29. canvas_draw_str_aligned(canvas, 64, 32, AlignCenter, AlignTop, "Commands");
  30. snprintf(buffer, sizeof(buffer), "Version: %s", XREMOTE_VERSION);
  31. canvas_draw_str_aligned(canvas, 64, 42, AlignCenter, AlignTop, buffer);
  32. elements_button_center(canvas, "Back");
  33. }
  34. static void xremote_infoscreen_model_init(XRemoteInfoscreenModel* const model) {
  35. model->some_value = 1;
  36. }
  37. bool xremote_infoscreen_input(InputEvent* event, void* context) {
  38. furi_assert(context);
  39. XRemoteInfoscreen* instance = context;
  40. if(event->type == InputTypeRelease) {
  41. switch(event->key) {
  42. case InputKeyBack:
  43. with_view_model(
  44. instance->view,
  45. XRemoteInfoscreenModel * model,
  46. {
  47. UNUSED(model);
  48. instance->callback(XRemoteCustomEventInfoscreenBack, instance->context);
  49. },
  50. true);
  51. break;
  52. case InputKeyLeft:
  53. case InputKeyRight:
  54. case InputKeyUp:
  55. case InputKeyDown:
  56. case InputKeyOk:
  57. with_view_model(
  58. instance->view,
  59. XRemoteInfoscreenModel * model,
  60. {
  61. UNUSED(model);
  62. instance->callback(XRemoteCustomEventInfoscreenOk, instance->context);
  63. },
  64. true);
  65. break;
  66. case InputKeyMAX:
  67. break;
  68. }
  69. }
  70. return true;
  71. }
  72. void xremote_infoscreen_exit(void* context) {
  73. furi_assert(context);
  74. }
  75. void xremote_infoscreen_enter(void* context) {
  76. furi_assert(context);
  77. XRemoteInfoscreen* instance = (XRemoteInfoscreen*)context;
  78. with_view_model(
  79. instance->view,
  80. XRemoteInfoscreenModel * model,
  81. { xremote_infoscreen_model_init(model); },
  82. true);
  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. { xremote_infoscreen_model_init(model); },
  97. true);
  98. return instance;
  99. }
  100. void xremote_infoscreen_free(XRemoteInfoscreen* instance) {
  101. furi_assert(instance);
  102. with_view_model(
  103. instance->view, XRemoteInfoscreenModel * model, { UNUSED(model); }, true);
  104. view_free(instance->view);
  105. free(instance);
  106. }
  107. View* xremote_infoscreen_get_view(XRemoteInfoscreen* instance) {
  108. furi_assert(instance);
  109. return instance->view;
  110. }