Subversion Repositories Projects

Rev

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

Rev Author Line No. Line
2136 - 1
/*****************************************************************************
2
 *   Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de                  *
3
 *   Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net                  *
4
 *   Copyright (C) 2013 Christian "Cebra" Brandtner, brandtner@brandtner.net *
5
 *   Copyright (C) 2011 Harald Bongartz                                      *
6
 *                                                                           *
7
 *   This program is free software; you can redistribute it and/or modify    *
8
 *   it under the terms of the GNU General Public License as published by    *
9
 *   the Free Software Foundation; either version 2 of the License.          *
10
 *                                                                           *
11
 *   This program is distributed in the hope that it will be useful,         *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
14
 *   GNU General Public License for more details.                            *
15
 *                                                                           *
16
 *   You should have received a copy of the GNU General Public License       *
17
 *   along with this program; if not, write to the                           *
18
 *   Free Software Foundation, Inc.,                                         *
19
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.               *
20
 *                                                                           *
21
 *                                                                           *
22
 *   Credits to:                                                             *
23
 *   Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN  *
24
 *                          http://www.mikrokopter.de                        *
25
 *   Gregor "killagreg" Stobrawa for his version of the MK code              *
26
 *   Thomas Kaiser "thkais" for the original project. See                    *
27
 *                          http://www.ft-fanpage.de/mikrokopter/            *
28
 *                          http://forum.mikrokopter.de/topic-4061-1.html    *
29
 *   Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code *
30
 *                          http://www.mylifesucks.de/oss/c-osd/             *
31
 *   Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility*
32
 *****************************************************************************/
33
//############################################################################
34
//# HISTORY  eeprom.c
35
//#
36
//# 03.08.2015 CB
37
//# - chg: Obsolete Parameter geändert und für FollowMe verwendet, EEprom Version bleibt gleich
38
//#        Parameter FM_Refresh in FM_Azimuth geändert
39
//#        Parameter hyst_u_min in FM_Distance geändert
40
//#        Initialisierung der neuen Parameter hinzugefügt
41
//#
42
//# 17.06.2014 OG
43
//# - chg: ReadParameter() - Updatecode auf 139
44
//#
45
//# 13.06.2014 OG
46
//# - chg: Delete_EEPROM(() Unterstuetzung Config.PKTOffTimeout (ehemals LCD_DisplayMode)
47
//#
48
//# 30.05.2014 OG
49
//# - chg: Delete_EEPROM() Config.Lipo_UOffset auf 10000 gesetzt (vorher 8500)
50
//#
51
//# 26.05.2014 OG
52
//# - chg: Config.LCD_DisplayMode als "OBSOLETE" markiert
53
//#
54
//# 14.05.2014 OG
55
//# - chg: include "../mk/paramset.h" geaendert auf "../mksettings/paramset.h"
56
//#
57
//# 07.05.2014 OG
58
//# - chg: EEpromversion erhoeht auf 138
59
//#        -> keine neuen Parameter, neue Version nur fuer geanderte
60
//#           Initialisierung von MKParam_Favs
61
//# - fix: ReadParameter() - Vorbelegung von Config.MKParam_Favs von 255 auf 0 geaendert
62
//#        ab EEprom-Version 138
63
//# - fix: Delete_EEPROM() - Vorbelegung von Config.MKParam_Favs von 255 auf 0 geaendert
64
//# - fix: ReadParameter() - Kommentare zu Version 136 und 137 korrigiert
65
//#        bzgl. der PKT-Versionsangabe und Datum ergaenzt
66
//#
67
//# 06.04.2014 OG
68
//# - chg: ReadParameter(): umgestellt auf lcdx_printp_center()
69
//# - chg: EEpromversion erhoeht auf 137
70
//# - add: ReadParameter(): upgrade Config.Wlan_HomeSSID, Config.Wlan_HomePassword
71
//# - add: ReadParameter(): upgrade Config.UseBLE, Config.MKParam_Favs
72
//# - add: Delete_EEPROM(): init von Config.Wlan_HomeSSID, Config.Wlan_HomePassword
73
//#
74
//# 01.04.2014 OG
75
//# - add: Delete_EEPROM(): init von Config.UseBLE
76
//# - add: Delete_EEPROM(): init von Config.MKParam_Favs
77
//#
78
//# 27.03.2014 OG
79
//# - chg: ReadParameter() Niederländisch wird auf Englisch umgeschaltet
80
//#         -> Vorbereitung zum entfernen der Niederländischen Sprache
81
//#
82
//# 11.02.2014 Cebra
83
//# - add: Delete EEProm: Config.OSD_ShowCellU = false;
84
//#
85
//# 03.02.2014 OG
86
//# - add: Config.OSD_ShowCellU in ReadParameter (EEpromversion 0x87)
87
//#
88
//# 30.01.2014 OG
89
//# - add: Unterstuetzung fuer USE_BLUETOOTH
90
//#
91
//# 07.07.2013 OG
92
//# - chg: Strings fuer WLan gekuerzt
93
//#
94
//# 04.07.2013 Cebra
95
//# - add: neue Parameter fuer Wlan; EEpromversion erhoeht auf 0x85
96
//#
97
//# 04.07.2013 OG
98
//# - add: Config.OSD_UseScreen; Epromversion erhoeht auf 0x84
99
//#
100
//# 03.07.2013 OG
101
//# - chg: ReadParameter() - PKT-Upgrade restrukturiert bzgl. inkrementelle
102
//#        Updates vorheriger Versionen
103
//#
104
//# 02.07.2013 Cebra
105
//# - add: neue Parameter fuer Wlan; EEpromversion erhoeht auf 83
106
//#
107
//# 02.07.2013 OG
108
//# - chg: frei geworden: Config.OSD_HomeMKView (nicht mehr benoetigt)
109
//#
110
//# 26.06.2013 OG
111
//# - chg: frei geworden: Config.PKT_StartInfo (nicht mehr benoetigt)
112
//#
113
//# 24.06.2013 OG
114
//# - fix: ReadParameter(): ergaenzt um bt_fixname() um ggf. ungueltige
115
//#        Zeichen im Bluetooth-Namen zu eliminieren
116
//#
117
//# 23.06.2013 OG
118
//# - chg: Delete_EEPROM(): Default von Config.Lipo_UOffset von 6000 auf 8500 gesetzt
119
//# - chg: Delete_EEPROM(): Default von Config.bt_name auf "PKT" gekuerzt
120
//# - chg: Delete_EEPROM(): Config.bt_name -> nicht mehr mit Leerzeichen auffuellen!
121
//#
122
//# 20.06.2013 CB
123
//# - chg: EEPROM Versionsänderung auf 82 wegen Wechsel LCD_Orientation zu OSD_ShowMKSetting
124
//#
125
//# 15.06.2013 OG
126
//# - chg: Config.LCD_ORIENTATION zu Config.OSD_ShowMKSetting
127
//#
128
//# 13.06.2013 OG
129
//# - fix: Config.PKT_Accutyp hinzugefuegt in Delete_EEPROM()
130
//# - chg: Default GPS-LastPosition auf 0/0 gesetzt in Delete_EEPROM()
131
//# - chg: Default Config.PKT_StartInfo auf false gesetzt in Delete_EEPROM()
132
//# - chg: Code Layout
133
//#
134
//# 31.05.2013 CB
135
//# - chg: EEPROM Strukturänderung auf Version 81, Versionsanpassung angepasst
136
//#
137
//# 05.05.2013 Cebra
138
//# - add: PKT Zeitsetup EEPROM Parameter
139
//# 28.03.2013 CB
140
//# - add: save and upgrade OSD_Statistic, GPS_User, MKErr_Log in EEProm structure variable
141
//############################################################################
142
 
