Merge pull request #10558 from iNavFlight/MrD_Correct-comments-on-OSD-symbols
[inav.git] / src / main / flight / mixer_profile.h
blob947ca701553b07c40b3f045203d51c73cda9a879
1 #pragma once
3 #include "config/parameter_group.h"
4 #include "flight/failsafe.h"
5 #include "flight/mixer.h"
6 #include "flight/servos.h"
8 #ifndef MAX_MIXER_PROFILE_COUNT
9 #define MAX_MIXER_PROFILE_COUNT 2
10 #endif
12 typedef struct mixerConfig_s {
13 int8_t motorDirectionInverted;
14 uint8_t platformType;
15 bool hasFlaps;
16 int16_t appliedMixerPreset;
17 bool motorstopOnLow;
18 bool PIDProfileLinking;
19 bool automated_switch;
20 int16_t switchTransitionTimer;
21 bool tailsitterOrientationOffset;
22 } mixerConfig_t;
23 typedef struct mixerProfile_s {
24 mixerConfig_t mixer_config;
25 motorMixer_t MotorMixers[MAX_SUPPORTED_MOTORS];
26 servoMixer_t ServoMixers[MAX_SERVO_RULES];
27 } mixerProfile_t;
29 PG_DECLARE_ARRAY(mixerProfile_t, MAX_MIXER_PROFILE_COUNT, mixerProfiles);
30 typedef enum {
31 MIXERAT_REQUEST_NONE, //no request, stats checking only
32 MIXERAT_REQUEST_RTH,
33 MIXERAT_REQUEST_LAND,
34 MIXERAT_REQUEST_ABORT,
35 } mixerProfileATRequest_e;
37 //mixerProfile Automated Transition PHASE
38 typedef enum {
39 MIXERAT_PHASE_IDLE,
40 MIXERAT_PHASE_TRANSITION_INITIALIZE,
41 MIXERAT_PHASE_TRANSITIONING,
42 MIXERAT_PHASE_DONE,
43 } mixerProfileATState_e;
45 typedef struct mixerProfileAT_s {
46 mixerProfileATState_e phase;
47 bool transitionInputMixing;
48 timeMs_t transitionStartTime;
49 timeMs_t transitionStabEndTime;
50 timeMs_t transitionTransEndTime;
51 } mixerProfileAT_t;
52 extern mixerProfileAT_t mixerProfileAT;
53 bool checkMixerATRequired(mixerProfileATRequest_e required_action);
54 bool mixerATUpdateState(mixerProfileATRequest_e required_action);
56 extern mixerConfig_t currentMixerConfig;
57 extern int currentMixerProfileIndex;
58 extern int nextMixerProfileIndex;
59 extern bool isMixerTransitionMixing;
60 #define mixerConfig() (&(mixerProfiles(systemConfig()->current_mixer_profile_index)->mixer_config))
61 #define mixerConfigMutable() ((mixerConfig_t *) mixerConfig())
63 #define primaryMotorMixer(_index) (&(mixerProfiles(systemConfig()->current_mixer_profile_index)->MotorMixers)[_index])
64 #define primaryMotorMixerMutable(_index) ((motorMixer_t *)primaryMotorMixer(_index))
65 #define customServoMixers(_index) (&(mixerProfiles(systemConfig()->current_mixer_profile_index)->ServoMixers)[_index])
66 #define customServoMixersMutable(_index) ((servoMixer_t *)customServoMixers(_index))
68 static inline const mixerProfile_t* mixerProfiles_CopyArray_by_index(int _index) { return &mixerProfiles_CopyArray[_index]; }
69 #define primaryMotorMixer_CopyArray() (mixerProfiles_CopyArray_by_index(systemConfig()->current_mixer_profile_index)->MotorMixers)
70 #define customServoMixers_CopyArray() (mixerProfiles_CopyArray_by_index(systemConfig()->current_mixer_profile_index)->ServoMixers)
72 #define mixerConfigByIndex(index) (&(mixerProfiles(index)->mixer_config))
73 #define mixerMotorMixersByIndex(index) (mixerProfiles(index)->MotorMixers)
74 #define mixerServoMixersByIndex(index) (mixerProfiles(index)->ServoMixers)
76 bool platformTypeConfigured(flyingPlatformType_e platformType);
77 bool outputProfileHotSwitch(int profile_index);
78 bool checkMixerProfileHotSwitchAvalibility(void);
79 void activateMixerConfig(void);
80 void mixerConfigInit(void);
81 void outputProfileUpdateTask(timeUs_t currentTimeUs);