Skip to content

Commit

Permalink
rpi_rc_in move to px4 work queue
Browse files Browse the repository at this point in the history
  • Loading branch information
dagar committed May 24, 2019
1 parent da62101 commit 5ebb0d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
19 changes: 5 additions & 14 deletions src/drivers/rpi_rc_in/rpi_rc_in.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ RcInput::~RcInput()
_mem = nullptr;
}

work_cancel(HPWORK, &_work);
ScheduleClear();
_is_running = false;
}

Expand All @@ -68,6 +68,7 @@ int RcInput::rpi_rc_init()

return 0;
}

int RcInput::start()
{
int result = 0;
Expand All @@ -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;
}
Expand All @@ -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);
}
}

Expand Down
12 changes: 4 additions & 8 deletions src/drivers/rpi_rc_in/rpi_rc_in.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -61,10 +61,10 @@

namespace rpi_rc_in
{
class RcInput
class RcInput, public px4::ScheduledWorkItem

This comment has been minimized.

Copy link
@gijsvesch

gijsvesch Jul 31, 2019

This is not correct: replace by :

{
public:
RcInput() = default;
RcInput() : ScheduledWorkItem(px4::wq_configurations::hp_default) {}

~RcInput();

Expand All @@ -74,23 +74,19 @@ class RcInput
/** @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 = {};
Expand Down

0 comments on commit 5ebb0d5

Please sign in to comment.