2 * This file is part of INAV.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with INAV. If not, see <http://www.gnu.org/licenses/>.
21 #if (defined(USE_HEADTRACKER_MSP) && defined(USE_HEADTRACKER))
23 #include "build/debug.h"
25 #include "common/utils.h"
26 #include "common/time.h"
27 #include "common/maths.h"
29 #include "drivers/headtracker_common.h"
31 #include "io/headtracker_msp.h"
33 static bool isReady
= false;
34 static headTrackerVTable_t headTrackerMspVTable
= {
36 .getDeviceType
= heatTrackerMspGetDeviceType
,
37 .isReady
= heatTrackerMspIsReady
,
41 static headTrackerDevice_t headTrackerMspDevice
= {
42 .vTable
= &headTrackerMspVTable
,
49 void mspHeadTrackerInit(void)
51 if(headTrackerConfig()->devType
== HEADTRACKER_MSP
) {
52 headTrackerCommonSetDevice(&headTrackerMspDevice
);
56 void mspHeadTrackerReceiverNewData(uint8_t *data
, unsigned int dataSize
)
58 if(dataSize
!= sizeof(headtrackerMspMessage_t
)) {
59 SD(fprintf(stderr
, "[headTracker]: invalid data size %d\n", dataSize
));
60 static int errorCount
= 0;
61 DEBUG_SET(DEBUG_HEADTRACKING
, 7, errorCount
++);
62 DEBUG_SET(DEBUG_HEADTRACKING
, 5, (sizeof(headtrackerMspMessage_t
)));
63 DEBUG_SET(DEBUG_HEADTRACKING
, 6, dataSize
);
67 DEBUG_SET(DEBUG_HEADTRACKING
, 6, dataSize
);
69 headtrackerMspMessage_t
*status
= (headtrackerMspMessage_t
*)data
;
71 headTrackerMspDevice
.pan
= constrain(status
->pan
, HEADTRACKER_RANGE_MIN
, HEADTRACKER_RANGE_MAX
);
72 headTrackerMspDevice
.tilt
= constrain(status
->tilt
, HEADTRACKER_RANGE_MIN
, HEADTRACKER_RANGE_MAX
);
73 headTrackerMspDevice
.roll
= constrain(status
->roll
, HEADTRACKER_RANGE_MIN
, HEADTRACKER_RANGE_MAX
);
74 headTrackerMspDevice
.expires
= micros() + MAX_HEADTRACKER_DATA_AGE_US
;
76 DEBUG_SET(DEBUG_HEADTRACKING
, 0, headTrackerMspDevice
.pan
);
77 DEBUG_SET(DEBUG_HEADTRACKING
, 1, headTrackerMspDevice
.tilt
);
78 DEBUG_SET(DEBUG_HEADTRACKING
, 2, headTrackerMspDevice
.roll
);
79 DEBUG_SET(DEBUG_HEADTRACKING
, 3, headTrackerMspDevice
.expires
);
82 headTrackerDevType_e
heatTrackerMspGetDeviceType(const headTrackerDevice_t
*headTrackerDevice
) {
83 UNUSED(headTrackerDevice
);
84 return HEADTRACKER_MSP
;
88 bool heatTrackerMspIsReady(const headTrackerDevice_t
*headTrackerDevice
)
90 UNUSED(headTrackerDevice
);
91 return headTrackerConfig()->devType
== HEADTRACKER_MSP
&& isReady
;