143
#include "../cpu.h"
144
#include <avr/io.h>
145
#include <avr/pgmspace.h>
146
#include <util/delay.h>
147
#include <stdio.h>
148
#include <stdlib.h>
149
#include <string.h>
150
#include <stdarg.h>
151
#include <avr/interrupt.h>
152
#include <avr/eeprom.h>
153
#include <stdbool.h>
154
#include <avr/wdt.h>
155
#include "../lcd/lcd.h"
156
#include "../main.h"
157
#include "../timer/timer.h"
158
#include "eeprom.h"
159
#include "../wi232/Wi232.h"
160
#include "../setup/setup.h"
161
#include "../bluetooth/bluetooth.h"
162
#include "../mk-data-structs.h"
163
#include "../connect.h"
164
#include "../tracking/ng_servo.h"
165
#include "../tracking/tracking.h"
166
#include "../osd/osd.h"
167
#include "../uart/uart1.h"
168
#include "../messages.h"
169
#include "../osd/osddata.h"
170
#include "../mksettings/paramset.h"
171
 
172
//------------------------------------------------------------------------------------------
173
 
174
ST EEMEM EEStruct;
175
 
176
ST Config;
177
 
178
 
179
//#############################################################
180
// ANMERKUNG OG:
181
//
182
// es ware besser wenn die gesamte Config-struct zum PC
183
// gesendet wird anstatt aufbreitete Textlines. Das spart
184
// Speicher im PKT (der ist limitiert).
185
//
186
// Die Aufbereitung der Daten (Umrechnungen) kann dann auf
187
// der PC Seite erfolgen.
188
//
189
// Nachteil dabei: wenn sich die Config-struct des PKT
190
// ändert muss auch das PKT-Tool auf dem PC angepasst werden.
191
//
192
//CB: deshalb ist das auch jetzt auskommentiert
193
//
194
//#############################################################
195
 
196
 
197
//char printbuff[100];
198
 
