Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
xtnctx authored Oct 2, 2023
1 parent 27b3d03 commit 275ff56
Showing 1 changed file with 43 additions and 15 deletions.
58 changes: 43 additions & 15 deletions Arduino Nano 33 BLE Sense/loadmodelsdcard.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ uint8_t *loadedModel;
bool x = true;
File myFile;

uint8_t file_buffers[120 * 1024];
size_t file_buffer_length = sizeof(file_buffers) / sizeof(file_buffers[0]);

void setup() {
Serial.begin(9600);
while (!Serial);

bool sdBegin = SD.begin(10);
while (!sdBegin) {
Serial.println("Trying to initialize...");
Expand All @@ -23,26 +24,53 @@ void loop() {
// re-open the file for reading:
delay(5000);
if (x){
myFile = SD.open("head.h");
myFile = SD.open("xtnctx.h");
if (myFile) {
Serial.println("head.h:");
size_t modelSize = myFile.size();
Serial.println("xtnctx.h:");
String file = "";
String code = "";
uint32_t file_length = myFile.size();

// read all values
while (myFile.available()) {
file = myFile.readString();
}
// close the file:
myFile.close();


// Convert each value separated with spaces to int using the String.toInt()
// then assign it to the file_buffers index


uint32_t new_size = 0;

for (uint32_t i=0; i<file_length; i++) {
code += file[i];
if(file[i] == ' ') {
file_buffers[new_size] = code.toInt();
new_size++;
code = "";
}
// get last code
if(i == file_length-1) {
file_buffers[new_size] = code.toInt();
new_size++;
code = "";
}

for (size_t i = 0; i < modelSize; i++) {
Serial.println(myFile.read());
}

for (size_t i=new_size; i<file_buffer_length; i++) {
file_buffers[i] = 0;
}
Serial.println("Done!");

// // read from the file until there's nothing else in it:
// while (myFile.available()) {
// Serial.write(myFile.read());
// }
// close the file:
myFile.close();

} else {
// if the file didn't open, print an error:
Serial.println("error opening head--ryan.h");
if (SD.exists("head.h")) Serial.println("head.h exist.");
Serial.println("error opening xtnctx.h");
if (SD.exists("xtnctx.h")) Serial.println("xtnctx.h exist.");
}
}
x = false;
Expand Down

0 comments on commit 275ff56

Please sign in to comment.