APM:Libraries
AP_RCProtocol_PPMSum.cpp
Go to the documentation of this file.
1 /*
2  * This file is free software: you can redistribute it and/or modify it
3  * under the terms of the GNU General Public License as published by the
4  * Free Software Foundation, either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * This file is distributed in the hope that it will be useful, but
8  * WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License along
13  * with this program. If not, see <http://www.gnu.org/licenses/>.
14  *
15  * Code by Andrew Tridgell and Siddharth Bharat Purohit
16  */
17 
18 #include "AP_RCProtocol_PPMSum.h"
19 
20 /*
21  process a PPM-sum pulse of the given width
22  */
23 void AP_RCProtocol_PPMSum::process_pulse(uint32_t width_s0, uint32_t width_s1)
24 {
25  uint32_t width_usec = width_s0 + width_s1;
26  if (width_usec >= 2700) {
27  // a long pulse indicates the end of a frame. Reset the
28  // channel counter so next pulse is channel 0
29  if (ppm_state._channel_counter >= MIN_RCIN_CHANNELS) {
30  add_input(ppm_state._channel_counter, ppm_state._pulse_capt, false);
31  }
32  ppm_state._channel_counter = 0;
33  return;
34  }
35  if (ppm_state._channel_counter == -1) {
36  // we are not synchronised
37  return;
38  }
39 
40  /*
41  we limit inputs to between 700usec and 2300usec. This allows us
42  to decode SBUS on the same pin, as SBUS will have a maximum
43  pulse width of 100usec
44  */
45  if (width_usec > 700 && width_usec < 2300) {
46  // take a reading for the current channel
47  // buffer these
48  ppm_state._pulse_capt[ppm_state._channel_counter] = width_usec;
49 
50  // move to next channel
51  ppm_state._channel_counter++;
52  }
53 
54  // if we have reached the maximum supported channels then
55  // mark as unsynchronised, so we wait for a wide pulse
56  if (ppm_state._channel_counter >= MAX_RCIN_CHANNELS) {
57  add_input(ppm_state._channel_counter, ppm_state._pulse_capt, false);
58  ppm_state._channel_counter = -1;
59  }
60 }
#define MAX_RCIN_CHANNELS
Definition: AP_RCProtocol.h:21
#define MIN_RCIN_CHANNELS
Definition: AP_RCProtocol.h:22
struct AP_RCProtocol_PPMSum::@180 ppm_state
void process_pulse(uint32_t width_s0, uint32_t width_s1) override
void add_input(uint8_t num_channels, uint16_t *values, bool in_failsafe)