Subversion Repositories FlightCtrl

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1538 killagreg 1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
// + Copyright (c) Holger Buss, Ingo Busker
3
// + Nur für den privaten Gebrauch
4
// + porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
5
// + www.MikroKopter.com
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
8
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
9
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
10
// + bzgl. der Nutzungsbedingungen aufzunehmen.
11
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
12
// + Verkauf von Luftbildaufnahmen, usw.
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
15
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
17
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
18
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
19
// + eindeutig als Ursprung verlinkt werden
20
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
22
// + Benutzung auf eigene Gefahr
23
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
24
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
25
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
26
// + mit unserer Zustimmung zulässig
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
29
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
31
// + this list of conditions and the following disclaimer.
32
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
33
// +     from this software without specific prior written permission.
34
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
35
// +     for non-commercial use (directly or indirectly)
36
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
37
// +     with our written permission
38
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
39
// +     clearly linked as origin
40
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
41
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
42
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
45
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
46
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
47
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
48
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
50
// +  POSSIBILITY OF SUCH DAMAGE.
51
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
52
 
53
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
54
// + Contant Values
55
// + 0-250 -> normale Values
56
// + 251 -> Poti1
57
// + 252 -> Poti2
58
// + 253 -> Poti3
59
// + 254 -> Poti4
60
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
61
 
62
#ifndef EEMEM
63
#define EEMEM __attribute__ ((section (".eeprom")))
64
#endif
65
 
66
 
67
#include <avr/eeprom.h>
68
#include <string.h>
69
#include "eeprom.h"
70
#include "printf_P.h"
71
#include "led.h"
72
#include "main.h"
73
#include "fc.h"
74
 
75
 
76
// byte array in eeprom
77
uint8_t EEPromArray[E2END+1] EEMEM;
78
 
79
paramset_t              ParamSet;
80
MixerTable_t    Mixer;
81
 
82
 
