ublox.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include "ublox_i.h"
  2. bool ublox_custom_event_callback(void* context, uint32_t event) {
  3. furi_assert(context);
  4. Ublox* ublox = context;
  5. return scene_manager_handle_custom_event(ublox->scene_manager, event);
  6. }
  7. bool ublox_back_event_callback(void* context) {
  8. furi_assert(context);
  9. Ublox* ublox = context;
  10. return scene_manager_handle_back_event(ublox->scene_manager);
  11. }
  12. Ublox* ublox_alloc() {
  13. Ublox* ublox = malloc(sizeof(Ublox));
  14. ublox->view_dispatcher = view_dispatcher_alloc();
  15. ublox->scene_manager = scene_manager_alloc(&ublox_scene_handlers, ublox);
  16. view_dispatcher_enable_queue(ublox->view_dispatcher);
  17. view_dispatcher_set_event_callback_context(ublox->view_dispatcher, ublox);
  18. view_dispatcher_set_custom_event_callback(ublox->view_dispatcher, ublox_custom_event_callback);
  19. view_dispatcher_set_navigation_event_callback(ublox->view_dispatcher, ublox_back_event_callback);
  20. ublox->worker = ublox_worker_alloc();
  21. ublox->gui = furi_record_open(RECORD_GUI);
  22. ublox->submenu = submenu_alloc();
  23. view_dispatcher_add_view(ublox->view_dispatcher, UbloxViewMenu, submenu_get_view(ublox->submenu));
  24. ublox->widget = widget_alloc();
  25. view_dispatcher_add_view(ublox->view_dispatcher, UbloxViewWidget, widget_get_view(ublox->widget));
  26. ublox->data_display = data_display_alloc();
  27. view_dispatcher_add_view(ublox->view_dispatcher, UbloxViewDataDisplay, data_display_get_view(ublox->data_display));
  28. ublox->variable_item_list = variable_item_list_alloc();
  29. view_dispatcher_add_view(ublox->view_dispatcher, UbloxViewVariableItemList, variable_item_list_get_view(ublox->variable_item_list));
  30. ublox->notifications = furi_record_open(RECORD_NOTIFICATION);
  31. // Establish default data display state
  32. (ublox->data_display_state).view_mode = UbloxDataDisplayViewModeHandheld;
  33. (ublox->data_display_state).backlight_mode = UbloxDataDisplayBacklightDefault;
  34. (ublox->data_display_state).refresh_rate = 2;
  35. (ublox->data_display_state).notify_mode = UbloxDataDisplayNotifyOn;
  36. (ublox->device_state).odometer_mode = UbloxOdometerModeRunning;
  37. // "suitable for most applications" according to u-blox.
  38. (ublox->device_state).platform_model = UbloxPlatformModelPortable;
  39. ublox->gps_initted = false;
  40. return ublox;
  41. }
  42. void ublox_free(Ublox* ublox) {
  43. furi_assert(ublox);
  44. ublox_worker_stop(ublox->worker);
  45. ublox_worker_free(ublox->worker);
  46. view_dispatcher_remove_view(ublox->view_dispatcher, UbloxViewMenu);
  47. submenu_free(ublox->submenu);
  48. view_dispatcher_remove_view(ublox->view_dispatcher, UbloxViewWidget);
  49. widget_free(ublox->widget);
  50. view_dispatcher_remove_view(ublox->view_dispatcher, UbloxViewDataDisplay);
  51. data_display_free(ublox->data_display);
  52. view_dispatcher_remove_view(ublox->view_dispatcher, UbloxViewVariableItemList);
  53. variable_item_list_free(ublox->variable_item_list);
  54. view_dispatcher_free(ublox->view_dispatcher);
  55. scene_manager_free(ublox->scene_manager);
  56. furi_record_close(RECORD_GUI);
  57. furi_record_close(RECORD_NOTIFICATION);
  58. ublox->gui = NULL;
  59. free(ublox);
  60. }
  61. int32_t ublox_app(void* p) {
  62. UNUSED(p);
  63. Ublox* ublox = ublox_alloc();
  64. view_dispatcher_attach_to_gui(ublox->view_dispatcher, ublox->gui, ViewDispatcherTypeFullscreen);
  65. scene_manager_next_scene(ublox->scene_manager, UbloxSceneStart);
  66. view_dispatcher_run(ublox->view_dispatcher);
  67. // force restore the default backlight
  68. notification_message_block(ublox->notifications, &sequence_display_backlight_enforce_auto);
  69. ublox_free(ublox);
  70. return 0;
  71. }