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/>.
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
30 #include "common/time.h"
32 #include "drivers/time.h"
34 #include "config/feature.h"
43 HEADTRACKER_SERIAL
= 1,
45 HEADTRACKER_UNKNOWN
= 0xFF
46 } headTrackerDevType_e
;
49 struct headTrackerVTable_s
;
51 typedef struct headTrackerDevice_s
{
52 const struct headTrackerVTable_s
*vTable
;
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
;
82 } headTrackerConfig_t
;
84 PG_DECLARE(headTrackerConfig_t
, headTrackerConfig
);
86 void headTrackerCommonInit(void);
87 void headTrackerCommonSetDevice(headTrackerDevice_t
*headTrackerDevice
);
88 headTrackerDevice_t
*headTrackerCommonDevice(void);
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);