Preparation for conversion to parameter groups 7

This commit is contained in:
Martin Budden 2017-02-15 09:20:21 +00:00
parent 4f4c14a02d
commit d2ac5d84b1
9 changed files with 42 additions and 52 deletions

View File

@ -166,7 +166,7 @@
#define displayPortProfileMax7456Mutable(x) (&masterConfig.displayPortProfileMax7456) #define displayPortProfileMax7456Mutable(x) (&masterConfig.displayPortProfileMax7456)
#define displayPortProfileOledMutable(x) (&masterConfig.displayPortProfileOled) #define displayPortProfileOledMutable(x) (&masterConfig.displayPortProfileOled)
#define servoParams(x) (&servoProfile()->servoConf[i]) #define servoParams(x) (&servoProfile()->servoConf[x])
#define adjustmentRanges(x) (&adjustmentProfile()->adjustmentRanges[x]) #define adjustmentRanges(x) (&adjustmentProfile()->adjustmentRanges[x])
#define rxFailsafeChannelConfigs(x) (&masterConfig.rxConfig.failsafe_channel_configurations[x]) #define rxFailsafeChannelConfigs(x) (&masterConfig.rxConfig.failsafe_channel_configurations[x])
#define osdConfig(x) (&masterConfig.osdProfile) #define osdConfig(x) (&masterConfig.osdProfile)

View File

@ -23,7 +23,6 @@
#include <math.h> #include <math.h>
#include <ctype.h> #include <ctype.h>
//#define USE_PARAMETER_GROUPS
#include "platform.h" #include "platform.h"
// FIXME remove this for targets that don't need a CLI. Perhaps use a no-op macro when USE_CLI is not enabled // FIXME remove this for targets that don't need a CLI. Perhaps use a no-op macro when USE_CLI is not enabled

View File

@ -906,7 +906,7 @@ void activateConfig(void)
mixerUseConfigs(&masterConfig.airplaneConfig); mixerUseConfigs(&masterConfig.airplaneConfig);
#ifdef USE_SERVOS #ifdef USE_SERVOS
servoUseConfigs(&masterConfig.servoMixerConfig, masterConfig.servoProfile.servoConf, &masterConfig.gimbalConfig, &masterConfig.channelForwardingConfig); servoUseConfigs(&masterConfig.servoMixerConfig, masterConfig.servoProfile.servoConf, &masterConfig.channelForwardingConfig);
#endif #endif
imuConfigure(throttleCorrectionConfig()->throttle_correction_angle); imuConfigure(throttleCorrectionConfig()->throttle_correction_angle);

View File

