system_settings.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #include "system_settings.h"
  2. #include <loader/loader.h>
  3. #include <lib/toolbox/value_index.h>
  4. const char* const log_level_text[] = {
  5. "Default",
  6. "None",
  7. "Error",
  8. "Warning",
  9. "Info",
  10. "Debug",
  11. "Trace",
  12. };
  13. const uint32_t log_level_value[] = {
  14. FuriLogLevelDefault,
  15. FuriLogLevelNone,
  16. FuriLogLevelError,
  17. FuriLogLevelWarn,
  18. FuriLogLevelInfo,
  19. FuriLogLevelDebug,
  20. FuriLogLevelTrace,
  21. };
  22. static void log_level_changed(VariableItem* item) {
  23. // SystemSettings* app = variable_item_get_context(item);
  24. uint8_t index = variable_item_get_current_value_index(item);
  25. variable_item_set_current_value_text(item, log_level_text[index]);
  26. furi_hal_rtc_set_log_level(log_level_value[index]);
  27. }
  28. const char* const debug_text[] = {
  29. "OFF",
  30. "ON",
  31. };
  32. static void debug_changed(VariableItem* item) {
  33. uint8_t index = variable_item_get_current_value_index(item);
  34. variable_item_set_current_value_text(item, debug_text[index]);
  35. if(index) {
  36. furi_hal_rtc_set_flag(FuriHalRtcFlagDebug);
  37. } else {
  38. furi_hal_rtc_reset_flag(FuriHalRtcFlagDebug);
  39. }
  40. loader_update_menu();
  41. }
  42. const char* const heap_trace_mode_text[] = {
  43. "None",
  44. "Main",
  45. #if FURI_DEBUG
  46. "Tree",
  47. "All",
  48. #endif
  49. };
  50. const uint32_t heap_trace_mode_value[] = {
  51. FuriHalRtcHeapTrackModeNone,
  52. FuriHalRtcHeapTrackModeMain,
  53. #if FURI_DEBUG
  54. FuriHalRtcHeapTrackModeTree,
  55. FuriHalRtcHeapTrackModeAll,
  56. #endif
  57. };
  58. static void heap_trace_mode_changed(VariableItem* item) {
  59. // SystemSettings* app = variable_item_get_context(item);
  60. uint8_t index = variable_item_get_current_value_index(item);
  61. variable_item_set_current_value_text(item, heap_trace_mode_text[index]);
  62. furi_hal_rtc_set_heap_track_mode(heap_trace_mode_value[index]);
  63. }
  64. static uint32_t system_settings_exit(void* context) {
  65. UNUSED(context);
  66. return VIEW_NONE;
  67. }
  68. SystemSettings* system_settings_alloc() {
  69. SystemSettings* app = malloc(sizeof(SystemSettings));
  70. // Load settings
  71. app->gui = furi_record_open(RECORD_GUI);
  72. app->view_dispatcher = view_dispatcher_alloc();
  73. view_dispatcher_enable_queue(app->view_dispatcher);
  74. view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
  75. view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
  76. VariableItem* item;
  77. uint8_t value_index;
  78. app->var_item_list = variable_item_list_alloc();
  79. item = variable_item_list_add(
  80. app->var_item_list, "Log Level", COUNT_OF(log_level_text), log_level_changed, app);
  81. value_index = value_index_uint32(
  82. furi_hal_rtc_get_log_level(), log_level_value, COUNT_OF(log_level_text));
  83. variable_item_set_current_value_index(item, value_index);
  84. variable_item_set_current_value_text(item, log_level_text[value_index]);
  85. item = variable_item_list_add(
  86. app->var_item_list, "Debug", COUNT_OF(debug_text), debug_changed, app);
  87. value_index = furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug) ? 1 : 0;
  88. variable_item_set_current_value_index(item, value_index);
  89. variable_item_set_current_value_text(item, debug_text[value_index]);
  90. item = variable_item_list_add(
  91. app->var_item_list,
  92. "Heap Trace",
  93. COUNT_OF(heap_trace_mode_text),
  94. heap_trace_mode_changed,
  95. app);
  96. value_index = value_index_uint32(
  97. furi_hal_rtc_get_heap_track_mode(), heap_trace_mode_value, COUNT_OF(heap_trace_mode_text));
  98. furi_hal_rtc_set_heap_track_mode(heap_trace_mode_value[value_index]);
  99. variable_item_set_current_value_index(item, value_index);
  100. variable_item_set_current_value_text(item, heap_trace_mode_text[value_index]);
  101. view_set_previous_callback(
  102. variable_item_list_get_view(app->var_item_list), system_settings_exit);
  103. view_dispatcher_add_view(
  104. app->view_dispatcher,
  105. SystemSettingsViewVarItemList,
  106. variable_item_list_get_view(app->var_item_list));
  107. view_dispatcher_switch_to_view(app->view_dispatcher, SystemSettingsViewVarItemList);
  108. return app;
  109. }
  110. void system_settings_free(SystemSettings* app) {
  111. furi_assert(app);
  112. // Variable item list
  113. view_dispatcher_remove_view(app->view_dispatcher, SystemSettingsViewVarItemList);
  114. variable_item_list_free(app->var_item_list);
  115. // View dispatcher
  116. view_dispatcher_free(app->view_dispatcher);
  117. // Records
  118. furi_record_close(RECORD_GUI);
  119. free(app);
  120. }
  121. int32_t system_settings_app(void* p) {
  122. UNUSED(p);
  123. SystemSettings* app = system_settings_alloc();
  124. view_dispatcher_run(app->view_dispatcher);
  125. system_settings_free(app);
  126. return 0;
  127. }