83
/***************************************************/
84
/*    Default Values for parameter set 1           */
85
/***************************************************/
86
void ParamSet_DefaultSet1(void) // sport
87
{
88
        if(BoardRelease >= 20)
89
        {
90
                ParamSet.GyroD = 5;
91
                ParamSet.DriftComp = 0;
92
                ParamSet.GyroAccFactor = 27;
93
                ParamSet.AngleTurnOverNick = 78;
94
                ParamSet.AngleTurnOverRoll = 78;
95
        }
96
        else
97
        {
98
                ParamSet.GyroD = 3;
99
                ParamSet.DriftComp = 32;
100
                ParamSet.GyroAccFactor = 30;
101
                ParamSet.AngleTurnOverNick = 85;
102
                ParamSet.AngleTurnOverRoll = 85;
103
        }
104
        ParamSet.ChannelAssignment[CH_GAS]       = 1;
105
        ParamSet.ChannelAssignment[CH_ROLL]  = 2;
106
        ParamSet.ChannelAssignment[CH_NICK]  = 3;
107
        ParamSet.ChannelAssignment[CH_YAW]   = 4;
108
        ParamSet.ChannelAssignment[CH_POTI1] = 5;
109
        ParamSet.ChannelAssignment[CH_POTI2] = 6;
110
        ParamSet.ChannelAssignment[CH_POTI3] = 7;
111
        ParamSet.ChannelAssignment[CH_POTI4] = 8;
112
        ParamSet.Config0 = CFG0_AXIS_COUPLING_ACTIVE | CFG0_COMPASS_ACTIVE | CFG0_GPS_ACTIVE | CFG0_HEIGHT_SWITCH;//CFG0_HEIGHT_CONTROL | CFG0_COMPASS_FIX;
113
        ParamSet.Config1 = 0;
114
        ParamSet.Config2 = CFG2_HEIGHT_LIMIT;//|CFG2_SENSITIVE_RC;
115
        ParamSet.HeightMinGas = 30;
116
        ParamSet.MaxHeight     = 251;
117
        ParamSet.HeightP      = 10;
118
        ParamSet.HeightD  = 30;
119
        ParamSet.Height_ACC_Effect = 30;
120
        ParamSet.Height_HoverBand = 5;
121
        ParamSet.Height_GPS_Z = 64;
122
        ParamSet.Height_StickNeutralPoint = 0; // Value : 0-250 (0 = Hoover-Estimation)
123
        ParamSet.Height_Gain = 20;
124
        ParamSet.StickP = 14;
125
        ParamSet.StickD = 16;
126
        ParamSet.StickYawP = 12;
127
        ParamSet.GasMin = 8;
128
        ParamSet.GasMax = 230;
129
        ParamSet.CompassYawEffect = 128;
130
        ParamSet.GyroP = 80;
131
        ParamSet.GyroI = 150;
132
        ParamSet.GyroYawP = 80;
133
        ParamSet.GyroYawI = 150;
134
        ParamSet.LowVoltageWarning = 33;  // automatic cell detection for values < 50
135
        ParamSet.EmergencyGas = 35;
136
        ParamSet.EmergencyGasDuration = 30;
137
        ParamSet.UfoArrangement = 0;
138
        ParamSet.IFactor = 32;
139
        ParamSet.UserParam1 = 0;
140
        ParamSet.UserParam2 = 0;
141
        ParamSet.UserParam3 = 0;
142
        ParamSet.UserParam4 = 0;
143
        ParamSet.UserParam5 = 0;
144
        ParamSet.UserParam6 = 0;
145
        ParamSet.UserParam7 = 0;
146
        ParamSet.UserParam8 = 0;
147
        ParamSet.ServoCompInvert = 1;
148
        ParamSet.ServoRefresh = 6;
149
        ParamSet.ServoNickControl = 100;
150
        ParamSet.ServoNickComp = 40;
151
        ParamSet.ServoNickMin = 0;
152
        ParamSet.ServoNickMax = 250;
153
        ParamSet.ServoRollControl = 100;
154
        ParamSet.ServoRollComp = 40;
155
        ParamSet.ServoRollMin = 0;
156
        ParamSet.ServoRollMax = 250;
157
        ParamSet.LoopGasLimit = 50;
158
        ParamSet.LoopThreshold = 90;
159
        ParamSet.LoopHysteresis = 50;
160
        ParamSet.AxisCoupling1 = 90;
161
        ParamSet.AxisCoupling2 = 80;
162
        ParamSet.AxisCouplingYawCorrection = 1;
163
        ParamSet.GyroAccTrim = 16;
164
        ParamSet.DynamicStability = 100;
165
        ParamSet.J16Bitmask = 95;
166
        ParamSet.J17Bitmask = 243;
167
        ParamSet.J16Bitmask_Warning = 0xAA;
168
        ParamSet.J17Bitmask_Warning = 0xAA;
169
        ParamSet.J16Timing = 15;
170
        ParamSet.J17Timing = 15;
171
        ParamSet.NaviGpsModeControl = 252;
172
        ParamSet.NaviGpsGain = 100;
173
        ParamSet.NaviGpsP = 90;
174
        ParamSet.NaviGpsI = 90;
175
        ParamSet.NaviGpsD = 90;
176
        ParamSet.NaviGpsPLimit = 75;
177
        ParamSet.NaviGpsILimit = 75;
178
        ParamSet.NaviGpsDLimit = 75;
179
        ParamSet.NaviGpsACC = 0;
180
        ParamSet.NaviGpsMinSat = 6;
181
        ParamSet.NaviStickThreshold = 8;
182
        ParamSet.NaviWindCorrection = 90;
183
        ParamSet.NaviSpeedCompensation = 30;
184
        ParamSet.NaviOperatingRadius = 100;
185
        ParamSet.NaviAngleLimitation = 100;
186
        ParamSet.NaviPHLoginTime = 4;
187
        memcpy(ParamSet.Name, "Sport\0",6);
188
}
189
 
190
 
