Browse Source

rpi_rc_in move to px4 work queue

sbg
Daniel Agar 6 years ago
parent
commit
5ebb0d5d96
  1. 19
      src/drivers/rpi_rc_in/rpi_rc_in.cpp
  2. 12
      src/drivers/rpi_rc_in/rpi_rc_in.h

19
src/drivers/rpi_rc_in/rpi_rc_in.cpp

@ -42,7 +42,7 @@ RcInput::~RcInput()
_mem = nullptr; _mem = nullptr;
} }
work_cancel(HPWORK, &_work); ScheduleClear();
_is_running = false; _is_running = false;
} }
@ -68,6 +68,7 @@ int RcInput::rpi_rc_init()
return 0; return 0;
} }
int RcInput::start() int RcInput::start()
{ {
int result = 0; int result = 0;
@ -80,11 +81,8 @@ int RcInput::start()
} }
_is_running = true; _is_running = true;
result = work_queue(HPWORK, &_work, (worker_t) & RcInput::cycle_trampoline, this, 0);
if (result == -1) { ScheduleNow();
_is_running = false;
}
return result; return result;
} }
@ -94,19 +92,12 @@ void RcInput::stop()
_should_exit = true; _should_exit = true;
} }
void RcInput::cycle_trampoline(void *arg) void RcInput::Run()
{
RcInput *dev = reinterpret_cast<RcInput *>(arg);
dev->_cycle();
}
void RcInput::_cycle()
{ {
_measure(); _measure();
if (!_should_exit) { if (!_should_exit) {
work_queue(HPWORK, &_work, (worker_t) & RcInput::cycle_trampoline, this, ScheduleDelayed(RCINPUT_MEASURE_INTERVAL_US);
USEC2TICK(RCINPUT_MEASURE_INTERVAL_US));
} }
} }

12
src/drivers/rpi_rc_in/rpi_rc_in.h

@ -49,7 +49,7 @@
#include <unistd.h> #include <unistd.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>
@ -61,10 +61,10 @@
namespace rpi_rc_in namespace rpi_rc_in
{ {
class RcInput class RcInput, public px4::ScheduledWorkItem
{ {
public: public:
RcInput() = default; RcInput() : ScheduledWorkItem(px4::wq_configurations::hp_default) {}
~RcInput(); ~RcInput();
@ -74,23 +74,19 @@ public:
/** @return 0 on success, -errno on failure */ /** @return 0 on success, -errno on failure */
void stop(); void stop();
/** Trampoline for the work queue. */
static void cycle_trampoline(void *arg);
bool is_running() bool is_running()
{ {
return _is_running; return _is_running;
} }
private: private:
void _cycle(); void Run() override;
void _measure(); void _measure();
int rpi_rc_init(); int rpi_rc_init();
bool _should_exit = false; bool _should_exit = false;
bool _is_running = false; bool _is_running = false;
struct work_s _work = {};
orb_advert_t _rcinput_pub = nullptr; orb_advert_t _rcinput_pub = nullptr;
int _channels = 8; //D8R-II plus int _channels = 8; //D8R-II plus
struct input_rc_s _data = {}; struct input_rc_s _data = {};

Loading…
Cancel
Save