Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
superbitrf_rc.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Freek van Tienen <freek.v.tienen@gmail.com>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
27 #ifndef RADIO_CONTROL_SUPERBITRF_RC_H
28 #define RADIO_CONTROL_SUPERBITRF_RC_H
29 
30 #include "subsystems/datalink/superbitrf.h"
31 
32 /* Theoretically you could have 14 channel over DSM2/DSMX */
33 #ifndef RADIO_CONTROL_NB_CHANNEL
34 #define RADIO_CONTROL_NB_CHANNEL 14
35 #endif
36 
37 /* The channel ordering is always the same for DSM2 and DSMX */
38 #define RADIO_THROTTLE 0
39 #define RADIO_ROLL 1
40 #define RADIO_PITCH 2
41 #define RADIO_YAW 3
42 #define RADIO_GEAR 4
43 #define RADIO_FLAP 5
44 #define RADIO_AUX1 5
45 #define RADIO_AUX2 6
46 #define RADIO_AUX3 7
47 #define RADIO_AUX4 8
48 #define RADIO_AUX5 9
49 #define RADIO_AUX6 10
50 #define RADIO_AUX7 11
51 #define RADIO_AUX8 12
52 #define RADIO_AUX9 13
53 
54 /* Map the MODE default to the gear switch */
55 #ifndef RADIO_MODE
56 #define RADIO_MODE RADIO_GEAR
57 #endif
58 
59 /* Macro that normalize superbitrf rc_values to radio values */
60 #define NormalizeRcDl(_in, _out, _count) { \
61  uint8_t i; \
62  for(i = 0; i < _count; i++) { \
63  if(i == RADIO_THROTTLE) { \
64  _out[i] = (_in[i] + MAX_PPRZ) / 2; \
65  Bound(_out[i], 0, MAX_PPRZ); \
66  } else { \
67  _out[i] = -_in[i]; \
68  Bound(_out[i], MIN_PPRZ, MAX_PPRZ); \
69  } \
70  } \
71 }
72 
73 /* The radio control event handler */
74 #define RadioControlEvent(_received_frame_handler) { \
75  cyrf6936_event(&superbitrf.cyrf6936); \
76  superbitrf_event(); \
77  if(superbitrf.rc_frame_available) { \
78  radio_control.frame_cpt++; \
79  radio_control.time_since_last_frame = 0; \
80  radio_control.radio_ok_cpt = 0; \
81  radio_control.status = RC_OK; \
82  NormalizeRcDl(superbitrf.rc_values,radio_control.values \
83  ,superbitrf.num_channels); \
84  _received_frame_handler(); \
85  superbitrf.rc_frame_available = FALSE; \
86  } \
87 }
88 
89 #endif /* RADIO_CONTROL_SUPERBITRF_RC_H */