191
/***************************************************/
192
/*    Default Values for parameter set 2           */
193
/***************************************************/
194
void ParamSet_DefaultSet2(void) // normal
195
{
196
        if(BoardRelease >= 20)
197
        {
198
                ParamSet.GyroD = 5;
199
                ParamSet.DriftComp = 0;
200
                ParamSet.GyroAccFactor = 27;
201
                ParamSet.AngleTurnOverNick = 78;
202
                ParamSet.AngleTurnOverRoll = 78;
203
        }
204
        else
205
        {
206
                ParamSet.GyroD = 3;
207
                ParamSet.DriftComp = 32;
208
                ParamSet.GyroAccFactor = 30;
209
                ParamSet.AngleTurnOverNick = 85;
210
                ParamSet.AngleTurnOverRoll = 85;
211
        }
212
        ParamSet.ChannelAssignment[CH_GAS]   = 1;
213
        ParamSet.ChannelAssignment[CH_ROLL]  = 2;
214
        ParamSet.ChannelAssignment[CH_NICK]  = 3;
215
        ParamSet.ChannelAssignment[CH_YAW]   = 4;
216
        ParamSet.ChannelAssignment[CH_POTI1] = 5;
217
        ParamSet.ChannelAssignment[CH_POTI2] = 6;
218
        ParamSet.ChannelAssignment[CH_POTI3] = 7;
219
        ParamSet.ChannelAssignment[CH_POTI4] = 8;
220
        ParamSet.Config0 = CFG0_AXIS_COUPLING_ACTIVE | CFG0_COMPASS_ACTIVE | CFG0_GPS_ACTIVE | CFG0_HEIGHT_SWITCH;//CFG0_HEIGHT_CONTROL | CFG0_COMPASS_FIX;
221
        ParamSet.Config1 = 0;
222
        ParamSet.Config2 = CFG2_HEIGHT_LIMIT;//|CFG2_SENSITIVE_RC;
223
        ParamSet.HeightMinGas = 30;
224
        ParamSet.MaxHeight     = 251;
225
        ParamSet.HeightP      = 10;
226
        ParamSet.HeightD  = 30;
227
        ParamSet.Height_ACC_Effect = 30;
228
        ParamSet.Height_HoverBand = 5;
229
        ParamSet.Height_GPS_Z = 64;
230
        ParamSet.Height_StickNeutralPoint = 0; // Value : 0-250 (0 = Hoover-Estimation)
231
        ParamSet.Height_Gain = 15;
232
        ParamSet.StickP = 10;
233
        ParamSet.StickD = 16;
234
        ParamSet.StickYawP = 6;
235
        ParamSet.GasMin = 8;
236
        ParamSet.GasMax = 230;
237
        ParamSet.CompassYawEffect = 128;
238
        ParamSet.GyroP = 90;
239
        ParamSet.GyroI = 120;
240
        ParamSet.GyroYawP = 90;
241
        ParamSet.GyroYawI = 120;
242
        ParamSet.LowVoltageWarning = 33; // auto cell detection for values < 50
243
        ParamSet.EmergencyGas = 35;
244
        ParamSet.EmergencyGasDuration = 30;
245
        ParamSet.UfoArrangement = 0;
246
        ParamSet.IFactor = 32;
247
        ParamSet.UserParam1 = 0;
248
        ParamSet.UserParam2 = 0;
249
        ParamSet.UserParam3 = 0;
250
        ParamSet.UserParam4 = 0;
251
        ParamSet.UserParam5 = 0;
252
        ParamSet.UserParam6 = 0;
253
        ParamSet.UserParam7 = 0;
254
        ParamSet.UserParam8 = 0;
255
        ParamSet.ServoCompInvert = 1;
256
        ParamSet.ServoRefresh = 6;
257
        ParamSet.ServoNickControl = 100;
258
        ParamSet.ServoNickComp = 40;
259
        ParamSet.ServoNickMin = 0;
260
        ParamSet.ServoNickMax = 250;
261
        ParamSet.ServoRollControl = 100;
262
        ParamSet.ServoRollComp = 40;
263
        ParamSet.ServoRollMin = 0;
264
        ParamSet.ServoRollMax = 250;
265
        ParamSet.LoopGasLimit = 50;
266
        ParamSet.LoopThreshold = 90;
267
        ParamSet.LoopHysteresis = 50;
268
        ParamSet.AxisCoupling1 = 90;
269
        ParamSet.AxisCoupling2 = 80;
270
        ParamSet.AxisCouplingYawCorrection = 60;
271
        ParamSet.GyroAccTrim = 32;
272
        ParamSet.DynamicStability = 75;
273
        ParamSet.J16Bitmask = 95;
274
        ParamSet.J17Bitmask = 243;
275
        ParamSet.J16Bitmask_Warning = 0xAA;
276
        ParamSet.J17Bitmask_Warning = 0xAA;
277
        ParamSet.J16Timing = 20;
278
        ParamSet.J17Timing = 20;
279
        ParamSet.NaviGpsModeControl = 252;
280
        ParamSet.NaviGpsGain = 100;
281
        ParamSet.NaviGpsP = 90;
282
        ParamSet.NaviGpsI = 90;
283
        ParamSet.NaviGpsD = 90;
284
        ParamSet.NaviGpsPLimit = 75;
285
        ParamSet.NaviGpsILimit = 75;
286
        ParamSet.NaviGpsDLimit = 75;
287
        ParamSet.NaviGpsACC = 0;
288
        ParamSet.NaviGpsMinSat = 6;
289
        ParamSet.NaviStickThreshold = 8;
290
        ParamSet.NaviWindCorrection = 90;
291
        ParamSet.NaviSpeedCompensation = 30;
292
        ParamSet.NaviOperatingRadius = 100;
293
        ParamSet.NaviAngleLimitation = 100;
294
        ParamSet.NaviPHLoginTime = 4;
295
        memcpy(ParamSet.Name, "Normal\0", 7);
296
}
297
 
