refactor: what counts as an event moves into its own evaluator, so a search can ask the same question the trigger asks

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Martino FerrariandClaude Sonnet 4.6 committed 2026-10-07 17:15:37 +02:00
1 parent 178cf54ef6
commit b3fd9ae00f
6 files changed
+189 -50

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: 2026 Martino Ferrari
#include "condition.hpp"
namespace udpscope {
void EventDetector::configure(const EventCondition& c) noexcept {
if (c == cond_) return;
cond_ = c;
reset();
}
void EventDetector::reset() noexcept {
have_prev_ = false;
prev_ = 0.0;
}
double EventDetector::feed(double value, double t) noexcept {
if (!have_prev_) {
prev_ = value;
have_prev_ = true;
return kNoEvent;
}
double event = kNoEvent;
switch (cond_.type) {
case TriggerType::Edge:
event = feed_edge(value, t);
break;
case TriggerType::PulseWidth:
case TriggerType::Window:
case TriggerType::Dropout:
break; // implemented in the tasks that add their panel rows
}
// After the handler: every crossing test above reads `prev_` as the previous sample.
prev_ = value;
return event;
}
double EventDetector::feed_edge(double value, double t) noexcept {
const bool up = crossed_up(value);
const bool down = crossed_down(value);
const bool fired = (cond_.edge == TriggerEdge::Rising && up) ||
(cond_.edge == TriggerEdge::Falling && down) ||
(cond_.edge == TriggerEdge::Both && (up || down));
return fired ? t : kNoEvent;
}
} // namespace udpscope