Rev 1908 | Rev 1961 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1908 | Rev 1960 | ||
---|---|---|---|
Line 61... | Line 61... | ||
61 | 61 | ||
62 | #ifndef EEMEM |
62 | #ifndef EEMEM |
63 | #define EEMEM __attribute__ ((section (".eeprom"))) |
63 | #define EEMEM __attribute__ ((section (".eeprom"))) |
Line 64... | Line -... | ||
64 | #endif |
- | |
65 | - | ||
66 | #include <avr/eeprom.h> |
64 | #endif |
67 | #include <string.h> |
65 | |
68 | #include "eeprom.h" |
66 | #include "eeprom.h" |
69 | #include "printf_P.h" |
- | |
70 | #include "output.h" |
- | |
71 | // TODO: Get rid of these. They have nothing to do with eeprom. |
- | |
72 | #include "flight.h" |
67 | #include "printf_P.h" |
Line 73... | Line 68... | ||
73 | #include "rc.h" |
68 | #include "output.h" |
74 | #include "sensors.h" |
69 | #include <avr/eeprom.h> |
Line 75... | Line -... | ||
75 | - | ||
76 | // byte array in eeprom |
- | |
77 | uint8_t EEPromArray[E2END + 1] EEMEM; |
- | |
78 | - | ||
79 | paramset_t staticParams; |
- | |
80 | MixerTable_t Mixer; |
- | |
81 | - | ||
82 | /* |
- | |
83 | * Default for your own experiments here, so you don't have to reset them |
- | |
84 | * from MK-Tool all the time. |
- | |
85 | */ |
- | |
86 | void setDefaultUserParams(void) { |
- | |
87 | uint8_t i; |
- | |
88 | for (i = 0; i < sizeof(staticParams.UserParams1); i++) { |
- | |
89 | staticParams.UserParams1[i] = 0; |
- | |
90 | } |
- | |
91 | for (i = 0; i < sizeof(staticParams.UserParams2); i++) { |
- | |
92 | staticParams.UserParams2[i] = 0; |
- | |
93 | } |
- | |
94 | /* |
- | |
95 | * While we are still using userparams for flight parameters, do set |
- | |
96 | * some safe & meaningful default values. |
- | |
97 | */ |
- | |
98 | staticParams.UserParams1[3] = 12; // Throttle stick D=12 |
- | |
99 | staticParams.UserParams2[0] = 0b11010101; // All gyro filter constants 2; acc. 4 |
- | |
100 | staticParams.UserParams2[1] = 2; // H&I motor smoothing. |
- | |
101 | staticParams.UserParams2[2] = 120; // Yaw I factor |
- | |
102 | staticParams.UserParams2[3] = 100; // Max Z acceleration for acc. correction of angles. |
- | |
103 | } |
- | |
104 | - | ||
105 | void setOtherDefaults(void) { |
- | |
106 | /* Channel assignments were changed to the normal: |
- | |
107 | * Aileron/roll=1, elevator/pitch=2, throttle=3, yaw/rudder=4 |
- | |
108 | */ |
- | |
109 | staticParams.ChannelAssignment[CH_PITCH] = 2; |
- | |
110 | staticParams.ChannelAssignment[CH_ROLL] = 1; |
- | |
111 | staticParams.ChannelAssignment[CH_THROTTLE] = 3; |
- | |
112 | staticParams.ChannelAssignment[CH_YAW] = 4; |
- | |
113 | staticParams.ChannelAssignment[CH_POTS + 0] = 5; |
- | |
114 | staticParams.ChannelAssignment[CH_POTS + 1] = 6; |
- | |
115 | staticParams.ChannelAssignment[CH_POTS + 2] = 7; |
- | |
116 | staticParams.ChannelAssignment[CH_POTS + 3] = 8; |
- | |
117 | staticParams.GlobalConfig = /* CFG_AXIS_COUPLING_ACTIVE | */ CFG_HEADING_HOLD; // CFG_COMPASS_ACTIVE | CFG_GPS_ACTIVE;//CFG_HEIGHT_CONTROL | CFG_HEIGHT_SWITCH | CFG_COMPASS_FIX; |
- | |
118 | staticParams.HeightMinGas = 30; |
- | |
119 | staticParams.MaxHeight = 251; |
- | |
120 | staticParams.HeightP = 10; |
- | |
121 | staticParams.HeightD = 30; |
- | |
122 | staticParams.Height_ACC_Effect = 30; |
- | |
123 | staticParams.Height_Gain = 4; |
- | |
124 | staticParams.StickP = 8; |
- | |
125 | staticParams.StickD = 12; |
- | |
126 | staticParams.StickYawP = 12; |
- | |
127 | staticParams.MinThrottle = 8; |
- | |
128 | staticParams.MaxThrottle = 230; |
- | |
129 | staticParams.CompassYawEffect = 128; |
- | |
130 | staticParams.GyroP = 80; |
- | |
131 | staticParams.GyroI = 100; |
- | |
132 | staticParams.LowVoltageWarning = 101; // 3.7 each for 3S |
- | |
133 | staticParams.EmergencyGas = 35; |
- | |
134 | staticParams.EmergencyGasDuration = 30; |
- | |
135 | staticParams.Unused0 = 0; |
- | |
136 | staticParams.IFactor = 32; |
- | |
137 | staticParams.ServoPitchControl = 100; |
- | |
138 | staticParams.ServoPitchComp = 40; |
- | |
139 | staticParams.ServoPitchCompInvert = 0; |
- | |
140 | staticParams.ServoPitchMin = 50; |
- | |
141 | staticParams.ServoPitchMax = 150; |
- | |
142 | staticParams.ServoRefresh = 5; |
- | |
143 | staticParams.LoopGasLimit = 50; |
- | |
144 | staticParams.LoopThreshold = 90; |
- | |
145 | staticParams.LoopHysteresis = 50; |
- | |
146 | staticParams.BitConfig = 0; |
- | |
147 | staticParams.AxisCoupling1 = 90; |
- | |
148 | staticParams.AxisCoupling2 = 67; |
- | |
149 | staticParams.AxisCouplingYawCorrection = 0; |
- | |
150 | staticParams.DynamicStability = 50; |
- | |
151 | staticParams.J16Bitmask = 95; |
- | |
152 | staticParams.J17Bitmask = 243; |
- | |
153 | staticParams.J16Timing = 15; |
- | |
154 | staticParams.J17Timing = 15; |
- | |
155 | staticParams.NaviGpsModeControl = 253; |
- | |
156 | staticParams.NaviGpsGain = 100; |
- | |
157 | staticParams.NaviGpsP = 90; |
- | |
158 | staticParams.NaviGpsI = 90; |
- | |
159 | staticParams.NaviGpsD = 90; |
- | |
160 | staticParams.NaviGpsPLimit = 75; |
- | |
161 | staticParams.NaviGpsILimit = 75; |
- | |
162 | staticParams.NaviGpsDLimit = 75; |
- | |
163 | staticParams.NaviGpsACC = 0; |
- | |
164 | staticParams.NaviGpsMinSat = 6; |
- | |
165 | staticParams.NaviStickThreshold = 8; |
- | |
166 | staticParams.NaviWindCorrection = 90; |
- | |
167 | staticParams.NaviSpeedCompensation = 30; |
- | |
168 | staticParams.NaviOperatingRadius = 100; |
- | |
169 | staticParams.NaviAngleLimitation = 100; |
- | |
170 | staticParams.NaviPHLoginTime = 4; |
- | |
171 | } |
- | |
172 | - | ||
173 | /***************************************************/ |
- | |
174 | /* Default Values for parameter set 1 */ |
- | |
175 | /***************************************************/ |
- | |
176 | void ParamSet_DefaultSet1(void) { // sport |
- | |
177 | setOtherDefaults(); |
- | |
178 | gyro_setDefaults(); |
- | |
179 | setDefaultUserParams(); |
- | |
180 | staticParams.GlobalConfig = CFG_ROTARY_RATE_LIMITER |
- | |
181 | /* | CFG_AXIS_COUPLING_ACTIVE*/; |
- | |
182 | staticParams.EmergencyGasDuration = 200; |
- | |
183 | staticParams.J16Timing = 10; |
- | |
184 | staticParams.J17Timing = 10; |
- | |
185 | memcpy(staticParams.Name, "Sport\0", 6); |
- | |
186 | } |
- | |
187 | - | ||
188 | /***************************************************/ |
- | |
189 | /* Default Values for parameter set 2 */ |
- | |
190 | /***************************************************/ |
- | |
191 | void ParamSet_DefaultSet2(void) { // normal |
- | |
192 | setOtherDefaults(); |
- | |
193 | gyro_setDefaults(); |
- | |
194 | setDefaultUserParams(); |
- | |
195 | staticParams.GlobalConfig = CFG_ROTARY_RATE_LIMITER |
- | |
196 | /* | CFG_AXIS_COUPLING_ACTIVE*/ ; |
- | |
197 | staticParams.Height_Gain = 3; |
- | |
198 | staticParams.EmergencyGasDuration = 200; |
- | |
199 | staticParams.J16Timing = 20; |
- | |
200 | staticParams.J17Timing = 20; |
- | |
201 | memcpy(staticParams.Name, "Normal\0", 7); |
- | |
202 | } |
- | |
203 | - | ||
204 | /***************************************************/ |
- | |
205 | /* Default Values for parameter set 3 */ |
- | |
206 | /***************************************************/ |
- | |
207 | void ParamSet_DefaultSet3(void) { // beginner |
- | |
208 | setOtherDefaults(); |
- | |
209 | gyro_setDefaults(); |
- | |
210 | setDefaultUserParams(); |
- | |
211 | staticParams.GlobalConfig = CFG_ROTARY_RATE_LIMITER |
- | |
212 | /* | CFG_AXIS_COUPLING_ACTIVE */; |
- | |
213 | staticParams.Height_Gain = 3; |
- | |
214 | staticParams.EmergencyGasDuration = 200; |
- | |
215 | staticParams.J16Timing = 30; |
- | |
216 | staticParams.J17Timing = 30; |
70 | |
217 | memcpy(staticParams.Name, "Beginner\0", 9); |
71 | // byte array in eeprom |
218 | } |
72 | uint8_t EEPromArray[E2END + 1] EEMEM; |
219 | 73 | ||
220 | /***************************************************/ |
74 | /***************************************************/ |
221 | /* Read Parameter from EEPROM as byte */ |
75 | /* Read Parameter from EEPROM as byte */ |
Line 222... | Line 76... | ||
222 | /***************************************************/ |
76 | /***************************************************/ |
223 | uint8_t GetParamByte(uint16_t param_id) { |
77 | uint8_t getParamByte(uint16_t param_id) { |
224 | return eeprom_read_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id]); |
78 | return eeprom_read_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id]); |
225 | } |
79 | } |
226 | 80 | ||
227 | /***************************************************/ |
81 | /***************************************************/ |
Line 228... | Line 82... | ||
228 | /* Write Parameter to EEPROM as byte */ |
82 | /* Write Parameter to EEPROM as byte */ |
229 | /***************************************************/ |
83 | /***************************************************/ |
230 | void SetParamByte(uint16_t param_id, uint8_t value) { |
84 | void setParamByte(uint16_t param_id, uint8_t value) { |
231 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value); |
85 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value); |
232 | } |
86 | } |
233 | 87 | ||
234 | /***************************************************/ |
88 | /***************************************************/ |
Line 235... | Line 89... | ||
235 | /* Read Parameter from EEPROM as word */ |
89 | /* Read Parameter from EEPROM as word */ |
236 | /***************************************************/ |
90 | /***************************************************/ |
237 | uint16_t GetParamWord(uint16_t param_id) { |
91 | uint16_t getParamWord(uint16_t param_id) { |
238 | return eeprom_read_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN |
92 | return eeprom_read_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN |
- | 93 | + param_id]); |
|
- | 94 | } |
|
- | 95 | ||
- | 96 | /***************************************************/ |
|
239 | + param_id]); |
97 | /* Write Parameter to EEPROM as word */ |
- | 98 | /***************************************************/ |
|
- | 99 | void setParamWord(uint16_t param_id, uint16_t value) { |
|
- | 100 | eeprom_write_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value); |
|
- | 101 | } |
|
- | 102 | ||
- | 103 | uint8_t calculateChecksum(uint8_t* data, uint16_t length) { |
|
- | 104 | uint8_t result = 0; |
|
- | 105 | for (uint16_t i=0; i<length; i++) { |
|
- | 106 | result += data[i]; |
|
- | 107 | } |
|
- | 108 | return result; |
|
- | 109 | } |
|
- | 110 | ||
- | 111 | void writeChecksummedBlock(uint8_t revisionNumber, uint8_t* data, uint16_t length, uint16_t offset) { |
|
- | 112 | uint8_t checksum = calculateChecksum(data+1, length-1); |
|
- | 113 | data[0] = checksum; |
|
240 | } |
114 | data[1] = revisionNumber; |
241 | 115 | eeprom_write_block(data, &EEPromArray[offset], length); |
|
Line 242... | Line 116... | ||
242 | /***************************************************/ |
116 | } |
243 | /* Write Parameter to EEPROM as word */ |
117 | |
244 | /***************************************************/ |
118 | uint8_t readChecksummedBlock(uint8_t revisionNumber, uint8_t* target, uint16_t length, uint16_t offset) { |
245 | void SetParamWord(uint16_t param_id, uint16_t value) { |
119 | eeprom_read_block(target, &EEPromArray[offset], length); |
246 | eeprom_write_word( |
120 | uint8_t checksum = calculateChecksum(target+1, length-1); |
247 | (uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value); |
121 | return (checksum != target[0] || revisionNumber != target[1]); |
248 | } |
- | |
249 | 122 | } |
|
250 | /***************************************************/ |
123 | |
251 | /* Read Parameter Set from EEPROM */ |
- | |
252 | /***************************************************/ |
- | |
253 | // number [1..5] |
124 | /***************************************************/ |
Line 254... | Line 125... | ||
254 | void ParamSet_ReadFromEEProm(uint8_t setnumber) { |
125 | /* Read Parameter Set from EEPROM */ |
255 | if ((1 > setnumber) || (setnumber > 5)) |
126 | /***************************************************/ |
256 | setnumber = 3; |
127 | // number [1..5] |
257 | eeprom_read_block((uint8_t *) &staticParams.ChannelAssignment[0], |
128 | uint8_t paramSet_readFromEEProm(uint8_t setnumber) { |
258 | &EEPromArray[EEPROM_ADR_PARAMSET_BEGIN + PARAMSET_STRUCT_LEN * (setnumber |
129 | uint16_t offset = EEPROM_ADR_PARAMSET_BEGIN + (setnumber-1)*sizeof(paramset_t); |
- | 130 | output_init(); // what's that doing here?? |
|
- | 131 | return readChecksummedBlock(EEPARAM_REVISION, (uint8_t*)&staticParams, sizeof(paramset_t), offset); |
|
- | 132 | } |
|
259 | - 1)], PARAMSET_STRUCT_LEN); |
133 | |
- | 134 | /***************************************************/ |
|
- | 135 | /* Write Parameter Set to EEPROM */ |
|
- | 136 | /***************************************************/ |
|
260 | output_init(); |
137 | // number [1..5] |
261 | } |
138 | void paramSet_writeToEEProm(uint8_t setnumber) { |
262 | 139 | uint16_t offset = EEPROM_ADR_PARAMSET_BEGIN + (setnumber-1)*sizeof(paramset_t); |
|
263 | /***************************************************/ |
140 | writeChecksummedBlock(EEPARAM_REVISION, (uint8_t*)&staticParams, sizeof(paramset_t), offset); |
- | 141 | // set this parameter set to active set |
|
- | 142 | setActiveParamSet(setnumber); |
|
- | 143 | output_init(); // what's that doing here?? |
|
264 | /* Write Parameter Set to EEPROM */ |
144 | } |
265 | /***************************************************/ |
145 | |
- | 146 | void paramSet_readOrDefault() { |
|
266 | // number [1..5] |
147 | uint8_t setnumber = getActiveParamSet(); |
267 | void ParamSet_WriteToEEProm(uint8_t setnumber) { |
148 | // parameter version check |
- | 149 | if (setnumber<1 ||setnumber>5 || paramSet_readFromEEProm(setnumber)) { |
|
- | 150 | // if version check faild |
|
268 | if (setnumber > 5) |
151 | printf("\n\rInit Parameter in EEPROM"); |
- | 152 | for (uint8_t i=6; i>0; i--) { |
|
- | 153 | paramSet_default(i); // Fill staticParams Structure to default parameter set 1 (Sport) |
|
- | 154 | paramSet_writeToEEProm(i); |
|
- | 155 | } |
|
- | 156 | // default-Setting is parameter set 3 |
|
- | 157 | setActiveParamSet(1); |
|
- | 158 | } |
|
- | 159 | ||
- | 160 | printf("\n\rUsing Parameter Set %d", getActiveParamSet()); |
|
- | 161 | } |
|
269 | setnumber = 5; |
162 | |
- | 163 | /***************************************************/ |
|
- | 164 | /* MixerTable */ |
|
- | 165 | /***************************************************/ |
|
- | 166 | uint8_t mixerMatrix_readFromEEProm(void) { |
|
- | 167 | return readChecksummedBlock(EEMIXER_REVISION, (uint8_t*)&mixerMatrix, EEPROM_ADR_MIXER_TABLE, sizeof(mixerMatrix_t)); |
|
270 | if (setnumber < 1) |
168 | } |
- | 169 | ||
- | 170 | void mixerMatrix_writeToEEProm(void) { |
|
- | 171 | writeChecksummedBlock(EEMIXER_REVISION, (uint8_t*)&mixerMatrix, EEPROM_ADR_MIXER_TABLE, sizeof(mixerMatrix_t)); |
|
271 | return; |
172 | } |
272 | eeprom_write_block((uint8_t *) &staticParams.ChannelAssignment[0], |
173 | |
- | 174 | void mixerMatrix_readOrDefault(void) { |
|
- | 175 | // load mixer table |
|
- | 176 | if (mixerMatrix_readFromEEProm()) { |
|
- | 177 | printf("\n\rGenerating default mixerMatrix"); |
|
- | 178 | mixerMatrix_default(); // Quadro |
|
- | 179 | mixerMatrix_writeToEEProm(); |
|
- | 180 | } |
|
- | 181 | // determine motornumber |
|
- | 182 | requiredMotors = 0; |
|
- | 183 | for (uint8_t i=0; i<MAX_MOTORS; i++) { |
|
- | 184 | if (mixerMatrix.motor[i][MIX_THROTTLE]) |
|
- | 185 | requiredMotors++; |
|
- | 186 | } |
|
- | 187 | ||
- | 188 | printf("\n\rMixer-Config: '%s' (%u Motors)",mixerMatrix.name, requiredMotors); |
|
- | 189 | printf("\n\r=============================="); |
|
- | 190 | } |
|
- | 191 | ||
273 | &EEPromArray[EEPROM_ADR_PARAMSET_BEGIN + PARAMSET_STRUCT_LEN * (setnumber |
192 | /***************************************************/ |
Line -... | Line 193... | ||
- | 193 | /* ChannelMap */ |
|
- | 194 | /***************************************************/ |
|
- | 195 | uint8_t channelMap_readFromEEProm(void) { |
|
- | 196 | return readChecksummedBlock(CHANNELMAP_REVISION, (uint8_t*)&channelMap, EEPROM_ADR_CHANNELMAP, sizeof(channelMap_t)); |
|
- | 197 | } |
|
- | 198 | ||
- | 199 | void channelMap_writeToEEProm(void) { |
|
- | 200 | writeChecksummedBlock(CHANNELMAP_REVISION, (uint8_t*)&channelMap, EEPROM_ADR_CHANNELMAP, sizeof(channelMap_t)); |
|
- | 201 | } |
|
- | 202 | ||
- | 203 | void channelMap_readOrDefault(void) { |
|
- | 204 | if (!channelMap_readFromEEProm()) { |
|
- | 205 | printf("\n\rGenerating default channel map"); |
|
- | 206 | channelMap_default(); |
|
- | 207 | channelMap_writeToEEProm(); |
|
- | 208 | } |
|
- | 209 | } |
|
274 | - 1)], PARAMSET_STRUCT_LEN); |
210 | |
275 | eeprom_write_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAMSET_LENGTH], |
211 | uint8_t accOffset_readFromEEProm(void) { |
276 | PARAMSET_STRUCT_LEN); |
212 | return readChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&accOffset, EEPROM_ADR_ACCOFFSET, sizeof(sensorOffset_t)); |
277 | eeprom_write_block(&staticParams.ChannelAssignment[0], |
213 | } |
278 | &EEPromArray[EEPROM_ADR_CHANNELS], 8); // backup the first 8 bytes that is the rc channel mapping |
214 | |
279 | // set this parameter set to active set |
215 | void accOffset_writeToEEProm(void) { |
280 | setActiveParamSet(setnumber); |
216 | writeChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&accOffset, EEPROM_ADR_ACCOFFSET, sizeof(sensorOffset_t)); |
281 | output_init(); |
217 | } |
282 | } |
- | |
283 | 218 | ||
284 | /***************************************************/ |
219 | |
285 | /* Get active parameter set */ |
220 | /***************************************************/ |
Line 286... | Line 221... | ||
286 | /***************************************************/ |
221 | /* Get active parameter set */ |
287 | uint8_t getActiveParamSet(void) { |
222 | /***************************************************/ |
288 | uint8_t setnumber; |
223 | uint8_t getActiveParamSet(void) { |
289 | setnumber = eeprom_read_byte(&EEPromArray[PID_ACTIVE_SET]); |
224 | uint8_t setnumber; |
290 | if (setnumber > 5) { |
- | |
291 | setnumber = 3; |
- | |
292 | eeprom_write_byte(&EEPromArray[PID_ACTIVE_SET], setnumber); |
- | |
293 | } |
- | |
294 | return (setnumber); |
225 | setnumber = eeprom_read_byte(&EEPromArray[PID_ACTIVE_SET]); |
295 | } |
- | |
296 | - | ||
297 | /***************************************************/ |
- | |
298 | /* Set active parameter set */ |
- | |
299 | /***************************************************/ |
- | |
300 | void setActiveParamSet(uint8_t setnumber) { |
- | |
301 | if (setnumber > 5) |
- | |
302 | setnumber = 5; |
- | |
303 | if (setnumber < 1) |
- | |
304 | setnumber = 1; |
- | |
305 | eeprom_write_byte(&EEPromArray[PID_ACTIVE_SET], setnumber); |
- | |
306 | } |
- | |
307 | - | ||
308 | /***************************************************/ |
- | |
309 | /* Read MixerTable from EEPROM */ |
- | |
310 | /***************************************************/ |
- | |
311 | uint8_t MixerTable_ReadFromEEProm(void) { |
- | |
312 | if (eeprom_read_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE]) |
- | |
313 | == EEMIXER_REVISION) { |
- | |
314 | eeprom_read_block((uint8_t *) &Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], |
- | |
315 | sizeof(Mixer)); |
- | |
316 | return 1; |
- | |
317 | } else |
- | |
318 | return 0; |
- | |
319 | } |
- | |
320 | - | ||
321 | /***************************************************/ |
- | |
322 | /* Write Mixer Table to EEPROM */ |
- | |
323 | /***************************************************/ |
- | |
324 | uint8_t MixerTable_WriteToEEProm(void) { |
- | |
325 | if (Mixer.Revision == EEMIXER_REVISION) { |
- | |
326 | eeprom_write_block((uint8_t *) &Mixer, |
- | |
327 | &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
- | |
328 | return 1; |
- | |
329 | } else |
- | |
330 | return 0; |
- | |
331 | } |
- | |
332 | - | ||
333 | /***************************************************/ |
- | |
334 | /* Default Values for Mixer Table */ |
- | |
335 | /***************************************************/ |
- | |
336 | void MixerTable_Default(void) { // Quadro |
- | |
337 | uint8_t i; |
- | |
338 | Mixer.Revision = EEMIXER_REVISION; |
- | |
339 | // clear mixer table (but preset throttle) |
- | |
340 | for (i = 0; i < 16; i++) { |
- | |
341 | Mixer.Motor[i][MIX_THROTTLE] = i < 4 ? 64 : 0; |
- | |
342 | Mixer.Motor[i][MIX_PITCH] = 0; |
- | |
343 | Mixer.Motor[i][MIX_ROLL] = 0; |
- | |
344 | Mixer.Motor[i][MIX_YAW] = 0; |
- | |
345 | } |
- | |
346 | // default = Quadro |
- | |
347 | Mixer.Motor[0][MIX_PITCH] = +64; |
- | |
348 | Mixer.Motor[0][MIX_YAW] = +64; |
- | |
349 | Mixer.Motor[1][MIX_PITCH] = -64; |
- | |
350 | Mixer.Motor[1][MIX_YAW] = +64; |
- | |
351 | Mixer.Motor[2][MIX_ROLL] = -64; |
- | |
352 | Mixer.Motor[2][MIX_YAW] = -64; |
- | |
353 | Mixer.Motor[3][MIX_ROLL] = +64; |
- | |
354 | Mixer.Motor[3][MIX_YAW] = -64; |
- | |
355 | memcpy(Mixer.Name, "Quadro\0", 7); |
- | |
356 | } |
- | |
357 | - | ||
358 | /***************************************************/ |
- | |
359 | /* Initialize EEPROM Parameter Sets */ |
- | |
360 | /***************************************************/ |
- | |
361 | void ParamSet_Init(void) { |
- | |
362 | uint8_t Channel_Backup = 1, i, j; |
- | |
363 | // parameter version check |
- | |
364 | if (eeprom_read_byte(&EEPromArray[PID_PARAM_REVISION]) != EEPARAM_REVISION) { |
- | |
365 | // if version check faild |
- | |
366 | printf("\n\rInit Parameter in EEPROM"); |
- | |
367 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE], 0xFF); // reset also mixer table |
- | |
368 | // check if channel mapping backup is valid |
- | |
369 | for (j = 0; j < 4 && Channel_Backup; j++) { |
- | |
370 | if (eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS + 0]) >= 12) |
- | |
371 | Channel_Backup = 0; |
- | |
372 | } |
- | |
373 | // fill all 5 parameter settings |
- | |
374 | for (i = 1; i < 6; i++) { |
- | |
375 | switch (i) { |
- | |
376 | case 1: |
- | |
377 | ParamSet_DefaultSet1(); // Fill staticParams Structure to default parameter set 1 (Sport) |
- | |
378 | break; |
- | |
379 | case 2: |
- | |
380 | ParamSet_DefaultSet2(); // Kamera |
- | |
381 | break; |
- | |
382 | case 3: |
- | |
383 | ParamSet_DefaultSet3(); // Beginner |
- | |
384 | break; |
- | |
385 | default: |
- | |
386 | ParamSet_DefaultSet2(); // Kamera |
- | |
387 | break; |
- | |
388 | } |
- | |
389 | if (Channel_Backup) { // if we have a rc channel mapping backup in eeprom |
- | |
390 | // restore it |
- | |
391 | for (j = 0; j < 8; j++) { |
- | |
392 | staticParams.ChannelAssignment[j] = eeprom_read_byte( |
- | |
393 | &EEPromArray[EEPROM_ADR_CHANNELS + j]); |
- | |
394 | } |
- | |
395 | } |
- | |
396 | ParamSet_WriteToEEProm(i); |
- | |
397 | } |
- | |
398 | // default-Setting is parameter set 3 |
- | |
399 | setActiveParamSet(1); |
- | |
400 | // update version info |
- | |
401 | SetParamByte(PID_PARAM_REVISION, EEPARAM_REVISION); |
- | |
402 | } |
- | |
403 | // read active parameter set to staticParams stucture |
- | |
404 | ParamSet_ReadFromEEProm(getActiveParamSet()); |
- | |
405 | printf("\n\rUsing Parameter Set %d", getActiveParamSet()); |
- | |
406 | - | ||
407 | // load mixer table |
- | |
408 | if (!MixerTable_ReadFromEEProm()) { |
- | |
409 | printf("\n\rGenerating default Mixer Table"); |
- | |
410 | MixerTable_Default(); // Quadro |
- | |
411 | MixerTable_WriteToEEProm(); |
226 | if (setnumber > 4) { |
- | 227 | setActiveParamSet(setnumber = 0); |