Skip to content

Commit

Permalink
wip: working on triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
klonyyy committed Aug 23, 2023
1 parent da8c6ec commit cdda0ce
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Gui/GuiSwoControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,27 @@ void Gui::drawSettingsSwo()
{settings.coreFrequency = std::stoi(str);
tracePlotHandler->setSettings(settings); });

ImGui::Text("Trace prescaler ");
ImGui::Text("trace prescaler ");
ImGui::SameLine();
drawInputText("prescaler", settings.tracePrescaler, [&](std::string str)
{settings.tracePrescaler = std::stoi(str);
tracePlotHandler->setSettings(settings); });

const char* triggers[] = {"OFF", "CH0", "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "CH8", "CH9"};
int32_t trigerCombo = settings.tracePrescaler + 1;
ImGui::Text("trigger channel ");
ImGui::SameLine();
if (ImGui::Combo("##combo", &trigerCombo, triggers, IM_ARRAYSIZE(triggers)))
{
settings.triggerChannel = trigerCombo - 1;
tracePlotHandler->setSettings(settings);
}

ImGui::Text("trigger level ");
ImGui::SameLine();
drawInputText("level", settings.triggerLevel, [&](std::string str)
{settings.triggerLevel = std::stod(str);
tracePlotHandler->setSettings(settings); });
}
void Gui::drawIndicatorsSwo()
{
Expand Down
29 changes: 29 additions & 0 deletions src/PlotHandler/TracePlotHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,20 @@ std::string TracePlotHandler::getLastReaderError() const
return traceReader->getLastErrorMsg();
}

void TracePlotHandler::setTriggerChannel(int32_t triggerChannel)
{
traceSettings.triggerChannel = triggerChannel;
}

int32_t TracePlotHandler::getTriggerChannel() const
{
return traceSettings.triggerChannel;
}

void TracePlotHandler::dataHandler()
{
uint32_t cnt = 0;

while (!done)
{
if (viewerState == state::RUN)
Expand Down Expand Up @@ -94,13 +106,27 @@ void TracePlotHandler::dataHandler()
else if (plot->getDomain() == Plot::Domain::ANALOG)
newPoint = *(float*)&traces[i];

if (traceTriggered == false && i == traceSettings.triggerChannel && newPoint > traceSettings.triggerLevel)
{
logger->warn("Trigger!");
traceTriggered = true;
timestamp = 0;
cnt = 0;
}

/* thread-safe part */
std::lock_guard<std::mutex>
lock(*mtx);
plot->addPoint(ser->var->getName(), newPoint);
plot->addTimePoint(time);
i++;
}
if (traceTriggered && cnt++ >= (traceSettings.maxPoints * 0.9))
{
logger->warn("After-trigger trace collcted. Stopping.");
viewerState.store(state::STOP);
stateChangeOrdered.store(true);
}
}
else
std::this_thread::sleep_for(std::chrono::milliseconds(20));
Expand All @@ -121,7 +147,10 @@ void TracePlotHandler::dataHandler()
viewerState = state::STOP;
}
else
{
traceReader->stopAcqusition();
traceTriggered = false;
}
stateChangeOrdered = false;
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/PlotHandler/TracePlotHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class TracePlotHandler : public PlotHandlerBase
uint32_t tracePrescaler = 10;
uint32_t maxPoints = 10000;
uint32_t maxViewportPoints = 5000;
int32_t triggerChannel = -1;
double triggerLevel = 0.9;
} Settings;

TracePlotHandler(std::atomic<bool>& done, std::mutex* mtx, std::shared_ptr<spdlog::logger> logger);
Expand All @@ -30,6 +32,9 @@ class TracePlotHandler : public PlotHandlerBase

std::string getLastReaderError() const;

void setTriggerChannel(int32_t triggerChannel);
int32_t getTriggerChannel() const;

std::map<std::string, std::shared_ptr<Variable>> traceVars;

private:
Expand All @@ -39,6 +44,7 @@ class TracePlotHandler : public PlotHandlerBase
Settings traceSettings{};
std::shared_ptr<StlinkTraceDevice> traceDevice;
std::unique_ptr<TraceReader> traceReader;
bool traceTriggered = false;
static constexpr uint32_t channels = 10;
double time = 0.0;
};
Expand Down

0 comments on commit cdda0ce

Please sign in to comment.