199
//void print_data_int8( const char *text, int8_t *variable)
200
//{
201
//  sprintf(printbuff, "%d", *variable);
202
//  uart1_puts_p(text); uart1_puts(printbuff); uart1_puts("\r\n");
203
//}
204
////
205
////
206
//void print_data_uint8( const char *text, uint8_t *variable)
207
//{
208
//  sprintf(printbuff, "%d", *variable);
209
//  uart1_puts_p(text); uart1_puts(printbuff); uart1_puts("\r\n");
210
//}
211
//
212
//
213
//void print_data_uint16( const char *text, uint16_t *variable)
214
//{
215
//  sprintf(printbuff, "%d", *variable);
216
//  uart1_puts_p(text); uart1_puts(printbuff); uart1_puts("\r\n");
217
//}
218
//
219
//
220
//void print_data_int16( const char *text, int16_t *variable)
221
//{
222
//  sprintf(printbuff, "%d", *variable);
223
//  uart1_puts_p(text); uart1_puts(printbuff); uart1_puts("\r\n");
224
//}
225
//
226
//
227
//void print_data_char( const char *text, char *variable, uint8_t length)
228
//{
229
//  uart1_puts_p(text);
230
//  uart1_puts(variable);
231
//  uart1_puts("\r\n");
232
//}
233
//
234
//
235
//void print_time( const char *text, PKTdatetime_t variable)
236
//{
237
//    uart1_puts_p(text);
238
//    sprintf(printbuff, "%d", variable.day);
239
//    uart1_puts(printbuff);
240
//    uart1_puts(".");
241
//    sprintf(printbuff, "%d", variable.month);
242
//    uart1_puts(printbuff);
243
//    uart1_puts(".");
244
//    sprintf(printbuff, "%d", variable.year);
245
//    uart1_puts(printbuff);
246
////    uart1_puts(" ");
247
////    sprintf(printbuff, "%d", variable.seconds);
248
////    uart1_puts(printbuff);
249
//    uart1_puts("\r\n");
250
//}
251
//
252
//
253
//
254
//void print_OSD_Statistic(void)
255
//{
256
//  print_time (PSTR("begin_StatTime:"),Config.OSD_Statistic.begin_StatTime);
257
//  print_time (PSTR("end_StatTime:"),Config.OSD_Statistic.end_StatTime);
258
//  print_data_uint16 (PSTR("total_FlyTime:"),&Config.OSD_Statistic.total_FlyTime);
259
//  print_data_uint16 (PSTR("last_FlyTime:"),&Config.OSD_Statistic.last_FlyTime);
260
//  print_data_uint16 (PSTR("count_Errorcode:"),&Config.OSD_Statistic.count_Errorcode);
261
//  print_data_int16 (PSTR("max_Altimeter:"),&Config.OSD_Statistic.max_Altimeter);
262
//  print_data_uint16 (PSTR("max_GroundSpeed:"),&Config.OSD_Statistic.max_GroundSpeed);
263
//  print_data_uint16 (PSTR("max_Distance:"),&Config.OSD_Statistic.max_Distance);
264
//  print_data_uint16 (PSTR("max_Current:"),&Config.OSD_Statistic.max_Current);
265
//  print_data_uint16 (PSTR("max_Capacity:"),&Config.OSD_Statistic.max_Capacity);
266
//  print_data_int16 (PSTR("max_Variometer:"),&Config.OSD_Statistic.max_Variometer);
267
//  print_data_int8 (PSTR("max_AngleNick:"),&Config.OSD_Statistic.max_AngleNick);
268
//  print_data_int8 (PSTR("max_AngleRoll:"),&Config.OSD_Statistic.max_AngleRoll);
269
//  print_data_uint8 (PSTR("RC Quality:"),&Config.OSD_Statistic.max_RCQuality);
270
//  print_data_int16 (PSTR("max_TopSpeed:"),&Config.OSD_Statistic.max_TopSpeed);
271
//  print_data_int8 (PSTR("min_AngleNick:"),&Config.OSD_Statistic.min_AngleNick);
272
//  print_data_int8 (PSTR("min_AngleRoll:"),&Config.OSD_Statistic.min_AngleRoll);
273
//  print_data_uint8 (PSTR("min_RCQuality:"),&Config.OSD_Statistic.min_RCQuality);
274
//  print_data_uint8 (PSTR("min_UBat:"),&Config.OSD_Statistic.min_UBat);
275
//  print_data_uint8 (PSTR("LiPoCells:"),&Config.OSD_Statistic.LiPoCells);
276
//  print_data_uint8 (PSTR("BL_Count:"),&Config.OSD_Statistic.BL_Count);
277
//}
278
 
279
 
280
 
281
//void SendConfigData(void)
282
//{
283
 
