Skip to content

Commit

Permalink
refactored main to setup flash memory stuff and for better formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
SnailDragon committed Oct 21, 2024
1 parent 3f57907 commit 7fbb2e4
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions ascendfsw/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
int verifySensors();
int verifyStorage();
void storeData(String data);
String readSensorData();
void handleDataInterface();

// Global variables
// sensor classes
Expand Down Expand Up @@ -53,6 +55,7 @@ bool storages_verify[storages_len];
#define ON_BOARD_LED_PIN 25
#define HEARTBEAT_PIN_0 14
#define HEARTBEAT_PIN_1 15
#define DATA_INTERFACE_PIN 1

// global variables for main
// loop counter
Expand All @@ -65,7 +68,7 @@ unsigned int it = 0;
void setup() {
// start serial
Serial.begin(115200);
while (!Serial)
while (!Serial) // remove before flight
;

// setup heartbeat pins
Expand Down Expand Up @@ -114,22 +117,26 @@ void loop() {
digitalWrite(HEARTBEAT_PIN_0, (it & 0x1));
digitalWrite(HEARTBEAT_PIN_1, (it & 0x1));

// switch to data recovery mode
if(digitalRead(DATA_INTERFACE_PIN) == HIGH){
handleDataInterface();
return;
}

// start print line with iteration number
Serial.print("it: " + String(it) + "\t");

// build csv row
String csv_row = String(millis()) + ",";
for (int i = 0; i < sensors_len; i++) {
if (sensors_verify[i]) {
csv_row += sensors[i]->getDataCSV();
}
}
String csv_row = readSensorData();

// print csv row
Serial.println(csv_row);

// store csv
// store csv row
storeData(csv_row);

delay(500);
digitalWrite(ON_BOARD_LED_PIN, it % 2);
delay(500); // remove before flight
digitalWrite(ON_BOARD_LED_PIN, (it & 0x1)); // toggle light with iteration
}

/**
Expand Down Expand Up @@ -157,6 +164,16 @@ int verifySensors() {
return count;
}

String readSensorData(){
String csv_row = String(millis()) + ",";
for (int i = 0; i < sensors_len; i++) {
if (sensors_verify[i]) {
csv_row += sensors[i]->getDataCSV();
}
}
return csv_row;
}

/**
* @brief Verifies the connection with each storage device
*
Expand Down Expand Up @@ -186,6 +203,10 @@ void storeData(String data) {
}
}

void handleDataInterface(){

}

/** -------------------------------------------------------------------
* CORE 1 CODE ONLY AFTER THIS, DO NOT MIX CODE FOR THE CORES
* -------------------------------------------------------------------
Expand Down

0 comments on commit 7fbb2e4

Please sign in to comment.