linux_sbus move to px4 work queue

This commit is contained in:
Daniel Agar
2019-05-24 12:58:55 -04:00
parent 4dd017cd59
commit 78d35f2677
2 changed files with 10 additions and 20 deletions
+5 -11
View File
@@ -119,8 +119,8 @@ int RcInput::start(char *device, int channels)
} }
_isRunning = true; _isRunning = true;
result = work_queue(HPWORK, &_work, (worker_t) & RcInput::cycle_trampoline,
this, 0); ScheduleNow();
if (result == -1) { if (result == -1) {
_isRunning = false; _isRunning = false;
@@ -134,20 +134,14 @@ void RcInput::stop()
close(_device_fd); close(_device_fd);
_shouldExit = true; _shouldExit = true;
} }
//---------------------------------------------------------------------------------------------------------// //---------------------------------------------------------------------------------------------------------//
void RcInput::cycle_trampoline(void *arg) void RcInput::Run()
{
RcInput *dev = reinterpret_cast<RcInput *>(arg);
dev->_cycle();
}
//---------------------------------------------------------------------------------------------------------//
void RcInput::_cycle()
{ {
_measure(); _measure();
if (!_shouldExit) { if (!_shouldExit) {
work_queue(HPWORK, &_work, (worker_t) & RcInput::cycle_trampoline, this, ScheduleDelayed(RCINPUT_MEASURE_INTERVAL_US);
USEC2TICK(RCINPUT_MEASURE_INTERVAL_US));
} }
} }
//---------------------------------------------------------------------------------------------------------// //---------------------------------------------------------------------------------------------------------//
+5 -9
View File
@@ -48,7 +48,7 @@
#include <asm-generic/termbits.h> #include <asm-generic/termbits.h>
#include <errno.h> #include <errno.h>
#include <px4_config.h> #include <px4_config.h>
#include <px4_workqueue.h> #include <px4_work_queue/ScheduledWorkItem.hpp>
#include <px4_defines.h> #include <px4_defines.h>
#include <drivers/drv_hrt.h> #include <drivers/drv_hrt.h>
#include <uORB/uORB.h> #include <uORB/uORB.h>
@@ -66,13 +66,13 @@
namespace linux_sbus namespace linux_sbus
{ {
class RcInput class RcInput : public px4::ScheduledWorkItem
{ {
public: public:
RcInput() : RcInput() :
ScheduledWorkItem(px4::wq_configurations::hp_default),
_shouldExit(false), _shouldExit(false),
_isRunning(false), _isRunning(false),
_work { },
_rcinput_pub(nullptr), _rcinput_pub(nullptr),
_data { }, _sbusData { 0x0f, 0x01, 0x04, 0x20, 0x00, _data { }, _sbusData { 0x0f, 0x01, 0x04, 0x20, 0x00,
0xff, 0x07, 0x40, 0x00, 0x02, 0xff, 0x07, 0x40, 0x00, 0x02,
@@ -82,7 +82,7 @@ public:
{ } { }
~RcInput() ~RcInput()
{ {
work_cancel(HPWORK, &_work); ScheduleClear();
_isRunning = false; _isRunning = false;
close(_device_fd); close(_device_fd);
} }
@@ -90,20 +90,16 @@ public:
int start(char *device, int channels); int start(char *device, int channels);
void stop(); void stop();
/** Trampoline for the work queue. */
static void cycle_trampoline(void *arg);
bool isRunning() bool isRunning()
{ {
return _isRunning; return _isRunning;
} }
private: private:
void _cycle(); void Run() override;
void _measure(); void _measure();
bool _shouldExit; bool _shouldExit;
bool _isRunning; bool _isRunning;
struct work_s _work;
orb_advert_t _rcinput_pub; orb_advert_t _rcinput_pub;
struct input_rc_s _data; struct input_rc_s _data;
uint8_t _sbusData[25]; uint8_t _sbusData[25];