mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-29 03:36:07 +08:00
Fix code style
This commit is contained in:
@@ -36,16 +36,18 @@
|
||||
|
||||
using namespace rpi_rc_in;
|
||||
//---------------------------------------------------------------------------------------------------------//
|
||||
int RcInput::rpi_rc_init() {
|
||||
int RcInput::rpi_rc_init()
|
||||
{
|
||||
int i;
|
||||
|
||||
//--------------初始化共享内存映射----------------------------//
|
||||
if ((this->shmid = shmget(this->key, sizeof(int) * this->_channels, 0666))
|
||||
< 0) {
|
||||
< 0) {
|
||||
PX4_WARN("无法访问共享内存");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((this->mem = (int*) shmat(this->shmid, NULL, 0)) == (void *) -1) {
|
||||
if ((this->mem = (int *) shmat(this->shmid, NULL, 0)) == (void *) - 1) {
|
||||
PX4_WARN("无法映射共享内存");
|
||||
return -1;
|
||||
}
|
||||
@@ -65,7 +67,8 @@ int RcInput::rpi_rc_init() {
|
||||
return 0;
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------//
|
||||
int RcInput::start() {
|
||||
int RcInput::start()
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
result = rpi_rc_init();
|
||||
@@ -77,7 +80,7 @@ int RcInput::start() {
|
||||
|
||||
_isRunning = true;
|
||||
result = work_queue(HPWORK, &_work, (worker_t) & RcInput::cycle_trampoline,
|
||||
this, 0);
|
||||
this, 0);
|
||||
|
||||
if (result == -1) {
|
||||
_isRunning = false;
|
||||
@@ -86,30 +89,35 @@ int RcInput::start() {
|
||||
return result;
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------//
|
||||
void RcInput::stop() {
|
||||
void RcInput::stop()
|
||||
{
|
||||
_shouldExit = true;
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------//
|
||||
void RcInput::cycle_trampoline(void *arg) {
|
||||
void RcInput::cycle_trampoline(void *arg)
|
||||
{
|
||||
RcInput *dev = reinterpret_cast<RcInput *>(arg);
|
||||
dev->_cycle();
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------//
|
||||
void RcInput::_cycle() {
|
||||
void RcInput::_cycle()
|
||||
{
|
||||
_measure();
|
||||
|
||||
if (!_shouldExit) {
|
||||
work_queue(HPWORK, &_work, (worker_t) & RcInput::cycle_trampoline, this,
|
||||
USEC2TICK(RCINPUT_MEASURE_INTERVAL_US));
|
||||
USEC2TICK(RCINPUT_MEASURE_INTERVAL_US));
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------//
|
||||
void RcInput::_measure(void) {
|
||||
void RcInput::_measure(void)
|
||||
{
|
||||
uint64_t ts;
|
||||
// PWM 数据发布
|
||||
int i=0;
|
||||
for(i=0;i<_channels;++i){
|
||||
_data.values[i] = *(this->mem+i);
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i < _channels; ++i) {
|
||||
_data.values[i] = *(this->mem + i);
|
||||
}
|
||||
|
||||
ts = hrt_absolute_time();
|
||||
@@ -131,14 +139,17 @@ void RcInput::_measure(void) {
|
||||
* Print the correct usage.
|
||||
*/
|
||||
|
||||
static void rpi_rc_in::usage(const char *reason) {
|
||||
static void rpi_rc_in::usage(const char *reason)
|
||||
{
|
||||
if (reason) {
|
||||
PX4_ERR("%s", reason);
|
||||
}
|
||||
|
||||
PX4_INFO("用法: rpi_rc_in {start|stop|status}");
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------//
|
||||
int rpi_rc_in_main(int argc, char **argv) {
|
||||
int rpi_rc_in_main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 2) {
|
||||
usage("missing command");
|
||||
return 1;
|
||||
|
||||
@@ -50,19 +50,23 @@
|
||||
#include <uORB/uORB.h>
|
||||
#include <uORB/topics/input_rc.h>
|
||||
#define RCINPUT_MEASURE_INTERVAL_US 20000
|
||||
namespace rpi_rc_in {
|
||||
class RcInput {
|
||||
namespace rpi_rc_in
|
||||
{
|
||||
class RcInput
|
||||
{
|
||||
public:
|
||||
int *mem;
|
||||
key_t key;
|
||||
int shmid;
|
||||
RcInput() :
|
||||
mem(nullptr),key(4096),shmid(0),_shouldExit(false), _isRunning(false), _work { }, _rcinput_pub(
|
||||
nullptr), _channels(8),//D8R-II plus
|
||||
_data { } {
|
||||
mem(nullptr), key(4096), shmid(0), _shouldExit(false), _isRunning(false), _work { }, _rcinput_pub(
|
||||
nullptr), _channels(8),//D8R-II plus
|
||||
_data { }
|
||||
{
|
||||
//memset(_ch_fd, 0, sizeof(_ch_fd));
|
||||
}
|
||||
~RcInput() {
|
||||
~RcInput()
|
||||
{
|
||||
this->mem = nullptr;
|
||||
work_cancel(HPWORK, &_work);
|
||||
_isRunning = false;
|
||||
@@ -77,7 +81,8 @@ public:
|
||||
/* Trampoline for the work queue. */
|
||||
static void cycle_trampoline(void *arg);
|
||||
|
||||
bool isRunning() {
|
||||
bool isRunning()
|
||||
{
|
||||
return _isRunning;
|
||||
}
|
||||
|
||||
@@ -85,7 +90,7 @@ private:
|
||||
void _cycle();
|
||||
void _measure();
|
||||
|
||||
bool _shouldExit;bool _isRunning;
|
||||
bool _shouldExit; bool _isRunning;
|
||||
struct work_s _work;
|
||||
orb_advert_t _rcinput_pub;
|
||||
int _channels;
|
||||
|
||||
Reference in New Issue
Block a user