ublox.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #include "ublox_i.h"
  2. const NotificationSequence sequence_new_reading = {
  3. //&message_vibro_on,
  4. &message_green_255,
  5. &message_delay_100,
  6. &message_green_0,
  7. //&message_vibro_off,
  8. NULL,
  9. };
  10. bool ublox_custom_event_callback(void* context, uint32_t event) {
  11. furi_assert(context);
  12. Ublox* ublox = context;
  13. return scene_manager_handle_custom_event(ublox->scene_manager, event);
  14. }
  15. bool ublox_back_event_callback(void* context) {
  16. furi_assert(context);
  17. Ublox* ublox = context;
  18. return scene_manager_handle_back_event(ublox->scene_manager);
  19. }
  20. Ublox* ublox_alloc() {
  21. Ublox* ublox = malloc(sizeof(Ublox));
  22. ublox->view_dispatcher = view_dispatcher_alloc();
  23. ublox->scene_manager = scene_manager_alloc(&ublox_scene_handlers, ublox);
  24. view_dispatcher_enable_queue(ublox->view_dispatcher);
  25. view_dispatcher_set_event_callback_context(ublox->view_dispatcher, ublox);
  26. view_dispatcher_set_custom_event_callback(ublox->view_dispatcher, ublox_custom_event_callback);
  27. view_dispatcher_set_navigation_event_callback(
  28. ublox->view_dispatcher, ublox_back_event_callback);
  29. ublox->worker = ublox_worker_alloc();
  30. ublox->gui = furi_record_open(RECORD_GUI);
  31. view_dispatcher_attach_to_gui(
  32. ublox->view_dispatcher, ublox->gui, ViewDispatcherTypeFullscreen);
  33. ublox->submenu = submenu_alloc();
  34. view_dispatcher_add_view(
  35. ublox->view_dispatcher, UbloxViewMenu, submenu_get_view(ublox->submenu));
  36. ublox->widget = widget_alloc();
  37. view_dispatcher_add_view(
  38. ublox->view_dispatcher, UbloxViewWidget, widget_get_view(ublox->widget));
  39. ublox->variable_item_list = variable_item_list_alloc();
  40. view_dispatcher_add_view(
  41. ublox->view_dispatcher,
  42. UbloxViewVariableItemList,
  43. variable_item_list_get_view(ublox->variable_item_list));
  44. ublox->text_input = text_input_alloc();
  45. view_dispatcher_add_view(
  46. ublox->view_dispatcher, UbloxViewTextInput, text_input_get_view(ublox->text_input));
  47. ublox->data_display = data_display_alloc();
  48. view_dispatcher_add_view(
  49. ublox->view_dispatcher, UbloxViewDataDisplay, data_display_get_view(ublox->data_display));
  50. ublox->notifications = furi_record_open(RECORD_NOTIFICATION);
  51. ublox->storage = furi_record_open(RECORD_STORAGE);
  52. ublox->log_state = UbloxLogStateNone;
  53. // files do actually belong here
  54. ublox->logfile_folder = furi_string_alloc_set(STORAGE_APP_DATA_PATH_PREFIX);
  55. // Establish default data display state
  56. (ublox->data_display_state).view_mode = UbloxDataDisplayViewModeHandheld;
  57. (ublox->data_display_state).refresh_rate = 2;
  58. (ublox->data_display_state).notify_mode = UbloxDataDisplayNotifyOn;
  59. (ublox->data_display_state).backlight_mode = UbloxDataDisplayBacklightDefault;
  60. (ublox->device_state).odometer_mode = UbloxOdometerModeRunning;
  61. // "suitable for most applications" according to u-blox.
  62. (ublox->device_state).platform_model = UbloxPlatformModelPortable;
  63. ublox->gps_initted = false;
  64. return ublox;
  65. }
  66. #define TAG "ublox"
  67. //#include "ublox_worker_i.h"
  68. void ublox_free(Ublox* ublox) {
  69. furi_assert(ublox);
  70. // no need to stop the worker, plus it causes the app to crash by NULL
  71. // pointer dereference from context in the worker struct
  72. //FURI_LOG_I(TAG, "stop worker");
  73. //ublox_worker_stop(ublox->worker);
  74. //FURI_LOG_I(TAG, "%p", ublox->worker->context);
  75. FURI_LOG_I(TAG, "free worker");
  76. ublox_worker_free(ublox->worker);
  77. view_dispatcher_remove_view(ublox->view_dispatcher, UbloxViewMenu);
  78. submenu_free(ublox->submenu);
  79. view_dispatcher_remove_view(ublox->view_dispatcher, UbloxViewWidget);
  80. widget_free(ublox->widget);
  81. view_dispatcher_remove_view(ublox->view_dispatcher, UbloxViewDataDisplay);
  82. data_display_free(ublox->data_display);
  83. view_dispatcher_remove_view(ublox->view_dispatcher, UbloxViewVariableItemList);
  84. variable_item_list_free(ublox->variable_item_list);
  85. view_dispatcher_remove_view(ublox->view_dispatcher, UbloxViewTextInput);
  86. text_input_free(ublox->text_input);
  87. view_dispatcher_free(ublox->view_dispatcher);
  88. scene_manager_free(ublox->scene_manager);
  89. furi_record_close(RECORD_GUI);
  90. ublox->gui = NULL;
  91. furi_record_close(RECORD_NOTIFICATION);
  92. ublox->notifications = NULL;
  93. furi_record_close(RECORD_STORAGE);
  94. ublox->storage = NULL;
  95. if(ublox->logfile_folder != NULL) {
  96. furi_string_free(ublox->logfile_folder);
  97. }
  98. free(ublox);
  99. }
  100. int32_t ublox_app(void* p) {
  101. UNUSED(p);
  102. Ublox* ublox = ublox_alloc();
  103. scene_manager_next_scene(ublox->scene_manager, UbloxSceneStart);
  104. view_dispatcher_run(ublox->view_dispatcher);
  105. // force restore the default backlight on exit
  106. // TODO: this is breaking the backlight timeout for everything
  107. // else: test by opening ublox, then leaving and opening DAP
  108. // Link. DAP Link should force the backlight on but doesn't.
  109. if ((ublox->data_display_state).backlight_mode == UbloxDataDisplayBacklightOn) {
  110. notification_message_block(ublox->notifications, &sequence_display_backlight_enforce_auto);
  111. }
  112. ublox_free(ublox);
  113. return 0;
  114. }