ReduxLib C++ 2026.1.2
Loading...
Searching...
No Matches
CanandcolorSettings.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 <cinttypes>
6#include <unordered_map>
7#include <optional>
8#include <units/time.h>
9#include <units/angle.h>
10#include "redux/canand/CanandSettings.h"
11#include "CanandcolorDetails.h"
12#include "ColorPeriod.h"
13#include "ProximityPeriod.h"
14#include "DigoutFrameTrigger.h"
15#include "DigoutPinConfig.h"
16
18
19/**
20 * Canandcolor configuration settings.
21 *
22 * Instances of this class act as a settings map: setters populate fields to be sent to the device, while getters return
23 * `std::nullopt` if the setting value is not present in the current map.
24 *
25 * Example code:
26 * ```cpp
27 * Canandcolor color{0};
28 *
29 * CanandcolorSettings settings;
30 * settings.SetColorFramePeriod(20_ms);
31 * settings.SetProximityFramePeriod(20_ms);
32 * settings.SetLampLEDBrightness(0.5);
33 * settings.SetDigoutPinConfig(0, ActiveHighDigoutPinConfig{});
34 * settings.SetDigoutFrameTrigger(0, DigoutFrameTrigger::kRisingAndFalling);
35 *
36 * color.SetSettings(settings, 20_ms);
37 * ```
38 */
40 public:
41 CanandcolorSettings() = default;
42 const std::vector<uint8_t>& SettingAddresses() const override;
43
44 /**
45 * Sets the status frame period.
46 * @param period frame period; clamped by the device
47 * @return reference to this object
48 */
49 CanandcolorSettings& SetStatusFramePeriod(units::second_t period);
50
51 /**
52 * Sets the proximity frame period.
53 * @param period frame period; clamped by the device
54 * @return reference to this object
55 */
57
58 /**
59 * Sets the color frame period.
60 * @param period frame period; clamped by the device
61 * @return reference to this object
62 */
63 CanandcolorSettings& SetColorFramePeriod(units::second_t period);
64
65 /**
66 * Sets the digital output frame period.
67 * @param period frame period; clamped by the device
68 * @return reference to this object
69 */
70 CanandcolorSettings& SetDigoutFramePeriod(units::second_t period);
71
72 /**
73 * Gets the configured status frame period, if present.
74 * @return optional frame period
75 */
76 std::optional<units::second_t> GetStatusFramePeriod();
77
78 /**
79 * Gets the configured proximity frame period, if present.
80 * @return optional frame period
81 */
82 std::optional<units::second_t> GetProximityFramePeriod();
83
84 /**
85 * Gets the configured color frame period, if present.
86 * @return optional frame period
87 */
88 std::optional<units::second_t> GetColorFramePeriod();
89
90 /**
91 * Gets the configured digital output frame period, if present.
92 * @return optional frame period
93 */
94 std::optional<units::second_t> GetDigoutFramePeriod();
95
96 /**
97 * Sets the lamp LED brightness.
98 * @param brightness desired brightness, clamped to [0..1]
99 * @return reference to this object
100 */
102
103 /**
104 * Sets the color integration period.
105 * @param period integration period enum
106 * @return reference to this object
107 */
109
110 /**
111 * Sets the proximity integration period.
112 * @param period integration period enum
113 * @return reference to this object
114 */
116
117 /**
118 * Gets the lamp LED brightness, if present.
119 * @return optional brightness [0..1]
120 */
121 std::optional<double> GetLampLEDBrightness();
122
123 /**
124 * Gets the configured color integration period, if present.
125 * @return optional integration period enum
126 */
127 std::optional<ColorPeriod> GetColorIntegrationPeriod();
128
129 /**
130 * Gets the configured proximity integration period, if present.
131 * @return optional integration period enum
132 */
133 std::optional<ProximityPeriod> GetProximityIntegrationPeriod();
134
135 /**
136 * Enables aligning proximity frames to the integration period.
137 * @param align true to align frames
138 * @return reference to this object
139 */
141
142 /**
143 * Enables aligning color frames to the integration period.
144 * @param align true to align frames
145 * @return reference to this object
146 */
148
149 /**
150 * Gets whether proximity frames are aligned to the integration period, if present.
151 * @return optional flag
152 */
154
155 /**
156 * Gets whether color frames are aligned to the integration period, if present.
157 * @return optional flag
158 */
160
161 /**
162 * Sets the digital output pin behavior for one output.
163 *
164 * Typical usage is one of:
165 * - DisabledDigoutPinConfig
166 * - ActiveHighDigoutPinConfig
167 * - ActiveLowDigoutPinConfig
168 * - DataSourcePinConfig (mirror an internal data source)
169 *
170 * @param digout output index (0 for digout1, 1 for digout2)
171 * @param config pin configuration
172 * @return reference to this object
173 */
175
176 /**
177 * Sets whether a digital output frame is emitted on changes to a given output.
178 *
179 * @param digout output index (0 for digout1, 1 for digout2)
180 * @param trigger trigger behavior
181 * @return reference to this object
182 */
184
185 /**
186 * Gets the raw pin configuration value for one output, if present.
187 * @param digout output index (0 for digout1, 1 for digout2)
188 * @return optional raw value
189 */
190 std::optional<uint64_t> GetDigoutPinConfig(uint8_t digout);
191
192 /**
193 * Gets the digital output frame trigger for one output, if present.
194 * @param digout output index (0 for digout1, 1 for digout2)
195 * @return optional trigger
196 */
197 std::optional<DigoutFrameTrigger> GetDigoutFrameTrigger(uint8_t digout);
198};
199
200} // namespace redux::sensors::canandcolor
Definition CanandSettings.h:21
Definition CanandcolorSettings.h:39
CanandcolorSettings & SetProximityFramePeriod(units::second_t period)
CanandcolorSettings & SetProximityIntegrationPeriod(ProximityPeriod period)
std::optional< units::second_t > GetDigoutFramePeriod()
std::optional< units::second_t > GetStatusFramePeriod()
CanandcolorSettings & SetDigoutFramePeriod(units::second_t period)
std::optional< bool > GetAlignColorFramesToIntegrationPeriod()
std::optional< units::second_t > GetColorFramePeriod()
const std::vector< uint8_t > & SettingAddresses() const override
std::optional< uint64_t > GetDigoutPinConfig(uint8_t digout)
std::optional< ColorPeriod > GetColorIntegrationPeriod()
CanandcolorSettings & SetAlignColorFramesToIntegrationPeriod(bool align)
std::optional< bool > GetAlignProximityFramesToIntegrationPeriod()
std::optional< ProximityPeriod > GetProximityIntegrationPeriod()
CanandcolorSettings & SetDigoutFrameTrigger(uint8_t digout, DigoutFrameTrigger trigger)
std::optional< DigoutFrameTrigger > GetDigoutFrameTrigger(uint8_t digout)
std::optional< units::second_t > GetProximityFramePeriod()
CanandcolorSettings & SetDigoutPinConfig(uint8_t digout, const DigoutPinConfig &config)
CanandcolorSettings & SetColorIntegrationPeriod(ColorPeriod period)
CanandcolorSettings & SetLampLEDBrightness(double brightness)
CanandcolorSettings & SetStatusFramePeriod(units::second_t period)
CanandcolorSettings & SetColorFramePeriod(units::second_t period)
CanandcolorSettings & SetAlignProximityFramesToIntegrationPeriod(bool align)
Definition DigoutPinConfig.h:15
Definition Canandcolor.h:19
ProximityPeriod
Definition ProximityPeriod.h:13
DigoutFrameTrigger
Definition DigoutFrameTrigger.h:13
ColorPeriod
Definition ColorPeriod.h:13