@ -243,13 +243,13 @@ void init(void)
#ifdef SPEKTRUM_BIND #ifdef SPEKTRUM_BIND
if (feature(FEATURE_RX_SERIAL)) { if (feature(FEATURE_RX_SERIAL)) {
switch (rxConfig()->serialrx_provider) { switch (rxConfig()->serialrx_provider) {
case SERIALRX_SPEKTRUM1024: case SERIALRX_SPEKTRUM1024:
case SERIALRX_SPEKTRUM2048: case SERIALRX_SPEKTRUM2048:
// Spektrum satellite binding if enabled on startup. // Spektrum satellite binding if enabled on startup.
// Must be called before that 100ms sleep so that we don't lose satellite's binding window after startup. // Must be called before that 100ms sleep so that we don't lose satellite's binding window after startup.
// The rest of Spektrum initialization will happen later - via spektrumInit() // The rest of Spektrum initialization will happen later - via spektrumInit()
spektrumBind(rxConfig()); spektrumBind(rxConfigMutable());
break; break;
} }
} }
#endif #endif
@ -273,7 +273,7 @@ void init(void)
mixerInit(mixerConfig()->mixerMode, customMotorMixerMutable(0)); mixerInit(mixerConfig()->mixerMode, customMotorMixerMutable(0));
#ifdef USE_SERVOS #ifdef USE_SERVOS
servoMixerInit(masterConfig.customServoMixer); servoMixerInit(customServoMixers(0));
#endif #endif
uint16_t idlePulse = motorConfig()->mincommand; uint16_t idlePulse = motorConfig()->mincommand;
@ -461,7 +461,7 @@ void init(void)
#endif #endif
#ifdef LED_STRIP #ifdef LED_STRIP
ledStripInit(ledStripConfig()); ledStripInit();
if (feature(FEATURE_LED_STRIP)) { if (feature(FEATURE_LED_STRIP)) {
ledStripEnable(); ledStripEnable();

View File

@ -56,7 +56,6 @@ static servoMixerConfig_t *servoMixerConfig;
static uint8_t servoRuleCount = 0; static uint8_t servoRuleCount = 0;
static servoMixer_t currentServoMixer[MAX_SERVO_RULES]; static servoMixer_t currentServoMixer[MAX_SERVO_RULES];
static gimbalConfig_t *gimbalConfig;
int16_t servo[MAX_SUPPORTED_SERVOS]; int16_t servo[MAX_SUPPORTED_SERVOS];
static int useServo; static int useServo;
static servoParam_t *servoConf; static servoParam_t *servoConf;
@ -146,11 +145,10 @@ const mixerRules_t servoMixers[] = {
static servoMixer_t *customServoMixers; static servoMixer_t *customServoMixers;
void servoUseConfigs(servoMixerConfig_t *servoMixerConfigToUse, servoParam_t *servoParamsToUse, struct gimbalConfig_s *gimbalConfigToUse, struct channelForwardingConfig_s *channelForwardingConfigToUse) void servoUseConfigs(servoMixerConfig_t *servoMixerConfigToUse, servoParam_t *servoParamsToUse, struct channelForwardingConfig_s *channelForwardingConfigToUse)
{ {
servoMixerConfig = servoMixerConfigToUse; servoMixerConfig = servoMixerConfigToUse;
servoConf = servoParamsToUse; servoConf = servoParamsToUse;
gimbalConfig = gimbalConfigToUse;
channelForwardingConfig = channelForwardingConfigToUse; channelForwardingConfig = channelForwardingConfigToUse;
} }

View File

@ -134,8 +134,7 @@ void writeServos(void);
void filterServos(void); void filterServos(void);
void servoMixerInit(servoMixer_t *customServoMixers); void servoMixerInit(servoMixer_t *customServoMixers);
struct gimbalConfig_s; void servoUseConfigs(servoMixerConfig_t *servoConfigToUse, servoParam_t *servoParamsToUse, struct channelForwardingConfig_s *channelForwardingConfigToUse);
void servoUseConfigs(servoMixerConfig_t *servoConfigToUse, servoParam_t *servoParamsToUse, struct gimbalConfig_s *gimbalConfigToUse, struct channelForwardingConfig_s *channelForwardingConfigToUse);
void servoMixerLoadMix(int index, servoMixer_t *customServoMixers); void servoMixerLoadMix(int index, servoMixer_t *customServoMixers);
void loadCustomServoMixer(void); void loadCustomServoMixer(void);
void servoConfigureOutput(void); void servoConfigureOutput(void);

View File

@ -90,7 +90,6 @@ PG_REGISTER_WITH_RESET_FN(specialColorIndexes_t, specialColors, PG_SPECIAL_COLOR
static bool ledStripInitialised = false; static bool ledStripInitialised = false;
static bool ledStripEnabled = true; static bool ledStripEnabled = true;
static ledStripConfig_t * currentLedStripConfig;
static void ledStripDisable(void); static void ledStripDisable(void);
@ -184,7 +183,7 @@ STATIC_UNIT_TESTED void determineLedStripDimensions(void)
int maxY = 0; int maxY = 0;
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) { for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
const ledConfig_t *ledConfig = &currentLedStripConfig->ledConfigs[ledIndex]; const ledConfig_t *ledConfig = &ledStripConfig()->ledConfigs[ledIndex];
maxX = MAX(ledGetX(ledConfig), maxX); maxX = MAX(ledGetX(ledConfig), maxX);
maxY = MAX(ledGetY(ledConfig), maxY); maxY = MAX(ledGetY(ledConfig), maxY);
@ -206,7 +205,7 @@ STATIC_UNIT_TESTED void updateLedCount(void)
int count = 0, countRing = 0, countScanner= 0; int count = 0, countRing = 0, countScanner= 0;
for (int ledIndex = 0; ledIndex < LED_MAX_STRIP_LENGTH; ledIndex++) { for (int ledIndex = 0; ledIndex < LED_MAX_STRIP_LENGTH; ledIndex++) {
const ledConfig_t *ledConfig = &currentLedStripConfig->ledConfigs[ledIndex]; const ledConfig_t *ledConfig = &ledStripConfig()->ledConfigs[ledIndex];
if (!(*ledConfig)) if (!(*ledConfig))
break; break;
@ -236,7 +235,7 @@ void reevaluateLedConfig(void)
// get specialColor by index // get specialColor by index
static hsvColor_t* getSC(ledSpecialColorIds_e index) static hsvColor_t* getSC(ledSpecialColorIds_e index)
{ {
return &currentLedStripConfig->colors[currentLedStripConfig->specialColors.color[index]]; return &ledStripConfig()->colors[ledStripConfig()->specialColors.color[index]];
} }
static const char directionCodes[LED_DIRECTION_COUNT] = { 'N', 'E', 'S', 'W', 'U', 'D' }; static const char directionCodes[LED_DIRECTION_COUNT] = { 'N', 'E', 'S', 'W', 'U', 'D' };
@ -260,7 +259,7 @@ bool parseLedStripConfig(int ledIndex, const char *config)
}; };
static const char chunkSeparators[PARSE_STATE_COUNT] = {',', ':', ':', ':', '\0'}; static const char chunkSeparators[PARSE_STATE_COUNT] = {',', ':', ':', ':', '\0'};
ledConfig_t *ledConfig = &currentLedStripConfig->ledConfigs[ledIndex]; ledConfig_t *ledConfig = &ledStripConfig()->ledConfigs[ledIndex];
memset(ledConfig, 0, sizeof(ledConfig_t)); memset(ledConfig, 0, sizeof(ledConfig_t));
int x = 0, y = 0, color = 0; // initialize to prevent warnings int x = 0, y = 0, color = 0; // initialize to prevent warnings
@ -379,7 +378,7 @@ typedef enum {
static quadrant_e getLedQuadrant(const int ledIndex) static quadrant_e getLedQuadrant(const int ledIndex)
{ {
const ledConfig_t *ledConfig = &currentLedStripConfig->ledConfigs[ledIndex]; const ledConfig_t *ledConfig = &ledStripConfig()->ledConfigs[ledIndex];
int x = ledGetX(ledConfig); int x = ledGetX(ledConfig);
int y = ledGetY(ledConfig); int y = ledGetY(ledConfig);
@ -421,7 +420,7 @@ static const struct {
static hsvColor_t* getDirectionalModeColor(const int ledIndex, const modeColorIndexes_t *modeColors) static hsvColor_t* getDirectionalModeColor(const int ledIndex, const modeColorIndexes_t *modeColors)
{ {
const ledConfig_t *ledConfig = &currentLedStripConfig->ledConfigs[ledIndex]; const ledConfig_t *ledConfig = &ledStripConfig()->ledConfigs[ledIndex];
quadrant_e quad = getLedQuadrant(ledIndex); quadrant_e quad = getLedQuadrant(ledIndex);
for (unsigned i = 0; i < ARRAYLEN(directionQuadrantMap); i++) { for (unsigned i = 0; i < ARRAYLEN(directionQuadrantMap); i++) {
@ -429,7 +428,7 @@ static hsvColor_t* getDirectionalModeColor(const int ledIndex, const modeColorIn
quadrant_e quadMask = directionQuadrantMap[i].quadrantMask; quadrant_e quadMask = directionQuadrantMap[i].quadrantMask;
if (ledGetDirectionBit(ledConfig, dir) && (quad & quadMask)) if (ledGetDirectionBit(ledConfig, dir) && (quad & quadMask))
return &currentLedStripConfig->colors[modeColors->color[dir]]; return &ledStripConfig()->colors[modeColors->color[dir]];
} }
return NULL; return NULL;
} }
@ -455,7 +454,7 @@ static const struct {
static void applyLedFixedLayers() static void applyLedFixedLayers()
{ {
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) { for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
const ledConfig_t *ledConfig = &currentLedStripConfig->ledConfigs[ledIndex]; const ledConfig_t *ledConfig = &ledStripConfig()->ledConfigs[ledIndex];
hsvColor_t color = *getSC(LED_SCOLOR_BACKGROUND); hsvColor_t color = *getSC(LED_SCOLOR_BACKGROUND);
int fn = ledGetFunction(ledConfig); int fn = ledGetFunction(ledConfig);
@ -463,13 +462,13 @@ static void applyLedFixedLayers()
switch (fn) { switch (fn) {
case LED_FUNCTION_COLOR: case LED_FUNCTION_COLOR:
color = currentLedStripConfig->colors[ledGetColor(ledConfig)]; color = ledStripConfig()->colors[ledGetColor(ledConfig)];
break; break;
case LED_FUNCTION_FLIGHT_MODE: case LED_FUNCTION_FLIGHT_MODE:
for (unsigned i = 0; i < ARRAYLEN(flightModeToLed); i++) for (unsigned i = 0; i < ARRAYLEN(flightModeToLed); i++)
if (!flightModeToLed[i].flightMode || FLIGHT_MODE(flightModeToLed[i].flightMode)) { if (!flightModeToLed[i].flightMode || FLIGHT_MODE(flightModeToLed[i].flightMode)) {
hsvColor_t *directionalColor = getDirectionalModeColor(ledIndex, &currentLedStripConfig->modeColors[flightModeToLed[i].ledMode]); hsvColor_t *directionalColor = getDirectionalModeColor(ledIndex, &ledStripConfig()->modeColors[flightModeToLed[i].ledMode]);
if (directionalColor) { if (directionalColor) {
color = *directionalColor; color = *directionalColor;
} }
@ -510,7 +509,7 @@ static void applyLedFixedLayers()
static void applyLedHsv(uint32_t mask, const hsvColor_t *color) static void applyLedHsv(uint32_t mask, const hsvColor_t *color)
{ {
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) { for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
const ledConfig_t *ledConfig = &currentLedStripConfig->ledConfigs[ledIndex]; const ledConfig_t *ledConfig = &ledStripConfig()->ledConfigs[ledIndex];
if ((*ledConfig & mask) == mask) if ((*ledConfig & mask) == mask)
setLedHsv(ledIndex, color); setLedHsv(ledIndex, color);
} }
@ -708,7 +707,7 @@ static void applyLedIndicatorLayer(bool updateNow, timeUs_t *timer)
} }
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) { for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
const ledConfig_t *ledConfig = &currentLedStripConfig->ledConfigs[ledIndex]; const ledConfig_t *ledConfig = &ledStripConfig()->ledConfigs[ledIndex];
if (ledGetOverlayBit(ledConfig, LED_OVERLAY_INDICATOR)) { if (ledGetOverlayBit(ledConfig, LED_OVERLAY_INDICATOR)) {
if (getLedQuadrant(ledIndex) & quadrants) if (getLedQuadrant(ledIndex) & quadrants)
setLedHsv(ledIndex, flashColor); setLedHsv(ledIndex, flashColor);
@ -748,7 +747,7 @@ static void applyLedThrustRingLayer(bool updateNow, timeUs_t *timer)
} }
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) { for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
const ledConfig_t *ledConfig = &currentLedStripConfig->ledConfigs[ledIndex]; const ledConfig_t *ledConfig = &ledStripConfig()->ledConfigs[ledIndex];
if (ledGetFunction(ledConfig) == LED_FUNCTION_THRUST_RING) { if (ledGetFunction(ledConfig) == LED_FUNCTION_THRUST_RING) {
bool applyColor; bool applyColor;
@ -759,7 +758,7 @@ static void applyLedThrustRingLayer(bool updateNow, timeUs_t *timer)
} }
if (applyColor) { if (applyColor) {
const hsvColor_t *ringColor = &currentLedStripConfig->colors[ledGetColor(ledConfig)]; const hsvColor_t *ringColor = &ledStripConfig()->colors[ledGetColor(ledConfig)];
setLedHsv(ledIndex, ringColor); setLedHsv(ledIndex, ringColor);
} }
@ -875,7 +874,7 @@ static void applyLedAnimationLayer(bool updateNow, timeUs_t *timer)
int nextRow = (frameCounter + 1 < animationFrames) ? frameCounter + 1 : 0; int nextRow = (frameCounter + 1 < animationFrames) ? frameCounter + 1 : 0;
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) { for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
const ledConfig_t *ledConfig = &currentLedStripConfig->ledConfigs[ledIndex]; const ledConfig_t *ledConfig = &ledStripConfig()->ledConfigs[ledIndex];
if (ledGetY(ledConfig) == previousRow) { if (ledGetY(ledConfig) == previousRow) {
setLedHsv(ledIndex, getSC(LED_SCOLOR_ANIMATION)); setLedHsv(ledIndex, getSC(LED_SCOLOR_ANIMATION));
@ -937,7 +936,7 @@ void ledStripUpdate(timeUs_t currentTimeUs)
return; return;
} }
if (IS_RC_MODE_ACTIVE(BOXLEDLOW) && !(currentLedStripConfig->ledstrip_visual_beeper && isBeeperOn())) { if (IS_RC_MODE_ACTIVE(BOXLEDLOW) && !(ledStripConfig()->ledstrip_visual_beeper && isBeeperOn())) {
if (ledStripEnabled) { if (ledStripEnabled) {
ledStripDisable(); ledStripDisable();
ledStripEnabled = false; ledStripEnabled = false;
@ -968,7 +967,7 @@ void ledStripUpdate(timeUs_t currentTimeUs)
// apply all layers; triggered timed functions has to update timers // apply all layers; triggered timed functions has to update timers
scaledThrottle = ARMING_FLAG(ARMED) ? scaleRange(rcData[THROTTLE], PWM_RANGE_MIN, PWM_RANGE_MAX, 0, 100) : 0; scaledThrottle = ARMING_FLAG(ARMED) ? scaleRange(rcData[THROTTLE], PWM_RANGE_MIN, PWM_RANGE_MAX, 0, 100) : 0;
scaledAux = scaleRange(rcData[currentLedStripConfig->ledstrip_aux_channel], PWM_RANGE_MIN, PWM_RANGE_MAX, 0, HSV_HUE_MAX + 1); scaledAux = scaleRange(rcData[ledStripConfig()->ledstrip_aux_channel], PWM_RANGE_MIN, PWM_RANGE_MAX, 0, HSV_HUE_MAX + 1);
applyLedFixedLayers(); applyLedFixedLayers();
@ -984,7 +983,7 @@ bool parseColor(int index, const char *colorConfig)
{ {
const char *remainingCharacters = colorConfig; const char *remainingCharacters = colorConfig;
hsvColor_t *color = &currentLedStripConfig->colors[index]; hsvColor_t *color = &ledStripConfig()->colors[index];
bool result = true; bool result = true;
static const uint16_t hsv_limit[HSV_COLOR_COMPONENT_COUNT] = { static const uint16_t hsv_limit[HSV_COLOR_COMPONENT_COUNT] = {
@ -1037,15 +1036,15 @@ bool setModeColor(ledModeIndex_e modeIndex, int modeColorIndex, int colorIndex)
if (modeIndex < LED_MODE_COUNT) { // modeIndex_e is unsigned, so one-sided test is enough if (modeIndex < LED_MODE_COUNT) { // modeIndex_e is unsigned, so one-sided test is enough
if(modeColorIndex < 0 || modeColorIndex >= LED_DIRECTION_COUNT) if(modeColorIndex < 0 || modeColorIndex >= LED_DIRECTION_COUNT)
return false; return false;
currentLedStripConfig->modeColors[modeIndex].color[modeColorIndex] = colorIndex; ledStripConfig()->modeColors[modeIndex].color[modeColorIndex] = colorIndex;
} else if (modeIndex == LED_SPECIAL) { } else if (modeIndex == LED_SPECIAL) {
if (modeColorIndex < 0 || modeColorIndex >= LED_SPECIAL_COLOR_COUNT) if (modeColorIndex < 0 || modeColorIndex >= LED_SPECIAL_COLOR_COUNT)
return false; return false;
currentLedStripConfig->specialColors.color[modeColorIndex] = colorIndex; ledStripConfig()->specialColors.color[modeColorIndex] = colorIndex;
} else if (modeIndex == LED_AUX_CHANNEL) { } else if (modeIndex == LED_AUX_CHANNEL) {
if (modeColorIndex < 0 || modeColorIndex >= 1) if (modeColorIndex < 0 || modeColorIndex >= 1)
return false; return false;
currentLedStripConfig->ledstrip_aux_channel = colorIndex; ledStripConfig()->ledstrip_aux_channel = colorIndex;
} else { } else {
return false; return false;
} }
@ -1103,26 +1102,21 @@ void applyDefaultSpecialColors(specialColorIndexes_t *specialColors)
memcpy_fn(specialColors, &defaultSpecialColors, sizeof(defaultSpecialColors)); memcpy_fn(specialColors, &defaultSpecialColors, sizeof(defaultSpecialColors));
} }
void ledStripInit(ledStripConfig_t *ledStripConfig) void ledStripInit()
{ {
currentLedStripConfig = ledStripConfig; ledConfigs = ledStripConfig()->ledConfigs;
colors = ledStripConfig()->colors;
ledConfigs = currentLedStripConfig->ledConfigs; modeColors = ledStripConfig()->modeColors;
colors = currentLedStripConfig->colors; specialColors = ledStripConfig()->specialColors;
modeColors = currentLedStripConfig->modeColors;
specialColors = currentLedStripConfig->specialColors;
ledStripInitialised = false; ledStripInitialised = false;
} }
void ledStripEnable(void) void ledStripEnable(void)
{ {
if (currentLedStripConfig == NULL) {
return;
}
reevaluateLedConfig(); reevaluateLedConfig();
ledStripInitialised = true; ledStripInitialised = true;
ws2811LedStripInit(currentLedStripConfig->ioTag); ws2811LedStripInit(ledStripConfig()->ioTag);
} }
static void ledStripDisable(void) static void ledStripDisable(void)

View File

@ -183,7 +183,7 @@ bool parseLedStripConfig(int ledIndex, const char *config);
void generateLedConfig(ledConfig_t *ledConfig, char *ledConfigBuffer, size_t bufferSize); void generateLedConfig(ledConfig_t *ledConfig, char *ledConfigBuffer, size_t bufferSize);
void reevaluateLedConfig(void); void reevaluateLedConfig(void);
void ledStripInit(ledStripConfig_t *ledStripConfig); void ledStripInit(void);
void ledStripEnable(void); void ledStripEnable(void);
void ledStripUpdate(timeUs_t currentTimeUs); void ledStripUpdate(timeUs_t currentTimeUs);

View File

@ -28,4 +28,4 @@ void spektrumBind(rxConfig_t *rxConfig);
bool spektrumInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig); bool spektrumInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig);
void srxlRxWriteTelemetryData(const void *data, int len); void srxlRxWriteTelemetryData(const void *data, int len);
bool srxlRxIsActive(void); bool srxlRxIsActive(void);