Blackbox device type 'file' (SITL) considered working when file handler is available
[inav.git] / src / main / drivers / headtracker_common.h
blob8c177e3e0f07aa7c80ef8d2efd7bafa5a920cd18
1 /*
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/>.
18 #pragma once
20 #include "platform.h"
22 #define MAX_HEADTRACKER_DATA_AGE_US HZ2US(25)
23 #define HEADTRACKER_RANGE_MIN -2048
24 #define HEADTRACKER_RANGE_MAX 2047
26 #ifdef USE_HEADTRACKER
28 #include <stdint.h>
30 #include "common/time.h"
32 #include "drivers/time.h"
34 #include "config/feature.h"
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
41 typedef enum {
42 HEADTRACKER_NONE = 0,
43 HEADTRACKER_SERIAL = 1,
44 HEADTRACKER_MSP = 2,
45 HEADTRACKER_UNKNOWN = 0xFF
46 } headTrackerDevType_e;
49 struct headTrackerVTable_s;
51 typedef struct headTrackerDevice_s {
52 const struct headTrackerVTable_s *vTable;
53 int pan;
54 int tilt;
55 int roll;
56 timeUs_t expires;
57 } headTrackerDevice_t;
59 // {set,get}BandAndChannel: band and channel are 1 origin
60 // {set,get}PowerByIndex: 0 = Power OFF, 1 = device dependent
61 // {set,get}PitMode: 0 = OFF, 1 = ON
63 typedef struct headTrackerVTable_s {
64 void (*process)(headTrackerDevice_t *headTrackerDevice, timeUs_t currentTimeUs);
65 headTrackerDevType_e (*getDeviceType)(const headTrackerDevice_t *headTrackerDevice);
66 bool (*isReady)(const headTrackerDevice_t *headTrackerDevice);
67 bool (*isValid)(const headTrackerDevice_t *headTrackerDevice);
68 int (*getPanPWM)(const headTrackerDevice_t *headTrackerDevice);
69 int (*getTiltPWM)(const headTrackerDevice_t *headTrackerDevice);
70 int (*getRollPWM)(const headTrackerDevice_t *headTrackerDevice);
71 int (*getPan)(const headTrackerDevice_t *headTrackerDevice);
72 int (*getTilt)(const headTrackerDevice_t *headTrackerDevice);
73 int (*getRoll)(const headTrackerDevice_t *headTrackerDevice);
74 } headTrackerVTable_t;
77 typedef struct headTrackerConfig_s {
78 headTrackerDevType_e devType;
79 float pan_ratio;
80 float tilt_ratio;
81 float roll_ratio;
82 } headTrackerConfig_t;
84 PG_DECLARE(headTrackerConfig_t, headTrackerConfig);
86 void headTrackerCommonInit(void);
87 void headTrackerCommonSetDevice(headTrackerDevice_t *headTrackerDevice);
88 headTrackerDevice_t *headTrackerCommonDevice(void);
90 // VTable functions
91 void headTrackerCommonProcess(headTrackerDevice_t *headTrackerDevice, timeUs_t currentTimeUs);
92 headTrackerDevType_e headTrackerCommonGetDeviceType(const headTrackerDevice_t *headTrackerDevice);
93 bool headTrackerCommonIsReady(const headTrackerDevice_t *headtrackerDevice);
94 bool headTrackerCommonIsValid(const headTrackerDevice_t *headtrackerDevice);
96 // Scaled value, constrained to PWM_RANGE_MIN~PWM_RANGE_MAX
97 int headTrackerCommonGetPanPWM(const headTrackerDevice_t *headTrackerDevice);
98 int headTrackerCommonGetTiltPWM(const headTrackerDevice_t *headTrackerDevice);
99 int headTrackerCommonGetRollPWM(const headTrackerDevice_t *headTrackerDevice);
101 // Scaled value, constrained to -2048~2047
102 int headTrackerCommonGetPan(const headTrackerDevice_t *headTrackerDevice);
103 int headTrackerCommonGetTilt(const headTrackerDevice_t *headTrackerDevice);
104 int headTrackerCommonGetRoll(const headTrackerDevice_t *headTrackerDevice);
106 void taskUpdateHeadTracker(timeUs_t currentTimeUs);
108 bool headtrackerCommonIsEnabled(void);
111 #ifdef __cplusplus
113 #endif
115 #endif