298
 
299
/***************************************************/
300
/*    Default Values for parameter set 3           */
301
/***************************************************/
302
void ParamSet_DefaultSet3(void) // beginner
303
{
304
        if(BoardRelease >= 20)
305
        {
306
                ParamSet.GyroD = 5;
307
                ParamSet.DriftComp = 0;
308
                ParamSet.GyroAccFactor = 27;         // Value : 1-64
309
                ParamSet.AngleTurnOverNick = 78;
310
                ParamSet.AngleTurnOverRoll = 78;
311
        }
312
        else
313
        {
314
                ParamSet.GyroD = 3;
315
                ParamSet.DriftComp = 32;
316
                ParamSet.GyroAccFactor = 30;         // Value : 1-64
317
                ParamSet.AngleTurnOverNick = 85;
318
                ParamSet.AngleTurnOverRoll = 85;
319
        }
320
        ParamSet.ChannelAssignment[CH_GAS]   = 1;
321
        ParamSet.ChannelAssignment[CH_ROLL]  = 2;
322
        ParamSet.ChannelAssignment[CH_NICK]  = 3;
323
        ParamSet.ChannelAssignment[CH_YAW]   = 4;
324
        ParamSet.ChannelAssignment[CH_POTI1] = 5;
325
        ParamSet.ChannelAssignment[CH_POTI2] = 6;
326
        ParamSet.ChannelAssignment[CH_POTI3] = 7;
327
        ParamSet.ChannelAssignment[CH_POTI4] = 8;
328
        ParamSet.Config0 = CFG0_AXIS_COUPLING_ACTIVE | CFG0_COMPASS_ACTIVE | CFG0_GPS_ACTIVE | CFG0_HEIGHT_SWITCH;//CFG0_HEIGHT_CONTROL | CFG0_COMPASS_FIX | CFG0_ROTARY_RATE_LIMITER;
329
        ParamSet.Config1 = 0;
330
        ParamSet.Config2 = CFG2_HEIGHT_LIMIT;//|CFG2_SENSITIVE_RC;
331
        ParamSet.HeightMinGas = 30;
332
        ParamSet.MaxHeight     = 251;
333
        ParamSet.HeightP      = 10;
334
        ParamSet.HeightD  = 30;
335
        ParamSet.Height_ACC_Effect = 30;
336
        ParamSet.Height_HoverBand = 5;
337
        ParamSet.Height_GPS_Z = 64;
338
        ParamSet.Height_StickNeutralPoint = 0; // Value : 0-250 (0 = Hoover-Estimation)
339
        ParamSet.Height_Gain = 15;
340
        ParamSet.StickP = 8;
341
        ParamSet.StickD = 16;
342
        ParamSet.StickYawP  = 6;
343
        ParamSet.GasMin = 8;
344
        ParamSet.GasMax = 230;
345
        ParamSet.CompassYawEffect = 128;
346
        ParamSet.GyroP = 100;
347
        ParamSet.GyroI = 120;
348
        ParamSet.GyroYawP = 100;
349
        ParamSet.GyroYawI = 120;
350
        ParamSet.LowVoltageWarning = 33;  // auto cell detection for values < 50
351
        ParamSet.EmergencyGas = 35;
352
        ParamSet.EmergencyGasDuration = 20;
353
        ParamSet.UfoArrangement = 0;
354
        ParamSet.IFactor = 16;
355
        ParamSet.UserParam1 = 0;
356
        ParamSet.UserParam2 = 0;
357
        ParamSet.UserParam3 = 0;
358
        ParamSet.UserParam4 = 0;
359
        ParamSet.UserParam5 = 0;
360
        ParamSet.UserParam6 = 0;
361
        ParamSet.UserParam7 = 0;
362
        ParamSet.UserParam8 = 0;
363
        ParamSet.ServoCompInvert = 1;
364
        ParamSet.ServoRefresh = 6;
365
        ParamSet.ServoNickControl = 100;
366
        ParamSet.ServoNickComp = 40;
367
        ParamSet.ServoNickMin = 0;
368
        ParamSet.ServoNickMax = 250;
369
        ParamSet.ServoRollControl = 100;
370
        ParamSet.ServoRollComp = 40;
371
        ParamSet.ServoRollMin = 0;
372
        ParamSet.ServoRollMax = 250;
373
        ParamSet.LoopGasLimit = 50;
374
        ParamSet.LoopThreshold = 90;
375
        ParamSet.LoopHysteresis = 50;
376
        ParamSet.AxisCoupling1 = 90;
377
        ParamSet.AxisCoupling2 = 80;
378
        ParamSet.AxisCouplingYawCorrection = 70;
379
        ParamSet.GyroAccTrim = 32;
380
        ParamSet.DynamicStability = 50;
381
        ParamSet.J16Bitmask = 95;
382
        ParamSet.J17Bitmask = 243;
383
        ParamSet.J16Bitmask_Warning = 0xAA;
384
        ParamSet.J17Bitmask_Warning = 0xAA;
385
        ParamSet.J16Timing = 30;
386
        ParamSet.J17Timing = 30;
387
        ParamSet.NaviGpsModeControl = 252;
388
        ParamSet.NaviGpsGain = 100;
389
        ParamSet.NaviGpsP = 90;
390
        ParamSet.NaviGpsI = 90;
391
        ParamSet.NaviGpsD = 90;
392
        ParamSet.NaviGpsPLimit = 75;
393
        ParamSet.NaviGpsILimit = 75;
394
        ParamSet.NaviGpsDLimit = 75;
395
        ParamSet.NaviGpsACC = 0;
396
        ParamSet.NaviGpsMinSat = 6;
397
        ParamSet.NaviStickThreshold = 8;
398
        ParamSet.NaviWindCorrection = 90;
399
        ParamSet.NaviSpeedCompensation = 30;
400
        ParamSet.NaviOperatingRadius = 100;
401
        ParamSet.NaviAngleLimitation = 100;
402
        ParamSet.NaviPHLoginTime = 4;
403
        memcpy(ParamSet.Name, "Beginner\0", 9);
404
}
405
 