284
//  print_data_uint8 (strGet(START_VERSIONCHECK),&Config.Version );
285
//  print_data_uint8 (strGet(LOWBAT),&Config.MK_LowBat );
286
//  print_data_uint8 (strGet(LOWBAT),&Config.DisplayTimeout );
287
//  print_data_uint8 (strGet(LOWBAT),&Config.DisplayLanguage );
288
//  print_data_uint8 (strGet(WITXRX),&Config.WiTXRXChannel);
289
//  print_data_uint8 (strGet(WINETWG),&Config.WiNetworkGroup);
290
//  print_data_uint8 (strGet(WINETWM),&Config.WiNetworkMode);
291
//  print_data_uint8 (strGet(WITIMEOUT),&Config.WiTXTO);
292
//  print_data_uint8 (strGet(WIUART),&Config.WiUartMTU);
293
//  print_data_uint8 (strGet(DISPLAY8),&Config.OSD_ShowMKSetting);
294
//  print_data_uint8 (strGet(DISPLAY7),&Config.LCD_DisplayMode);
295
//  print_data_uint8 (strGet(DISPLAY6),&Config.LCD_Kontrast);
296
//  print_data_uint8 (strGet(DISPLAY5),&Config.LCD_Helligkeit);
297
//  print_data_uint8 (PSTR("USB-Betrieb:"),&Config.USBBT);
298
//  print_data_uint8 (PSTR("Uart-FC/Wi:"),&Config.U02SV2);
299
//  print_data_uint8 (PSTR("PKT-Debug:"),&Config.Debug);
300
//  print_data_uint8 (PSTR("Wi232 eingebaut:"),&Config.UseWi);
301
//  print_data_uint8 (PSTR("BTM222 eingebaut:"),&Config.UseBT);
302
//  print_data_uint8 (PSTR("Wi232 ok:"),&Config.WiIsSet);
303
//  print_data_uint8 (PSTR("BTM222 ok:"),&Config.BTIsSet);
304
//  print_data_uint8 (PSTR("BTM222 Slave:"),&Config.BTIsSlave);
305
//
306
//  print_data_char (PSTR("BTM222 Pin:"),&Config.bt_pin[0],bt_pin_length );
307
//  print_data_char (PSTR("BTM222 Name:"),&Config.bt_name[0],bt_name_length);
308
//  print_data_char (PSTR("BTM222 REID:"),&Config.RE_ID[0],RE_ID_length );
309
//  print_data_char (PSTR("BTM222 MAC:"),&Config.bt_Mac[0],bt_mac_length);
310
//  print_data_char (PSTR("GPS DevName:"),&Config.gps_UsedDevName[0],20);
311
//  print_data_char (PSTR("GPS MAC:"),&Config.gps_UsedMac[0],14);
312
//
313
//   print_data_int32 (PSTR("LastLongitude:"),&Config.LastLongitude);
314
////  print_data_int32(PSTR("LastLatitude:"),&Config.LastLatitude);
315
//
316
//  print_data_uint8 (PSTR("PKT_IdleBeep:"),&Config.PKT_IdleBeep);
317
//  print_data_uint8 (strGet(DISPLAY2),&Config.PKT_StartInfo);
318
//  print_data_uint16 (strGet(LIPO3),&Config.Lipo_UOffset);
319
//  print_data_uint8 (strGet(LIPO2),&Config.PKT_Accutyp);
320
//  print_data_uint8 (strGet(DISPLAY9),&Config.OSD_RCErrorbeep);
321
//  print_data_uint8 (strGet(OSD_Invert_Out),&Config.OSD_InvertOut);
322
//  print_data_uint8 (strGet(OSD_LED_Form),&Config.OSD_LEDform);
323
//  print_data_uint8 (strGet(OSD_Send_OSD),&Config.OSD_SendOSD);
324
//  print_data_uint8 (strGet(FALLSPEED),&Config.OSD_Fallspeed);
325
//  print_data_uint8 (strGet(OSD_VARIOBEEP),&Config.OSD_VarioBeep);
326
//  print_data_uint8 (strGet(OSD_HOMEMKVIEW),&Config.OSD_HomeMKView);
327
//  print_data_uint16 (strGet(OSD_MAHWARNING),&Config.OSD_mAh_Warning);
328
//  print_data_uint8 (strGet(OSD_SCREENMODE),&Config.OSD_ScreenMode);
329
//  print_data_uint8 (strGet(OSD_LIPOBAR),&Config.OSD_LipoBar);
330
//  print_data_uint8 (strGet(PKT_BAUDRATE),&Config.PKT_Baudrate);
331
//  print_data_uint16 (strGet(FOLLOWME_1),&Config.FM_Refresh);
332
//  print_data_uint16 (strGet(FOLLOWME_2),&Config.FM_Speed);
333
//  print_data_uint16 (strGet(FOLLOWME_3),&Config.FM_Radius);
334
//  print_data_uint8 (strGet(HWSOUND),&Config.HWSound);
335
//  print_data_uint8 (strGet(HWBEEPER),&Config.HWBeeper);
336
//  print_data_uint8 (PSTR("sIdxSteps:"),&Config.sIdxSteps);
337
//  print_data_uint8 (strGet(SV_TEST3),&Config.servo_frame);
338
//  print_data_uint8 (strGet(SV_SINGLESTEP),&Config.single_step);
339
//  print_data_uint8 (strGet(SV_COUNTTEST),&Config.repeat);
340
//  print_data_uint8 (strGet(SV_PAUSEEND),&Config.pause);
341
//  print_data_uint8 (strGet(SV_PAUSEINC),&Config.pause_step);
342
////  print_data_int8 (,&Config.tracking);
343
////  print_data_int8 (,&Config.track_tx);
344
//  print_data_uint16 (PSTR("Stick1_min:"),&Config.stick_min[0]);
345
//  print_data_uint16 (PSTR("Stick2_min:"),&Config.stick_min[1]);
346
//  print_data_uint16 (PSTR("Stick3_min:"),&Config.stick_min[2]);
347
//  print_data_uint16 (PSTR("Stick4_min:"),&Config.stick_min[3]);
348
//  print_data_uint16 (PSTR("Stick5_min:"),&Config.stick_min[4]);
349
//  print_data_uint16 (PSTR("Stick1_max:"),&Config.stick_max[0]);
350
//  print_data_uint16 (PSTR("Stick2_max:"),&Config.stick_max[1]);
351
//  print_data_uint16 (PSTR("Stick3_max:"),&Config.stick_max[2]);
352
//  print_data_uint16 (PSTR("Stick4_max:"),&Config.stick_max[3]);
353
//  print_data_uint16 (PSTR("Stick5_max:"),&Config.stick_max[4]);
354
//  print_data_uint8 (PSTR("Stick1_typ:"),&Config.stick_typ[0]);
355
//  print_data_uint8 (PSTR("Stick2_typ:"),&Config.stick_typ[1]);
356
//  print_data_uint8 (PSTR("Stick3_typ:"),&Config.stick_typ[2]);
357
//  print_data_uint8 (PSTR("Stick4_typ:"),&Config.stick_typ[3]);
358
//  print_data_uint8 (PSTR("Stick5_typ:"),&Config.stick_typ[4]);
359
//  print_data_uint8 (PSTR("Stick1_neutral:"),&Config.stick_neutral[0]);
360
//  print_data_uint8 (PSTR("Stick2_neutral"),&Config.stick_neutral[1]);
361
//  print_data_uint8 (PSTR("Stick3_neutral:"),&Config.stick_neutral[2]);
362
//  print_data_uint8 (PSTR("Stick4_neutral:"),&Config.stick_neutral[3]);
363
//  print_data_uint8 (PSTR("Stick5_neutral:"),&Config.stick_neutral[4]);
364
//  print_data_uint8 (strGet(LIPO_MESSUNG),&Config.Lipomessung);
365
//  print_OSD_Statistic();
366
//}
367
 
368
 
369
//--------------------------------------------------------------
370
//--------------------------------------------------------------
371
void WriteWiInitFlag(void)
372
{
373
       Config.WiIsSet = true;
374
}
375
 
376
 
