timezone.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #include "timezone.h"
  2. #include <lib/toolbox/args.h>
  3. #include "../../../config/config.h"
  4. #include "../../../../scenes/scene_director.h"
  5. #include "../../cli_common_helpers.h"
  6. #define TOTP_CLI_COMMAND_TIMEZONE_ARG_TIMEZONE "TIMEZONE"
  7. void totp_cli_command_timezone_print_help() {
  8. TOTP_CLI_PRINTF("\t" TOTP_CLI_COMMAND_TIMEZONE " " TOTP_CLI_OPTIONAL_PARAM(TOTP_CLI_ARG(TOTP_CLI_COMMAND_TIMEZONE_ARG_TIMEZONE)) "\r\n");
  9. TOTP_CLI_PRINTF("\t\t" TOTP_CLI_ARG(TOTP_CLI_COMMAND_TIMEZONE_ARG_TIMEZONE) " - " TOTP_CLI_OPTIONAL_PARAM_MARK " timezone offset in hours to be set, if not provided then current timezone offset will be printed\r\n\r\n");
  10. }
  11. void totp_cli_command_timezone_handle(PluginState* plugin_state, FuriString* args) {
  12. FuriString* temp_str = furi_string_alloc();
  13. if (args_read_string_and_trim(args, temp_str)) {
  14. float tz = strtof(furi_string_get_cstr(temp_str), NULL);
  15. if (tz >= -12.75f && tz <= 12.75f) {
  16. plugin_state->timezone_offset = tz;
  17. totp_config_file_update_timezone_offset(tz);
  18. TOTP_CLI_PRINTF("Timezone is set to %f\r\n", tz);
  19. if (plugin_state->current_scene == TotpSceneGenerateToken) {
  20. totp_scene_director_activate_scene(plugin_state, TotpSceneNone, NULL);
  21. totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
  22. } else if (plugin_state->current_scene == TotpSceneAppSettings) {
  23. totp_scene_director_activate_scene(plugin_state, TotpSceneNone, NULL);
  24. totp_scene_director_activate_scene(plugin_state, TotpSceneAppSettings, NULL);
  25. }
  26. } else {
  27. TOTP_CLI_PRINTF("Invalid timezone offset\r\n");
  28. }
  29. } else {
  30. TOTP_CLI_PRINTF("Current timezone offset is %f\r\n", plugin_state->timezone_offset);
  31. }
  32. furi_string_free(temp_str);
  33. }