Skip to content

Commit 12b6e76

Browse files
added partitioning, did 'some' refactoring
1 parent 083b2ce commit 12b6e76

23 files changed

+1799
-534
lines changed

.vscode/settings.json

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,46 @@
66
"unordered_map": "cpp",
77
"vector": "cpp",
88
"string_view": "cpp",
9-
"initializer_list": "cpp"
9+
"initializer_list": "cpp",
10+
"atomic": "cpp",
11+
"bit": "cpp",
12+
"*.tcc": "cpp",
13+
"cctype": "cpp",
14+
"clocale": "cpp",
15+
"cmath": "cpp",
16+
"compare": "cpp",
17+
"concepts": "cpp",
18+
"cstdarg": "cpp",
19+
"cstddef": "cpp",
20+
"cstdint": "cpp",
21+
"cstdio": "cpp",
22+
"cstdlib": "cpp",
23+
"cstring": "cpp",
24+
"cwchar": "cpp",
25+
"cwctype": "cpp",
26+
"exception": "cpp",
27+
"algorithm": "cpp",
28+
"functional": "cpp",
29+
"iterator": "cpp",
30+
"memory": "cpp",
31+
"memory_resource": "cpp",
32+
"numeric": "cpp",
33+
"optional": "cpp",
34+
"random": "cpp",
35+
"system_error": "cpp",
36+
"tuple": "cpp",
37+
"type_traits": "cpp",
38+
"utility": "cpp",
39+
"iosfwd": "cpp",
40+
"iostream": "cpp",
41+
"istream": "cpp",
42+
"limits": "cpp",
43+
"new": "cpp",
44+
"numbers": "cpp",
45+
"ostream": "cpp",
46+
"ranges": "cpp",
47+
"stdexcept": "cpp",
48+
"streambuf": "cpp",
49+
"typeinfo": "cpp"
1050
}
1151
}
5.43 MB
Binary file not shown.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <Arduino.h>
2+
#include <Arduino_UnifiedStorage.h>
3+
#include <vector>
4+
5+
6+
7+
void testWriting(Arduino_UnifiedStorage * storage){
8+
Folder root = storage->getRootFolder();
9+
UFile file = root.createFile("file.txt", FileMode::WRITE);
10+
file.write("writing stuff to the file");
11+
file.changeMode(FileMode::READ);
12+
Serial.println("Reading from file: " + file.readAsString());
13+
file.close();
14+
file.remove();
15+
}
16+
17+
const char* createPartitionName(int i) {
18+
char buffer[20]; // Adjust the size accordingly
19+
snprintf(buffer, sizeof(buffer), "Part%d", i);
20+
return buffer;
21+
}
22+
23+
void testAllPartitions(std::vector<Partition> partitions){
24+
for (size_t i = 1; i < partitions.size() + 1; ++i) {
25+
const char * partitionName = createPartitionName(i);
26+
27+
InternalStorage thisPartition = InternalStorage(i, partitionName, partitions[i - 1].fs);
28+
if(thisPartition.begin()){
29+
Serial.println("Succesfully initialised partition: " + String(partitionName));
30+
testWriting(&thisPartition);
31+
}
32+
}
33+
}
34+
35+
void setup(){
36+
37+
38+
39+
Serial.begin(115200);
40+
while(!Serial);
41+
42+
std::vector<Partition> onePartition = {{16384, FS_LITTLEFS}};
43+
InternalStorage::partition(onePartition);
44+
testAllPartitions(onePartition);
45+
delay(5000);
46+
47+
48+
std::vector<Partition> fourPartitions = {{4096, FS_LITTLEFS}, {4096, FS_LITTLEFS}, {4096, FS_LITTLEFS}, {4096, FS_LITTLEFS}};
49+
InternalStorage::partition(fourPartitions);
50+
testAllPartitions(fourPartitions);
51+
delay(5000);
52+
53+
}
54+
55+
void loop(){
56+
57+
58+
}

examples/OptaLogger/OptaLogger.ino

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ INSTRUCTIONS
2222

2323
#include "Arduino_UnifiedStorage.h"
2424
#include <vector>
25-
#include <Output.h>
2625