377
//--------------------------------------------------------------
378
//--------------------------------------------------------------
379
void WriteBTInitFlag(void)
380
{
381
     Config.BTIsSet = true;
382
}
383
//--------------------------------------------------------------
384
//--------------------------------------------------------------
385
void WriteWLInitFlag(void)
386
{
387
     Config.WLIsSet = true;
388
}
389
 
390
//--------------------------------------------------------------
391
//--------------------------------------------------------------
392
void WriteBTSlaveFlag(void)
393
{
394
     Config.BTIsSlave = true;
395
}
396
 
397
 
398
//--------------------------------------------------------------
399
//--------------------------------------------------------------
400
void WriteBTMasterFlag(void)
401
{
402
     Config.BTIsSlave = false;
403
}
404
 
405
 
406
//--------------------------------------------------------------
407
//--------------------------------------------------------------
408
void WriteLastPosition( uint32_t ELongitude, uint32_t ELatitude)
409
 
410
{
411
    Config.LastLongitude = ELongitude;
412
    Config.LastLatitude  = ELatitude;
413
}
414
 
415
 
416
 
417
//--------------------------------------------------------------
418
//--------------------------------------------------------------
419
void ReadParameter( void )
420
{
421
    eeprom_read_block( (void*)&Config, (const void*)&EEStruct, sizeof(ST) );
422
 
423
    // DEBUG !!
424
    //Config.Version = 0x82;
425
    //WriteParameter();
426
    //return;
427
 
428
 
429
    //-------------------
430
    // ggf. ungueltige Zeichen aus dem
431
    // Bluetooth-Namen eliminieren
432
    //-------------------
433
    #ifdef USE_BLUETOOTH
434
    bt_fixname();
435
    #endif
436
 
437
    //-------------------
438
    // 27.03.2014 OG
439
    // Als Vorbereitung die Niederländische Sprache
440
    // zu entfernen wird hier ggf. Niederländisch
441
    // auf Englisch umgeschaltet
442
    //-------------------
443
    if( Config.DisplayLanguage == 2 )   // 2 = ehemals Niederländisch
444
        Config.DisplayLanguage = 1;     // -> wird zu 1 = Englisch
445
 
446
    //-------------------
447
    // 0. EEprom-Version nicht geaendert
448
    //-------------------
449
    if( Config.Version == EEpromVersion )                   // nichts zu tun...
450
    {
451
        return;                                             // !!! EXIT !!!
452
    }
453
 
454
 
455
    //-------------------
456
    // 1. PKT-Upgrade NICHT Update faehig
457
    //    ODER Downgrade
458
    //
459
    // 0x77 = PKT Version 3.6.6a
460
    //-------------------
461
    if( (Config.Version < 0x77) || (Config.Version > EEpromVersion) )
462
    {
463
        Delete_EEPROM();
464
        return;                                             // !!! EXIT !!!
465
    }
466
 
467
 
468
    //-------------------
469
    // 2. PKT-Upgrade
470
    //-------------------
471
 
472
    //++++++++++++++++++++++++++++
473
    // bei Eeprom-Versionwechsel
474
    // IMMER loeschen
475
    //++++++++++++++++++++++++++++
476
#ifdef USE_WAYPOINTS
477
    PointList_Clear();                                      // Init Waypoints
478
#endif
479
    STAT_Init();                                            // Init OSD Statistik
480
    GPS_User_Init();                                        // Init GPS Positionen
481
    MKErr_Log_Init();                                       // Init MK Errorlog
482
 
483
 
484
    //++++++++++++++++++++++++++++
485
    // inkrementelle Updates
486
    //++++++++++++++++++++++++++++
487
 
488
    //-----------------------------
489
    //--- ab PKT v3.6.9bX6
490
    //-----------------------------
491
    if( Config.Version < 0x81 )
492
    {
493
        Config.timezone   = 1;
494
        Config.summertime = 1;
495
    }
496
 
497
    //-----------------------------
498
    //--- ab PKT v3.7.0b
499
    //-----------------------------
500
    if( Config.Version < 0x82 )
501
    {
502
        Config.OSD_ShowMKSetting = true;
503
    }
504
 
505
    //-----------------------------
506
    //--- ab PKT v3.7.0e
507
    //-----------------------------
508
    if( Config.Version < 0x83 )
509
    {
510
        Config.UseWL   = false;
511
        Config.WLIsSet = false;
512
        strcpy_P( Config.Wlan_SSID    , PSTR("PKT"));       // Wlan
513
        strcpy_P( Config.Wlan_Password, PSTR("12345678"));  // Wlan
514
    }
515
 
516
    //-----------------------------
517
    //--- ab PKT v3.7.0eX1
518
    //-----------------------------
519
    if( Config.Version < 0x84 )
520
    {
521
        Config.OSD_UseScreen = 0xffffffff;                  // alle verfuegbaren OSD-Screens eingeschaltet
522
    }
523
 
524
    //-----------------------------
525
    //--- ab PKT v3.7.0f
526
    //-----------------------------
527
    if( Config.Version < 0x85 )
528
    {
529
       Config.Wlan_DHCP    = 0;
530
       Config.Wlan_WPA     = 0;
531
       Config.Wlan_Adhoc   = true;
532
       Config.Wlan_Channel = 1;
533
       strcpy_P( Config.Wlan_IP     , PSTR("169.254.001.001"));
534
       strcpy_P( Config.Wlan_Netmask, PSTR("255.255.000.000"));
535
       strcpy_P( Config.Wlan_Gateway, PSTR("169.254.001.001"));
536
    }
537
 
538
    //-----------------------------
539
    //--- ab PKT v3.7.3cX5
540
    //-----------------------------
541
    if( Config.Version < 0x87 )
542
    {
543
        Config.OSD_ShowCellU = false;                      //
544
    }
545
 
546
 
547
    //-----------------------------
548
    //--- 01.04.2014 OG
549
    //--- ab PKT v3.7.4aX7
550
    //-----------------------------
551
    if( Config.Version < 136 )
552
    {
553
        Config.UseBLE = false;                                              // Bluetooth 4 LowPower wird genutzt (RedBearLab BLE Mini) wird an SV2 genutzt (SV2 Patch erforderlich)
554
        memset( Config.MKParam_Favs, param_EOF, MAX_MKPARAM_FAVORITES );    // Array von MK-Parameter Favoriten des Benutzers
555
    }
556
 
557
 
558
    //-----------------------------
559
    //--- 06.04.2014 OG
560
    //--- ab PKT v3.7.4aX8
561
    //-----------------------------
562
    if( Config.Version < 137 )
563
    {
564
        strcpy_P( Config.Wlan_HomeSSID    , PSTR(""));                      // WiFly Home-Wlan: SSID (Home-WLAN)
565
        strcpy_P( Config.Wlan_HomePassword, PSTR(""));                      // WiFly Home-Wlan: Passwort (Home-WLAN)
566
    }
567
 
568
 
569
    //-----------------------------
570
    //--- 07.05.2014 OG
571
    //--- ab PKT v3.80bX3
572
    //-----------------------------
573
    if( Config.Version < 138 )
574
    {
575
        memset( Config.MKParam_Favs, 0, MAX_MKPARAM_FAVORITES );            // Array von MK-Parameter Favoriten des Benutzers (Vorbelegung jetzt 0)
576
    }
577
 
578
 
579
    //-----------------------------
580
    //--- 17.06.2014 OG
581
    //--- ab PKT v3.80cX5
582
    //-----------------------------
583
    if( Config.Version < 139 )
584
    {
585
        Config.PKTOffTimeout = 0;                                           // autom. PKT ausschalten nach n Minuten (0=immer an)
586
    }
587
 
588
 
589
 
590
    //-------------------
591
    // 3. Update Message
592
    //-------------------
593
    Config.Version = EEpromVersion;                         // Update EEPROM version number
594
    sei();
595
 
596
    lcd_cls();
597
    lcdx_printp_center( 2, PSTR("EEProm updated to"), MNORMAL, 0,0);
598
    lcdx_printp_center( 3, PSTR("new Version")      , MNORMAL, 0,0);
599
    lcdx_printp_center( 5, PSTR("check settings!")  , MNORMAL, 0,0);
600
    lcd_printp_at (18, 7, PSTR("OK")                , MNORMAL);         // Keyline
601
 
602
    while( !get_key_press(1 << KEY_ENTER) );
603
    WriteParameter();
604
    cli();
605
}
606
 
