Skip to content

Commit ad67361

Browse files
added boolean returns for begin, format, unmount
1 parent 0ba5cf0 commit ad67361

File tree

8 files changed

+51
-51
lines changed

8 files changed

+51
-51
lines changed

src/Arduino_UnifiedStorage.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ class Arduino_UnifiedStorage {
3636
*
3737
* @return 1 if successful, 0 if failed.
3838
*/
39-
virtual int begin() = 0;
39+
virtual bool begin() = 0;
4040

4141
/**
4242
* Initializes the storage with the specified file system.
4343
* @param fs The desired file system (FS_FAT or FS_LITTLEFS).
4444
* @return 1 if successful, 0 if failed.
4545
*/
46-
virtual int begin(FileSystems fs) = 0;
46+
virtual bool begin(FileSystems fs) = 0;
4747

4848
/**
4949
* Unmounts the storage.
5050
* @return 1 if successful, 0 if failed.
5151
*/
52-
virtual int unmount() = 0;
52+
virtual bool unmount() = 0;
5353

5454
/**
5555
* Retrieves the root folder of the storage.
@@ -61,7 +61,7 @@ class Arduino_UnifiedStorage {
6161
* Formats the storage with the selected file system.
6262
* @return 1 if successful, 0 if failed.
6363
*/
64-
virtual int format(FileSystems fs) = 0;
64+
virtual bool format(FileSystems fs) = 0;
6565

6666
};
6767

src/InternalStorage.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ InternalStorage::InternalStorage(int partition, const char * name, FileSystems f
1717
this -> fs = fs;
1818
}
1919