2726
constexpr auto baudrate { 115200 };
2827

2928

3029
#define USB_MOUNTED_LED LED_D0
30+
#define SUCCESFULLY_COPIED_LED
3131

3232

3333

34-
InternalStorage internalStorage = InternalStorage();
34+
InternalStorage internalStorage = InternalStorage(true, "userData", FS_FAT);
3535
USBStorage usbStorage = USBStorage();
3636
std::vector<String> sensorDataBuffer;
3737

@@ -90,10 +90,10 @@ void performUpdate() {
9090
backingUP = true;
9191
unsigned lastUpdateBytes = lastUpdateFile.readAsString().toInt(); // Read the last update size from the file
9292

93-
printFormatted("Last update bytes: " + String(lastUpdateBytes) + "\n");
93+
printToSerialOrRS485("Last update bytes: " + String(lastUpdateBytes) + "\n");
9494

9595
if (lastUpdateBytes >= bytesWritten) {
96-
printFormatted("No new data to copy. \n");
96+
printToSerialOrRS485("No new data to copy. \n");
9797
backupFile.close();
9898
lastUpdateFile.close();
9999
backingUP = false;
@@ -102,14 +102,14 @@ void performUpdate() {
102102

103103
logFile.seek(lastUpdateBytes); // Move the file pointer to the last update position
104104
unsigned long totalBytesToMove = bytesWritten - lastUpdateBytes;
105-
printFormatted("New update bytes: " + String(totalBytesToMove) + "\n");
105+
printToSerialOrRS485("New update bytes: " + String(totalBytesToMove) + "\n");
106106

107107
uint8_t* buffer = new uint8_t[totalBytesToMove];
108108

109109
size_t bytesRead = logFile.read(buffer, totalBytesToMove);
110110
size_t bytesMoved = backupFile.write(buffer, bytesRead); // Only write the bytes that haven't been backed up yet
111111

112-
printFormatted("Successfully copied " + String(bytesMoved) + " new bytes.");
112+
printToSerialOrRS485("Successfully copied " + String(bytesMoved) + " new bytes.");
113113

114114
lastUpdateFile.changeMode(FileMode::WRITE); // Open the last update file in write mode
115115
lastUpdateFile.write(String(lastUpdateBytes + bytesMoved)); // Update the last update size
@@ -130,48 +130,47 @@ void performUpdate() {
130130
// Function to backup data to USB storage
131131
void backupToUSB() {
132132
if (usbAvailable) {
133-
printFormatted("USB Mass storage is available \n");
133+
printToSerialOrRS485("USB Mass storage is available \n");
134134
delay(100);
135135
if (!usbStorage.isMounted()) {
136136

137-
printFormatted("Mounting USB Mass Storage \n");
137+
printToSerialOrRS485("Mounting USB Mass Storage \n");
138138
digitalWrite(USB_MOUNTED_LED, LOW);
139139
if(usbStorage.begin()){
140140
performUpdate();
141141
}
142142

143143
} else if (usbStorage.isMounted()) {
144-
printFormatted("USB Mass storage is connected, performing update \n");
144+
printToSerialOrRS485("USB Mass storage is connected, performing update \n");
145145
performUpdate();
146146

147147
}
148148
} else {
149-
printFormatted("USB Mass storage is not available \n");
149+
printToSerialOrRS485("USB Mass storage is not available \n");
150150
}
151151

152-
153152
}
154153

155154

156155
void setup() {
157156
beginRS485(baudrate);
158157

159158

160-
usbStorage.registerHotplugCallback(connectionCallback);
161-
usbStorage.registerUnplugCallback(disconnectionCallback);
159+
usbStorage.onConnect(connectionCallback);
160+
usbStorage.onDisconnect(disconnectionCallback);
162161

163162
pinMode(USB_MOUNTED_LED, OUTPUT);
164-
printFormatted("Formatting internal storage... \n");
163+
printToSerialOrRS485("Formatting internal storage... \n");
165164
int formatted = internalStorage.format(FS_LITTLEFS);
166-
printFormatted("QSPI Format status: " + String(formatted) + "\n");
165+
printToSerialOrRS485("QSPI Format status: " + String(formatted) + "\n");
167166

168167

169168

170169
if (!internalStorage.begin()) {
171-
printFormatted("Failed to initialize internal storage \n");
170+
printToSerialOrRS485("Failed to initialize internal storage \n");
172171
return;
173172
} else {
174-
printFormatted("Initialized storage \n");
173+
printToSerialOrRS485("Initialized storage \n");
175174
}
176175

177176
}

examples/PortentaH7Logger/PortentaH7Logger.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ void setup() {
160160
Serial.begin(115200);
161161
while(!Serial);
162162

163-
usbStorage.registerHotplugCallback(connectionCallback);
164-
usbStorage.registerUnplugCallback(disconnectionCallback);
163+
usbStorage.onConnect(connectionCallback);
164+
usbStorage.onDisconnect(disconnectionCallback);
165165

166166
pinMode(USB_MOUNTED_LED, OUTPUT);
167167
Serial.print("Formatting internal storage... \n");

extras/tests/TestExisting/TestExisting.ino

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

2020
internalStorage.format(FS_LITTLEFS);
2121
internalStorage.begin();
22-
22+
c
2323

2424
Folder root = internalStorage.getRootFolder();
2525

2626

2727
// Test copyTo
28-
printFormatted("Testing copyTo... \n");
28+
printToSerialOrRS485("Testing copyTo... \n");
2929
Folder sourceFolder2 = root.createSubfolder("source_folder");
30-
printFormatted("Folder 1 created \n");
30+
printToSerialOrRS485("Folder 1 created \n");
3131

32-
printFormatted("Trying to create a folder on top of an existing one... without overwrite \n");
32+
printToSerialOrRS485("Trying to create a folder on top of an existing one... without overwrite \n");
3333
Folder sourceFolder3 = root.createSubfolder("source_folder");
3434

35-
printFormatted("Trying to create a folder on top of an existing one... with overwrite \n");
35+
printToSerialOrRS485("Trying to create a folder on top of an existing one... with overwrite \n");
3636
Folder sourceFolder4 = root.createSubfolder("source_folder", true);
3737

3838
Folder destinationFolder2 = root.createSubfolder("destination_folder");
39-
printFormatted("Folder 2 created \n");
39+
printToSerialOrRS485("Folder 2 created \n");
4040

4141

4242

4343
bool copyResult = sourceFolder2.copyTo(destinationFolder2, true); // Overwrite if exists
4444
if (copyResult) {
45-
printFormatted("Copy successful \n");
45+
printToSerialOrRS485("Copy successful \n");
4646
} else {
47-
printFormatted("Copy failed \n");
47+
printToSerialOrRS485("Copy failed \n");
4848
}
4949

5050

@@ -54,12 +54,12 @@ void setup() {
5454
Folder sourceFolder = root.createSubfolder("source");
5555
Folder destinationFolder = root.createSubfolder("destination");
5656

57-
printFormatted("Testing moveTo... \n");
57+
printToSerialOrRS485("Testing moveTo... \n");
5858
bool moveResult = sourceFolder.moveTo(destinationFolder, true); // Overwrite if exists
5959
if (moveResult) {
60-
printFormatted("Move successful \n");
60+
printToSerialOrRS485("Move successful \n");
6161
} else {
62-
printFormatted("Move failed \n");
62+
printToSerialOrRS485("Move failed \n");
6363
}
6464

6565

@@ -73,10 +73,10 @@ void setup() {
7373

7474

7575
bool success = someFile.copyTo(someOtherFolder);
76-
printFormatted("trying to copy file without overwrite: %d\n", success);
76+
printToSerialOrRS485("trying to copy file without overwrite: %d\n", success);
7777

7878
success = someFile.copyTo(someOtherFolder,true);
79-
printFormatted("trying to copy file with overwrite: %d \n", success);
79+
printToSerialOrRS485("trying to copy file with overwrite: %d \n", success);
8080

8181
}
8282

0 commit comments

Comments
 (0)