607
 
608
 
609
//--------------------------------------------------------------
610
//--------------------------------------------------------------
611
void WriteParameter( void )
612
{
613
    copy_line(7);
614
    lcd_printp_at( 0, 7, PSTR("   Write EEPROM    "), MNORMAL);
615
    eeprom_update_block( (const void*)&Config, (void*)&EEStruct, sizeof(ST) );
616
    paste_line(7);
617
}
618
 
619
 
620
 
621
//--------------------------------------------------------------
622
//--------------------------------------------------------------
623
void Delete_EEPROM( void )
624
{
625
    uint8_t i;
626
 
627
    // EEPROM auf Default setzen
628
 
629
    lcd_cls();
630
    lcd_printp_at( 0, 0, PSTR(" EEPROM Parameter    "), MINVERS);
631
    lcd_printp_at( 0, 1, PSTR("werden auf")           , MNORMAL);
632
    lcd_printp_at( 0, 2, PSTR("Standardwerte gesetzt"), MNORMAL);
633
 
634
    Config.MK_LowBat        = 137;                              // 13,7V
635
    Config.DisplayTimeout   = 0;                                // Display immer an (autom. LCD ausschalten nach n Minuten)
636
    Config.DisplayLanguage  = 5;                                // default undefined
637
    Config.WiTXRXChannel    = 1;                                // Kanal 1 MK Standard
638
    Config.WiNetworkGroup   = 66;                               // Gruppe 66  MK Standard
639
    Config.WiNetworkMode    = NetMode_Normal;                   // MK Standard
640
    Config.WiTXTO           = TWaitTime16;                      // MK Standard
641
    Config.WiUartMTU        = UartMTU64;                        // MK Standard
642
    Config.OSD_ShowMKSetting= true;                             // Anzeige MK-Setting beim OSD Start
643
    Config.PKTOffTimeout    = 0;                                // PKT immer an (autom. PKT ausschalten nach n Minuten)
644
    Config.LCD_Kontrast     = 20;                               // Kontrast normal
645
    Config.LCD_Helligkeit   = 100;                              // Helligkeit in %
646
    Config.USBBT            = 0;                                // USB Betrieb
647
    Config.U02SV2           = 0;                                // SV2 (Kabel) Standard
648
    Config.Debug            = 0;                                // kein Debug
649
    Config.UseWi            = false;                            // Wi.232 eingebaut?
650
    Config.UseBT            = false;                            // BT-222 eingebaut?
651
    Config.WiIsSet          = false;                            // Flag für die Initialisierung Wi232
652
    Config.BTIsSet          = false;                            // Flag für die Initialisierung Bluetooth
653
    Config.BTIsSlave        = true;                             // Slave Flag setzen
654
    Config.PKT_IdleBeep     = 0;                                // kein Piepsen bei Inaktivität
655
    Config.PKT_StartInfo    = false;                            //   * FREI * (ehemals: PKT Startinfo anzeigen)
656
    Config.OSD_RCErrorbeep  = true;                             // OSD Receiveerrorbeep
657
    Config.OSD_InvertOut    = false;                            // LED Anzeige invertiren
658
    Config.OSD_LEDform      = 1;                                // Form der Anzeige ( + oder schwarz)
659
    Config.OSD_SendOSD      = false;                            // OSD Daten an SV2
660
    Config.OSD_Fallspeed    = 40;                               // maximale Sinkrate
661
    Config.OSD_VarioBeep    = 1;                                // Vario Beep ein
662
    Config.OSD_HomeMKView   = true;                             //   * FREI * (ehemals: Home Circle from MK View)
663
    Config.OSD_mAh_Warning  = 10000;                            // mAh Warnschwelle
664
    Config.OSD_ScreenMode   = 0;                                // Variante des OSD Screen
665
    Config.OSD_LipoBar      = 0;                                // Bargraphanzeige für MK Lipo
666
    Config.PKT_Baudrate     = Baud_57600;                       // Baudrate für BT und Wi232
667
    Config.PKT_Accutyp      = true;                             // verwendeter Akkutyp (true=Lipo, false=LiON)
668
    Config.Lipo_UOffset     = 10000;                            // Offset für PKT-Lipomessung
669
    Config.FM_Azimuth       = 0;                                // FollowMe Azimuth
670
    Config.FM_Distance      = 0;                                // FollowMe Distance
671
    Config.FM_Speed         = 30;                               // FollowMe Speed in m/s *0.1
672
    Config.FM_Radius        = 5;                                // Waypoint Tolerance Radius in meter
673
    Config.HWSound          = 0;                                // Hardware Sounderweiterung an PD7
674
    Config.HWBeeper         = 1;                                // Hardware Beeper an PC7
675
    Config.Volume           = 0;                                // Lautstaerke
676
    Config.LastLongitude    = 0x00000000;
677
    Config.LastLatitude     = 0x00000000;
678
 
679
    strcpy_P(Config.bt_pin , PSTR("0000"));
680
    strcpy_P(Config.bt_name, PSTR("PKT"));                      // Bluetooth-Name max. 10 Zeichen! - NICHT mit Leerzeichen auffüllen (bt_name_length)
681
    strcpy_P(Config.bt_Mac , PSTR("0000-00-000000"));
682
    strcpy_P(Config.RE_ID  , PSTR("0000"));
683
 
684
    for( i = 0; i < 20; i++)
685
    {
686
       Config.gps_UsedDevName[i]      = 0;                      // benutztes GPS Device Name
687
    }
688
    for( i = 0; i < 14; i++)
689
    {
690
       Config.gps_UsedMac[i] = '0';                             // benutztes GPS Device Mac Adresse
691
    }
692
    Config.gps_UseGPS       = false;                            // ist GPS aktiv?
693
    Config.gps_UsedGPSMouse = GPS_Bluetoothmouse1;
694
 
695
  //Config.WiIsSet          = false;                            // 15.07.2013 CB doppelt drin
696
  //Config.BTIsSet          = false;
697
    Config.Version          = EEpromVersion;
698
    Config.sIdxSteps        = STEPS_255;
699
    Config.servo[0].rev     = SERVO_REV;
700
    Config.servo[0].min     = SERVO_I0_RIGHT;
701
    Config.servo[0].max     = SERVO_I0_LEFT;
702
    Config.servo[0].mid     = SERVO_I0_MIDDLE;
703
    Config.servo[1].rev     = SERVO_REV;
704
    Config.servo[1].min     = SERVO_I0_RIGHT;
705
    Config.servo[1].max     = SERVO_I0_LEFT;
706
    Config.servo[1].mid     = SERVO_I0_MIDDLE;
707
    Config.servo_frame      = SERVO_PERIODE;
708
    Config.single_step      = SINGLE_STEP;                      // nur bei Test-Servo
709
    Config.repeat           = REPEAT;                           // nur bei Test-Servo
710
    Config.pause            = PAUSE;                            // nur bei Test-Servo
711
    Config.pause_step       = PAUSE_STEP;                       // nur bei Test-Servo
712
    Config.tracking         = TRACKING_MIN;
713
    Config.track_hyst       = TRACKING_HYSTERESE;
714
    Config.track_tx         = 0;
715
 
716
    for( i=0; i<5; i++)
717
    {
718
       Config.stick_min[i]      = 30+i;                         // Joystick
719
       Config.stick_max[i]      = 270+i;                        // Joystick
720
       Config.stick_typ[i]      = 0;                            // Joystick
721
       Config.stick_dir[i]      = 0;                            // Joystick
722
       Config.stick_neutral[i]  = 0;                            // Joystick
723
    }
724
 
725
    Config.Lipomessung          = true;
726
 
727
    Config.timezone             = 1;
728
    Config.summertime           = 1;
729
 
730
    strcpy_P( Config.Wlan_SSID    , PSTR("PKT"));               // Wlan
731
    strcpy_P( Config.Wlan_Password, PSTR("12345678"));          // Wlan
732
    Config.WLIsSet              = false;                        // Wlan
733
    Config.UseWL                = false;
734
    Config.OSD_UseScreen        = 0xffffffff;                   // alle OSD-Screens eingeschaltet
735
    Config.Wlan_DHCP            = 0;                            // kein DHCP
736
    Config.Wlan_WPA             = 0;                            // 0 = adhoc 1= WPA2
737
    Config.Wlan_Adhoc           = true;                         // Adhoc
738
    Config.Wlan_Channel         = 1;                            // Wlan Channel
739
    strcpy_P( Config.Wlan_IP     , PSTR("169.254.001.001"));
740
    strcpy_P( Config.Wlan_Netmask, PSTR("255.255.000.000"));
741
    strcpy_P( Config.Wlan_Gateway, PSTR("169.254.001.001"));
742
    Config.OSD_ShowCellU        = false;
743
    Config.UseBLE               = false;
744
 
745
    memset( Config.MKParam_Favs, 0, MAX_MKPARAM_FAVORITES );    // Favoriten MK-Parameter (Anzahl: MAX_MKPARAM_FAVORITES = 10)
746
 
747
    strcpy_P( Config.Wlan_HomeSSID    , PSTR(""));              // WiFly Home-Wlan: SSID (Home-WLAN)
748
    strcpy_P( Config.Wlan_HomePassword, PSTR(""));              // WiFly Home-Wlan: Passwort (Home-WLAN)
749
 
750
    //-------------------------------------------------
751
    //-------------------------------------------------
752
#ifdef USE_WAYPOINTS
753
    PointList_Clear();
754
#endif
755
    STAT_Init();                                                // Init OSD Statistik
756
    GPS_User_Init();                                            // Init GPS Positionen
757
    MKErr_Log_Init();                                           // Init MK Errorlog
758
 
759
    WriteParameter();
760
 
761
    //lcd_printp_at (0, 4, PSTR("Waypoints loeschen"), 0);
762
    //EEWayPointList_Clear();
763
 
764
    lcd_printp_at( 0, 6, PSTR("!!Check Parameter!! "), MNORMAL);
765
    lcd_printp_at(18, 7, PSTR("OK")                  , MNORMAL);
766
    sei();
767
    set_beep( 200, 0x0080, BeepNormal);
768
 
769
    while( !get_key_press (1 << KEY_ENTER) );
770
 
771
 
772
//#if defined HWVERSION3_9
773
    clr_V_On();
774
//#else
775
//
776
//  wdt_enable( WDTO_250MS );
777
//                  while (1)
778
//                  {;}
779
//#endif
780
}
781
 
