|
|
@ -55,7 +55,7 @@ |
|
|
|
#include <stdio.h> |
|
|
|
#include <stdio.h> |
|
|
|
#include <ctype.h> |
|
|
|
#include <ctype.h> |
|
|
|
|
|
|
|
|
|
|
|
#include <px4_workqueue.h> |
|
|
|
#include <px4_work_queue/ScheduledWorkItem.hpp> |
|
|
|
|
|
|
|
|
|
|
|
#include <perf/perf_counter.h> |
|
|
|
#include <perf/perf_counter.h> |
|
|
|
#include <systemlib/err.h> |
|
|
|
#include <systemlib/err.h> |
|
|
@ -81,7 +81,7 @@ |
|
|
|
#define SETTING_ENABLE 0x02 /**< on */ |
|
|
|
#define SETTING_ENABLE 0x02 /**< on */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RGBLED : public device::I2C |
|
|
|
class RGBLED : public device::I2C, public px4::ScheduledWorkItem |
|
|
|
{ |
|
|
|
{ |
|
|
|
public: |
|
|
|
public: |
|
|
|
RGBLED(int bus, int rgbled); |
|
|
|
RGBLED(int bus, int rgbled); |
|
|
@ -93,8 +93,6 @@ public: |
|
|
|
int status(); |
|
|
|
int status(); |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
work_s _work; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float _brightness; |
|
|
|
float _brightness; |
|
|
|
float _max_brightness; |
|
|
|
float _max_brightness; |
|
|
|
|
|
|
|
|
|
|
@ -108,8 +106,7 @@ private: |
|
|
|
|
|
|
|
|
|
|
|
LedController _led_controller; |
|
|
|
LedController _led_controller; |
|
|
|
|
|
|
|
|
|
|
|
static void led_trampoline(void *arg); |
|
|
|
void Run() override; |
|
|
|
void led(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int send_led_enable(bool enable); |
|
|
|
int send_led_enable(bool enable); |
|
|
|
int send_led_rgb(); |
|
|
|
int send_led_rgb(); |
|
|
@ -128,12 +125,8 @@ void rgbled_usage(); |
|
|
|
extern "C" __EXPORT int rgbled_main(int argc, char *argv[]); |
|
|
|
extern "C" __EXPORT int rgbled_main(int argc, char *argv[]); |
|
|
|
|
|
|
|
|
|
|
|
RGBLED::RGBLED(int bus, int rgbled) : |
|
|
|
RGBLED::RGBLED(int bus, int rgbled) : |
|
|
|
I2C("rgbled", RGBLED0_DEVICE_PATH, bus, rgbled |
|
|
|
I2C("rgbled", RGBLED0_DEVICE_PATH, bus, rgbled, 100000), |
|
|
|
#ifdef __PX4_NUTTX |
|
|
|
ScheduledWorkItem(px4::device_bus_to_wq(get_device_id())), |
|
|
|
, 100000 /* maximum speed supported */ |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
_work{}, |
|
|
|
|
|
|
|
_brightness(1.0f), |
|
|
|
_brightness(1.0f), |
|
|
|
_max_brightness(1.0f), |
|
|
|
_max_brightness(1.0f), |
|
|
|
_r(0), |
|
|
|
_r(0), |
|
|
@ -173,8 +166,9 @@ RGBLED::init() |
|
|
|
update_params(); |
|
|
|
update_params(); |
|
|
|
|
|
|
|
|
|
|
|
_running = true; |
|
|
|
_running = true; |
|
|
|
|
|
|
|
|
|
|
|
// kick off work queue
|
|
|
|
// kick off work queue
|
|
|
|
work_queue(LPWORK, &_work, (worker_t)&RGBLED::led_trampoline, this, 0); |
|
|
|
ScheduleNow(); |
|
|
|
|
|
|
|
|
|
|
|
return OK; |
|
|
|
return OK; |
|
|
|
} |
|
|
|
} |
|
|
@ -230,19 +224,11 @@ RGBLED::status() |
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
|
|
|
RGBLED::led_trampoline(void *arg) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
RGBLED *rgbl = reinterpret_cast<RGBLED *>(arg); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rgbl->led(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Main loop function |
|
|
|
* Main loop function |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void |
|
|
|
void |
|
|
|
RGBLED::led() |
|
|
|
RGBLED::Run() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!_should_run) { |
|
|
|
if (!_should_run) { |
|
|
|
if (_param_sub >= 0) { |
|
|
|
if (_param_sub >= 0) { |
|
|
@ -332,10 +318,8 @@ RGBLED::led() |
|
|
|
send_led_rgb(); |
|
|
|
send_led_rgb(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* re-queue ourselves to run again later */ |
|
|
|
/* re-queue ourselves to run again later */ |
|
|
|
work_queue(LPWORK, &_work, (worker_t)&RGBLED::led_trampoline, this, |
|
|
|
ScheduleDelayed(_led_controller.maximum_update_interval()); |
|
|
|
USEC2TICK(_led_controller.maximum_update_interval())); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|