EduArt Sensor Ring Library 4.0.0
Loading...
Searching...
No Matches
WS2812b_Device.hpp
Go to the documentation of this file.
1// Copyright (c) 2026 EduArt Robotik GmbH
2
9
10#pragma once
11
12#include <atomic>
13#include <chrono>
14#include <mutex>
15
20#include "sensorring/platform/SensorringExport.hpp"
21
22namespace eduart {
23
24namespace sensorring {
25
26namespace device {
27
32class SENSORRING_EXPORT WS2812b_Device : public Light {
33public:
40 WS2812b_Device(WS2812b_Params params, com::ComInterfaceID interface, unsigned int idx);
41
42 ~WS2812b_Device() = default;
43
48 bool configure() override;
49
54 bool setDistanceMapRange(double lower_m, double upper_m);
55
62 bool getDistanceMapRange(double& lower_m, double& upper_m);
63
69 bool setDistanceMapMaxBrightness(std::int64_t brightness);
70
76 bool getDistanceMapMaxBrightness(std::int64_t& brightness);
77
82 const WS2812b_Params& getParams() const override { return _params; }
83
84 // --- Light interface overrides ---
85
93 void setLight(LightMode mode, std::uint8_t r, std::uint8_t g, std::uint8_t b) override;
94
98 static void syncLight();
99
100protected:
102 WS2812b_Device(WS2812b_Params params, com::ComInterface* interface, unsigned int idx);
103
104private:
110 void comCallback(const com::ComEndpoint source, std::uint8_t command, const std::vector<uint8_t>& data) override;
111
112 bool requestParameter(std::uint8_t command, std::vector<uint8_t>& data);
113
114 static constexpr std::chrono::milliseconds GET_PARAMETER_SLEEP = std::chrono::milliseconds(10);
115 static constexpr std::chrono::milliseconds GET_PARAMETER_TIMEOUT = std::chrono::milliseconds(100);
116
117 std::mutex _parameter_mutex;
118 std::mutex _state_mutex;
119 std::atomic<bool> _got_update = false;
120 std::uint8_t _pending_parameter = 0;
121 std::vector<uint8_t> _parameter_data;
122
123 WS2812b_Params _params;
124
125 struct Setting {
127 std::uint8_t red = 0;
128 std::uint8_t green = 0;
129 std::uint8_t blue = 0;
130 } _last_setting;
131};
132
133} // namespace device
134
135} // namespace sensorring
136
137} // namespace eduart
Interface type definition.
Light mode definition.
LightMode
Light mode enumeration.
Definition LightMode.hpp:24
@ Off
All LEDs off.
Definition LightMode.hpp:25
Abstract interface for light/LED actuator devices.
Parameter structure for the WS2812b LED strip.
Light(DeviceID id, com::ComInterface *interface, com::ComEndpoint target)
Construct a Light with Device params.
WS2812b_Device(WS2812b_Params params, com::ComInterface *interface, unsigned int idx)
Construct with a non-owning communication interface supplied by a subclass.
WS2812b_Device(WS2812b_Params params, com::ComInterfaceID interface, unsigned int idx)
Construct a new WS2812b device instance.
bool getDistanceMapRange(double &lower_m, double &upper_m)
Read the current distance map range from the board in meters.
const WS2812b_Params & getParams() const override
Get the parameters used to configure this device.
Definition WS2812b_Device.hpp:82
bool configure() override
Re-apply runtime configuration after board reset.
static void syncLight()
Synchronize pending light updates on all WS2812b devices.
void setLight(LightMode mode, std::uint8_t r, std::uint8_t g, std::uint8_t b) override
Set the light mode and color. Enqueues a per-device CAN command into the action queue.
bool getDistanceMapMaxBrightness(std::int64_t &brightness)
Read the current distance map peak channel brightness from the board.
bool setDistanceMapRange(double lower_m, double upper_m)
Set the distance map range in meters and verify it by reading it back.
bool setDistanceMapMaxBrightness(std::int64_t brightness)
Set distance map peak channel brightness and verify it by reading it back.
Uniquely identifies a communication endpoint as a (Direction, BoardAddress, DeviceId) tuple.
Definition ComEndpoint.hpp:37
Uniquely identifies a communication interface by type and name.
Definition ComInterfaceID.hpp:51
Parameter structure of the WS2812b LEDs.
Definition WS2812b_Params.hpp:25