MAV'RIC
joystick_parsing.h
1 /*******************************************************************************
2  * Copyright (c) 2009-2014, MAV'RIC Development Team
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  ******************************************************************************/
31 
32 /*******************************************************************************
33  * \file joystick_parsing.h
34  *
35  * \author MAV'RIC Team
36  *
37  * \brief This file is to decode the set manual command message from MAVLink
38  *
39  ******************************************************************************/
40 
41 
42 #ifndef JOYSTICK_PARSING_H__
43 #define JOYSTICK_PARSING_H__
44 
45 #ifdef __cplusplus
46  extern "C" {
47 #endif
48 
49 #include "stabilisation.h"
50 #include "state.h"
51 
52 #define MAX_JOYSTICK_RANGE 0.8
53 
57 typedef enum
58 {
59  BUTTON_UNPRESSED = 0,
60  BUTTON_PRESSED = 1,
61 } button_pressed_t;
62 
66 typedef union
67 {
68  uint16_t button_mask;
69  // unamed bitfield structure, use to access directly the flags
70  struct
71  {
72  button_pressed_t button_16 : 1;
73  button_pressed_t button_15 : 1;
74  button_pressed_t button_14 : 1;
75  button_pressed_t button_13 : 1;
76  button_pressed_t button_12 : 1;
77  button_pressed_t button_11 : 1;
78  button_pressed_t button_10 : 1;
79  button_pressed_t button_9 : 1;
80  button_pressed_t button_8 : 1;
81  button_pressed_t button_7 : 1;
82  button_pressed_t button_6 : 1;
83  button_pressed_t button_5 : 1;
84  button_pressed_t button_4 : 1;
85  button_pressed_t button_3 : 1;
86  button_pressed_t button_2 : 1;
87  button_pressed_t button_1 : 1;
88  };
89  // identical bitfield, but named (useful for initialisation)
90  struct
91  {
92  button_pressed_t button_16 : 1;
93  button_pressed_t button_15 : 1;
94  button_pressed_t button_14 : 1;
95  button_pressed_t button_13 : 1;
96  button_pressed_t button_12 : 1;
97  button_pressed_t button_11 : 1;
98  button_pressed_t button_10 : 1;
99  button_pressed_t button_9 : 1;
100  button_pressed_t button_8 : 1;
101  button_pressed_t button_7 : 1;
102  button_pressed_t button_6 : 1;
103  button_pressed_t button_5 : 1;
104  button_pressed_t button_4 : 1;
105  button_pressed_t button_3 : 1;
106  button_pressed_t button_2 : 1;
107  button_pressed_t button_1 : 1;
108  } button;
110 
111 
115 typedef struct
116 {
117  float x; // Longitudinal (pitch)
118  float y; // Lateral (roll)
119  float z; // Certical (thrust)
120  float r; // Rotation (yaw)
122 
123 
127 typedef struct
128 {
130  joystick_channels_t channels;
131  // control_command_t* controls; ///< The pointer to the controls structure
134 
135 
144 bool joystick_parsing_init(joystick_parsing_t* joystick_parsing, state_t* state);
145 
146 
153 void joystick_parsing_get_velocity_vector_from_joystick(joystick_parsing_t* joystick_parsing, control_command_t* controls);
154 
155 
162 void joystick_parsing_get_attitude_command_from_joystick(joystick_parsing_t* joystick_parsing, control_command_t* controls);
163 
164 
171 void joystick_parsing_button_mask(joystick_parsing_t* joystick_parsing, uint16_t buttons);
172 
173 
174 #ifdef __cplusplus
175 }
176 #endif
177 
178 #endif // JOYSTICK_PARSING_H__
joystick_button_t buttons
The bit mask of the button pressed.
Definition: joystick_parsing.h:129
The control command typedef.
Definition: stabilisation.h:77
The state structure.
Definition: state.h:79
Joystick Channels.
Definition: joystick_parsing.h:115
state_t * state
The pointer to the state structure.
Definition: joystick_parsing.h:132
The structure for the joystick parsing.
Definition: joystick_parsing.h:127
The union structure for the bit mask of the joystick buttons.
Definition: joystick_parsing.h:66