system_settings.c 3.3 KB

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