48 #include <px4_platform_common/getopt.h> 49 #include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp> 54 #define SUB_ADDR_START 0x01 55 #define SUB_ADDR_PWM0 0x81 56 #define SUB_ADDR_PWM1 0x82 57 #define SUB_ADDR_PWM2 0x83 58 #define SUB_ADDR_SETTINGS 0x84 60 #define SETTING_NOT_POWERSAVE 0x01 61 #define SETTING_ENABLE 0x02 63 class RGBLED :
public device::I2C,
public px4::ScheduledWorkItem
66 RGBLED(
int bus,
int rgbled);
93 int get(
bool &on,
bool &powersave, uint8_t &r, uint8_t &g, uint8_t &b);
100 RGBLED *g_rgbled =
nullptr;
109 ScheduledWorkItem(MODULE_NAME,
px4::device_bus_to_wq(get_device_id()))
118 while (
_running && ++counter < 10) {
162 unsigned prevretries = _retries;
165 if ((ret =
get(on, powersave, r, g, b)) !=
OK ||
171 _retries = prevretries;
182 int ret =
get(on, powersave, r, g, b);
187 DEVICE_LOG(
"red: %u, green: %u, blue: %u", (
unsigned)r, (
unsigned)g, (
unsigned)b);
190 PX4_WARN(
"failed to read led");
223 switch (led_control_data.
leds[0].
color) {
224 case led_control_s::COLOR_RED:
229 case led_control_s::COLOR_GREEN:
234 case led_control_s::COLOR_BLUE:
239 case led_control_s::COLOR_AMBER:
240 case led_control_s::COLOR_YELLOW:
241 _r = 255;
_g = 255;
_b = 0;
245 case led_control_s::COLOR_PURPLE:
246 _r = 255;
_g = 0;
_b = 255;
250 case led_control_s::COLOR_CYAN:
251 _r = 0;
_g = 255;
_b = 255;
255 case led_control_s::COLOR_WHITE:
256 _r = 255;
_g = 255;
_b = 255;
287 uint8_t settings_byte = 0;
297 return transfer(msg,
sizeof(msg),
nullptr, 0);
307 const uint8_t
msg[6] = {
312 return transfer(msg,
sizeof(msg),
nullptr, 0);
316 RGBLED::get(
bool &on,
bool &powersave, uint8_t &r, uint8_t &g, uint8_t &b)
318 uint8_t result[2] = {0, 0};
321 ret = transfer(
nullptr, 0, &result[0], 2);
327 r = (result[0] & 0x0f) << 4;
328 g = (result[1] & 0xf0);
329 b = (result[1] & 0x0f) << 4;
340 maxbrt = maxbrt > 15 ? 15 : maxbrt;
341 maxbrt = maxbrt < 0 ? 0 : maxbrt;
354 PX4_INFO(
"missing command: try 'start', 'status', 'stop'");
355 PX4_INFO(
"options:");
356 PX4_INFO(
" -b i2cbus (%d)", PX4_I2C_BUS_LED);
357 PX4_INFO(
" -a addr (0x%x)",
ADDR);
364 int rgbledadr =
ADDR;
370 const char *myoptarg =
nullptr;
372 while ((ch = px4_getopt(argc, argv,
"a:b:", &myoptind, &myoptarg)) != EOF) {
375 rgbledadr = strtol(myoptarg,
nullptr, 0);
379 i2cdevice = strtol(myoptarg,
nullptr, 0);
388 if (myoptind >= argc) {
393 const char *verb = argv[myoptind];
395 if (!strcmp(verb,
"start")) {
396 if (g_rgbled !=
nullptr) {
397 PX4_WARN(
"already started");
401 if (i2cdevice == -1) {
403 i2cdevice = PX4_I2C_BUS_EXPANSION;
404 g_rgbled =
new RGBLED(PX4_I2C_BUS_EXPANSION, rgbledadr);
406 if (g_rgbled !=
nullptr &&
OK != g_rgbled->init()) {
411 if (g_rgbled ==
nullptr) {
413 if (PX4_I2C_BUS_LED == PX4_I2C_BUS_EXPANSION) {
414 PX4_WARN(
"no RGB led on bus #%d", i2cdevice);
418 i2cdevice = PX4_I2C_BUS_LED;
422 if (g_rgbled ==
nullptr) {
423 g_rgbled =
new RGBLED(i2cdevice, rgbledadr);
425 if (g_rgbled ==
nullptr) {
426 PX4_WARN(
"alloc failed");
430 if (
OK != g_rgbled->init()) {
433 PX4_WARN(
"no RGB led on bus #%d", i2cdevice);
442 if (g_rgbled ==
nullptr) {
443 PX4_WARN(
"not started");
448 if (!strcmp(verb,
"status")) {
453 if (!strcmp(verb,
"stop")) {
#define ADDR
I2C adress of TCA62724FMG.
#define SUB_ADDR_PWM0
blue (without auto-increment)
__EXPORT int param_get(param_t param, void *val)
Copy the value of a parameter.
int maximum_update_interval() const
get maxium time between two consecutive calls to update() in us.
LedControlDataSingle leds[BOARD_MAX_LEDS]
#define SUB_ADDR_PWM2
red (without auto-increment)
uint8_t brightness
brightness in [0, 255]
Global flash based parameter store.
uint8_t color
one of led_control_s::COLOR_*
static char msg[NUM_MSG][CONFIG_USART1_TXBUFSIZE]
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
#define SUB_ADDR_SETTINGS
settings (without auto-increment)
void Run() override
Main loop function.
LedController _led_controller
void init()
Activates/configures the hardware registers.
#define DEVICE_LOG(FMT,...)
int send_led_rgb()
Send RGB PWM settings to LED driver according to current color and brightness.
uORB::Subscription _parameter_update_sub
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
RGBLED(int bus, int rgbled)
#define SUB_ADDR_PWM1
green (without auto-increment)
bool updated()
Check if there is a new update.
__EXPORT param_t param_find(const char *name)
Look up a parameter by name.
__EXPORT int rgbled_main(int argc, char *argv[])
volatile bool _should_run
int update(LedControlData &control_data)
Update and retrieve the Led state.
Led controller helper class, used by Led drivers.
int send_led_enable(bool enable)
Sent ENABLE flag to LED driver.
#define RGBLED0_DEVICE_PATH
bool copy(void *dst)
Copy the struct.
#define SETTING_NOT_POWERSAVE
power-save mode not off
class LedController Handles the led_control topic: blinking, priorities and state updates...
int get(bool &on, bool &powersave, uint8_t &r, uint8_t &g, uint8_t &b)
Base class for devices connected via I2C.