406
/***************************************************/
407
/*       Read Parameter from EEPROM as byte        */
408
/***************************************************/
409
uint8_t GetParamByte(uint16_t param_id)
410
{
411
        return eeprom_read_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id]);
412
}
413
 
414
/***************************************************/
415
/*       Write Parameter to EEPROM as byte         */
416
/***************************************************/
417
void SetParamByte(uint16_t param_id, uint8_t value)
418
{
419
        eeprom_write_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value);
420
}
421
 
422
/***************************************************/
423
/*       Read Parameter from EEPROM as word        */
424
/***************************************************/
425
uint16_t GetParamWord(uint16_t param_id)
426
{
427
        return eeprom_read_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id]);
428
}
429
 
430
/***************************************************/
431
/*       Write Parameter to EEPROM as word         */
432
/***************************************************/
433
void SetParamWord(uint16_t param_id, uint16_t value)
434
{
435
        eeprom_write_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value);
436
}
437
 
438
/***************************************************/
439
/*       Read Parameter Set from EEPROM            */
440
/***************************************************/
441
// number [1..5]
442
void ParamSet_ReadFromEEProm(uint8_t setnumber)
443
{
444
        if((1 > setnumber) || (setnumber > 5)) setnumber = 3;
445
        eeprom_read_block((uint8_t *) &ParamSet.ChannelAssignment[0], &EEPromArray[EEPROM_ADR_PARAMSET_BEGIN + PARAMSET_STRUCT_LEN * (setnumber - 1)], PARAMSET_STRUCT_LEN);
446
        LED_Init();
447
}
448
 
