Skip to content

Commit bf06d23

Browse files
authoredNov 7, 2024··
Merge pull request #41 from LexxPluss/AMRSW-1126-dcrease-led-brightness
Amrsw 1126 dcrease led brightness
2 parents 70e24a4 + df11c8e commit bf06d23

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
 

‎lexxpluss_apps/src/led_controller.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,33 @@ class led_controller_impl {
145145
case msg::RGB_BLINK: fill_blink(led_rgb{.r{message.rgb[0]}, .g{message.rgb[1]}, .b{message.rgb[2]}}, message.cpm); break;
146146
case msg::RGB_BREATH: fill_fade(led_rgb{.r{message.rgb[0]}, .g{message.rgb[1]}, .b{message.rgb[2]}}, message.cpm);break;
147147
}
148+
clamp();
148149
update();
149150
++counter;
150151
}
152+
led_rgb clamp_rgb(led_rgb rgb) const {
153+
auto const max_channel_value{std::max({rgb.r, rgb.g, rgb.b})};
154+
auto const acc_channel_value(static_cast<float>(rgb.r) + static_cast<float>(rgb.g) + static_cast<float>(rgb.b));
155+
156+
auto const channel_wise_ratio{static_cast<float>(clamp_threshold) / max_channel_value};
157+
auto const agg_ratio{3 * static_cast<float>(clamp_threshold) / acc_channel_value};
158+
auto const clamp_ratio = std::min(channel_wise_ratio, agg_ratio);
159+
if (1.0f <= clamp_ratio) {
160+
return rgb;
161+
}
162+
163+
return led_rgb{
164+
.r=static_cast<uint8_t>(clamp_ratio * rgb.r + 0.5f),
165+
.g=static_cast<uint8_t>(clamp_ratio * rgb.g + 0.5f),
166+
.b=static_cast<uint8_t>(clamp_ratio * rgb.b + 0.5f)
167+
};
168+
}
169+
void clamp() {
170+
for (uint32_t i{0}; i < PIXELS; ++i) {
171+
pixeldata[LED_LEFT][i] = clamp_rgb(pixeldata[LED_LEFT][i]);
172+
pixeldata[LED_RIGHT][i] = clamp_rgb(pixeldata[LED_RIGHT][i]);
173+
}
174+
}
151175
void update() {
152176
std::copy(&pixeldata[LED_LEFT][0], &pixeldata[LED_LEFT][PIXELS_BACK], &pixeldata_back[LED_LEFT][0]);
153177
std::copy(&pixeldata[LED_RIGHT][0], &pixeldata[LED_RIGHT][PIXELS_BACK], &pixeldata_back[LED_RIGHT][0]);
@@ -337,6 +361,7 @@ class led_controller_impl {
337361
const device *dev[4]{nullptr, nullptr, nullptr, nullptr};
338362
led_rgb pixeldata[2][PIXELS], pixeldata_back[2][PIXELS_BACK];
339363
uint32_t counter{0};
364+
static constexpr uint8_t clamp_threshold{0x80};
340365
static const led_rgb emergency_stop, amr_mode, agv_mode, mission_pause, path_blocked, manual_drive;
341366
static const led_rgb dock_mode, waiting_for_job, orange, sequence, move_actuator, lockdown, black;
342367
} impl;

0 commit comments

Comments
 (0)
Please sign in to comment.