782
 
783
//--------------------------------------------------------------
784
//
785
//void EEWayPointList_Clear(void)           // löschen der Waypointliste im EEProm
786
//{
787
//  uint8_t i;
788
//  PKTWayPoint.Waypoint.Position.Latitude = 0;
789
//  PKTWayPoint.Waypoint.Position.Longitude = 0;
790
//  PKTWayPoint.Waypoint.Position.Altitude = 0;
791
//  PKTWayPoint.Waypoint.Heading = 361;
792
 
793
//  for(i = 0; i < MAX_WPLIST_LEN; i++)
794
//  {
795
//      PKTWayPointDirectory.WPList.WPDirectory[i] = 0;
796
//  }
797
 
798
//  for(i = 0; i < NumberOfWaypoints; i++)
799
//  {
800
//      lcd_printp (PSTR("."), 0);
801
//      eeprom_write_byte (&EEWayPointList[i].WPIndex, i);
802
//      eeprom_write_byte (&EEWayPointList[i].Waypoint.Position.Status, INVALID);
803
//      eeprom_write_block ((const void*)&PKTWayPoint.Waypoint.Position.Latitude, (void*)&EEWayPointList[i].Waypoint.Position.Latitude, sizeof(EEWayPointList[i].Waypoint.Position.Latitude));
804
//      eeprom_write_block ((const void*)&PKTWayPoint.Waypoint.Position.Longitude, (void*)&EEWayPointList[i].Waypoint.Position.Longitude, sizeof(EEWayPointList[i].Waypoint.Position.Longitude));
805
//      eeprom_write_block ((const void*)&PKTWayPoint.Waypoint.Position.Altitude, (void*)&EEWayPointList[i].Waypoint.Position.Altitude, sizeof(EEWayPointList[i].Waypoint.Position.Altitude));
806
//      eeprom_write_block ((const void*)&PKTWayPoint.Waypoint.Heading, (void*)&EEWayPointList[i].Waypoint.Heading, sizeof(EEWayPointList[i].Waypoint.Heading));
807
//
808
//      eeprom_write_byte (&EEWayPointList[i].Waypoint.ToleranceRadius, 0);     // in meters, if the MK is within that range around the target, then the next target is triggered
809
//      eeprom_write_byte (&EEWayPointList[i].Waypoint.HoldTime, 0);            // in seconds, if the was once in the tolerance area around a WP, this time defines the delay before the next WP is triggered
810
//      eeprom_write_byte (&EEWayPointList[i].Waypoint.Type, POINT_TYPE_INVALID);
811
//      eeprom_write_byte (&EEWayPointList[i].Waypoint.Event_Flag, 0);          // future implementation
812
//      eeprom_write_byte (&EEWayPointList[i].Waypoint.AltitudeRate, 0);        // no change of setpoint
813
//  }
814
 
815
//  for(i = 0; i < NumberOfWPLists; i++)
816
//  {
817
//      lcd_printp (PSTR("."), 0);
818
//      eeprom_write_byte (&EEWPDirectory[i].WPList.WPListnumber, i);
819
//      eeprom_write_byte (&EEWPDirectory[i].WPList.WPListAktiv, false);
820
//      eeprom_write_byte (&EEWPDirectory[i].WPList.POI_CAM_NICK_CTR, 0);
821
//      eeprom_write_byte (&EEWPDirectory[i].WPList.UsePOI, 0);
822
//      eeprom_write_block ((const void*)&PKTWayPointDirectory.WPList.WPDirectory, (void*)&EEWPDirectory[i].WPList.WPDirectory, sizeof(EEWPDirectory[i].WPList.WPDirectory));
823
//
824
//  }
825
//  lcd_printp (PSTR("\r\n"), 0);
826
 
827
//}