ReduxLib C++ 2026.1.2
Loading...
Searching...
No Matches
DigoutSlotBuilder.h
1// Copyright (c) Bagholders of Redux Robotics and other contributors.
2// This is open source and can be modified and shared under the Mozilla Public License v2.0.
3
4#pragma once
5#include <cstdint>
6#include "DigoutSlot.h"
7#include "units/time.h"
8
10
11/**
12 * Helper for constructing DigoutSlot instances.
13 *
14 * Typical usage:
15 * ```cpp
16 * using namespace redux::sensors::canandcolor;
17 * DigoutSlot slot = DigoutSlotBuilder()
18 * .GreaterThan(DataSource::kProximity, DataSource::kZero)
19 * .Add(-0.5)
20 * .BuildTerminateChain();
21 * ```
22 */
24 public:
26
27 /**
28 * Builds a slot with `lhs == rhs`.
29 * @param lhs left hand data source
30 * @param rhs right hand data source
31 * @return builder handle
32 */
34 /**
35 * Builds a slot with `lhs < rhs`.
36 * @param lhs left hand data source
37 * @param rhs right hand data source
38 * @return builder handle
39 */
41 /**
42 * Builds a slot with `lhs > rhs`.
43 * @param lhs left hand data source
44 * @param rhs right hand data source
45 * @return builder handle
46 */
48 /**
49 * Builds a slot with `lhs <= rhs`.
50 * @param lhs left hand data source
51 * @param rhs right hand data source
52 * @return builder handle
53 */
55 /**
56 * Builds a slot with `lhs >= rhs`.
57 * @param lhs left hand data source
58 * @param rhs right hand data source
59 * @return builder handle
60 */
62
63 /**
64 * Copies one data source directly to another (device-defined behavior).
65 * @param lhs left-hand side data source
66 * @param rhs right-hand side data source
67 * @return reference to this builder
68 */
70
71 /**
72 * Sets this slot to be true if the previous slot has been true for at least the given duration.
73 * @param durationMs duration in milliseconds
74 * @return reference to this builder
75 */
76 DigoutSlotBuilder& PrevSlotTrue(units::millisecond_t durationMs);
77
78 /**
79 * Sets this slot to be true if the previous chain clause has been true for at least the given duration.
80 * @param durationMs duration in milliseconds
81 * @return reference to this builder
82 */
83 DigoutSlotBuilder& PrevChainTrueFor(units::millisecond_t durationMs);
84
85 /**
86 * Sets this slot to be true for at least the given duration (device-defined behavior).
87 * @param durationMs duration in milliseconds
88 * @return reference to this builder
89 */
90 DigoutSlotBuilder& TrueFor(units::millisecond_t durationMs);
91
92 /**
93 * Applies a scaling factor (device-defined) to this slot.
94 * @param factor scaling factor
95 * @return reference to this builder
96 */
97 DigoutSlotBuilder& Scale(double factor);
98
99 /**
100 * Applies an additive offset (device-defined) to this slot.
101 * @param offset offset in normalized units
102 * @return reference to this builder
103 */
104 DigoutSlotBuilder& Add(double offset);
105
106 /**
107 * Builds a DigoutSlot with the specified next-slot action.
108 * @param nextAction how to combine with the next slot
109 * @return constructed DigoutSlot
110 */
112
113 /**
114 * Builds a DigoutSlot that terminates the chain.
115 * @return constructed DigoutSlot
116 */
118
119 private:
120 DataSource lhs = DataSource::kZero;
121 DataSource rhs = DataSource::kZero;
122 DigoutOperation opcode = DigoutOperation::kEquals;
123 int32_t additiveImmediate = 0;
124 uint8_t scalingImmediate = 0;
125 bool invertValue = false;
126};
127
128} // namespace redux::sensors::canandcolor
Definition DigoutSlotBuilder.h:23
DigoutSlotBuilder & LessThan(DataSource lhs, DataSource rhs)
DigoutSlotBuilder & TrueFor(units::millisecond_t durationMs)
DigoutSlotBuilder & Scale(double factor)
DigoutSlotBuilder & PrevChainTrueFor(units::millisecond_t durationMs)
DigoutSlot Build(NextSlotAction nextAction)
DigoutSlotBuilder & GreaterThanOrEquals(DataSource lhs, DataSource rhs)
DigoutSlotBuilder & DirectSourceToSource(DataSource lhs, DataSource rhs)
DigoutSlotBuilder & Add(double offset)
DigoutSlotBuilder & Equals(DataSource lhs, DataSource rhs)
DigoutSlotBuilder & PrevSlotTrue(units::millisecond_t durationMs)
DigoutSlotBuilder & LessThanOrEquals(DataSource lhs, DataSource rhs)
DigoutSlotBuilder & GreaterThan(DataSource lhs, DataSource rhs)
Definition DigoutSlot.h:19
Definition Canandcolor.h:19
DataSource
Definition DataSource.h:15
DigoutOperation
Definition DigoutOperation.h:14
NextSlotAction
Definition NextSlotAction.h:12