mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-22 01:12:31 +00:00
rpi_rc_in move to px4 work queue
This commit is contained in:
@@ -42,7 +42,7 @@ RcInput::~RcInput()
|
||||
_mem = nullptr;
|
||||
}
|
||||
|
||||
work_cancel(HPWORK, &_work);
|
||||
ScheduleClear();
|
||||
_is_running = false;
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ int RcInput::rpi_rc_init()
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int RcInput::start()
|
||||
{
|
||||
int result = 0;
|
||||
@@ -80,11 +81,8 @@ int RcInput::start()
|
||||
}
|
||||
|
||||
_is_running = true;
|
||||
result = work_queue(HPWORK, &_work, (worker_t) & RcInput::cycle_trampoline, this, 0);
|
||||
|
||||
if (result == -1) {
|
||||
_is_running = false;
|
||||
}
|
||||
ScheduleNow();
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -94,19 +92,12 @@ void RcInput::stop()
|
||||
_should_exit = true;
|
||||
}
|
||||
|
||||
void RcInput::cycle_trampoline(void *arg)
|
||||
{
|
||||
RcInput *dev = reinterpret_cast<RcInput *>(arg);
|
||||
dev->_cycle();
|
||||
}
|
||||
|
||||
void RcInput::_cycle()
|
||||
void RcInput::Run()
|
||||
{
|
||||
_measure();
|
||||
|
||||
if (!_should_exit) {
|
||||
work_queue(HPWORK, &_work, (worker_t) & RcInput::cycle_trampoline, this,
|
||||
USEC2TICK(RCINPUT_MEASURE_INTERVAL_US));
|
||||
ScheduleDelayed(RCINPUT_MEASURE_INTERVAL_US);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include <px4_config.h>
|
||||
#include <px4_workqueue.h>
|
||||
#include <px4_work_queue/ScheduledWorkItem.hpp>
|
||||
#include <px4_defines.h>
|
||||
|
||||
#include <drivers/drv_hrt.h>
|
||||
@@ -61,10 +61,10 @@
|
||||
|
||||
namespace rpi_rc_in
|
||||
{
|
||||
class RcInput
|
||||
class RcInput, public px4::ScheduledWorkItem
|
||||
{
|
||||
public:
|
||||
RcInput() = default;
|
||||
RcInput() : ScheduledWorkItem(px4::wq_configurations::hp_default) {}
|
||||
|
||||
~RcInput();
|
||||
|
||||
@@ -74,23 +74,19 @@ public:
|
||||
/** @return 0 on success, -errno on failure */
|
||||
void stop();
|
||||
|
||||
/** Trampoline for the work queue. */
|
||||
static void cycle_trampoline(void *arg);
|
||||
|
||||
bool is_running()
|
||||
{
|
||||
return _is_running;
|
||||
}
|
||||
|
||||
private:
|
||||
void _cycle();
|
||||
void Run() override;
|
||||
void _measure();
|
||||
|
||||
int rpi_rc_init();
|
||||
|
||||
bool _should_exit = false;
|
||||
bool _is_running = false;
|
||||
struct work_s _work = {};
|
||||
orb_advert_t _rcinput_pub = nullptr;
|
||||
int _channels = 8; //D8R-II plus
|
||||
struct input_rc_s _data = {};
|
||||
|
||||
Reference in New Issue
Block a user