Skip to content

Commit e344173

Browse files
Merge pull request #11 from arduino-libraries/refactorings
Apply Refactorings
2 parents c6e987d + 69e37a4 commit e344173

File tree

2 files changed

+19
-62
lines changed

2 files changed

+19
-62
lines changed

Diff for: src/USBStorage.cpp

+17-58
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,22 @@
66

77
#define MAX_TRIES 10
88

9-
USBStorage::USBStorage(){
10-
#if defined(ARDUINO_PORTENTA_C33)
11-
register_hotplug_callback(DEV_USB, [](){
12-
usb_available = !usb_available;
9+
bool USBStorage::usb_available = false;
1310

14-
});
11+
USBStorage::USBStorage(){
12+
#if defined(ARDUINO_PORTENTA_C33)
13+
register_hotplug_callback(DEV_USB, [](){
14+
usb_available = !usb_available;
15+
});
1516
#endif
1617
}
1718

18-
1919
int USBStorage::begin(FileSystems fs){
2020
this -> fs = fs;
2121
this -> begin();
2222
}
2323

2424
int USBStorage::begin(){
25-
26-
27-
2825
int attempts = 0;
2926
int err = mount(DEV_USB, this->fs, MNT_DEFAULT);
3027

@@ -43,14 +40,12 @@ int USBStorage::begin(){
4340
return err == 0;
4441
}
4542

46-
4743
int USBStorage::unmount(){
4844
auto unmountResult = umount(DEV_USB);
4945

5046

5147
if(unmountResult == 0){
5248
this -> connected = false;
53-
} else {
5449
}
5550

5651
return unmountResult == 0;
@@ -60,7 +55,6 @@ Folder USBStorage::getRootFolder(){
6055
return Folder("/usb");
6156
}
6257

63-
6458
bool USBStorage::isAvailable(){
6559
return usb_available;
6660
}
@@ -69,62 +63,27 @@ bool USBStorage::isConnected(){
6963
return this -> connected;
7064
}
7165

72-
73-
/*
74-
75-
7666
void USBStorage::checkConnection(){
77-
#if defined(ARDUINO_PORTENTA_H7_M7)
78-
USBHost * host;
79-
USBDeviceConnected * dev;
80-
unsigned long currentMillis = millis();
81-
boolean found = false;
82-
83-
if (currentMillis - previousMillis >= interval) {
84-
this -> previousMillis = currentMillis;
85-
host = USBHost::getHostInst();
86-
if(host->getDevice(0) != NULL){
87-
this->available = true;
88-
} else {
89-
this->available = false;
90-
}
91-
}
92-
#endif
93-
}
94-
*/
95-
96-
97-
void USBStorage::checkConnection(){
98-
#if defined(ARDUINO_PORTENTA_H7_M7)
9967
USBHost * host;
10068
USBDeviceConnected * dev;
69+
#if defined(ARDUINO_PORTENTA_H7_M7)
10170
unsigned long currentMillis = millis();
10271
boolean found = false;
10372

10473
if (currentMillis - previousMillis >= interval) {
105-
this -> previousMillis = currentMillis;
106-
107-
host = USBHost::getHostInst();
108-
109-
110-
if ((dev = host->getDevice(0)) != NULL) {
111-
usb_available = true;
112-
113-
uint8_t ceva = dev->getNbIntf();
114-
found = true;
115-
} else {
116-
usb_available = false;
117-
}
74+
this->previousMillis = currentMillis;
75+
host = USBHost::getHostInst();
76+
77+
if ((dev = host->getDevice(0)) != NULL){
78+
usb_available = true;
79+
found = true;
80+
} else{
81+
usb_available = false;
82+
}
11883
}
119-
120-
121-
122-
123-
#endif
84+
#endif
12485
}
12586

126-
127-
12887
int USBStorage::formatFAT(){
12988
this -> begin();
13089
this -> unmount();

Diff for: src/USBStorage.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
#ifndef USBStorage_H
44
#define USBStorage_H
55

6-
7-
static bool usb_available = false;
8-
96
/**
107
* Represents a USB storage using the Arduino Unified Storage library.
118
*/
@@ -83,7 +80,8 @@ class USBStorage : public Arduino_UnifiedStorage {
8380
FileSystems fs = FS_FAT;
8481
bool connected = false;
8582
unsigned long previousMillis;
86-
int interval = 500;
83+
unsigned int interval = 500;
84+
static bool usb_available;
8785
};
8886

8987
#endif

0 commit comments

Comments
 (0)