Skip to content

Commit 943a875

Browse files
fixes and tweaks
1 parent 817aeae commit 943a875

File tree

6 files changed

+124
-134
lines changed

6 files changed

+124
-134
lines changed

examples/AdvancedUSBInternalOperations/AdvancedUSBInternalOperations.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ void setup() {
6363
while (!Serial);
6464

6565
// Mount the USB storage
66-
if(usbStorage.begin(FS_FAT)){
66+
if(usbStorage.begin()){
6767
Serial.println("USB storage mounted.");
6868
} else {
6969
Serial.println(errno);
7070
}
7171

72-
if(internalStorage.begin(FS_FAT)){
72+
if(internalStorage.begin()){
7373
Serial.println("Internal storage mounted.");
7474
} else {
7575
Serial.println(errno);

examples/BackupInternalPartitions/BackupInternalPartitions.ino

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,14 @@ void setup(){
8989
Serial.begin(115200);
9090
while(!Serial);
9191

92-
thumbDrive.onConnect(onConnected);
93-
94-
Serial.println("Waiting for a USB thumb drive to be plugged in...");
95-
96-
}
97-
98-
99-
void loop(){
100-
if(connected && !done){
101-
Serial.println("USB Thumb Drive has been inserted");
92+
Serial.println("USB Thumb Drive has been inserted");
10293
bool thumbMounted = thumbDrive.begin(FS_FAT);
10394
if(thumbMounted){
10495
Serial.println("USB Thumb Drive has been mounted");
10596

10697
Folder thumbRoot = thumbDrive.getRootFolder();
10798
String folderName = "InternalBackup_" + String(millis());
99+
Serial.println(folderName);
108100
Folder backupFolder = thumbRoot.createSubfolder(folderName);
109101

110102
int partitionIndex = 0;
@@ -132,9 +124,15 @@ void loop(){
132124
}
133125

134126
thumbDrive.unmount();
135-
done = true;
127+
136128

137129
Serial.println("DONE, you can restart the board now");
138130
}
139-
}
131+
132+
133+
}
134+
135+
136+
void loop(){
137+
140138
}

examples/InternalStoragePartitioning/InternalStoragePartitioning.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include <vector>
3737

3838
// Create a vector of partitions with one partition of 16MB using LittleFS
39-
std::vector<Partition> partitioningScheme = {{2048, FS_FAT}, {6144, FS_FAT} {8192, FS_LITTLEFS}};
39+
std::vector<Partition> partitioningScheme = {{2048, FS_FAT}, {6144, FS_FAT}, {8192, FS_LITTLEFS}};
4040

4141

4242
// Function to test writing to a file in the specified storage partition
@@ -64,7 +64,7 @@ void testAllPartitions(std::vector<Partition> partitions) {
6464
const char *partitionName = createPartitionName(i);
6565

6666
// Create an InternalStorage object for the partition
67-
InternalStorage thisPartition = InternalStorage(i, partitionName, partitions[i - 1].fileSystem);
67+
InternalStorage thisPartition = InternalStorage(i, partitionName, partitions[i - 1].fileSystemType);
6868

6969
// Check if the partition can be mounted
7070
if (thisPartition.begin()) {
@@ -90,7 +90,7 @@ void listPartitions(){
9090
partitionIndex ++;
9191
Serial.println("Partition " + String(partitionIndex));
9292
Serial.println("\t * Size: " + String(partition.size));
93-
Serial.println("\t * Type: " + prettyPrintFileSystemType(partitions.fileSystem));
93+
Serial.println("\t * Type: " + prettyPrintFileSystemType(partition.fileSystemType));
9494
Serial.println();
9595
}
9696
}

examples/Logger/Logger.ino

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121
So as long as the status LED is off you can safely remove the drive.
2222
The sketch will log to internal storage in the meantime, and wait for the USB drive to be inserted again.
2323
*/
24-
24+
#define ARDUINO_UNIFIED_STORAGE_DEBUG
2525
#include "Arduino_UnifiedStorage.h"
26-
#include "Logger.h"
2726
#include <vector>
2827

2928

@@ -98,10 +97,10 @@ void performUpdate() {
9897
backingUP = true;
9998
unsigned lastUpdateBytes = lastUpdateFile.readAsString().toInt(); // Read the last update size from the file
10099

101-
printlnToSerialOrRS485("Last update bytes: " + String(lastUpdateBytes));
100+
debugPrint("Last update bytes: " + String(lastUpdateBytes));
102101

103102
if (lastUpdateBytes >= bytesWritten) {
104-
printlnToSerialOrRS485("No new data to copy. ");
103+
debugPrint("No new data to copy. ");
105104
backupFile.close();
106105
lastUpdateFile.close();
107106
backingUP = false;
@@ -110,14 +109,14 @@ void performUpdate() {
110109

111110
logFile.seek(lastUpdateBytes); // Move the file pointer to the last update position
112111
unsigned long totalBytesToMove = bytesWritten - lastUpdateBytes;
113-
printlnToSerialOrRS485("New update bytes: " + String(totalBytesToMove));
112+
debugPrint("New update bytes: " + String(totalBytesToMove));
114113

115114
uint8_t* buffer = new uint8_t[totalBytesToMove];
116115

117116
size_t bytesRead = logFile.read(buffer, totalBytesToMove);
118117
size_t bytesMoved = backupFile.write(buffer, bytesRead); // Only write the bytes that haven't been backed up yet
119118

120-
printlnToSerialOrRS485("Successfully copied " + String(bytesMoved) + " new bytes. ");
119+
debugPrint("Successfully copied " + String(bytesMoved) + " new bytes. ");
121120

122121
lastUpdateFile.changeMode(FileMode::WRITE); // Open the last update file in write mode
123122
lastUpdateFile.write(String(lastUpdateBytes + bytesMoved)); // Update the last update size
@@ -139,32 +138,32 @@ void performUpdate() {
139138
void backupToUSB() {
140139
if(usbAvailable && !usbIntialized){
141140
usbStorage.begin();
142-
printlnToSerialOrRS485("First drive insertion, creating folders... ");
141+
debugPrint("First drive insertion, creating folders... ");
143142
Folder usbRoot = usbStorage.getRootFolder();
144143
String folderName = "LoggerBackup" + String(random(9999));
145144
backupFolder = usbRoot.createSubfolder(folderName);
146-
printlnToSerialOrRS485("Successfully created backup folder: " + backupFolder.getPathAsString());
145+
debugPrint("Successfully created backup folder: " + backupFolder.getPathAsString());
147146
usbStorage.unmount();
148147
usbIntialized = true;
149148
}
150149
else if(usbAvailable && usbIntialized) {
151-
printlnToSerialOrRS485("USB Mass storage is available ");
150+
debugPrint("USB Mass storage is available ");
152151
delay(100);
153152
if (!usbStorage.isMounted()) {
154153

155-
printlnToSerialOrRS485("Mounting USB Mass Storage ");
154+
debugPrint("Mounting USB Mass Storage ");
156155
digitalWrite(USB_MOUNTED_LED, LOW);
157156
if(usbStorage.begin()){
158157
performUpdate();
159158
}
160159

161160
} else if (usbStorage.isMounted()) {
162-
printlnToSerialOrRS485("USB Mass storage is connected, performing update ");
161+
debugPrint("USB Mass storage is connected, performing update ");
163162
performUpdate();
164163

165164
}
166165
} else {
167-
printlnToSerialOrRS485("USB Mass storage is not available ");
166+
debugPrint("USB Mass storage is not available ");
168167
}
169168

170169

@@ -186,17 +185,17 @@ void setup() {
186185
usbStorage.onDisconnect(disconnectionCallback);
187186

188187
pinMode(USB_MOUNTED_LED, OUTPUT);
189-
printlnToSerialOrRS485("Formatting internal storage... ");
188+
debugPrint("Formatting internal storage... ");
190189
int formatted = internalStorage.format(FS_LITTLEFS);
191-
printlnToSerialOrRS485("QSPI Format status: " + String(formatted));
190+
debugPrint("QSPI Format status: " + String(formatted));
192191

193192

194193

195194
if (!internalStorage.begin()) {
196-
printlnToSerialOrRS485("Failed to initialize internal storage ");
195+
debugPrint("Failed to initialize internal storage ");
197196
return;
198197
} else {
199-
printlnToSerialOrRS485("Initialized storage ");
198+
debugPrint("Initialized storage ");
200199
}
201200

202201
}

0 commit comments

Comments
 (0)