فهرست منبع

UI for reading DG2

Eric Betts 9 ماه پیش
والد
کامیت
320968003d
5فایلهای تغییر یافته به همراه32 افزوده شده و 10 حذف شده
  1. 3 0
      passy_i.h
  2. 8 8
      passy_reader.c
  3. 6 0
      scenes/passy_scene_main_menu.c
  4. 14 1
      scenes/passy_scene_read.c
  5. 1 1
      scenes/passy_scene_read_success.c

+ 3 - 0
passy_i.h

@@ -90,6 +90,9 @@ struct Passy {
     BitBuffer* DG1;
 
     PassyReadType read_type;
+
+    size_t offset;
+    size_t bytes_total;
 };
 
 typedef enum {

+ 8 - 8
passy_reader.c

@@ -450,24 +450,24 @@ NfcCommand passy_reader_state_machine(Passy* passy, PassyReader* passy_reader) {
             file_stream_open(stream, furi_string_get_cstr(path), FSAM_WRITE, FSOM_OPEN_ALWAYS);
 
             uint8_t chunk[PASSY_READER_DG2_CHUNK_SIZE];
-            size_t body_offset = start;
-            size_t chunk_count = (body_size + sizeof(chunk) - 1) / sizeof(chunk);
-            size_t i = 0;
+            passy->offset = start;
+            passy->bytes_total = body_size;
             do {
                 memset(chunk, 0, sizeof(chunk));
-                uint8_t Le = MIN(sizeof(chunk), (size_t)(body_size - body_offset));
+                uint8_t Le = MIN(sizeof(chunk), (size_t)(body_size - passy->offset));
 
-                ret = passy_reader_read_binary(passy_reader, body_offset, Le, chunk);
+                ret = passy_reader_read_binary(passy_reader, passy->offset, Le, chunk);
                 if(ret != NfcCommandContinue) {
                     view_dispatcher_send_custom_event(
                         passy->view_dispatcher, PassyCustomEventReaderError);
                     break;
                 }
-                body_offset += sizeof(chunk);
-                FURI_LOG_D(TAG, "chunk %02x/%02x offset %d", ++i, chunk_count, body_offset);
+                passy->offset += sizeof(chunk);
                 // passy_log_buffer(TAG, "chunk", chunk, sizeof(chunk));
                 stream_write(stream, chunk, Le);
-            } while(body_offset < body_size);
+                view_dispatcher_send_custom_event(
+                    passy->view_dispatcher, PassyCustomEventReaderReading);
+            } while(passy->offset < body_size);
 
             file_stream_close(stream);
             furi_record_close(RECORD_STORAGE);

+ 6 - 0
scenes/passy_scene_main_menu.c

@@ -42,6 +42,12 @@ void passy_scene_main_menu_on_enter(void* context) {
             SubmenuIndexReadDG1,
             passy_scene_main_menu_submenu_callback,
             passy);
+        submenu_add_item(
+            submenu,
+            "Read DG2",
+            SubmenuIndexReadDG2,
+            passy_scene_main_menu_submenu_callback,
+            passy);
     }
 
     view_dispatcher_switch_to_view(passy->view_dispatcher, PassyViewMenu);

+ 14 - 1
scenes/passy_scene_read.c

@@ -15,6 +15,7 @@ void passy_scene_read_on_enter(void* context) {
 
     passy->poller = nfc_poller_alloc(passy->nfc, NfcProtocolIso14443_4b);
     nfc_poller_start(passy->poller, passy_reader_poller_callback, passy);
+    passy->bytes_total = 0;
 
     passy_blink_start(passy);
 
@@ -38,7 +39,19 @@ bool passy_scene_read_on_event(void* context, SceneManagerEvent event) {
         } else if(event.event == PassyCustomEventReaderAuthenticated) {
             popup_set_header(popup, "Authenticated", 68, 30, AlignLeft, AlignTop);
         } else if(event.event == PassyCustomEventReaderReading) {
-            popup_set_header(popup, "Reading", 68, 30, AlignLeft, AlignTop);
+            if(passy->bytes_total == 0) {
+                popup_set_header(popup, "Reading", 68, 30, AlignLeft, AlignTop);
+            } else {
+                // Update the header with the current bytes read
+                char header[32];
+                snprintf(
+                    header,
+                    sizeof(header),
+                    "Reading\n%d/%dk",
+                    passy->offset,
+                    (passy->bytes_total / 1024));
+                popup_set_header(popup, header, 68, 30, AlignLeft, AlignTop);
+            }
         }
     } else if(event.type == SceneManagerEventTypeBack) {
         scene_manager_search_and_switch_to_previous_scene(

+ 1 - 1
scenes/passy_scene_read_success.c

@@ -123,7 +123,7 @@ void passy_scene_read_success_on_enter(void* context) {
         dg1 = 0;
 
     } else if(passy->read_type == PassyReadDG2) {
-        furi_string_cat_printf(str, "Saved to disk");
+        furi_string_cat_printf(str, "Saved to disk in apps_data/passy/\n");
     }
     text_box_set_font(passy->text_box, TextBoxFontText);
     text_box_set_text(passy->text_box, furi_string_get_cstr(passy->text_box_store));