finik_eth_app.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 =
  44. return app;
  45. }
  46. void finik_eth_app_free(FinikEthApp* app) {
  47. furi_assert(app);
  48. view_port_enabled_set(app->view_port, false);
  49. gui_remove_view_port(app->gui, app->view_port);
  50. view_port_free(app->view_port);
  51. furi_message_queue_free(app->event_queue);
  52. furi_record_close(RECORD_GUI);
  53. furi_record_close(RECORD_NOTIFICATION);
  54. }
  55. int32_t finik_eth_app(void* p) {
  56. UNUSED(p);
  57. FinikEthApp* app = finik_eth_app_alloc();
  58. InputEvent event;
  59. while(1) {
  60. if(furi_message_queue_get(app->event_queue, &event, 100) == FuriStatusOk) {
  61. if(event.type == InputTypePress) {
  62. if(event.key == InputKeyBack)
  63. break;
  64. else if(event.key == InputKeyUp) {
  65. FURI_LOG_I(TAG, "example_led_sequence");
  66. notification_message(app->notifications, &example_led_sequence);
  67. } else if(event.key == InputKeyDown) {
  68. FURI_LOG_I(TAG, "example_vibro_sequence");
  69. notification_message(app->notifications, &example_vibro_sequence);
  70. } else if(event.key == InputKeyOk) {
  71. FURI_LOG_I(TAG, "example_sound_sequence");
  72. notification_message(app->notifications, &example_sound_sequence);
  73. }
  74. } else if(event.type == InputTypeLong) {
  75. DrawMode mode = app->draw_mode;
  76. if(event.key == InputKeyLeft)
  77. app->draw_mode = (mode - 1 + TOTAL_DRAW_MODES) % TOTAL_DRAW_MODES;
  78. else if(event.key == InputKeyRight)
  79. app->draw_mode = (mode + 1) % TOTAL_DRAW_MODES;
  80. view_port_update(app->view_port);
  81. }
  82. }
  83. }
  84. finik_eth_app_free(app);
  85. return 0;
  86. }