1
0
mirror of https://gitlab.com/lander-team/static-load-test-code.git synced 2025-06-15 22:56:42 +00:00

writing every loop

This commit is contained in:
Brendan McGeeney 2021-11-19 16:32:19 -07:00
parent cfff87b1e4
commit 823e5773de

View File

@ -11,6 +11,7 @@ HX711 lc2;
HX711 lc3;
void write2CSV(struct LoadCells &);
void closeFile();
void initFile();
void read_lc0();
@ -27,7 +28,9 @@ const int pin_lc3 = 20;
const int chipSelect = BUILTIN_SDCARD;
File dataFile;
void setup() {
void setup()
{
// put your setup code here, to run once:
pinMode(lc_clock, INPUT);
@ -71,7 +74,11 @@ void setup() {
State.lc3 = lc3.get_value();
}
void loop() {
void loop()
{
dataFile = SD.open("loadCell.csv", FILE_WRITE);
dataFile.seek(EOF);
// put your main code here, to run repeatedly:
// write2CSV(State);
// delay(20);
@ -86,7 +93,8 @@ void read_lc1() { State.lc1 = lc1.get_value(); }
void read_lc2() { State.lc2 = lc2.get_value(); }
void read_lc3() { State.lc3 = lc3.get_value(); }
void write2CSV(LoadCells &State) {
void write2CSV(LoadCells &State)
{
dataFile.print(String(State.lc0, 5));
dataFile.print(",");
@ -99,10 +107,12 @@ void write2CSV(LoadCells &State) {
dataFile.close();
}
void initFile() {
void initFile()
{
Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
if (!SD.begin(chipSelect))
{
Serial.println("Card failed, or not present. \n\nABORTING SIMULATION");
}
Serial.println("Card initialized.");
@ -110,37 +120,49 @@ void initFile() {
int i = 1;
const char *fileName;
if (SD.exists("loadCell.csv")) {
while (i > 0.0) {
if (SD.exists("loadCell.csv"))
{
while (i > 0.0)
{
fileName = ("loadCell_" + String(i) + ".csv").c_str();
if (!SD.exists(fileName)) {
if (!SD.exists(fileName))
{
// Open simOut_i.csv
dataFile = SD.open(fileName, FILE_WRITE);
if (dataFile) {
if (dataFile)
{
Serial.println("File successfully opened!");
} else {
}
else
{
// if the file didn't open, print an error:
Serial.println("Error opening output file. \n\nABORTING SIMULATION");
}
i = 0.0;
} else {
}
else
{
i++;
}
}
} else {
}
else
{
// Open simOut.csv
dataFile = SD.open("simOut.csv", FILE_WRITE);
if (dataFile) {
if (dataFile)
{
Serial.println("File successfully opened!");
} else {
}
else
{
// if the file didn't open, print an error:
Serial.println("Error opening output file. \n\nABORTING SIMULATION");
}
}
dataFile.println("lc0,lc1,lc2,lc3");
dataFile.close();
}