wiegand_load.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "../wiegand.h"
  2. void wiegand_load_scene_on_enter(void* context) {
  3. App* app = context;
  4. bit_count = 0;
  5. DialogsFileBrowserOptions browser_options;
  6. dialog_file_browser_set_basic_options(&browser_options, WIEGAND_SAVE_EXTENSION, NULL);
  7. browser_options.base_path = WIEGAND_SAVE_FOLDER;
  8. furi_string_set(app->file_path, browser_options.base_path);
  9. FuriString* buffer = furi_string_alloc(1024);
  10. if(dialog_file_browser_show(app->dialogs, app->file_path, app->file_path, &browser_options)) {
  11. Storage* storage = furi_record_open(RECORD_STORAGE);
  12. File* data_file = storage_file_alloc(storage);
  13. if(storage_file_open(
  14. data_file, furi_string_get_cstr(app->file_path), FSAM_READ, FSOM_OPEN_EXISTING)) {
  15. while(!storage_file_eof(data_file)) {
  16. char ch;
  17. furi_string_reset(buffer);
  18. while(storage_file_read(data_file, &ch, 1) && !storage_file_eof(data_file)) {
  19. furi_string_push_back(buffer, ch);
  20. if(ch == '\n') {
  21. break;
  22. }
  23. }
  24. if(furi_string_start_with(buffer, "RAW_Data: ")) {
  25. bit_count = 0;
  26. int length = furi_string_size(buffer);
  27. uint32_t temp;
  28. char ch;
  29. for(int i = 8; i < length - 1; i++) {
  30. if(furi_string_get_char(buffer, i) == 'D') {
  31. i++;
  32. data[bit_count] = furi_string_get_char(buffer, i) == '1';
  33. i += 2; // Skip space
  34. temp = 0;
  35. while(i < length && (ch = furi_string_get_char(buffer, i)) != ' ') {
  36. temp = temp * 10 + (ch - '0');
  37. i++;
  38. }
  39. data_fall[bit_count] = temp;
  40. i++; // Skip space
  41. temp = 0;
  42. while(i < length && (ch = furi_string_get_char(buffer, i)) != ' ' &&
  43. ch != '\n') {
  44. temp = temp * 10 + (ch - '0');
  45. i++;
  46. }
  47. data_rise[bit_count] = temp;
  48. bit_count++;
  49. }
  50. }
  51. break;
  52. }
  53. }
  54. storage_file_close(data_file);
  55. }
  56. storage_file_free(data_file);
  57. furi_record_close(RECORD_STORAGE);
  58. }
  59. if(bit_count == 0) {
  60. scene_manager_search_and_switch_to_previous_scene(
  61. app->scene_manager, WiegandMainMenuScene);
  62. } else {
  63. data_saved = true;
  64. scene_manager_next_scene(app->scene_manager, WiegandDataScene);
  65. }
  66. }