Rev 1910 | Rev 2099 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1910 | Rev 1927 | ||
---|---|---|---|
Line 30... | Line 30... | ||
30 | * Default for your own experiments here, so you don't have to reset them |
30 | * Default for your own experiments here, so you don't have to reset them |
31 | * from MK-Tool all the time. |
31 | * from MK-Tool all the time. |
32 | */ |
32 | */ |
33 | void setDefaultUserParams(void) { |
33 | void setDefaultUserParams(void) { |
34 | uint8_t i; |
34 | uint8_t i; |
35 | for (i = 0; i < sizeof(staticParams.UserParams1); i++) { |
35 | for (i = 0; i < sizeof(staticParams.UserParams); i++) { |
36 | staticParams.UserParams1[i] = 0; |
- | |
37 | } |
- | |
38 | for (i = 0; i < sizeof(staticParams.UserParams2); i++) { |
- | |
39 | staticParams.UserParams2[i] = 0; |
36 | staticParams.UserParams[i] = 0; |
40 | } |
37 | } |
41 | /* |
38 | /* |
42 | * While we are still using userparams for flight parameters, do set |
39 | * While we are still using userparams for flight parameters, do set |
43 | * some safe & meaningful default values. |
40 | * some safe & meaningful default values. |
44 | */ |
41 | */ |
45 | staticParams.UserParams2[0] = 0xd5; //0b11010101; // All gyro filter constants 2; acc. 4 |
- | |
46 | staticParams.UserParams2[1] = 0; // H&I motor smoothing. |
- | |
47 | staticParams.UserParams2[2] = 120; // Yaw I factor |
- | |
48 | staticParams.UserParams2[3] = 100; // Max Z acceleration for acc. correction of angles. |
- | |
49 | } |
42 | } |
Line 50... | Line 43... | ||
50 | 43 | ||
51 | void setOtherDefaults(void) { |
44 | void setOtherDefaults(void) { |
52 | /* Channel assignments were changed to the normal: |
45 | /* Channel assignments were changed to the normal: |
Line 80... | Line 73... | ||
80 | staticParams.StickElevatorP = 10; |
73 | staticParams.StickElevatorP = 10; |
81 | staticParams.StickAileronsP = 10; |
74 | staticParams.StickAileronsP = 10; |
82 | staticParams.StickRudderP = 10; |
75 | staticParams.StickRudderP = 10; |
Line 83... | Line 76... | ||
83 | 76 | ||
84 | staticParams.LowVoltageWarning = 105; |
- | |
85 | staticParams.IFactor = 32; |
77 | staticParams.LowVoltageWarning = 105; |
86 | staticParams.ServoRefresh = 7; |
78 | staticParams.ServoRefresh = 7; |
87 | staticParams.BitConfig = 0; |
79 | staticParams.BitConfig = 0; |
88 | staticParams.J16Bitmask = 95; |
80 | staticParams.J16Bitmask = 95; |
89 | staticParams.J17Bitmask = 243; |
81 | staticParams.J17Bitmask = 243; |
90 | staticParams.J16Timing = 15; |
82 | staticParams.J16Timing = 15; |
91 | staticParams.J17Timing = 15; |
- | |
92 | 83 | staticParams.J17Timing = 15; |
|
93 | staticParams.ControlSigns = 2; |
84 | staticParams.ControlSigns = 2; |
Line 94... | Line -... | ||
94 | } |
- | |
95 | - | ||
96 | /***************************************************/ |
- | |
97 | /* Default Values for parameter set 1 */ |
85 | } |
98 | /***************************************************/ |
86 | |
99 | void ParamSet_DefaultSet1(void) { // sport |
87 | void setDefaults(void) { |
100 | setOtherDefaults(); |
88 | setOtherDefaults(); |
101 | gyro_setDefaults(); |
89 | gyro_setDefaults(); |
102 | setDefaultUserParams(); |
90 | setDefaultUserParams(); |
103 | staticParams.J16Timing = 10; |
- | |
104 | staticParams.J17Timing = 10; |
- | |
105 | memcpy(staticParams.Name, "Sport\0", 6); |
- | |
106 | } |
- | |
107 | - | ||
108 | /***************************************************/ |
- | |
109 | /* Default Values for parameter set 2 */ |
- | |
110 | /***************************************************/ |
- | |
111 | void ParamSet_DefaultSet2(void) { // normal |
- | |
112 | setOtherDefaults(); |
- | |
113 | gyro_setDefaults(); |
- | |
114 | setDefaultUserParams(); |
- | |
115 | staticParams.Height_Gain = 3; |
- | |
116 | staticParams.J16Timing = 20; |
- | |
117 | staticParams.J17Timing = 20; |
- | |
118 | memcpy(staticParams.Name, "Normal\0", 7); |
- | |
119 | } |
- | |
120 | - | ||
121 | /***************************************************/ |
- | |
122 | /* Default Values for parameter set 3 */ |
- | |
123 | /***************************************************/ |
- | |
124 | void ParamSet_DefaultSet3(void) { // beginner |
- | |
125 | setOtherDefaults(); |
- | |
126 | gyro_setDefaults(); |
- | |
127 | setDefaultUserParams(); |
- | |
128 | staticParams.Height_Gain = 3; |
- | |
129 | staticParams.J16Timing = 30; |
- | |
130 | staticParams.J17Timing = 30; |
91 | staticParams.J16Timing = 10; |
Line 131... | Line 92... | ||
131 | memcpy(staticParams.Name, "Beginner\0", 9); |
92 | staticParams.J17Timing = 10; |
132 | } |
93 | } |
133 | 94 | ||
Line 163... | Line 124... | ||
163 | 124 | ||
164 | /***************************************************/ |
125 | /***************************************************/ |
165 | /* Read Parameter Set from EEPROM */ |
126 | /* Read Parameter Set from EEPROM */ |
166 | /***************************************************/ |
127 | /***************************************************/ |
167 | // number [1..5] |
128 | // number [1..5] |
168 | void ParamSet_ReadFromEEProm(uint8_t setnumber) { |
- | |
169 | if ((1 > setnumber) || (setnumber > 5)) |
- | |
170 | setnumber = 3; |
129 | void ParamSet_ReadFromEEProm() { |
171 | eeprom_read_block((uint8_t *) &staticParams.ChannelAssignment[0], |
130 | eeprom_read_block((uint8_t *) &staticParams.ChannelAssignment[0], |
172 | &EEPromArray[EEPROM_ADR_PARAMSET_BEGIN + PARAMSET_STRUCT_LEN * (setnumber |
- | |
173 | - 1)], PARAMSET_STRUCT_LEN); |
131 | &EEPromArray[EEPROM_ADR_PARAMSET_BEGIN], PARAMSET_STRUCT_LEN); |
174 | output_init(); |
132 | output_init(); |
Line 175... | Line 133... | ||
175 | } |
133 | } |
176 | 134 | ||
177 | /***************************************************/ |
135 | /***************************************************/ |
178 | /* Write Parameter Set to EEPROM */ |
136 | /* Write Parameter Set to EEPROM */ |
179 | /***************************************************/ |
137 | /***************************************************/ |
180 | // number [1..5] |
- | |
181 | void ParamSet_WriteToEEProm(uint8_t setnumber) { |
- | |
182 | if (setnumber > 5) |
- | |
183 | setnumber = 5; |
- | |
184 | if (setnumber < 1) |
138 | // number [1..5] |
185 | return; |
139 | void ParamSet_WriteToEEProm() { |
186 | eeprom_write_block((uint8_t *) &staticParams.ChannelAssignment[0], |
- | |
187 | &EEPromArray[EEPROM_ADR_PARAMSET_BEGIN + PARAMSET_STRUCT_LEN * (setnumber |
140 | eeprom_write_block((uint8_t *) &staticParams.ChannelAssignment[0], |
188 | - 1)], PARAMSET_STRUCT_LEN); |
141 | &EEPromArray[EEPROM_ADR_PARAMSET_BEGIN], PARAMSET_STRUCT_LEN); |
189 | eeprom_write_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAMSET_LENGTH], |
142 | eeprom_write_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAMSET_LENGTH], |
190 | PARAMSET_STRUCT_LEN); |
143 | PARAMSET_STRUCT_LEN); |
191 | eeprom_write_block(&staticParams.ChannelAssignment[0], |
144 | eeprom_write_block(&staticParams.ChannelAssignment[0], |
192 | &EEPromArray[EEPROM_ADR_CHANNELS], 8); // backup the first 8 bytes that is the rc channel mapping |
- | |
193 | // set this parameter set to active set |
145 | &EEPromArray[EEPROM_ADR_CHANNELS], 8); // backup the first 8 bytes that is the rc channel mapping |
194 | setActiveParamSet(setnumber); |
146 | // set this parameter set to active set |
Line 195... | Line 147... | ||
195 | output_init(); |
147 | output_init(); |
196 | } |
148 | } |
Line 207... | Line 159... | ||
207 | } |
159 | } |
208 | return (setnumber); |
160 | return (setnumber); |
209 | } |
161 | } |
Line 210... | Line 162... | ||
210 | 162 | ||
211 | /***************************************************/ |
- | |
212 | /* Set active parameter set */ |
- | |
213 | /***************************************************/ |
- | |
214 | void setActiveParamSet(uint8_t setnumber) { |
- | |
215 | if (setnumber > 5) |
- | |
216 | setnumber = 5; |
- | |
217 | if (setnumber < 1) |
- | |
218 | setnumber = 1; |
- | |
219 | eeprom_write_byte(&EEPromArray[PID_ACTIVE_SET], setnumber); |
- | |
220 | } |
- | |
221 | - | ||
222 | /***************************************************/ |
163 | /***************************************************/ |
223 | /* Read MixerTable from EEPROM */ |
164 | /* Read MixerTable from EEPROM */ |
224 | /***************************************************/ |
165 | /***************************************************/ |
225 | uint8_t MixerTable_ReadFromEEProm(void) { |
166 | uint8_t MixerTable_ReadFromEEProm(void) { |
226 | if (eeprom_read_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE]) |
167 | if (eeprom_read_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE]) |
Line 271... | Line 212... | ||
271 | 212 | ||
272 | /***************************************************/ |
213 | /***************************************************/ |
273 | /* Initialize EEPROM Parameter Sets */ |
214 | /* Initialize EEPROM Parameter Sets */ |
274 | /***************************************************/ |
215 | /***************************************************/ |
275 | void ParamSet_Init(void) { |
216 | void ParamSet_Init(void) { |
276 | uint8_t Channel_Backup = 1, i, j; |
217 | uint8_t Channel_Backup = 1, j; |
277 | // parameter version check |
218 | // parameter version check |
278 | if (eeprom_read_byte(&EEPromArray[PID_PARAM_REVISION]) != EEPARAM_REVISION) { |
219 | if (eeprom_read_byte(&EEPromArray[PID_PARAM_REVISION]) != EEPARAM_REVISION) { |
279 | // if version check faild |
220 | // if version check faild |
280 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE], 0xFF); // reset also mixer table |
221 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE], 0xFF); // reset also mixer table |
281 | // check if channel mapping backup is valid |
222 | // check if channel mapping backup is valid |
282 | for (j = 0; j < 4 && Channel_Backup; j++) { |
223 | for (j = 0; j < 4 && Channel_Backup; j++) { |
283 | if (eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS + 0]) >= 12) |
224 | if (eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS + 0]) >= 12) |
284 | Channel_Backup = 0; |
225 | Channel_Backup = 0; |
285 | } |
226 | } |
286 | // fill all 5 parameter settings |
- | |
287 | for (i = 1; i < 6; i++) { |
- | |
288 | switch (i) { |
227 | // fill all 5 parameter settings |
289 | case 1: |
228 | |
290 | ParamSet_DefaultSet1(); // Fill staticParams Structure to default parameter set 1 (Sport) |
- | |
291 | break; |
- | |
292 | case 2: |
- | |
293 | ParamSet_DefaultSet2(); // Kamera |
- | |
294 | break; |
- | |
295 | case 3: |
- | |
296 | ParamSet_DefaultSet3(); // Beginner |
- | |
297 | break; |
- | |
298 | default: |
- | |
299 | ParamSet_DefaultSet2(); // Kamera |
- | |
300 | break; |
229 | setDefaults(); // Fill staticParams Structure to default parameter set 1 (Sport) |
301 | } |
230 | |
302 | if (Channel_Backup) { // if we have a rc channel mapping backup in eeprom |
231 | if (Channel_Backup) { // if we have a rc channel mapping backup in eeprom |
303 | // restore it |
232 | // restore it |
304 | for (j = 0; j < 8; j++) { |
233 | for (j = 0; j < 8; j++) { |
305 | staticParams.ChannelAssignment[j] = eeprom_read_byte( |
234 | staticParams.ChannelAssignment[j] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS + j]); |
306 | &EEPromArray[EEPROM_ADR_CHANNELS + j]); |
235 | } |
307 | } |
236 | } |
308 | } |
237 | |
309 | ParamSet_WriteToEEProm(i); |
238 | ParamSet_WriteToEEProm(); |
310 | } |
- | |
311 | // default-Setting is parameter set 3 |
- | |
312 | setActiveParamSet(1); |
239 | |
313 | // update version info |
240 | // update version info |
314 | SetParamByte(PID_PARAM_REVISION, EEPARAM_REVISION); |
241 | SetParamByte(PID_PARAM_REVISION, EEPARAM_REVISION); |
315 | } |
242 | } |
316 | // read active parameter set to staticParams stucture |
243 | // read active parameter set to staticParams stucture |
317 | ParamSet_ReadFromEEProm(getActiveParamSet()); |
244 | ParamSet_ReadFromEEProm(); |