Skip to content

Commit 6c89cfb

Browse files
Merge pull request #12 from arduino-libraries/refactorings
Refactor variable names and remove unused code
2 parents 8175e32 + c4d9b63 commit 6c89cfb

File tree

14 files changed

+77
-97
lines changed

14 files changed

+77
-97
lines changed

examples/BackupInternalPartitions/BackupInternalPartitions.ino

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ USBStorage thumbDrive = USBStorage();
3838

3939

4040
void addSomeFakeFiles(Folder * folder){
41-
Serial.println("* adding some fake files to: " + String(folder -> getPathString()));
41+
Serial.println("* adding some fake files to: " + String(folder -> getPathAsString()));
4242

4343
for (int i = 0; i < random(0, 9); i++){
4444
UFile thisFile = folder -> createFile("File_"+ String(random(999)), FileMode::WRITE);
45-
Serial.println("\t * " + thisFile.getPathString());
45+
Serial.println("\t * " + thisFile.getPathAsString());
4646
thisFile.write("writing stuff to the file");
4747
thisFile.close();
4848
}
@@ -51,20 +51,20 @@ void addSomeFakeFiles(Folder * folder){
5151
Folder subfolder = folder -> createSubfolder("ChildFolder_"+ String(random(999)));
5252
for (int i = 0; i < random(0, 9); i++){
5353
UFile thisFile = subfolder.createFile("File_"+ String(random(999)), FileMode::WRITE);
54-
Serial.println("\t * " + thisFile.getPathString());
54+
Serial.println("\t * " + thisFile.getPathAsString());
5555
thisFile.write("writing stuff to the file");
5656
thisFile.close();
5757
}
5858
}
5959

6060
void move(Folder * source, Folder * dest){
6161
for(Folder f: source -> getFolders()){
62-
Serial.println("* copying folder :" + String(f.getPathString()));
62+
Serial.println("* copying folder :" + String(f.getPathAsString()));
6363
f.moveTo(*dest);
6464
}
6565

6666
for(UFile f: source -> getFiles()){
67-
Serial.println("* copying file :" + String(f.getPathString()));
67+
Serial.println("* copying file :" + String(f.getPathAsString()));
6868
f.moveTo(*dest);
6969
}
7070
}
@@ -73,7 +73,7 @@ void move(Folder * source, Folder * dest){
7373
#if defined(ARDUINO_PORTENTA_C33)
7474
void backupPartitionsC33(Folder * backupFolder){
7575

76-
Serial.println("* backup location: " + String(backupFolder -> getPathString()));
76+
Serial.println("* backup location: " + String(backupFolder -> getPathAsString()));
7777

7878
int otaMounted = ota.begin(FS_FAT);
7979
Serial.println("* ota partition mount: " + String(otaMounted));
@@ -108,7 +108,7 @@ void backupPartitionsC33(Folder * backupFolder){
108108

109109
#if defined(ARDUINO_PORTENTA_H7_M7)
110110
void backupPartitionsH7(Folder * backupFolder){
111-
Serial.println("* backup location: " + String(backupFolder -> getPathString()));
111+
Serial.println("* backup location: " + String(backupFolder -> getPathAsString()));
112112

113113
int wifiMounted = wifi.begin(FS_FAT);
114114
Serial.println("* wifi partition mount: " + String(wifiMounted));

extras/tests/TestExisting/TestExisting.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void setup() {
1919

2020

2121
Folder root = internalStorage.getRootFolder();
22-
Serial.println(root.getPathString());
22+
Serial.println(root.getPathAsString());
2323

2424
// Test copyTo
2525
Serial.println("Testing copyTo...");
@@ -35,8 +35,8 @@ void setup() {
3535
Folder destinationFolder2 = root.createSubfolder("destination_folder");
3636
Serial.println("Folder 2 created");
3737

38-
Serial.println(sourceFolder2.getPathString());
39-
Serial.println(destinationFolder2.getPathString());
38+
Serial.println(sourceFolder2.getPathAsString());
39+
Serial.println(destinationFolder2.getPathAsString());
4040

4141
Serial.println();
4242
Serial.println();

extras/tests/TestFileOperations/TestFileOperations.ino

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ InternalStorage internal = InternalStorage();
2020

2121
bool testFileCreationWithOpen(Folder root) {
2222
UFile file = UFile();
23-
String path = root.getPathString() + "/test_open.txt";
23+
String path = root.getPathAsString() + "/test_open.txt";
2424
Serial.println(path);
2525
if (file.open(path, FileMode::WRITE)) {
2626
Serial.println("\n--- Test creating file using file.open ---");
@@ -104,7 +104,7 @@ bool testReadingAll(Folder root) {
104104
file.write(reinterpret_cast<const uint8_t*>("Hello, World!"), 13);
105105
file.close();
106106

107-
if (file.open(root.getPathString() + "/test_read.txt", FileMode::READ)) {
107+
if (file.open(root.getPathAsString() + "/test_read.txt", FileMode::READ)) {
108108
char buffer[file.available()];
109109
size_t bytesRead = file.read(reinterpret_cast<uint8_t*>(buffer), sizeof(buffer));
110110
buffer[bytesRead] = '\0'; // Null-terminate the string
@@ -136,7 +136,7 @@ bool testSeeking(Folder root) {
136136
file.close();
137137

138138

139-
if (file.open(root.getPathString() + "/test_seek.txt", FileMode::READ)) {
139+
if (file.open(root.getPathAsString() + "/test_seek.txt", FileMode::READ)) {
140140
Serial.println("\n--- Test seeking file ---");
141141
file.seek(7);
142142
char buffer[20];
@@ -163,7 +163,7 @@ bool testAvailableData(Folder root) {
163163
file.write(reinterpret_cast<const uint8_t*>("Hello, World!"), 13);
164164
file.close();
165165

166-
if (file.open(root.getPathString() + "/test_available.txt", FileMode::READ)) {
166+
if (file.open(root.getPathAsString() + "/test_available.txt", FileMode::READ)) {
167167
Serial.println("\n--- Test available data ---");
168168
int availableBytes = file.available();
169169
Serial.println("Available bytes in file (test_available.txt): " + String(availableBytes));
@@ -193,7 +193,7 @@ bool testCopyingFile(Folder root) {
193193

194194
if (destinationFolder.exists()) {
195195
Serial.println("\n--- Test copying a file ---");
196-
Serial.println("Source file name: " + String(sourceFile.getPathString()));
196+
Serial.println("Source file name: " + String(sourceFile.getPathAsString()));
197197

198198
if (sourceFile.copyTo(destinationFolder)) {
199199
Serial.println("File copied successfully!");
@@ -227,8 +227,8 @@ bool testMovingFile(Folder root) {
227227
UFile movedFile = sourceFileMove;
228228
if (movedFile.exists()) {
229229
Serial.println("\n--- Test moving a file ---");
230-
Serial.println("Source file name: " + String(sourceFileMove.getPathString()));
231-
Serial.println("Destination file name: " + String(destinationFolder.getPathString()) + "/test_source_move.txt");
230+
Serial.println("Source file name: " + String(sourceFileMove.getPathAsString()));
231+
Serial.println("Destination file name: " + String(destinationFolder.getPathAsString()) + "/test_source_move.txt");
232232
if (sourceFileMove.moveTo(destinationFolder)) {
233233
Serial.println("File moved successfully!");
234234
sourceFileMove.close();

extras/tests/TestFolderOperations/TestFolderOperations.ino

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ bool testFolderRenaming(Folder root) {
5858
Folder sourceFolder = root.createSubfolder("source_folder");
5959
if (sourceFolder.exists()) {
6060
Serial.println("\n--- Test renaming folder ---");
61-
Serial.println("Source folder name: " + String(sourceFolder.getPathString()));
61+
Serial.println("Source folder name: " + String(sourceFolder.getPathAsString()));
6262
if (sourceFolder.rename("renamed_folder")) {
63-
Serial.println("Folder renamed to: " + String(sourceFolder.getPathString()));
63+
Serial.println("Folder renamed to: " + String(sourceFolder.getPathAsString()));
6464
sourceFolder.remove();
6565
return true;
6666
} else {
@@ -79,8 +79,8 @@ bool testCopyingFolder(Folder root) {
7979

8080
if (sourceFolder.exists()) {
8181
Serial.println("\n--- Test copying a folder ---");
82-
Serial.println("Source folder name: " + String(sourceFolder.getPathString()));
83-
Serial.println("Destination folder name: " + String(copyDestination.getPathString()));
82+
Serial.println("Source folder name: " + String(sourceFolder.getPathAsString()));
83+
Serial.println("Destination folder name: " + String(copyDestination.getPathAsString()));
8484

8585

8686

@@ -108,8 +108,8 @@ bool testMovingFolder(Folder root) {
108108

109109
if (sourceFolderMove.exists()) {
110110
Serial.println("\n--- Test moving a folder ---");
111-
Serial.println("Source folder name: " + String(sourceFolderMove.getPathString()));
112-
Serial.println("Destination folder name: " + String(moveDestination.getPathString()));
111+
Serial.println("Source folder name: " + String(sourceFolderMove.getPathAsString()));
112+
Serial.println("Destination folder name: " + String(moveDestination.getPathAsString()));
113113
if (sourceFolderMove.moveTo(moveDestination)) {
114114
Serial.println("Folder moved successfully!");
115115
sourceFolderMove.remove();

keywords.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ copyTo KEYWORD2
4545
moveTo KEYWORD2
4646
getParentFolder KEYWORD2
4747
getPath KEYWORD2
48-
getPathString KEYWORD2
48+
getPathAsString KEYWORD2
4949

5050
isConnected KEYWORD2
5151
isAvailable KEYWORD2

src/Folder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const char* Folder::getPath() {
100100
return this->path.c_str();
101101
}
102102

103-
String Folder::getPathString() {
103+
String Folder::getPathAsString() {
104104
return String(this->getPath());
105105
}
106106

src/Folder.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class Folder {
8282
* @brief Returns the path of the file.
8383
* @return The path of the file as an Arduino String
8484
*/
85-
String getPathString();
85+
String getPathAsString();
8686

8787
/**
8888
* @brief Creates a subfolder in the directory.
@@ -160,10 +160,7 @@ class Folder {
160160
bool moveTo(String destination, bool overwrite = false);
161161

162162
private:
163-
164-
std::string dirname;
165163
std::string path;
166-
DIR * dir;
167164
};
168165

169166
#endif

src/InternalStorage.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "Arduino_UnifiedStorage.h"
22

33
InternalStorage::InternalStorage(){
4-
this -> fs = FS_FAT;
54

65
#if defined(ARDUINO_PORTENTA_C33)
76
this -> setQSPIPartition(2);
@@ -41,21 +40,17 @@ int InternalStorage::begin(){
4140

4241
if(this -> userDataFileSystem != nullptr){
4342
delete(this -> userDataFileSystem);
44-
4543
}
4644
this -> userDataFileSystem = new mbed::FATFileSystem(this->partitionName);
4745
} else {
4846

49-
if(this -> userDataFileSystem != nullptr){
50-
delete(this -> userDataFileSystem);
51-
47+
if(this -> userDataFileSystem != nullptr){
48+
delete(this -> userDataFileSystem);
5249
}
5350

54-
5551
this -> userDataFileSystem = new mbed::LittleFileSystem(this->partitionName);
5652
}
5753
int err = this -> userDataFileSystem -> mount(this -> userData);
58-
5954
if(err == 0) return 1;
6055
#endif
6156
}
@@ -69,13 +64,11 @@ Folder InternalStorage::getRootFolder(){
6964
return Folder(String("/" + String(this->partitionName)).c_str());
7065
}
7166

72-
7367
void InternalStorage::setQSPIPartition(int partition){
7468
this -> partitionNumber = partition;
7569
}
7670

7771
void InternalStorage::setQSPIPartitionName(const char * name){
78-
7972
this -> partitionName = (char *)name;
8073
}
8174

@@ -113,8 +106,8 @@ BlockDevice * InternalStorage::getBlockDevice(){
113106

114107

115108
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_OPTA)
116-
mbed::BlockDevice * InternalStorage::getBlockDevice(){
117-
return this -> blockDevice;
118-
}
109+
mbed::BlockDevice * InternalStorage::getBlockDevice(){
110+
return this -> blockDevice;
111+
}
119112

120113
#endif

src/InternalStorage.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ class InternalStorage : public Arduino_UnifiedStorage {
106106
int partitionNumber = 3;
107107
#endif
108108

109-
110109
char * partitionName = "user";
111110
FileSystems fs = FS_FAT;
112111
};

src/Types.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
#include <iostream>
1010
#include <vector>
1111

12-
13-
14-
1512
static bool copyFolder(const char* source, const char* destination) {
1613
DIR* dir = opendir(source);
1714
if (dir == nullptr) {

0 commit comments

Comments
 (0)