449
/***************************************************/
450
/*        Write Parameter Set to EEPROM            */
451
/***************************************************/
452
// number [1..5]
453
void ParamSet_WriteToEEProm(uint8_t setnumber)
454
{
455
        if(setnumber > 5) setnumber = 5;
456
        if(setnumber < 1) return;
457
        eeprom_write_block((uint8_t *) &ParamSet.ChannelAssignment[0], &EEPromArray[EEPROM_ADR_PARAMSET_BEGIN + PARAMSET_STRUCT_LEN * (setnumber - 1)], PARAMSET_STRUCT_LEN);
458
        eeprom_write_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAMSET_LENGTH], PARAMSET_STRUCT_LEN);
459
        eeprom_write_block( &ParamSet.ChannelAssignment[0], &EEPromArray[EEPROM_ADR_CHANNELS], 8); // backup the first 8 bytes that is the rc channel mapping
460
        // set this parameter set to active set
461
        SetActiveParamSet(setnumber);
462
        LED_Init();
463
}
464
 
465
/***************************************************/
466
/*          Read MixerTable from EEPROM            */
467
/***************************************************/
468
uint8_t MixerTable_ReadFromEEProm(void)
469
{
470
        if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE]) == EEMIXER_REVISION)
471
        {
472
                eeprom_read_block((uint8_t *) &Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer));
473
                return 1;
474
        }
475
        else return 0;
476
}
477
 
478
/***************************************************/
479
/*          Write Mixer Table to EEPROM            */
480
/***************************************************/
481
uint8_t MixerTable_WriteToEEProm(void)
482
{
483
        if(Mixer.Revision == EEMIXER_REVISION)
484
        {
485
                eeprom_write_block((uint8_t *) &Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer));
486
                return 1;
487
        }
488
        else return 0;
489
}
490
 
491
/***************************************************/
492
/*    Default Values for Mixer Table               */
493
/***************************************************/
494
void MixerTable_Default(void) // Quadro
495
{
496
        uint8_t i;
497
 
498
        Mixer.Revision = EEMIXER_REVISION;
499
        // clear mixer table
500
        for(i = 0; i < 16; i++)
501
        {
502
                Mixer.Motor[i][MIX_GAS]  = 0;
503
                Mixer.Motor[i][MIX_NICK] = 0;
504
                Mixer.Motor[i][MIX_ROLL] = 0;
505
                Mixer.Motor[i][MIX_YAW]  = 0;
506
        }
507
        // default = Quadro
508
        Mixer.Motor[0][MIX_GAS] = 64; Mixer.Motor[0][MIX_NICK] = +64; Mixer.Motor[0][MIX_ROLL] =   0; Mixer.Motor[0][MIX_YAW] = +64;
509
        Mixer.Motor[1][MIX_GAS] = 64; Mixer.Motor[1][MIX_NICK] = -64; Mixer.Motor[1][MIX_ROLL] =   0; Mixer.Motor[1][MIX_YAW] = +64;
510
        Mixer.Motor[2][MIX_GAS] = 64; Mixer.Motor[2][MIX_NICK] =   0; Mixer.Motor[2][MIX_ROLL] = -64; Mixer.Motor[2][MIX_YAW] = -64;
511
        Mixer.Motor[3][MIX_GAS] = 64; Mixer.Motor[3][MIX_NICK] =   0; Mixer.Motor[3][MIX_ROLL] = +64; Mixer.Motor[3][MIX_YAW] = -64;
512
        memcpy(Mixer.Name, "Quadro\0", 7);
513
}
514
 
