finik_eth_app.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #include "finik_eth_app.h"
  2. #include <furi.h>
  3. #include <gui/gui.h>
  4. #include <gui/elements.h>
  5. #include <input/input.h>
  6. #include <notification/notification_messages.h>
  7. #include "eth_worker.h"
  8. #define TAG "FinikEthApp"
  9. static void finik_eth_app_draw_callback(Canvas* canvas, void* ctx) {
  10. furi_assert(ctx);
  11. FinikEthApp* app = ctx;
  12. canvas_clear(canvas);
  13. DrawMode mode = app->draw_mode;
  14. if(mode == DRAW_ONLY_PICTURES || mode == DRAW_ALL)
  15. canvas_draw_icon(canvas, 0, 29, &I_amperka_ru_logo_128x35px);
  16. if(mode == DRAW_ONLY_TEXT || mode == DRAW_ALL) {
  17. canvas_set_font(canvas, FontPrimary);
  18. canvas_draw_str(canvas, 4, 8, "This is an example app!");
  19. canvas_set_font(canvas, FontSecondary);
  20. elements_multiline_text_aligned(
  21. canvas,
  22. 127,
  23. 15,
  24. AlignRight,
  25. AlignTop,
  26. "Some long long long long \n aligned multiline text");
  27. }
  28. }
  29. static void finik_eth_app_input_callback(InputEvent* input_event, void* ctx) {
  30. furi_assert(ctx);
  31. FuriMessageQueue* event_queue = ctx;
  32. furi_message_queue_put(event_queue, input_event, FuriWaitForever);
  33. }
  34. FinikEthApp* finik_eth_app_alloc() {
  35. FinikEthApp* app = malloc(sizeof(FinikEthApp));
  36. app->view_port = view_port_alloc();
  37. app->event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
  38. view_port_draw_callback_set(app->view_port, finik_eth_app_draw_callback, app);
  39. view_port_input_callback_set(app->view_port, finik_eth_app_input_callback, app->event_queue);
  40. app->gui = furi_record_open(RECORD_GUI);
  41. gui_add_view_port(app->gui, app->view_port, GuiLayerFullscreen);
  42. app->notifications = furi_record_open(RECORD_NOTIFICATION);
  43. app->eth_worker = eth_worker_alloc();
  44. eth_worker_task(app->eth_worker);
  45. return app;
  46. }
  47. void finik_eth_app_free(FinikEthApp* app) {
  48. furi_assert(app);
  49. view_port_enabled_set(app->view_port, false);
  50. gui_remove_view_port(app->gui, app->view_port);
  51. view_port_free(app->view_port);
  52. furi_message_queue_free(app->event_queue);
  53. furi_record_close(RECORD_GUI);
  54. furi_record_close(RECORD_NOTIFICATION);
  55. }
  56. int32_t finik_eth_app(void* p) {
  57. UNUSED(p);
  58. FinikEthApp* app = finik_eth_app_alloc();
  59. InputEvent event;
  60. while(1) {
  61. if(furi_message_queue_get(app->event_queue, &event, 100) == FuriStatusOk) {
  62. if(event.type == InputTypePress) {
  63. if(event.key == InputKeyBack)
  64. break;
  65. else if(event.key == InputKeyUp) {
  66. FURI_LOG_I(TAG, "example_led_sequence");
  67. notification_message(app->notifications, &example_led_sequence);
  68. } else if(event.key == InputKeyDown) {
  69. FURI_LOG_I(TAG, "example_vibro_sequence");
  70. notification_message(app->notifications, &example_vibro_sequence);
  71. } else if(event.key == InputKeyOk) {
  72. FURI_LOG_I(TAG, "example_sound_sequence");
  73. notification_message(app->notifications, &example_sound_sequence);
  74. }
  75. } else if(event.type == InputTypeLong) {
  76. DrawMode mode = app->draw_mode;
  77. if(event.key == InputKeyLeft)
  78. app->draw_mode = (mode - 1 + TOTAL_DRAW_MODES) % TOTAL_DRAW_MODES;
  79. else if(event.key == InputKeyRight)
  80. app->draw_mode = (mode + 1) % TOTAL_DRAW_MODES;
  81. view_port_update(app->view_port);
  82. }
  83. }
  84. }
  85. finik_eth_app_free(app);
  86. return 0;
  87. }