mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-18 03:03:34 +08:00
rgbled_ncp5623c move to px4 work queue
This commit is contained in:
@@ -54,7 +54,7 @@
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <px4_workqueue.h>
|
||||
#include <px4_work_queue/ScheduledWorkItem.hpp>
|
||||
|
||||
#include <perf/perf_counter.h>
|
||||
#include <systemlib/err.h>
|
||||
@@ -77,7 +77,7 @@
|
||||
#define NCP5623_LED_OFF 0x00 /**< off */
|
||||
|
||||
|
||||
class RGBLED_NPC5623C : public device::I2C
|
||||
class RGBLED_NPC5623C : public device::I2C, public px4::ScheduledWorkItem
|
||||
{
|
||||
public:
|
||||
RGBLED_NPC5623C(int bus, int rgbled);
|
||||
@@ -87,7 +87,6 @@ public:
|
||||
virtual int init();
|
||||
virtual int probe();
|
||||
private:
|
||||
work_s _work;
|
||||
|
||||
float _brightness;
|
||||
float _max_brightness;
|
||||
@@ -102,8 +101,7 @@ private:
|
||||
|
||||
LedController _led_controller;
|
||||
|
||||
static void led_trampoline(void *arg);
|
||||
void led();
|
||||
void Run() override;
|
||||
|
||||
int send_led_rgb();
|
||||
void update_params();
|
||||
@@ -122,12 +120,8 @@ void rgbled_ncp5623c_usage();
|
||||
extern "C" __EXPORT int rgbled_ncp5623c_main(int argc, char *argv[]);
|
||||
|
||||
RGBLED_NPC5623C::RGBLED_NPC5623C(int bus, int rgbled) :
|
||||
I2C("rgbled1", RGBLED1_DEVICE_PATH, bus, rgbled
|
||||
#ifdef __PX4_NUTTX
|
||||
, 100000 /* maximum speed supported */
|
||||
#endif
|
||||
),
|
||||
_work{},
|
||||
I2C("rgbled1", RGBLED1_DEVICE_PATH, bus, rgbled, 100000),
|
||||
ScheduledWorkItem(px4::device_bus_to_wq(get_device_id())),
|
||||
_brightness(1.0f),
|
||||
_max_brightness(1.0f),
|
||||
_r(0),
|
||||
@@ -174,7 +168,8 @@ RGBLED_NPC5623C::init()
|
||||
update_params();
|
||||
|
||||
_running = true;
|
||||
work_queue(LPWORK, &_work, (worker_t)&RGBLED_NPC5623C::led_trampoline, this, 0);
|
||||
|
||||
ScheduleNow();
|
||||
|
||||
return OK;
|
||||
}
|
||||
@@ -187,19 +182,11 @@ RGBLED_NPC5623C::probe()
|
||||
return write(NCP5623_LED_CURRENT, 0x00);
|
||||
}
|
||||
|
||||
void
|
||||
RGBLED_NPC5623C::led_trampoline(void *arg)
|
||||
{
|
||||
RGBLED_NPC5623C *rgbl = reinterpret_cast<RGBLED_NPC5623C *>(arg);
|
||||
|
||||
rgbl->led();
|
||||
}
|
||||
|
||||
/**
|
||||
* Main loop function
|
||||
*/
|
||||
void
|
||||
RGBLED_NPC5623C::led()
|
||||
RGBLED_NPC5623C::Run()
|
||||
{
|
||||
if (!_should_run) {
|
||||
if (_param_sub >= 0) {
|
||||
@@ -282,8 +269,7 @@ RGBLED_NPC5623C::led()
|
||||
}
|
||||
|
||||
/* re-queue ourselves to run again later */
|
||||
work_queue(LPWORK, &_work, (worker_t)&RGBLED_NPC5623C::led_trampoline, this,
|
||||
USEC2TICK(_led_controller.maximum_update_interval()));
|
||||
ScheduleDelayed(_led_controller.maximum_update_interval());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user