20-
int InternalStorage::begin(FileSystems fs){
20+
bool InternalStorage::begin(FileSystems fs){
2121
this -> fs = fs;
22-
this -> begin();
22+
return this -> begin();
2323
}
2424

25-
int InternalStorage::begin(){
25+
bool InternalStorage::begin(){
2626
#if defined(ARDUINO_PORTENTA_C33)
2727
this -> blockDevice = BlockDevice::get_default_instance();
2828
this -> userData = new MBRBlockDevice(this->blockDevice, this->partitionNumber);
@@ -51,13 +51,13 @@ int InternalStorage::begin(){
5151
this -> userDataFileSystem = new mbed::LittleFileSystem(this->partitionName);
5252
}
5353
int err = this -> userDataFileSystem -> mount(this -> userData);
54-
if(err == 0) return 1;
54+
return err == 0 ? true : false;
5555
#endif
5656
}
5757

58-
int InternalStorage::unmount(){
59-
int err = this -> userDataFileSystem -> unmount();
60-
if(err == 0) return 1;
58+
bool InternalStorage::unmount(){
59+
int err = this -> userDataFileSystem -> unmount();
60+
return err == 0 ? true : false;
6161
}
6262

6363
Folder InternalStorage::getRootFolder(){
@@ -72,7 +72,7 @@ void InternalStorage::setQSPIPartitionName(const char * name){
7272
this -> partitionName = (char *)name;
7373
}
7474

75-
int InternalStorage::format(FileSystems fs){
75+
bool InternalStorage::format(FileSystems fs){
7676
this -> begin();
7777
this -> unmount();
7878
this -> fs = fs;
@@ -81,18 +81,18 @@ int InternalStorage::format(FileSystems fs){
8181
if(fs == FS_FAT){
8282
#if defined(ARDUINO_PORTENTA_C33)
8383
this -> userDataFileSystem = new FATFileSystem(this->partitionName);
84-
return this -> userDataFileSystem -> reformat(this-> userData);
84+
return this -> userDataFileSystem -> reformat(this-> userData) == 0 ? true : false;
8585
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_OPTA)
8686
this -> userDataFileSystem = new mbed::FATFileSystem(this->partitionName);
87-
return this -> userDataFileSystem -> reformat(this-> userData);
87+
return this -> userDataFileSystem -> reformat(this-> userData) == 0 ? true : false;
8888
#endif
8989
} if (fs == FS_LITTLEFS) {
9090
#if defined(ARDUINO_PORTENTA_C33)
9191
this -> userDataFileSystem = new LittleFileSystem(this->partitionName);
92-
return this -> userDataFileSystem -> reformat(this-> userData);
92+
return this -> userDataFileSystem -> reformat(this-> userData) == 0 ? true : false;
9393
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_OPTA)
9494
this -> userDataFileSystem = new mbed::LittleFileSystem(this->partitionName);
95-
return this -> userDataFileSystem -> reformat(this-> userData);
95+
return this -> userDataFileSystem -> reformat(this-> userData) == 0 ? true : false;
9696
#endif
9797
}
9898
}

src/InternalStorage.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ class InternalStorage : public Arduino_UnifiedStorage {
2727
*
2828
* @return 1 if successful, 0 if failed.
2929
*/
30-
int begin() override;
30+
bool begin() override;
3131

3232
/**
3333
* Initializes the internal storage with the specified file system.
3434
*
3535
* @param fs The desired file system (FS_FAT or FS_LITTLEFS).
3636
* @return 1 if successful, 0 if failed.
3737
*/
38-
int begin(FileSystems fs) override;
38+
bool begin(FileSystems fs) override;
3939

4040
/**
4141
* Unmounts the internal storage.
4242
*
4343
* @return 1 if successful, 0 if failed.
4444
*/
45-
int unmount() override;
45+
bool unmount() override;
4646

4747
/**
4848
* Retrieves the root folder of the internal storage.
@@ -70,7 +70,7 @@ class InternalStorage : public Arduino_UnifiedStorage {
7070
*
7171
* @return 1 if successful, 0 if failed.
7272
*/
73-
int format(FileSystems fs) override;
73+
bool format(FileSystems fs) override;
7474

7575

7676
/**
@@ -100,8 +100,8 @@ class InternalStorage : public Arduino_UnifiedStorage {
100100
int partitionNumber = 3;
101101
#endif
102102

103-
char * partitionName = "user";
104-
FileSystems fs = FS_FAT;
103+
char * partitionName;
104+
FileSystems fs;
105105
};
106106

107107
#endif

src/SDStorage.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,38 @@ SDStorage::SDStorage(){
88

99
}
1010

11-
int SDStorage::begin(){
12-
return mount(DEV_SDCARD, this->fileSystem, MNT_DEFAULT) == 0;
11+
bool SDStorage::begin(){
12+
return mount(DEV_SDCARD, this->fileSystem, MNT_DEFAULT)== 0 ? true : false;
1313
}
1414

15-
int SDStorage::begin(FileSystems fs){
15+
bool SDStorage::begin(FileSystems fs){
1616
this -> fileSystem = fs;
17-
this -> begin();
17+
return this -> begin();
1818
}
1919

20-
int SDStorage::unmount(){
21-
return umount(DEV_SDCARD) == 0;
20+
bool SDStorage::unmount(){
21+
return umount(DEV_SDCARD) == 0 ? true : false;
2222
}
2323

2424
Folder SDStorage::getRootFolder(){
2525
return Folder("/sdcard");
2626
}
2727

28-
int SDStorage::format(FileSystems fs){
28+
bool SDStorage::format(FileSystems fs){
29+
int err = 0;
2930
if(fs == FS_FAT){
3031
this -> begin();
3132
this -> unmount();
3233
this -> fileSystem = FS_FAT;
33-
return mkfs(DEV_SDCARD, FS_FAT);
34+
err = mkfs(DEV_SDCARD, FS_FAT);
3435
} else if (fs == FS_LITTLEFS) {
3536
this -> begin();
3637
this -> unmount();
3738
this -> fileSystem = FS_LITTLEFS;
38-
return mkfs(DEV_SDCARD, FS_LITTLEFS);
39+
err = mkfs(DEV_SDCARD, FS_LITTLEFS);
3940
}
4041

42+
return err == 0 ? true : false;
4143
}
4244

4345

src/SDStorage.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ class SDStorage: public Arduino_UnifiedStorage {
2222
*
2323
* @return 1 if successful, 0 if failed.
2424
*/
25-
int begin() override ;
25+
bool begin() override ;
2626

2727
/**
2828
* Initializes the SD card storage with the specified file system.
2929
*
3030
* @param fs The desired file system (FS_FAT or FS_LITTLEFS).
3131
* @return 1 if successful, 0 if failed.
3232
*/
33-
int begin(FileSystems fs) override;
33+
bool begin(FileSystems fs) override;
3434

3535
/**
3636
* Unmounts the SD card storage.
3737
*
3838
* @return 1 if successful, 0 if failed.
3939
*/
40-
int unmount() override;
40+
bool unmount() override;
4141

4242
/**
4343
* Retrieves the root folder of the SD card storage.
@@ -51,7 +51,7 @@ class SDStorage: public Arduino_UnifiedStorage {
5151
*
5252
* @return 1 if successful, 0 if failed.
5353
*/
54-
int format(FileSystems fs) override;
54+
bool format(FileSystems fs) override;
5555

5656
private:
5757
FileSystems fileSystem = FS_FAT;

src/UFile.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,6 @@ bool UFile::moveTo(Folder destinationFolder, bool overwrite) {
269269
bool UFile::moveTo(const char* destinationPath, bool overwrite){
270270
std::string newPath = replaceFirstPathComponent(path, destinationPath);
271271

272-
FILE* destinationFile = fopen(newPath.c_str(), "r");
273-
274272
fclose(filePointer);
275273
if (!copyTo(destinationPath, overwrite)) {
276274
return false; // Return false if the copy operation fails
@@ -281,7 +279,7 @@ bool UFile::moveTo(const char* destinationPath, bool overwrite){
281279
return false;
282280
}
283281

284-
open(newPath.c_str(), fileMode); // sure about that ?
282+
//open(newPath.c_str(), fileMode); // sure about that ?
285283
path = newPath;
286284

287285
return true;

src/USBStorage.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ USBStorage::USBStorage(){
1717
#endif
1818
}
1919

20-
int USBStorage::begin(FileSystems fs){
20+
bool USBStorage::begin(FileSystems fs){
2121
this -> fileSystem = fs;
22-
this -> begin();
22+
return this -> begin();
2323
}
2424

25-
int USBStorage::begin(){
25+
bool USBStorage::begin(){
2626
int attempts = 0;
2727
int err = mount(DEV_USB, this->fileSystem, MNT_DEFAULT);
2828

@@ -38,18 +38,18 @@ int USBStorage::begin(){
3838
this -> connected = false;
3939
}
4040

41-
return err == 0;
41+
return err == 0 ? true : false;
4242
}
4343

44-
int USBStorage::unmount(){
44+
bool USBStorage::unmount(){
4545
auto unmountResult = umount(DEV_USB);
4646

4747

4848
if(unmountResult == 0){
4949
this -> connected = false;
5050
}
5151

52-
return unmountResult == 0;
52+
return unmountResult == 0 ? true : false;
5353
}
5454

5555
Folder USBStorage::getRootFolder(){
@@ -85,17 +85,17 @@ void USBStorage::checkConnection(){
8585
#endif
8686
}
8787

88-
int USBStorage::format(FileSystems fs){
88+
bool USBStorage::format(FileSystems fs){
8989
if(fs == FS_FAT){
9090
this -> begin();
9191
this -> unmount();
9292
this -> fileSystem = FS_FAT;
93-
return mkfs(DEV_USB, FS_FAT);
93+
return mkfs(DEV_USB, FS_FAT) == 0 ? true : false;
9494
} else if(FS_LITTLEFS) {
9595
this -> begin();
9696
this -> unmount();
9797
this -> fileSystem = FS_LITTLEFS;
98-
return mkfs(DEV_USB, FS_LITTLEFS);
98+
return mkfs(DEV_USB, FS_LITTLEFS) == 0 ? true : false;
9999
}
100100

101101
}

src/USBStorage.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ class USBStorage : public Arduino_UnifiedStorage {
1919
*
2020
* @return 1 if successful, 0 if failed.
2121
*/
22-
int begin() override;
22+
bool begin() override;
2323

2424
/**
2525
* Initializes the USB storage with the specified file system.
2626
*
2727
* @param fs The desired file system (FS_FAT or FS_LITTLEFS).
2828
* @return 1 if successful, 0 if failed.
2929
*/
30-
int begin(FileSystems fs) override;
30+
bool begin(FileSystems fs) override;
3131

3232
/**
3333
* Unmounts the USB storage.
3434
*
3535
* @return 1 if successful, 0 if failed.
3636
*/
37-
int unmount() override;
37+
bool unmount() override;
3838

3939
/**
4040
* Retrieves the root folder of the USB storage.
@@ -48,7 +48,7 @@ class USBStorage : public Arduino_UnifiedStorage {
4848
*
4949
* @return 1 if successful, 0 if failed.
5050
*/
51-
int format(FileSystems fs) override;
51+
bool format(FileSystems fs) override;
5252

5353
/**
5454
* Checks if the USB storage is connected.

0 commit comments

Comments
 (0)