515
 
516
/***************************************************/
517
/*       Get active parameter set                  */
518
/***************************************************/
519
uint8_t GetActiveParamSet(void)
520
{
521
        uint8_t setnumber;
522
        setnumber = eeprom_read_byte(&EEPromArray[PID_ACTIVE_SET]);
523
        if(setnumber > 5)
524
        {
525
                setnumber = 3;
526
                eeprom_write_byte(&EEPromArray[PID_ACTIVE_SET], setnumber);
527
        }
528
        return(setnumber);
529
}
530
 
531
/***************************************************/
532
/*       Set active parameter set                  */
533
/***************************************************/
534
void SetActiveParamSet(uint8_t setnumber)
535
{
536
        if(setnumber > 5) setnumber = 5;
537
        if(setnumber < 1) setnumber = 1;
538
        eeprom_write_byte(&EEPromArray[PID_ACTIVE_SET], setnumber);
539
}
540
 
541
/***************************************************/
542
/*       Initialize EEPROM Parameter Sets          */
543
/***************************************************/
544
void ParamSet_Init(void)
545
{
546
        uint8_t Channel_Backup  = 0, i;
547
        // parameter version  check
548
        if(eeprom_read_byte(&EEPromArray[PID_PARAM_REVISION]) != EEPARAM_REVISION)
549
        {
550
                // if version check faild
551
                printf("\n\rInit Parameter in EEPROM");
552
                eeprom_write_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE], 0xFF); // reset also mixer table
553
                // check if channel mapping backup is valid
554
                if(             (eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+0]) < 12)
555
                    &&  (eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+1]) < 12)
556
                    &&  (eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+2]) < 12)
557
                    &&  (eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+3]) < 12)
558
                   )
559
                {
560
                        Channel_Backup = 1;
561
                }
562
                // fill all 5 parameter settings
563
                for (i = 1;i < 6; i++)
564
                {
565
                        switch(i)
566
                        {
567
                                case 1:
568
                                        ParamSet_DefaultSet1(); // Fill ParamSet Structure to default parameter set 1 (Sport)
569
                                        break;
570
                                case 2:
571
                                        ParamSet_DefaultSet2(); // Kamera
572
                                        break;
573
                                case 3:
574
                                        ParamSet_DefaultSet3(); // Beginner
575
                                        break;
576
                                default:
577
                                        ParamSet_DefaultSet2(); // Kamera
578
                                        break;
579
                        }
580
                        if(Channel_Backup) // if we have a rc channel mapping backup in eeprom
581
                        {
582
                                // restore it
583
                                ParamSet.ChannelAssignment[0] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+0]);
584
                                ParamSet.ChannelAssignment[1] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+1]);
585
                                ParamSet.ChannelAssignment[2] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+2]);
586
                                ParamSet.ChannelAssignment[3] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+3]);
587
                                ParamSet.ChannelAssignment[4] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+4]);
588
                                ParamSet.ChannelAssignment[5] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+5]);
589
                                ParamSet.ChannelAssignment[6] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+6]);
590
                                ParamSet.ChannelAssignment[7] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+7]);
591
                        }
592
                        ParamSet_WriteToEEProm(i);
593
                }
594
                // default-Setting is parameter set 3
595
                SetActiveParamSet(3);
596
                // update version info
597
                SetParamByte(PID_PARAM_REVISION, EEPARAM_REVISION);
598
        }
599
        // read active parameter set to ParamSet stucture
600
        ParamSet_ReadFromEEProm(GetActiveParamSet());
601
        printf("\n\rUsing Parameter Set %d", GetActiveParamSet());
602
 
603
        // load mixer table
604
        if(!MixerTable_ReadFromEEProm() )
605
        {
606
                printf("\n\rGenerating default Mixer Table");
607
                MixerTable_Default(); // Quadro
608
                MixerTable_WriteToEEProm();
609
        }
610
        // determine motornumber
611
        RequiredMotors = 0;
612
        for(i = 0; i < 16; i++)
613
        {
614
                if(Mixer.Motor[i][MIX_GAS] > 0) RequiredMotors++;
615
        }
616
 
617
        printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name, RequiredMotors);
618
        printf("\n\r==============================");
619
}