6
6
7
7
#define MAX_TRIES 10
8
8
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 ;
13
10
14
- });
11
+ USBStorage::USBStorage (){
12
+ #if defined(ARDUINO_PORTENTA_C33)
13
+ register_hotplug_callback (DEV_USB, [](){
14
+ usb_available = !usb_available;
15
+ });
15
16
#endif
16
17
}
17
18
18
-
19
19
int USBStorage::begin (FileSystems fs){
20
20
this -> fs = fs;
21
21
this -> begin ();
22
22
}
23
23
24
24
int USBStorage::begin (){
25
-
26
-
27
-
28
25
int attempts = 0 ;
29
26
int err = mount (DEV_USB, this ->fs , MNT_DEFAULT);
30
27
@@ -43,14 +40,12 @@ int USBStorage::begin(){
43
40
return err == 0 ;
44
41
}
45
42
46
-
47
43
int USBStorage::unmount (){
48
44
auto unmountResult = umount (DEV_USB);
49
45
50
46
51
47
if (unmountResult == 0 ){
52
48
this -> connected = false ;
53
- } else {
54
49
}
55
50
56
51
return unmountResult == 0 ;
@@ -60,7 +55,6 @@ Folder USBStorage::getRootFolder(){
60
55
return Folder (" /usb" );
61
56
}
62
57
63
-
64
58
bool USBStorage::isAvailable (){
65
59
return usb_available;
66
60
}
@@ -69,62 +63,27 @@ bool USBStorage::isConnected(){
69
63
return this -> connected;
70
64
}
71
65
72
-
73
- /*
74
-
75
-
76
66
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)
99
67
USBHost * host;
100
68
USBDeviceConnected * dev;
69
+ #if defined(ARDUINO_PORTENTA_H7_M7)
101
70
unsigned long currentMillis = millis ();
102
71
boolean found = false ;
103
72
104
73
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
+ }
118
83
}
119
-
120
-
121
-
122
-
123
- #endif
84
+ #endif
124
85
}
125
86
126
-
127
-
128
87
int USBStorage::formatFAT (){
129
88
this -> begin ();
130
89
this -> unmount ();
0 commit comments