26#ifndef SBL_CONTROL_MERGE_HPP_
27#define SBL_CONTROL_MERGE_HPP_
44 static_assert(N > 0,
"Priority needs at least one source");
47 void set(uint8_t source,
float value,
bool active) {
51 values_[source] = value;
52 active_[source] = active;
56 float value()
const {
return value_; }
59 int8_t
winner()
const {
return winner_; }
64 for (uint8_t i = 0; i < N; ++i) {
66 winner_ =
static_cast<int8_t
>(i);
93 static_assert(N > 0,
"Latest needs at least one source");
96 explicit Latest(
float threshold = 0.001f) : threshold_(threshold) {}
98 void update(uint8_t source,
float value) {
102 if (!seen_[source]) {
103 seen_[source] =
true;
104 last_[source] = value;
107 float moved = value - last_[source];
111 if (moved > threshold_) {
116 void write(uint8_t source,
float value) {
120 seen_[source] =
true;
124 float value()
const {
return value_; }
127 int8_t
owner()
const {
return owner_; }
130 void take(uint8_t source,
float value) {
131 last_[source] = value;
133 owner_ =
static_cast<int8_t
>(source);
155 explicit Pickup(
float window = 0.01f) : window_(window) {}
167 const float d = source - value_;
168 const bool above = d > 0.0f;
169 const bool within = (d <= window_) && (d >= -window_);
170 const bool crossed = side_known_ && (above != above_);
171 if (!within && !crossed) {
185 float value()
const {
return value_; }
195 bool side_known_ =
false;
The last source to move wins.
A takeover source must reach the held value before it captures it.
float process(float source)
The highest-priority active source wins.
The control stack: scheduler, event queue, merge, CC mapping, calibration.