50,21 → 50,24 |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
#include <util/delay.h> |
#include <avr/eeprom.h> |
#include <stddef.h> |
#include "configuration.h" |
#include "eeprom.h" |
#include "timer0.h" |
|
int16_t variables[8] = {0,0,0,0,0,0,0,0}; |
fc_param_t dynamicParams = {48,251,16,58,64,8,150,150,2,10,{0,0,0,0,0,0,0,0},100,70,90,65,64,100,0,0,0}; |
dynamicParam_t dynamicParams = {48,251,16,58,64,8,150,150,2,10,{0,0,0,0,0,0,0,0},100,70,90,65,64,100,0,0,0}; |
uint8_t CPUType = ATMEGA644; |
uint8_t BoardRelease = 13; |
|
/************************************************************************ |
* Map the parameter to pot values |
* Replacing this code by the code below saved almost 1 kbyte. |
************************************************************************/ |
|
void configuration_applyVariablesToParams(void) { |
uint8_t i; |
#define SET_POT_MM(b,a,min,max) { if (a<255) {if (a>=251) b=variables[a-251]; else b=a;} if(b<=min) b=min; else if(b>=max) b=max;} |
#define SET_POT_MM(b,a,min,max) {if (a<255) {if (a>=251) b=variables[a-251]; else b=a;} if(b<=min) b=min; else if(b>=max) b=max;} |
#define SET_POT(b,a) { if (a<255) {if (a>=251) b=variables[a-251]; else b=a;}} |
SET_POT(dynamicParams.MaxHeight,staticParams.MaxHeight); |
SET_POT_MM(dynamicParams.HeightD,staticParams.HeightD,0,100); |
103,6 → 106,85 |
SET_POT(dynamicParams.ExternalControl,staticParams.ExternalControl); |
} |
|
const XLATION XLATIONS[] = { |
{offsetof(paramset_t, MaxHeight), offsetof(dynamicParam_t, MaxHeight)}, |
{offsetof(paramset_t, Height_ACC_Effect), offsetof(dynamicParam_t, Height_ACC_Effect)}, |
{offsetof(paramset_t, CompassYawEffect), offsetof(dynamicParam_t, CompassYawEffect)}, |
{offsetof(paramset_t, GyroI), offsetof(dynamicParam_t, GyroI)}, |
{offsetof(paramset_t, GyroD), offsetof(dynamicParam_t, GyroD)}, |
{offsetof(paramset_t, IFactor), offsetof(dynamicParam_t, IFactor)}, |
{offsetof(paramset_t, ServoPitchControl), offsetof(dynamicParam_t, ServoPitchControl)}, |
{offsetof(paramset_t, LoopGasLimit), offsetof(dynamicParam_t, LoopGasLimit)}, |
{offsetof(paramset_t, AxisCoupling1), offsetof(dynamicParam_t, AxisCoupling1)}, |
{offsetof(paramset_t, AxisCoupling2), offsetof(dynamicParam_t, AxisCoupling2)}, |
{offsetof(paramset_t, AxisCouplingYawCorrection), offsetof(dynamicParam_t, AxisCouplingYawCorrection)}, |
{offsetof(paramset_t, DynamicStability), offsetof(dynamicParam_t, DynamicStability)}, |
{offsetof(paramset_t, NaviGpsModeControl), |
offsetof(dynamicParam_t, NaviGpsModeControl)}, |
{offsetof(paramset_t, NaviGpsGain), offsetof(dynamicParam_t, NaviGpsGain)}, |
{offsetof(paramset_t, NaviGpsP), offsetof(dynamicParam_t, NaviGpsP)}, |
{offsetof(paramset_t, NaviGpsI), offsetof(dynamicParam_t, NaviGpsI)}, |
{offsetof(paramset_t, NaviGpsD), offsetof(dynamicParam_t, NaviGpsD)}, |
{offsetof(paramset_t, NaviGpsACC), offsetof(dynamicParam_t, NaviGpsACC)}, |
{offsetof(paramset_t, NaviWindCorrection), offsetof(dynamicParam_t, NaviWindCorrection)}, |
{offsetof(paramset_t, NaviSpeedCompensation), offsetof(dynamicParam_t, NaviSpeedCompensation)}, |
{offsetof(paramset_t, ExternalControl), offsetof(dynamicParam_t, ExternalControl)} |
}; |
|
const MMXLATION MMXLATIONS[] = { |
{offsetof(paramset_t, HeightD), offsetof(dynamicParam_t, HeightD),0,100}, |
{offsetof(paramset_t, HeightP), offsetof(dynamicParam_t, HeightD),0,150}, |
{offsetof(paramset_t, GyroP), offsetof(dynamicParam_t, GyroP),0,255}, |
{offsetof(paramset_t, J16Timing), offsetof(dynamicParam_t, J16Timing),1,255}, |
{offsetof(paramset_t, J17Timing), offsetof(dynamicParam_t, J17Timing),1,255}, |
{offsetof(paramset_t, NaviOperatingRadius), offsetof(dynamicParam_t, NaviOperatingRadius),10,255} |
}; |
|
uint8_t configuration_applyVariableToParam(uint8_t src, uint8_t min, uint8_t max) { |
uint8_t result; |
if (src>=251) result = variables[src-251]; |
else result = src; |
if (result < min) result = min; |
else if (result > max) result = max; |
return result; |
} |
|
void configuration_applyVariablesToParams_dead(void) { |
uint8_t i, src; |
uint8_t* pointerToTgt; |
for(i=0; i<sizeof(XLATIONS)/sizeof(XLATION); i++) { |
src = *((uint8_t*)(&staticParams + XLATIONS[i].sourceIdx)); |
pointerToTgt = (uint8_t*)(&dynamicParams + XLATIONS[i].targetIdx); |
if (src < 255) { |
*pointerToTgt = configuration_applyVariableToParam(src, 0, 255); |
} |
} |
|
for(i=0; i<sizeof(MMXLATIONS)/sizeof(MMXLATION); i++) { |
src = *((uint8_t*)(&staticParams + MMXLATIONS[i].sourceIdx)); |
pointerToTgt = (uint8_t*)(&dynamicParams + XLATIONS[i].targetIdx); |
if (src < 255) { |
*pointerToTgt = configuration_applyVariableToParam(src, MMXLATIONS[i].min, MMXLATIONS[i].max); |
} |
} |
|
for (i=0; i<sizeof(staticParams.UserParams1); i++) { |
src = *((uint8_t*)(&staticParams + offsetof(paramset_t, UserParams1) + i)); |
pointerToTgt = (uint8_t*)(&dynamicParams + offsetof(dynamicParam_t, UserParams) + i); |
if (src < 255) { |
*pointerToTgt = configuration_applyVariableToParam(src, 0, 255); |
} |
} |
|
for (i=0; i<sizeof(staticParams.UserParams2); i++) { |
src = *((uint8_t*)(&staticParams + offsetof(paramset_t, UserParams2) + i)); |
pointerToTgt = (uint8_t*)(&dynamicParams + offsetof(dynamicParam_t, UserParams) + sizeof(staticParams.UserParams1) + i); |
if (src < 255) { |
*pointerToTgt = configuration_applyVariableToParam(src, 0, 255); |
} |
} |
} |
|
uint8_t getCPUType(void) { // works only after reset or power on when the registers have default values |
uint8_t CPUType = ATMEGA644; |
if( (UCSR1A == 0x20) && (UCSR1C == 0x06) ) CPUType = ATMEGA644P; // initial Values for 644P after reset |