Skip to content

Commit

Permalink
clean up file handling
Browse files Browse the repository at this point in the history
  • Loading branch information
cameron-goddard committed Nov 21, 2024
1 parent 8a9a093 commit 538978b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/Control Tasks/SDControlTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,29 @@ void SDControlTask::begin() {
return;
}

File boot = SD.open("boot.txt", O_RDWR);
File boot = SD.open(constants::sd::boot_filename, O_RDWR);
if (boot) {
String read_out = boot.readStringUntil('\n');
file_count = read_out.toInt();
boot.seek(0);
file_count++;
boot.println(file_count);
boot.close();
} else {
boot = SD.open(constants::sd::boot_filename, FILE_WRITE);
boot.println(file_count);
boot.flush();
boot.close();
}

static char buffer[20];
sprintf(buffer, "data_%d.csv", file_count);

sfr::sd::filename = buffer;
sfr::sd::log_filename = buffer;
}

void SDControlTask::execute() {
file = SD.open(sfr::sd::filename, FILE_WRITE);
file = SD.open(sfr::sd::log_filename, FILE_WRITE);

String data = String(millis()) + "," +
String(sfr::motor::pulse_width_angle) + "," +
Expand Down
2 changes: 1 addition & 1 deletion src/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ namespace constants {
}

namespace sd {
constexpr char const *filename = "data.csv";
constexpr char const *boot_filename = "boot.txt";
}
} // namespace constants

Expand Down
2 changes: 1 addition & 1 deletion src/sfr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ namespace sfr {
} // namespace imu

namespace sd {
char const *filename = "data_0.csv";
char const *log_filename = "data_0.csv";
}
} // namespace sfr
2 changes: 1 addition & 1 deletion src/sfr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace sfr {
extern float gyro_z;
} // namespace imu
namespace sd {
extern char const *filename;
extern char const *log_filename;
}
} // namespace sfr

Expand Down

0 comments on commit 538978b

Please sign in to comment.