xremote_infoscreen.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. case InputKeyOk:
  44. with_view_model(
  45. instance->view,
  46. XRemoteInfoscreenModel * model,
  47. {
  48. UNUSED(model);
  49. instance->callback(XRemoteCustomEventInfoscreenOk, instance->context);
  50. },
  51. true);
  52. break;
  53. default:
  54. break;
  55. }
  56. }
  57. return true;
  58. }
  59. void xremote_infoscreen_exit(void* context) {
  60. furi_assert(context);
  61. }
  62. void xremote_infoscreen_enter(void* context) {
  63. furi_assert(context);
  64. XRemoteInfoscreen* instance = (XRemoteInfoscreen*)context;
  65. with_view_model(
  66. instance->view,
  67. XRemoteInfoscreenModel * model,
  68. { xremote_infoscreen_model_init(model); },
  69. true);
  70. }
  71. XRemoteInfoscreen* xremote_infoscreen_alloc() {
  72. XRemoteInfoscreen* instance = malloc(sizeof(XRemoteInfoscreen));
  73. instance->view = view_alloc();
  74. view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(XRemoteInfoscreenModel));
  75. view_set_context(instance->view, instance); // furi_assert crashes in events without this
  76. view_set_draw_callback(instance->view, (ViewDrawCallback)xremote_infoscreen_draw);
  77. view_set_input_callback(instance->view, xremote_infoscreen_input);
  78. //view_set_enter_callback(instance->view, xremote_infoscreen_enter);
  79. //view_set_exit_callback(instance->view, xremote_infoscreen_exit);
  80. with_view_model(
  81. instance->view,
  82. XRemoteInfoscreenModel * model,
  83. { xremote_infoscreen_model_init(model); },
  84. true);
  85. return instance;
  86. }
  87. void xremote_infoscreen_free(XRemoteInfoscreen* instance) {
  88. furi_assert(instance);
  89. with_view_model(instance->view, XRemoteInfoscreenModel * model, { UNUSED(model); }, true);
  90. view_free(instance->view);
  91. free(instance);
  92. }
  93. View* xremote_infoscreen_get_view(XRemoteInfoscreen* instance) {
  94. furi_assert(instance);
  95. return instance->view;
  96. }