@@ -36,7 +36,7 @@ constexpr boolean createFakeFiles = true;
3636boolean done = false ;
3737volatile boolean connected = false ;
3838
39- USBStorage thumbDrive = USBStorage() ;
39+ USBStorage thumbDrive;
4040
4141
4242void addSomeFakeFiles (Folder * folder){
@@ -72,14 +72,6 @@ void move(Folder * source, Folder * dest){
7272}
7373
7474
75- void onConnected (){
76- connected = true ;
77- }
78-
79- void onDisconnected (){
80- connected = false ;
81- }
82-
8375
8476
8577
@@ -89,46 +81,50 @@ void setup(){
8981 Serial.begin (115200 );
9082 while (!Serial);
9183
92- Serial.println (" USB Thumb Drive has been inserted" );
93- bool thumbMounted = thumbDrive.begin (FS_FAT);
94- if (thumbMounted){
95- Serial.println (" USB Thumb Drive has been mounted" );
84+ // toggle this to to true to enable logging output
85+ Arduino_UnifiedStorage::loggingEnabled = false ;
9686
97- Folder thumbRoot = thumbDrive.getRootFolder ();
98- String folderName = " InternalBackup_" + String (millis ());
99- Serial.println (folderName);
100- Folder backupFolder = thumbRoot.createSubfolder (folderName);
87+ thumbDrive = USBStorage ();
10188
102- int partitionIndex = 0 ;
89+ bool thumbMounted = thumbDrive.begin (FS_FAT);
90+ if (thumbMounted){
91+ Serial.println (" USB Thumb Drive has been mounted" );
10392
104- std::vector<Partition> partitions = InternalStorage::readPartitions ();
105- Serial.println (" Found " + String (partitions.size ()) + " partitions on internalStorage \n " );
93+ Folder thumbRoot = thumbDrive.getRootFolder ();
94+ String folderName = " InternalBackup_" + String (millis ());
95+ Serial.println (folderName);
96+ Folder backupFolder = thumbRoot.createSubfolder (folderName);
10697
107- for (auto part: partitions){
108- partitionIndex++;
109- const char * partitionName = createPartitionName (partitionIndex);
110- Folder thisPartitionBackupFolder = backupFolder.createSubfolder (partitionName);
98+ int partitionIndex = 0 ;
11199
112- InternalStorage thisPartition = InternalStorage (partitionIndex, partitionName, part. fileSystemType );
113- thisPartition. begin ( );
100+ std::vector<Partition> partitions = InternalStorage::readPartitions ( );
101+ Serial. println ( " Found " + String (partitions. size ()) + " partitions on internalStorage \n " );
114102
115- Folder partitionRootFolder = thisPartition.getRootFolder ();
116- Serial.println (partitionRootFolder.getPathAsString ());
103+ for (auto part: partitions){
104+ partitionIndex++;
105+ const char * partitionName = createPartitionName (partitionIndex);
106+ Folder thisPartitionBackupFolder = backupFolder.createSubfolder (partitionName);
117107
118- if (createFakeFiles){
119- addSomeFakeFiles (&partitionRootFolder);
120- }
108+ InternalStorage thisPartition = InternalStorage (partitionIndex, partitionName, part.fileSystemType );
109+ thisPartition.begin ();
121110
122- move (&partitionRootFolder, &thisPartitionBackupFolder);
123- thisPartition.unmount ();
124- }
111+ Folder partitionRootFolder = thisPartition.getRootFolder ();
112+ Serial.println (partitionRootFolder.getPathAsString ());
125113
126- thumbDrive.unmount ();
127-
114+ if (createFakeFiles){
115+ addSomeFakeFiles (&partitionRootFolder);
116+ }
128117
129- Serial.println (" DONE, you can restart the board now" );
118+ move (&partitionRootFolder, &thisPartitionBackupFolder);
119+ thisPartition.unmount ();
130120 }
131121
122+ thumbDrive.unmount ();
123+
124+
125+ Serial.println (" DONE, you can restart the board now" );
126+ }
127+
132128
133129}
134130
0 commit comments