Subversion Repositories FlightCtrl

Rev

Details | Last modification | View Log | RSS feed

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