Skip to content

Commit c4d9b63

Browse files
committed
Rename variables
1 parent 58971a3 commit c4d9b63

File tree

4 files changed

+44
-43
lines changed

4 files changed

+44
-43
lines changed

src/UFile.cpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
#include <cstdio>
44

5-
UFile::UFile() : fp(nullptr) {}
5+
UFile::UFile() : filePointer(nullptr) {}
66

7-
UFile::UFile(const char* path) : fp(nullptr), path(path) {}
7+
UFile::UFile(const char* path) : filePointer(nullptr), path(path) {}
88

99
UFile::~UFile() {
1010
close();
@@ -36,10 +36,10 @@ bool UFile::open(const char* filename, FileMode fileMode) {
3636
}
3737

3838
// Open the file
39-
fp = fopen(filename, mode);
40-
fm = fileMode;
39+
filePointer = fopen(filename, mode);
40+
this -> fileMode = fileMode;
4141

42-
if (fp == nullptr) {
42+
if (filePointer == nullptr) {
4343
// Failed to open the file
4444
return false;
4545
}
@@ -53,61 +53,61 @@ bool UFile::open(String filename, FileMode mode) {
5353

5454
void UFile::close() {
5555
// Close the file
56-
if (fp != nullptr) {
57-
fclose(fp);
56+
if (filePointer != nullptr) {
57+
fclose(filePointer);
5858
}
5959
}
6060

6161
bool UFile::seek(size_t offset) {
6262
// Seek to a specific position in the file
63-
if (fp == nullptr) {
63+
if (filePointer == nullptr) {
6464
// File pointer is not valid
6565
return false;
6666
}
6767

68-
int result = fseek(fp, offset, SEEK_SET);
68+
int result = fseek(filePointer, offset, SEEK_SET);
6969
return (result == 0);
7070
}
7171

7272
int UFile::available() {
7373
// Check the available data in the file
74-
if (fp == nullptr) {
74+
if (filePointer == nullptr) {
7575
// File pointer is not valid
7676
return 0;
7777
}
7878

79-
int currentPosition = ftell(fp);
80-
fseek(fp, 0, SEEK_END);
81-
int fileSize = ftell(fp);
82-
fseek(fp, currentPosition, SEEK_SET);
79+
int currentPosition = ftell(filePointer);
80+
fseek(filePointer, 0, SEEK_END);
81+
int fileSize = ftell(filePointer);
82+
fseek(filePointer, currentPosition, SEEK_SET);
8383

8484
return (fileSize - currentPosition);
8585
}
8686

8787
int UFile::read() {
8888
// Read a single byte from the file
89-
if (fp == nullptr) {
89+
if (filePointer == nullptr) {
9090
// File pointer is not valid
9191
return 0;
9292
}
9393

94-
int value = fgetc(fp);
94+
int value = fgetc(filePointer);
9595
return value;
9696
}
9797

9898
size_t UFile::read(uint8_t* buffer, size_t size) {
9999
// Read data from the file into the buffer
100-
if (fp == nullptr) {
100+
if (filePointer == nullptr) {
101101
// File pointer is not valid
102102
return 0;
103103
}
104104

105-
size_t bytesRead = fread(buffer, sizeof(uint8_t), size, fp);
105+
size_t bytesRead = fread(buffer, sizeof(uint8_t), size, filePointer);
106106
return bytesRead;
107107
}
108108

109109
String UFile::readAsString() {
110-
if (fp == nullptr) {
110+
if (filePointer == nullptr) {
111111
return String("");
112112
}
113113

@@ -128,33 +128,33 @@ String UFile::readAsString() {
128128

129129
size_t UFile::write(uint8_t value) {
130130
// Write a single byte to the file
131-
if (fp == nullptr) {
131+
if (filePointer == nullptr) {
132132
// File pointer is not valid
133133
return 0;
134134
}
135135

136-
int result = fputc(value, fp);
136+
int result = fputc(value, filePointer);
137137
return (result != EOF) ? 1 : 0;
138138
}
139139

140140
size_t UFile::write(String data) {
141-
if (fp == nullptr) {
141+
if (filePointer == nullptr) {
142142
// File pointer is not valid
143143
return 0;
144144
}
145145

146146
// Write data to the file
147-
size_t bytesWritten = fwrite(data.c_str(), sizeof(char), data.length(), fp);
147+
size_t bytesWritten = fwrite(data.c_str(), sizeof(char), data.length(), filePointer);
148148
return bytesWritten;
149149
}
150150

151151
size_t UFile::write(const uint8_t* buffer, size_t size) {
152-
if (fp == nullptr) {
152+
if (filePointer == nullptr) {
153153
// File pointer is not valid
154154
return 0;
155155
}
156156

157-
size_t bytesWritten = fwrite(buffer, sizeof(uint8_t), size, fp);
157+
size_t bytesWritten = fwrite(buffer, sizeof(uint8_t), size, filePointer);
158158
return bytesWritten;
159159
}
160160

@@ -271,7 +271,7 @@ bool UFile::moveTo(const char* destinationPath, bool overwrite){
271271

272272
FILE* destinationFile = fopen(newPath.c_str(), "r");
273273

274-
fclose(fp);
274+
fclose(filePointer);
275275
if (!copyTo(destinationPath, overwrite)) {
276276
return false; // Return false if the copy operation fails
277277
}
@@ -281,7 +281,7 @@ bool UFile::moveTo(const char* destinationPath, bool overwrite){
281281
return false;
282282
}
283283

284-
open(newPath.c_str(), fm); // sure about that ?
284+
open(newPath.c_str(), fileMode); // sure about that ?
285285
path = newPath;
286286

287287
return true;

src/UFile.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ class UFile{
199199

200200

201201
private:
202-
FILE* fp;
202+
FILE* filePointer;
203203
uint8_t* readBuffer;
204204
std::string path;
205-
FileMode fm;
205+
FileMode fileMode;
206206
};
207207
#endif

src/USBStorage.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,31 @@
44
#include <Arduino_USBHostMbed5.h>
55
#endif
66

7-
#define MAX_TRIES 10
7+
// The maximum number of attempts to mount the USB drive
8+
constexpr auto MAX_MOUNT_ATTEMPTS = 10;
89

9-
bool USBStorage::usb_available = false;
10+
bool USBStorage::usbAvailable = false;
1011

1112
USBStorage::USBStorage(){
1213
#if defined(ARDUINO_PORTENTA_C33)
1314
register_hotplug_callback(DEV_USB, [](){
14-
usb_available = !usb_available;
15+
usbAvailable = !usbAvailable;
1516
});
1617
#endif
1718
}
1819

1920
int USBStorage::begin(FileSystems fs){
20-
this -> fs = fs;
21+
this -> fileSystem = fs;
2122
this -> begin();
2223
}
2324

2425
int USBStorage::begin(){
2526
int attempts = 0;
26-
int err = mount(DEV_USB, this->fs, MNT_DEFAULT);
27+
int err = mount(DEV_USB, this->fileSystem, MNT_DEFAULT);
2728

28-
while (0 != err && attempts < MAX_TRIES) {
29+
while (0 != err && attempts < MAX_MOUNT_ATTEMPTS) {
2930
attempts +=1;
30-
err = mount(DEV_USB, this->fs, MNT_DEFAULT);
31+
err = mount(DEV_USB, this->fileSystem, MNT_DEFAULT);
3132
delay(1000);
3233
}
3334

@@ -56,7 +57,7 @@ Folder USBStorage::getRootFolder(){
5657
}
5758

5859
bool USBStorage::isAvailable(){
59-
return usb_available;
60+
return usbAvailable;
6061
}
6162

6263
bool USBStorage::isConnected(){
@@ -75,10 +76,10 @@ void USBStorage::checkConnection(){
7576
host = USBHost::getHostInst();
7677

7778
if ((dev = host->getDevice(0)) != NULL){
78-
usb_available = true;
79+
usbAvailable = true;
7980
found = true;
8081
} else{
81-
usb_available = false;
82+
usbAvailable = false;
8283
}
8384
}
8485
#endif
@@ -87,13 +88,13 @@ void USBStorage::checkConnection(){
8788
int USBStorage::formatFAT(){
8889
this -> begin();
8990
this -> unmount();
90-
this -> fs = FS_FAT;
91+
this -> fileSystem = FS_FAT;
9192
return mkfs(DEV_USB, FS_FAT);
9293
}
9394

9495
int USBStorage::formatLittleFS(){
9596
this -> begin();
9697
this -> unmount();
97-
this -> fs = FS_LITTLEFS;
98+
this -> fileSystem = FS_LITTLEFS;
9899
return mkfs(DEV_USB, FS_LITTLEFS);
99100
}

src/USBStorage.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ class USBStorage : public Arduino_UnifiedStorage {
7777
void checkConnection();
7878

7979
private:
80-
FileSystems fs = FS_FAT;
80+
FileSystems fileSystem = FS_FAT;
8181
bool connected = false;
8282
unsigned long previousMillis;
8383
unsigned int interval = 500;
84-
static bool usb_available;
84+
static bool usbAvailable;
8585
};
8686

8787
#endif

0 commit comments

Comments
 (0)