Skip to content

Commit

Permalink
change file logging format, display currently logged file
Browse files Browse the repository at this point in the history
  • Loading branch information
cameron-goddard committed Sep 1, 2024
1 parent 0eafe4e commit 4e57613
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,28 @@
#include <iomanip>

Controller::Controller(int handle) : test_stand(TestStand(handle)), tui(TUI(&test_stand)), handle(handle) {
INIT_SCAN_RATE = 100;
INIT_SCAN_RATE = 70;
SCANS_PER_READ = 1;

aDataSize = NUM_CHANNELS * SCANS_PER_READ;
aData = new double[sizeof(double) * aDataSize];
valid_input = false;
input = "";

// Create filename based on the number of previous data files in data/
if (!std::filesystem::exists("../data/")) {
std::filesystem::create_directories("../data/");
}

int file_count = 0;
for (const auto& entry : std::filesystem::directory_iterator("../data/")) {
if (std::filesystem::is_regular_file(entry.status())) {
file_count++;
}
}
filename = "../data/data_" + std::to_string(file_count) + ".csv";

tui.file_count = file_count;
}

// Instruct the view to update and process any input commands
Expand Down Expand Up @@ -84,7 +100,7 @@ void Controller::read(bool &running) {

std::ofstream file;
auto startTime = std::chrono::steady_clock::now();
file.open("test_data.csv", std::ios::out | std::ios::app);
file.open(filename, std::ios::out | std::ios::app);

err = LJM_GetHandleInfo(handle, NULL, &connectionType, NULL, NULL, NULL, NULL);
ErrorCheck(err, "LJM_GetHandleInfo");
Expand Down
2 changes: 2 additions & 0 deletions src/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class Controller {

bool data_mark = false;

std::string filename;

/**
* Processes a command that is entered through the TUI interface.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ TUI::TUI(TestStand *test_stand) {
wattron(input_container_window, COLOR_PAIR(TEXT_COLOR));
mvwprintw(input_container_window, 1, 2, "Enter a command below");
mvwprintw(input_container_window, 3, 2, "> ");

mvwprintw(input_container_window, 1, x_max - 30, "Data file: data_%d.csv", file_count);
wattroff(input_container_window, COLOR_PAIR(TEXT_COLOR));

refresh();
Expand Down Expand Up @@ -225,6 +227,7 @@ void TUI::update(double *data) {
}

mvwprintw(input_container_window, 3, 2, "> ");
mvwprintw(input_container_window, 1, x_max - 30, "Data file: data_%d.csv", file_count);
wattroff(valves_window, COLOR_PAIR(TEXT_COLOR));
wattroff(sensors_window, COLOR_PAIR(TEXT_COLOR));
wattroff(modes_window, COLOR_PAIR(TEXT_COLOR));
Expand Down
3 changes: 3 additions & 0 deletions src/view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class TUI {
*/
std::string input;

// TODO: Temporary fix, this is not elegant
int file_count;

private:
// TODO: Implement
void convert_data();
Expand Down

0 comments on commit 4e57613

Please sign in to comment.