Skip to content

Commit

Permalink
refactor: renamed ill-named enum
Browse files Browse the repository at this point in the history
  • Loading branch information
klonyyy committed Dec 4, 2024
1 parent 689af31 commit 8379a32
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ name = sine signals
visibility = true

[group2]
name = new group0
name = test

[group2-plot0]
name = new plot5
Expand Down
8 changes: 4 additions & 4 deletions src/DataHandler/DataHandlerBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class DataHandlerBase
{
public:
enum class state
enum class State
{
STOP = 0,
RUN = 1,
Expand All @@ -27,15 +27,15 @@ class DataHandlerBase

virtual std::string getLastReaderError() const = 0;

void setState(state state)
void setState(State state)
{
if (state == viewerState)
return;

viewerState = state;
stateChangeOrdered = true;
}
state getState() const
State getState() const
{
/* TODO possible deadlock */
while (stateChangeOrdered);
Expand All @@ -48,7 +48,7 @@ class DataHandlerBase
PlotHandler* plotHandler;
PlotHandler* tracePlotHandler;
std::atomic<bool>& done;
std::atomic<state> viewerState = state::STOP;
std::atomic<State> viewerState = State::STOP;
std::mutex* mtx;
std::thread dataHandle;
std::atomic<bool> stateChangeOrdered = false;
Expand Down
14 changes: 7 additions & 7 deletions src/DataHandler/TraceDataHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ void TraceDataHandler::dataHandler()

while (!done)
{
if (viewerState == state::RUN)
if (viewerState == State::RUN)
{
if (!traceReader->isValid())
{
logger->error("Trace invalid, stopping!");
viewerState = state::STOP;
viewerState = State::STOP;
stateChangeOrdered = true;
}

Expand Down Expand Up @@ -177,23 +177,23 @@ void TraceDataHandler::dataHandler()
if (traceTriggered && cnt++ >= (settings.maxPoints * 0.9))
{
logger->info("After-trigger trace collcted. Stopping.");
viewerState = state::STOP;
viewerState = State::STOP;
stateChangeOrdered = true;
}

if (errorFrames.size() > maxAllowedViewportErrors)
{
lastErrorMsg = "Too many error frames!";
logger->error("Too many error frames. Please modify your clock and prescaler settings. Stopping.");
viewerState = state::STOP;
viewerState = State::STOP;
stateChangeOrdered = true;
}

if (delayed3Frames.size() > maxAllowedViewportErrors)
{
lastErrorMsg = "Too many delayed timestamp 3 frames!";
logger->error("Too many delayed timestamp 3 frames. Please modify your clock and prescaler settings or limit the logged channels. Stopping.");
viewerState = state::STOP;
viewerState = State::STOP;
stateChangeOrdered = true;
}
}
Expand All @@ -202,7 +202,7 @@ void TraceDataHandler::dataHandler()

if (stateChangeOrdered)
{
if (viewerState == state::RUN)
if (viewerState == State::RUN)
{
std::array<bool, 32> activeChannels{};

Expand All @@ -219,7 +219,7 @@ void TraceDataHandler::dataHandler()
if (traceReader->startAcqusition(probeSettings, activeChannels))
time = 0;
else
viewerState = state::STOP;
viewerState = State::STOP;
}
else
{
Expand Down
10 changes: 5 additions & 5 deletions src/DataHandler/ViewerDataHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ void ViewerDataHandler::dataHandler()

while (!done)
{
if (viewerState == state::RUN)
if (viewerState == State::RUN)
{
double period = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();

if (probeSettings.mode == IDebugProbe::Mode::HSS)
{
if (!debugProbe->isValid())
setState(state::STOP);
setState(State::STOP);

auto maybeEntry = debugProbe->readSingleEntry();

Expand Down Expand Up @@ -128,7 +128,7 @@ void ViewerDataHandler::dataHandler()
if (debugProbe->readMemory(address, (uint8_t*)&value, size))
rawValues[address] = value;
else
setState(state::STOP);
setState(State::STOP);
}
double timestamp = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
updateVariables(timestamp, rawValues);
Expand All @@ -144,7 +144,7 @@ void ViewerDataHandler::dataHandler()

if (stateChangeOrdered)
{
if (viewerState == state::RUN)
if (viewerState == State::RUN)
{
createSampleList();
prepareCSVFile();
Expand All @@ -156,7 +156,7 @@ void ViewerDataHandler::dataHandler()
start = std::chrono::steady_clock::now();
}
else
viewerState = state::STOP;
viewerState = State::STOP;
}
else
{
Expand Down
20 changes: 10 additions & 10 deletions src/Gui/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void Gui::mainThread(std::string externalPath)
continue;
}

if (glfwGetWindowAttrib(window, GLFW_FOCUSED) || (traceDataHandler->getState() == DataHandlerBase::state::RUN) || (viewerDataHandler->getState() == DataHandlerBase::state::RUN))
if (glfwGetWindowAttrib(window, GLFW_FOCUSED) || (traceDataHandler->getState() == DataHandlerBase::State::RUN) || (viewerDataHandler->getState() == DataHandlerBase::State::RUN))
glfwSwapInterval(1);
else
glfwSwapInterval(4);
Expand All @@ -134,8 +134,8 @@ void Gui::mainThread(std::string externalPath)

if (glfwWindowShouldClose(window))
{
viewerDataHandler->setState(DataHandlerBase::state::STOP);
traceDataHandler->setState(DataHandlerBase::state::STOP);
viewerDataHandler->setState(DataHandlerBase::State::STOP);
traceDataHandler->setState(DataHandlerBase::State::STOP);

if (configHandler->isSavingRequired(projectElfPath))
askShouldSaveOnExit(glfwWindowShouldClose(window));
Expand Down Expand Up @@ -216,7 +216,7 @@ void Gui::drawMenu()
bool shouldSaveOnNew = false;
ImGui::BeginMainMenuBar();

bool active = !(viewerDataHandler->getState() == DataHandlerBase::state::RUN || traceDataHandler->getState() == DataHandlerBase::state::RUN);
bool active = !(viewerDataHandler->getState() == DataHandlerBase::State::RUN || traceDataHandler->getState() == DataHandlerBase::State::RUN);

if (ImGui::BeginMenu("File"))
{
Expand Down Expand Up @@ -269,15 +269,15 @@ void Gui::drawStartButton(DataHandlerBase* activeDataHandler)
bool shouldDisableButton = (!devicesList.empty() && devicesList.front() == noDevices);
ImGui::BeginDisabled(shouldDisableButton);

DataHandlerBase::state state = activeDataHandler->getState();
DataHandlerBase::State state = activeDataHandler->getState();

if (state == DataHandlerBase::state::RUN)
if (state == DataHandlerBase::State::RUN)
{
ImGui::PushStyleColor(ImGuiCol_Button, GuiHelper::green);
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, GuiHelper::greenLight);
ImGui::PushStyleColor(ImGuiCol_ButtonActive, GuiHelper::greenLightDim);
}
else if (state == DataHandlerBase::state::STOP)
else if (state == DataHandlerBase::State::STOP)
{
if (activeDataHandler->getLastReaderError() != "")
{
Expand All @@ -297,17 +297,17 @@ void Gui::drawStartButton(DataHandlerBase* activeDataHandler)
(ImGui::IsKeyPressed(ImGuiKey_Space, false) && !ImGui::IsPopupOpen("", ImGuiPopupFlags_AnyPopup))) &&
!shouldDisableButton)
{
if (state == DataHandlerBase::state::STOP)
if (state == DataHandlerBase::State::STOP)
{
logger->info("Start clicked!");
plotHandler->eraseAllPlotData();
tracePlotHandler->eraseAllPlotData();
activeDataHandler->setState(DataHandlerBase::state::RUN);
activeDataHandler->setState(DataHandlerBase::State::RUN);
}
else
{
logger->info("Stop clicked!");
activeDataHandler->setState(DataHandlerBase::state::STOP);
activeDataHandler->setState(DataHandlerBase::State::STOP);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Gui/Gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Gui
private:
static constexpr bool showDemoWindow = true;

const std::map<DataHandlerBase::state, std::string> viewerStateMap{{DataHandlerBase::state::RUN, "RUNNING"}, {DataHandlerBase::state::STOP, "STOPPED"}};
const std::map<DataHandlerBase::State, std::string> viewerStateMap{{DataHandlerBase::State::RUN, "RUNNING"}, {DataHandlerBase::State::STOP, "STOPPED"}};

std::thread threadHandle;
PlotHandler* plotHandler;
Expand Down
10 changes: 5 additions & 5 deletions src/Gui/GuiPlots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void Gui::drawPlotXY(std::shared_ptr<Plot> plot)
Variable* xAxisVariable = plot->getXAxisVariable();
std::string xLabel = xAxisVariable ? xAxisVariable->getName() : "";

if (viewerDataHandler->getState() == DataHandlerBase::state::RUN)
if (viewerDataHandler->getState() == DataHandlerBase::State::RUN)
{
ImPlot::SetupAxis(ImAxis_Y1, NULL, ImPlotAxisFlags_AutoFit);
ImPlot::SetupAxis(ImAxis_X1, xLabel.c_str(), ImPlotAxisFlags_AutoFit);
Expand Down Expand Up @@ -126,7 +126,7 @@ void Gui::drawPlotCurve(std::shared_ptr<Plot> plot)

if (ImPlot::BeginPlot(plot->getName().c_str(), ImVec2(-1, -1), ImPlotFlags_NoChild))
{
if (viewerDataHandler->getState() == DataHandlerBase::state::RUN)
if (viewerDataHandler->getState() == DataHandlerBase::State::RUN)
{
ViewerDataHandler::Settings settings = viewerDataHandler->getSettings();
ImPlot::SetupAxis(ImAxis_Y1, NULL, ImPlotAxisFlags_AutoFit);
Expand All @@ -146,7 +146,7 @@ void Gui::drawPlotCurve(std::shared_ptr<Plot> plot)
plot->setIsHovered(ImPlot::IsPlotHovered());
dragAndDropPlot(plot);

if (viewerDataHandler->getState() == DataHandlerBase::state::STOP)
if (viewerDataHandler->getState() == DataHandlerBase::State::STOP)
{
ImPlotRect plotLimits = ImPlot::GetPlotLimits();
handleMarkers(0, plot->markerX0, plotLimits, [&]()
Expand Down Expand Up @@ -268,7 +268,7 @@ void Gui::drawPlotTable(std::shared_ptr<Plot> plot)
if (!serPtr->visible)
continue;

ImGui::BeginDisabled(!serPtr->var->getIsCurrentlySampled() && viewerDataHandler->getState() == DataHandlerBase::state::RUN);
ImGui::BeginDisabled(!serPtr->var->getIsCurrentlySampled() && viewerDataHandler->getState() == DataHandlerBase::State::RUN);

ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
Expand All @@ -295,7 +295,7 @@ void Gui::drawPlotTable(std::shared_ptr<Plot> plot)

if (ImGui::InputText(inputName.c_str(), &valueToWrite, ImGuiInputTextFlags_CharsDecimal, NULL, NULL))
{
if (viewerDataHandler->getState() == DataHandlerBase::state::STOP)
if (viewerDataHandler->getState() == DataHandlerBase::State::STOP)
{
ImGui::PopStyleColor(3);
continue;
Expand Down
4 changes: 2 additions & 2 deletions src/Gui/GuiPlotsTree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class PlotsTree
ImGui::PushID(plt->getName().c_str());

/* reset markers when viewer is running */
if (viewerDataHandler->getState() == ViewerDataHandler::state::RUN)
if (viewerDataHandler->getState() == ViewerDataHandler::State::RUN)
{
plt->markerX0.setState(false);
plt->markerX1.setState(false);
Expand Down Expand Up @@ -178,7 +178,7 @@ class PlotsTree
std::optional<std::string> seriesNameToDelete = {};
for (auto& [name, ser] : plt->getSeriesMap())
{
ImGui::BeginDisabled(!ser->var->getIsCurrentlySampled() && viewerDataHandler->getState() == DataHandlerBase::state::RUN);
ImGui::BeginDisabled(!ser->var->getIsCurrentlySampled() && viewerDataHandler->getState() == DataHandlerBase::State::RUN);
ImGui::PushID(name.c_str());
ImGui::Checkbox("", &ser->visible);
ImGui::PopID();
Expand Down
10 changes: 5 additions & 5 deletions src/Gui/GuiSwoControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void Gui::drawSettingsSwo()
auto settings = traceDataHandler->getSettings();
auto state = traceDataHandler->getState();

if (state == DataHandlerBase::state::RUN)
if (state == DataHandlerBase::State::RUN)
ImGui::BeginDisabled();

ImGui::Text("core frequency [kHz] ");
Expand Down Expand Up @@ -48,7 +48,7 @@ void Gui::drawSettingsSwo()
ImGui::Checkbox("##rst", &shouldReset);
settings.shouldReset = shouldReset;

if (state != DataHandlerBase::state::STOP)
if (state != DataHandlerBase::State::STOP)
ImGui::EndDisabled();
else
traceDataHandler->setSettings(settings);
Expand Down Expand Up @@ -100,10 +100,10 @@ void Gui::drawPlotsTreeSwo()

plt->trigger.setState(traceDataHandler->getSettings().triggerChannel == iter++);

if (state == DataHandlerBase::state::RUN)
if (state == DataHandlerBase::State::RUN)
ImGui::BeginDisabled();
ImGui::Checkbox(std::string("##" + name).c_str(), &plt->getVisibilityVar());
if (state == DataHandlerBase::state::RUN)
if (state == DataHandlerBase::State::RUN)
ImGui::EndDisabled();

ImGui::SameLine();
Expand Down Expand Up @@ -141,7 +141,7 @@ void Gui::drawPlotsTreeSwo()
else
statisticsWindow.drawDigital(plt);

bool mx0 = (traceDataHandler->getState() == DataHandlerBase::state::RUN) ? false : plt->markerX0.getState();
bool mx0 = (traceDataHandler->getState() == DataHandlerBase::State::RUN) ? false : plt->markerX0.getState();
ImGui::Text("markers ");
ImGui::SameLine();
ImGui::Checkbox("##mx0", &mx0);
Expand Down
6 changes: 3 additions & 3 deletions src/Gui/GuiSwoPlots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void Gui::drawPlotCurveSwo(Plot* plot, ScrollingBuffer<double>& time, std::map<s
else
ImPlot::SetupAxis(ImAxis_X1, "time[s]", ImPlotAxisFlags_NoTickLabels | ImPlotAxisFlags_NoLabel);

if (traceDataHandler->getState() == DataHandlerBase::state::RUN)
if (traceDataHandler->getState() == DataHandlerBase::State::RUN)
{
auto settings = traceDataHandler->getSettings();
const double min = time.getOldestValue();
Expand Down Expand Up @@ -60,7 +60,7 @@ void Gui::drawPlotCurveSwo(Plot* plot, ScrollingBuffer<double>& time, std::map<s
plot->trigger.setValue(triggerLevel);
}

if (traceDataHandler->getState() == DataHandlerBase::state::STOP)
if (traceDataHandler->getState() == DataHandlerBase::State::STOP)
{
ImPlotRect plotLimits = ImPlot::GetPlotLimits();
handleMarkers(0, plot->markerX0, plotLimits, [&]()
Expand Down Expand Up @@ -99,7 +99,7 @@ void Gui::drawPlotCurveSwo(Plot* plot, ScrollingBuffer<double>& time, std::map<s
ImPlot::PlotScatter("###point", &timepoint, &value, 1, false);
}

if (traceDataHandler->getState() == DataHandlerBase::state::STOP)
if (traceDataHandler->getState() == DataHandlerBase::State::STOP)
{
auto errorTimestamps = traceDataHandler->getErrorTimestamps();
auto delayed3Timestamps = traceDataHandler->getDelayed3Timestamps();
Expand Down
4 changes: 2 additions & 2 deletions src/Gui/GuiVarTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class VariableTableWindow
static ImGuiTableFlags flags = ImGuiTableFlags_ScrollY | ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_Resizable;
static std::set<std::string> selection;

ImGui::BeginDisabled(viewerDataHandler->getState() == DataHandlerBase::state::RUN);
ImGui::BeginDisabled(viewerDataHandler->getState() == DataHandlerBase::State::RUN);
ImGui::Dummy(ImVec2(-1, 5));
GuiHelper::drawCenteredText("Variables");
ImGui::SameLine();
Expand Down Expand Up @@ -191,7 +191,7 @@ class VariableTableWindow
ImGui::PushStyleColor(ImGuiCol_ButtonActive, color);

if (viewerDataHandler->getSettings().stopAcqusitionOnElfChange)
viewerDataHandler->setState(DataHandlerBase::state::STOP);
viewerDataHandler->setState(DataHandlerBase::State::STOP);

if (viewerDataHandler->getSettings().refreshAddressesOnElfChange)
{
Expand Down

0 comments on commit 8379a32

Please sign in to comment.