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