-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
ppm_arch.c
101 lines (86 loc) · 3.32 KB
/
ppm_arch.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* $Id$
*
* Copyright (C) 2010 The Paparazzi Team
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "sys_time.h"
#include "subsystems/radio_control.h"
#include "subsystems/radio_control/ppm.h"
#include <inttypes.h>
#include <caml/mlvalues.h>
#ifdef USE_NPS
#include "nps_radio_control.h"
#endif
uint8_t ppm_cur_pulse;
uint32_t ppm_last_pulse_time;
bool_t ppm_data_valid;
void ppm_arch_init ( void ) {
ppm_last_pulse_time = 0;
ppm_cur_pulse = RADIO_CONTROL_NB_CHANNEL;
ppm_data_valid = FALSE;
ppm_frame_available = FALSE;
}
#ifdef RADIO_CONTROL
value update_rc_channel(value c, value v) {
ppm_pulses[Int_val(c)] = Double_val(v);
return Val_unit;
}
value send_ppm(value unit) {
ppm_frame_available = TRUE;
return unit;
}
#ifdef USE_NPS
#define PPM_OF_NPS(_nps, _neutral, _min, _max) \
((_nps) >= 0 ? (_neutral) + (_nps) * ((_max)-(_neutral)) : (_neutral) + (_nps) * ((_neutral)- (_min)))
void radio_control_feed(void) {
ppm_pulses[RADIO_ROLL] = PPM_OF_NPS(nps_radio_control.roll, \
RADIO_ROLL_NEUTRAL, \
RADIO_ROLL_MIN, \
RADIO_ROLL_MAX);
ppm_pulses[RADIO_PITCH] = PPM_OF_NPS(nps_radio_control.pitch, \
RADIO_PITCH_NEUTRAL, \
RADIO_PITCH_MIN, \
RADIO_PITCH_MAX);
ppm_pulses[RADIO_YAW] = PPM_OF_NPS(nps_radio_control.yaw, \
RADIO_YAW_NEUTRAL, \
RADIO_YAW_MIN, \
RADIO_YAW_MAX);
ppm_pulses[RADIO_THROTTLE] = PPM_OF_NPS(nps_radio_control.throttle, \
RADIO_THROTTLE_NEUTRAL, \
RADIO_THROTTLE_MIN, \
RADIO_THROTTLE_MAX);
ppm_pulses[RADIO_MODE] = PPM_OF_NPS(nps_radio_control.mode, \
RADIO_MODE_NEUTRAL, \
RADIO_MODE_MIN, \
RADIO_MODE_MAX);
ppm_frame_available = TRUE;
}
#endif
#else // RADIO_CONTROL
value update_rc_channel(value c __attribute__ ((unused)), value v __attribute__ ((unused))) {
return Val_unit;
}
value send_ppm(value unit) {
return unit;
}
#ifdef USE_NPS
void radio_control_feed(void) {}
#endif
#endif // RADIO_CONTROL