PX4 Firmware
PX4 Autopilot Software http://px4.io
rpi_rc_in.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2017 Fan.zhang. All rights reserved. 421395590@qq.com
4  * Copyright (c) 2017 PX4 Development Team. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * 3. Neither the name PX4 nor the names of its contributors may be
17  * used to endorse or promote products derived from this software
18  * without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  ****************************************************************************/
34 
35 #pragma once
36 
37 /*! @file rpi_rc_in.h
38  * Raspberry Pi driver to publish RC input from shared memory.
39  * It requires the ppmdecode program (https://github.com/crossa/raspberry-pi-ppm-rc-in)
40  */
41 
42 #include <sys/types.h>
43 #include <sys/stat.h>
44 #include <sys/ipc.h>
45 #include <sys/shm.h>
46 #include <fcntl.h>
47 #include <stdio.h>
48 #include <stdint.h>
49 #include <unistd.h>
50 
51 #include <px4_platform_common/px4_config.h>
52 #include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
53 #include <px4_platform_common/defines.h>
54 
55 #include <drivers/drv_hrt.h>
56 
57 #include <uORB/uORB.h>
58 #include <uORB/topics/input_rc.h>
59 
60 #define RCINPUT_MEASURE_INTERVAL_US 20000
61 
62 namespace rpi_rc_in
63 {
64 class RcInput : public px4::ScheduledWorkItem
65 {
66 public:
67  RcInput() : ScheduledWorkItem(MODULE_NAME, px4::wq_configurations::hp_default) {}
68 
69  ~RcInput();
70 
71  /** @return 0 on success, -errno on failure */
72  int start();
73 
74  /** @return 0 on success, -errno on failure */
75  void stop();
76 
77  bool is_running()
78  {
79  return _is_running;
80  }
81 
82 private:
83  void Run() override;
84  void _measure();
85 
86  int rpi_rc_init();
87 
88  bool _should_exit = false;
89  bool _is_running = false;
91  int _channels = 8; //D8R-II plus
92  struct input_rc_s _data = {};
93 
94  int *_mem = nullptr;
95  key_t _key = 4096; ///< shared memory key (matches the ppmdecode program's key)
96  int _shmid = 0;
97 };
98 
99 static void usage(const char *reason);
100 static RcInput *rc_input = nullptr;
101 }
102 extern "C" __EXPORT int rpi_rc_in_main(int argc, char **argv);
API for the uORB lightweight object broker.
Definition: I2C.hpp:51
key_t _key
shared memory key (matches the ppmdecode program&#39;s key)
Definition: rpi_rc_in.h:95
High-resolution timer with callouts and timekeeping.
__EXPORT int rpi_rc_in_main(int argc, char **argv)
Definition: rpi_rc_in.cpp:146
void Run() override
Definition: rpi_rc_in.cpp:95
static void usage(const char *reason)
Print the correct usage.
Definition: Commander.cpp:4238
orb_advert_t _rcinput_pub
Definition: rpi_rc_in.h:90
__BEGIN_DECLS typedef void * orb_advert_t
ORB topic advertiser handle.
Definition: uORB.h:134
Definition: bst.cpp:62
static RcInput * rc_input
Definition: rpi_rc_in.h:100
struct input_rc_s _data
Definition: rpi_rc_in.h:92