Skip to content

Commit 3abc601

Browse files
authored
Merge pull request #17 from arduino-libraries/clean-up
Clean up Code
2 parents 3592f5b + 17c3581 commit 3abc601

File tree

7 files changed

+38
-36
lines changed

7 files changed

+38
-36
lines changed

src/Arduino_UnifiedStorage.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,20 @@ class Arduino_UnifiedStorage {
3434
/**
3535
* Initializes the storage.
3636
*
37-
* @return 1 if successful, 0 if failed.
37+
* @return true if successful, false if failed.
3838
*/
3939
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).
44-
* @return 1 if successful, 0 if failed.
44+
* @return true if successful, false if failed.
4545
*/
4646
virtual bool begin(FileSystems fs) = 0;
4747

4848
/**
4949
* Unmounts the storage.
50-
* @return 1 if successful, 0 if failed.
50+
* @return true if successful, false if failed.
5151
*/
5252
virtual bool unmount() = 0;
5353

@@ -59,7 +59,7 @@ class Arduino_UnifiedStorage {
5959

6060
/**
6161
* Formats the storage with the selected file system.
62-
* @return 1 if successful, 0 if failed.
62+
* @return true if successful, false if failed.
6363
*/
6464
virtual bool format(FileSystems fs) = 0;
6565

src/InternalStorage.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,29 @@ InternalStorage::InternalStorage(){
1414
InternalStorage::InternalStorage(int partition, const char * name, FileSystems fs){
1515
this -> setQSPIPartition(partition);
1616
this -> setQSPIPartitionName(name);
17-
this -> fs = fs;
17+
this -> fileSystem = fs;
1818
}
1919

2020
bool InternalStorage::begin(FileSystems fs){
21-
this -> fs = fs;
21+
this -> fileSystem = fs;
2222
return this -> begin();
2323
}
2424

2525
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);
29-
if(this -> fs == FS_FAT){
29+
if(this -> fileSystem == FS_FAT){
3030
this -> userDataFileSystem = new FATFileSystem(this->partitionName);
3131
} else {
3232
this -> userDataFileSystem = new LittleFileSystem(this->partitionName);
3333
}
3434
int err = this -> userDataFileSystem -> mount(userData);
35-
return err == 0 ? true : false;
35+
return err == 0;
3636
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_OPTA)
3737
this -> blockDevice = QSPIFBlockDevice::get_default_instance();
3838
this -> userData = new mbed::MBRBlockDevice(this->blockDevice, this->partitionNumber);
39-
if(this -> fs == FS_FAT){
39+
if(this -> fileSystem == FS_FAT){
4040

4141
if(this -> userDataFileSystem != nullptr){
4242
delete(this -> userDataFileSystem);
@@ -51,13 +51,15 @@ bool InternalStorage::begin(){
5151
this -> userDataFileSystem = new mbed::LittleFileSystem(this->partitionName);
5252
}
5353
int err = this -> userDataFileSystem -> mount(this -> userData);
54-
return err == 0 ? true : false;
54+
return err == 0;
55+
#else
56+
return false; // Unsupported board
5557
#endif
5658
}
5759

5860
bool InternalStorage::unmount(){
5961
int err = this -> userDataFileSystem -> unmount();
60-
return err == 0 ? true : false;
62+
return err == 0;
6163
}
6264

6365
Folder InternalStorage::getRootFolder(){
@@ -75,24 +77,24 @@ void InternalStorage::setQSPIPartitionName(const char * name){
7577
bool InternalStorage::format(FileSystems fs){
7678
this -> begin();
7779
this -> unmount();
78-
this -> fs = fs;
80+
this -> fileSystem = fs;
7981

8082

8183
if(fs == FS_FAT){
8284
#if defined(ARDUINO_PORTENTA_C33)
8385
this -> userDataFileSystem = new FATFileSystem(this->partitionName);
84-
return this -> userDataFileSystem -> reformat(this-> userData) == 0 ? true : false;
86+
return this -> userDataFileSystem -> reformat(this-> userData) == 0;
8587
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_OPTA)
8688
this -> userDataFileSystem = new mbed::FATFileSystem(this->partitionName);
87-
return this -> userDataFileSystem -> reformat(this-> userData) == 0 ? true : false;
89+
return this -> userDataFileSystem -> reformat(this-> userData) == 0;
8890
#endif
8991
} if (fs == FS_LITTLEFS) {
9092
#if defined(ARDUINO_PORTENTA_C33)
9193
this -> userDataFileSystem = new LittleFileSystem(this->partitionName);
92-
return this -> userDataFileSystem -> reformat(this-> userData) == 0 ? true : false;
94+
return this -> userDataFileSystem -> reformat(this-> userData) == 0;
9395
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_OPTA)
9496
this -> userDataFileSystem = new mbed::LittleFileSystem(this->partitionName);
95-
return this -> userDataFileSystem -> reformat(this-> userData) == 0 ? true : false;
97+
return this -> userDataFileSystem -> reformat(this-> userData) == 0;
9698
#endif
9799
}
98100

src/InternalStorage.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ class InternalStorage : public Arduino_UnifiedStorage {
2525
/**
2626
* Initializes the internal storage.
2727
*
28-
* @return 1 if successful, 0 if failed.
28+
* @return true if successful, false if failed.
2929
*/
3030
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).
36-
* @return 1 if successful, 0 if failed.
36+
* @return true if successful, false if failed.
3737
*/
3838
bool begin(FileSystems fs) override;
3939

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

@@ -68,7 +68,7 @@ class InternalStorage : public Arduino_UnifiedStorage {
6868
/**
6969
* Formats the internal storage with the selceted file system.
7070
*
71-
* @return 1 if successful, 0 if failed.
71+
* @return true if successful, false if failed.
7272
*/
7373
bool format(FileSystems fs) override;
7474

@@ -101,7 +101,7 @@ class InternalStorage : public Arduino_UnifiedStorage {
101101
#endif
102102

103103
char * partitionName;
104-
FileSystems fs;
104+
FileSystems fileSystem;
105105
};
106106

107107
#endif

src/SDStorage.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SDStorage::SDStorage(){
99
}
1010

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

1515
bool SDStorage::begin(FileSystems fs){
@@ -18,7 +18,7 @@ bool SDStorage::begin(FileSystems fs){
1818
}
1919

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

2424
Folder SDStorage::getRootFolder(){
@@ -39,7 +39,7 @@ bool SDStorage::format(FileSystems fs){
3939
err = mkfs(DEV_SDCARD, FS_LITTLEFS);
4040
}
4141

42-
return err == 0 ? true : false;
42+
return err == 0;
4343
}
4444

4545

src/SDStorage.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ class SDStorage: public Arduino_UnifiedStorage {
2020
/**
2121
* Initializes the SD card storage.
2222
*
23-
* @return 1 if successful, 0 if failed.
23+
* @return true if successful, false if failed.
2424
*/
2525
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).
31-
* @return 1 if successful, 0 if failed.
31+
* @return true if successful, false if failed.
3232
*/
3333
bool begin(FileSystems fs) override;
3434

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

@@ -49,7 +49,7 @@ class SDStorage: public Arduino_UnifiedStorage {
4949
/**
5050
* Formats the SD card storage with the selected file system.
5151
*
52-
* @return 1 if successful, 0 if failed.
52+
* @return true if successful, false if failed.
5353
*/
5454
bool format(FileSystems fs) override;
5555

src/USBStorage.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ bool USBStorage::begin(){
3838
this -> connected = false;
3939
}
4040

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

4444
bool USBStorage::unmount(){
@@ -49,7 +49,7 @@ bool USBStorage::unmount(){
4949
this -> connected = false;
5050
}
5151

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

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

101101
}

src/USBStorage.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ class USBStorage : public Arduino_UnifiedStorage {
1717
/**
1818
* Initializes the USB storage.
1919
*
20-
* @return 1 if successful, 0 if failed.
20+
* @return true if successful, false if failed.
2121
*/
2222
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).
28-
* @return 1 if successful, 0 if failed.
28+
* @return true if successful, false if failed.
2929
*/
3030
bool begin(FileSystems fs) override;
3131

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

@@ -46,7 +46,7 @@ class USBStorage : public Arduino_UnifiedStorage {
4646
/**
4747
* Formats the USB storage with the selected file system.
4848
*
49-
* @return 1 if successful, 0 if failed.
49+
* @return true if successful, false if failed.
5050
*/
5151
bool format(FileSystems fs) override;
5252

0 commit comments

Comments
 (0)