Skip to content

Commit b0004ba

Browse files
some little fixes
1 parent c45a28e commit b0004ba

File tree

4 files changed

+16
-34
lines changed

4 files changed

+16
-34
lines changed

examples/advanced/advanced.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ After the file operations, the code prints the contents of both the USB storage
1313
It recursively prints the directories (marked as "[D]") and files (marked as "[F]") using the "printFolderContents" function.
1414
*/
1515

16-
#include "src/UnifiedStorage.h"
16+
#include "UnifiedStorage.h"
1717

1818

1919
USBStorage usbStorage = USBStorage();
@@ -56,7 +56,7 @@ void setup() {
5656

5757
// Mount the internal storage
5858
Serial.println("Reformatting internal storage to make sure we have a clean FS");
59-
internalStorage.reformatQSPIPartition();
59+
internalStorage.format();
6060

6161
internalStorage.begin();
6262
Serial.println("Internal storage mounted.");
@@ -77,7 +77,7 @@ void setup() {
7777
Serial.println("File copied successfully from internal storage to USB storage.");
7878
} else {
7979
Serial.println("Failed to copy file from internal storage to USB storage.");
80-
Serial.println(getErrInfo(errno));
80+
Serial.println(getErrno());
8181
}
8282

8383
// Move the subdirectory from internal storage to USB storage
@@ -86,7 +86,7 @@ void setup() {
8686
Serial.println("Subdirectory moved successfully from internal storage to USB storage.");
8787
} else {
8888
Serial.println("Failed to move subdirectory from internal storage to USB storage.");
89-
Serial.println(getErrInfo(errno));
89+
Serial.println(getErrno());
9090
}
9191

9292
// Print the content of the USB storage

examples/opta_logger/opta_logger.ino

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ unsigned long lastBackup = 0;
4242

4343

4444
bool backingUP = false;
45-
bool dontloop = false;
45+
4646

4747
// Function to run a given method periodically
4848
void runPeriodically(void (*method)(), unsigned long interval, unsigned long* variable) {
@@ -116,16 +116,14 @@ void performUpdate() {
116116
// Close the backup file
117117

118118
lastUpdateFile.changeMode(FileMode::WRITE); // Open the last update file in write mode
119-
lastUpdateFile.write(String(bytesWritten)); // Write the updated last update size to the file
120-
121-
lastUpdateFile.close();
119+
lastUpdateFile.write(String(bytesMoved)); // Write the updated last update size to the file
120+
122121
backupFile.close();
123122
logFile.close();
124-
123+
lastUpdateFile.close();
125124
delay(100);
126125

127126
Serial.println("Succesfully updated diff file");
128-
129127
usbStorage.unmount(); // Unmount the USB storage
130128

131129
digitalWrite(USB_MOUNTED_LED, HIGH);
@@ -143,24 +141,17 @@ void backupToUSB() {
143141
if (!usbStorage.isConnected()) {
144142

145143
Serial.println("Mounting USB Mass Storage");
146-
147-
144+
digitalWrite(USB_MOUNTED_LED, LOW);
148145
if(usbStorage.begin()){
149-
150-
digitalWrite(USB_MOUNTED_LED, LOW);
151146
performUpdate();
152-
153-
} else {
154-
}
147+
}
155148

156149

157150

158151
} else if (usbStorage.isConnected()) {
159152
Serial.println("USB Mass storage is connected, performing update");
160153
performUpdate();
161154

162-
} else if(dontloop){
163-
Serial.println("waiting for device to be removed");
164155
}
165156
} else {
166157
Serial.println("USB Mass storage is not available");

src/USBStorage.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define MAX_TRIES 10
88

99
USBStorage::USBStorage(){
10+
1011
}
1112

1213
void USBStorage::usbCallback(){
@@ -25,14 +26,12 @@ int USBStorage::begin(){
2526
register_hotplug_callback(DEV_USB, this->usbCallback);
2627
#endif
2728

28-
2929
int attempts = 0;
3030
int err = mount(DEV_USB, FS_FAT, MNT_DEFAULT);
3131

3232
while (0 != err && attempts < MAX_TRIES) {
3333
attempts +=1;
3434
err = mount(DEV_USB, FS_FAT, MNT_DEFAULT);
35-
delay(10);
3635
Serial.println(errno);
3736
}
3837

@@ -48,8 +47,6 @@ int USBStorage::begin(){
4847

4948
int USBStorage::unmount(){
5049
auto unmountResult = umount(DEV_USB);
51-
52-
5350

5451

5552
if(unmountResult == 0){
@@ -121,7 +118,7 @@ void USBStorage::checkConnection(){
121118

122119

123120
if ((dev = host->getDevice(0)) != NULL) {
124-
121+
this->available = true;
125122

126123
uint8_t ceva = dev->getNbIntf();
127124
/*
@@ -133,16 +130,10 @@ void USBStorage::checkConnection(){
133130
Serial.println(dev->getSubClass());
134131
*/
135132
found = true;
133+
} else {
134+
this->available = false;
136135
}
137-
138-
if(found){
139-
this->available = true;
140-
141-
} else {
142-
this->available = false;
143-
}
144-
145-
}
136+
}
146137

147138

148139

tests/test_qspi_usb_sd/test_qspi_usb_sd.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ void runRepeatedMountTest(UnifiedStorage * storage, String storageType, int n =
134134
file.close();
135135

136136
int umountResult = storage->unmount();
137-
if(umountResult != 1) {
137+
if(!umountResult) {
138138
Serial.println("Unmounting drive");
139139
Serial.println(umountResult);
140140
Serial.println(getErrno());

0 commit comments

Comments
 (0)