system_settings.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. static uint32_t system_settings_exit(void* context) {
  43. UNUSED(context);
  44. return VIEW_NONE;
  45. }
  46. SystemSettings* system_settings_alloc() {
  47. SystemSettings* app = malloc(sizeof(SystemSettings));
  48. // Load settings
  49. app->gui = furi_record_open(RECORD_GUI);
  50. app->view_dispatcher = view_dispatcher_alloc();
  51. view_dispatcher_enable_queue(app->view_dispatcher);
  52. view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
  53. view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
  54. VariableItem* item;
  55. uint8_t value_index;
  56. app->var_item_list = variable_item_list_alloc();
  57. item = variable_item_list_add(
  58. app->var_item_list, "Log Level", COUNT_OF(log_level_text), log_level_changed, app);
  59. value_index = value_index_uint32(
  60. furi_hal_rtc_get_log_level(), log_level_value, COUNT_OF(log_level_text));
  61. variable_item_set_current_value_index(item, value_index);
  62. variable_item_set_current_value_text(item, log_level_text[value_index]);
  63. item = variable_item_list_add(
  64. app->var_item_list, "Debug", COUNT_OF(debug_text), debug_changed, app);
  65. value_index = furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug) ? 1 : 0;
  66. variable_item_set_current_value_index(item, value_index);
  67. variable_item_set_current_value_text(item, debug_text[value_index]);
  68. view_set_previous_callback(
  69. variable_item_list_get_view(app->var_item_list), system_settings_exit);
  70. view_dispatcher_add_view(
  71. app->view_dispatcher,
  72. SystemSettingsViewVarItemList,
  73. variable_item_list_get_view(app->var_item_list));
  74. view_dispatcher_switch_to_view(app->view_dispatcher, SystemSettingsViewVarItemList);
  75. return app;
  76. }
  77. void system_settings_free(SystemSettings* app) {
  78. furi_assert(app);
  79. // Variable item list
  80. view_dispatcher_remove_view(app->view_dispatcher, SystemSettingsViewVarItemList);
  81. variable_item_list_free(app->var_item_list);
  82. // View dispatcher
  83. view_dispatcher_free(app->view_dispatcher);
  84. // Records
  85. furi_record_close(RECORD_GUI);
  86. free(app);
  87. }
  88. int32_t system_settings_app(void* p) {
  89. UNUSED(p);
  90. SystemSettings* app = system_settings_alloc();
  91. view_dispatcher_run(app->view_dispatcher);
  92. system_settings_free(app);
  93. return 0;
  94. }