Subversion Repositories Projects

Rev

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

Rev Author Line No. Line
1932 - 1
/*****************************************************************************
2
 *   Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de                  *
3
 *   Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net                  *
4
 *   Copyright (C) 2011 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
 
35
//############################################################################
36
//# HISTORY  setup.c
37
//#
38
//# 04.03.2013 Cebra
39
//# - del: OSD-Sreenmode ,is no longer necessary, last OSD-Screen is saved at shutdown
40
//############################################################################
41
 
42
 
43
//bt_connect
44
#include "../cpu.h"
45
#include <avr/io.h>
46
#include <avr/interrupt.h>
47
#include <avr/pgmspace.h>
48
#include <string.h>
49
#include <util/delay.h>
50
#include "../main.h"
51
#include "../setup/setup.h"
52
#include "../lcd/lcd.h"
53
#include "../eeprom/eeprom.h"
54
#include "../timer/timer.h"
55
#include "../menu.h"
56
#include "../wi232/Wi232.h"
57
#include "../bluetooth/bluetooth.h"
58
#include "../connect.h"
59
#include "../lipo/lipo.h"
60
#include "../messages.h"
61
#include "../eeprom/eeprom.h"
62
#include "../tracking/tracking.h"
63
#include "../uart/uart1.h"
64
#include "../osd/osd.h"
65
#include "../sound/pwmsine8bit.h"
66
#include "../tracking/servo_setup.h"
67
#include "../bluetooth/error.h"
68
#include "../stick/stick_setup.h"
69
 
70
 
71
 
72
uint8_t spalte;
73
uint8_t mmode;
74
uint8_t edit;
75
uint8_t LCD_Orientation;
76
uint8_t edit = 0;
77
uint8_t LCD_Change = 0;
78
uint8_t PKT_Change = 0;
79
uint16_t Pre;
80
uint16_t Pre16;
81
char EditString[21];
82
uint8_t bt_name_len;
83
uint8_t length_tmp;
84
uint8_t CheckGPS=false;
85
uint8_t Old_Baudrate = 0;              //Merkzelle für alte Baudrate
86
 
87
//--------------------------------------------------------------
88
#define ITEMS_PKT 13
89
 
90
const prog_char param_menuitems_pkt[ITEMS_PKT][NUM_LANG][18]= // zeilen,zeichen+1
91
    //    German,             English,            French,               Dutch
92
{
93
    {"Verbindung zum MK","connection to MK ","Aansluiting op MK"},
94
    {"PKT allgemein   \x1d","PKT global      \x1d","PKT global      \x1d"},
95
    {"Wi.232          \x1d","Wi.232          \x1d","Wi.232          \x1d"},
96
    {"BTM-222         \x1d","BTM-222         \x1d","BTM-222         \x1d"},
97
    {"Servo Menü      \x1d","servo menu      \x1d","servo menu      \x1d"},
98
    {"OSD Anzeige     \x1d","OSD screen      \x1d","OSD screen      \x1d"},
99
    {"GPS             \x1d","GPS             \x1d","GPS             \x1d"},
100
    {"Follow Me       \x1d","Follow Me       \x1d","Follow Me       \x1d"},
101
    {"Joystick        \x1d","joystick        \x1d","joystick        \x1d"},
102
    {"PKT-Akku        \x1d","PKT-Accu        \x1d","PKT-Accu        \x1d"},
103
    {"PKT Update       ","PKT Update       ","PKT Update       "},
104
    {"Debug PKT        ","Debug PKT        ","Debug PKT        "},
105
    {"EEProm Reset     ","EEProm Reset     ","EEProm Reset     "},
106
};
107
 
108
#define ITEMS_LCD 11
109
 
110
const prog_char param_menuitems_lcd[ITEMS_LCD][NUM_LANG][18]= // zeilen,zeichen+1
111
    //    German,             English,            French,               Dutch
112
{
113
    {"Infos beim Start ","info at startup  ","info bij opstart "},
114
    {"OSD Empfangsausf.","OSD receive Error","OSD receive Error"},
115
    {"Sprache          ","language         ","taal             "},
116
    {"Licht aus nach...","light off after  ","licht uit na     "},
117
    {"Helligkeit       ","brightness       ","helderheid       "},
118
    {"Kontrast         ","contrast         ","contrast         "},
119
    {"Normal/Invers    ","normal/inverted  ","Normal/inverted  "},
120
    {"Orientierung     ","orientation      ","orientatie       "},
121
    {"Vario Ton Erw.   ","Vario Sound Ext. ","Vario Sound Ext. "},
122
    {"Hardware Beeper  ","Hardware Beeper  ","Hardware Beeper  "},
123
    {"Lautstärke  Ton  ","Volume           ","Volume           "},
124
};
125
 
126
#define ITEMS_WI 9
127
 
128
const prog_char param_menuitems_wi[ITEMS_WI][NUM_LANG][18]= // zeilen,zeichen+1
129
    //    German,             English,            French,               Dutch
130
{
131
    {"Modul eingebaut? ","module built in? ","Module geinstal.?"},
132
    {"TX/RX Kanal      ","TX/RX Channel    ","TX/RX Channel    "},
133
    {"NetW. Gruppe     ","NetW. Group      ","NetW. Group      "},
134
    {"NetW. Mode       ","NetW. Mode       ","NetW. Mode       "},
135
    {"TX Timeout       ","TX Timeout       ","TX Timeout       "},
136
    {"TX MTU           ","TX MTU           ","TX MTU           "},
137
    {"Baudrate Wi232/BT","Baudrate Wi232/BT","Baudrate Wi232/BT"},
138
    {"Initialisieren   ","initialize       ","Initialize       "},
139
    {"Konfig. mit PC   ","config. with  PC ","Config. met PC   "},
140
};
141
 
142
 
143
#define ITEMS_BT 7
144
 
145
const prog_char param_menuitems_bt[ITEMS_BT][NUM_LANG][18]= // zeilen,zeichen+1
146
    //    German,             English,            Dutch
147
{
148
    {"Modul eingebaut? ","module built in? ","module geinstall?"},
149
    {"Name             ","name             ","Naam             "},
150
    {"Pin              ","pin              ","Pin              "},
151
    {"Initialisieren   ","initialize       ","Initialize       "},
152
    {"Bluetooth MAC-Adr","Bluetooth MAC-Adr","Bluetooth MAC-Adr"},
153
    {"RE-ID            ","RE-ID            ","RE-ID            "},
154
    {"Konfig. mit PC   ","config. with  PC ","Config. met PC   "},
155
};
156
 
157
#define ITEMS_Accu 2
158
 
159
const prog_char param_menuitems_Accu[ITEMS_Accu][NUM_LANG][18]= // zeilen,zeichen+1
160
    //    German,             English,            French,               Dutch
161
{
162
    {"PKT-Akkutyp      ","PKT-Accutyp      ","PKT-batterij type"},
163
    {"PKT Akku Messung ","PKT AccuMeasure  ","PKT batt. meting "},
164
};
165
 
166
#define ITEMS_GPS 6
167
 
168
const prog_char param_menuitems_GPS[ITEMS_GPS][NUM_LANG][18]= // zeilen,zeichen+1
169
    //    German,             English,            French,               Dutch
170
{
171
    {"wähle GPS Maus   ","select GPS mouse ","select GPS mouse "},
172
    {"Suche GPS Maus   ","search GPS mouse ","search GPS mouse "},
173
    {"GPS Maus Typ     ","GPS mouse typ    ","GPS mouse typ    "},
174
    {"GPS Maus aktiv?  ","GPS mouse activ? ","GPS mouse activ? "},
175
    {"Zeige GPS Device ","show GPS device  ","show GPS device  "},
176
    {"GPS Daten        ","GPS data         ","GPS data         "},
177
 
178
};
179
 
180
#define ITEMS_FOLLOWME 3
181
 
182
const prog_char param_menuitems_FOLLOWME[ITEMS_GPS][NUM_LANG][18]= // zeilen,zeichen+1
183
    //    German,             English,            French,               Dutch
184
{
185
    {"FollowMe Refresh","FollowMe Refresh","FollowMe Refresh"},
186
    {"FollowMe Speed  ","FollowMe Speed  ","FollowMe Speed  "},
187
    {"Toleranz Radius ","Tolerance Radius","Tolerance Radius"},
188
 
189
 
190
};
191
 
192
 
193
 
194
#define ITEMS_OSD 9
195
 
196
const prog_char param_menuitems_OSD[ITEMS_OSD][NUM_LANG][18]= // zeilen,zeichen+1
197
    //    German,             English,            French,               Dutch
198
{
199
    {"OUT1/2 Format    ","OUT1/2 format    ","OUT1/2 format    "},
200
    {"OUT1/2 Polarität ","OUT1/2 polarity  ","OUT1/2 polarity  "},
201
    {"Navi Daten an SV2","Navi data to SV2 ","Navi data to SV2 "},
202
    {"Max. Sinkrate m/s","max fallspeed m/s","max fallspeed m/s"},
203
    {"Variometer Beep  ","Variometer beep  ","Variometer beep  "},
204
    {"Home aus MK Sicht","home from MK view","home from MK view"},
205
    {"MK LowBat Warnung","MK LowBat warning","MK LoBat alarm   "},
206
    {"MK mAh    Warnung","MK mAh warning   ","MK mAh alarm     "},
207
    {"MK Volt    Balken","MK volt bargraph ","MK volt bargraph "},
208
};
209
 
210
//--------------------------------------------------------------
211
void Show_Error_HW12(void)
212
{
213
        lcd_cls();
214
        lcd_printp_at (0,3,PSTR("  Mit Hardware 1.x   "), 2);
215
        lcd_printp_at (0,4,PSTR("   nicht möglich    "), 2);
216
        _delay_ms(1000);
217
 
218
}
219
 
220
void Edit_printout(uint16_t Value,uint16_t min,uint16_t max, uint8_t what)
221
{
222
 
223
  switch (what)
224
    {
225
      case Show_uint3:           write_ndigit_number_u (16, 2,Value, 3, 0,0);break;
226
      case Show_uint5:           write_ndigit_number_u (16, 2,Value, 5, 0,0);break;
227
      case Show_uint10th:       write_ndigit_number_u_10th (16, 2,Value, 3, 0,0); break;
228
      case GPSMOUSE:
229
                                switch(Value)
230
                                {
231
                                  case GPS_Bluetoothmouse1: lcd_printp_at (12, 2, PSTR("BT-Mouse1"), 0);break;
232
                                  case GPS_Mikrokopter:     lcd_printp_at (12, 2, PSTR("Mikrokopt"), 0);break;
233
                                  lcd_printp_at (12, 2, PSTR("unknown"), 0);
234
                                  break;
235
 
236
                                }
237
                                break;
238
 
239
      case Wi_Netmode:
240
                                switch (Value)
241
                                {
242
                                        case    false :lcd_puts_at(15, 2, strGet(SLAVE), 0);
243
                                                break;
244
                                        case    true :lcd_puts_at(15, 2, strGet(NORMAL), 0);
245
                                                break;
246
                                        break;
247
                                }
248
                                break;
249
 
250
      case OnOff:
251
                                  switch (Value)
252
 
253
                                {
254
                                        case    false :lcd_puts_at(17, 2, strGet(OFF), 0);
255
                                                break;
256
                                        case    true :lcd_puts_at(17, 2, strGet(ON), 0);
257
                                                break;
258
                                        break;
259
                                }
260
                                  break;
261
 
262
      case YesNo:
263
                                  switch (Value)
264
 
265
                                {
266
                                        case    false :lcd_puts_at(17, 2, strGet(NOO), 0);
267
                                                break;
268
                                        case    true :lcd_puts_at(17, 2, strGet(YES), 0);
269
                                                break;
270
                                        break;
271
                                }
272
                                  break;
273
 
274
      case NormRev:
275
                                  switch (Value)
276
                            {
277
                                    case    false :lcd_puts_at(14, 2, strGet(NORMAL), 0);
278
                                            break;
279
                                    case    true :lcd_puts_at(14, 2, strGet(REVERSE), 0);
280
                                            break;
281
                                    break;
282
                            }
283
                               break;
284
 
285
 
286
 
287
      case Kontrast:       {
288
                                write_ndigit_number_u (16, 2,Value, 3, 0,0);
289
                                if (Value >= max)
290
                                {
291
                                        Value = max;
292
                                        set_beep ( 200, 0x0080, BeepNormal);
293
                                        write_ndigit_number_u (16, 2,Value, 3, 0,0);
294
                                }
295
                                else
296
                                {
297
                                       write_ndigit_number_u (16, 2,Value, 3, 0,0);
298
                                        cli();
299
                                        clr_A0 ();
300
                                        send_byte (0x81);
301
                                        send_byte (Value);      // Daten zum LCD senden
302
                                        set_A0 ();
303
                                        sei();
304
                                }
305
 
306
//                                break;
307
 
308
                                if (Value == min)
309
                                {
310
                                        write_ndigit_number_u (16, 2,Value, 3, 0,0);
311
                                        Value = min;
312
                                        set_beep ( 200, 0x0080, BeepNormal);
313
                                }
314
                                else
315
                                {
316
                                        write_ndigit_number_u (16, 2,Value, 3, 0,0);
317
                                        cli();
318
                                        clr_A0 ();
319
                                        send_byte (0x81);
320
                                        send_byte (Value);      // Daten zum LCD senden
321
                                        set_A0 ();
322
                                        sei();
323
                                }
324
 
325
                        }
326
                        break;
327
 
328
 
329
      case Baudrate:
330
                                switch (Value)
331
 
332
                        {
333
                                case    0x0 :   lcd_printp_at(15, 2, PSTR("2400  "), 0);
334
                                        break;
335
                                case    0x1 :   lcd_printp_at(15, 2, PSTR("9600  "), 0);
336
                                        break;
337
                                case    0x2 :   lcd_printp_at(15, 2, PSTR("19200 "), 0);
338
                                        break;
339
                                case    0x3 :   lcd_printp_at(15, 2, PSTR("38400 "), 0);
340
                                        break;
341
                                case    0x4 :   lcd_printp_at(15, 2, PSTR("57600 "), 0);
342
                                        break;
343
                                case    0x5 :   lcd_printp_at(15, 2, PSTR("115200"), 0);
344
                                        break;
345
                                case    0x6 :   lcd_printp_at(15, 2, PSTR("4800  "), 0);
346
                                        break;
347
                                break;
348
                        }
349
                        break;
350
case Language:
351
                          switch (Value)
352
                        {
353
                                case
354
                                         0x0 :  lcd_puts_at(10, 2, strGet(DEUTSCH), 0);//lcd_printp_at (14, 2, PSTR("Deutsch"), 0);
355
                                        break;
356
                                case    0x1 :   lcd_puts_at(10, 2, strGet(ENGLISCH), 0);//lcd_printp_at (14, 2, PSTR("English"), 0);
357
                                        break;
358
                                case    0x2 :   lcd_puts_at(10, 2, strGet(NETHERL), 0);//lcd_printp_at (14, 2, PSTR("Netherl"), 0);
359
                                        break;
360
                                break;
361
                        }
362
                       break;
363
case Sticktype:
364
                            switch (Value)
365
 
366
                          {
367
                                  case    false :lcd_puts_at(14, 2, strGet(POTI), 0);
368
                                          break;
369
                                  case    true :lcd_puts_at(14, 2, strGet(TASTER), 0);
370
                                          break;
371
                                  break;
372
                          }
373
                            break;
374
 
375
 
376
 
377
     break;
378
    }
379
 
380
}
381
 
382
uint16_t Edit_generic(uint16_t Value, uint16_t min, uint16_t max,uint8_t Text, uint8_t what)
383
{
384
    Pre = Value;
385
 
386
        lcd_cls();
387
    lcd_puts_at(0, 2, strGet(Text), 0);
388
    Edit_printout(Value,min,max, what);
389
    lcd_puts_at(0, 7, strGet(KEYLINE2), 0);
390
 
391
    do
392
    {
393
        if ((get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 2)) && (Value < max))
394
        {
395
            edit = 1;
396
            Value++;
397
            Edit_printout(Value,min,max, what);
398
            playTone(500,20,Config.Volume);
399
        }
400
        if ((get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 2)) && (Value > min))
401
        {
402
                edit = 1;
403
            Value--;
404
            Edit_printout(Value,min,max, what);
405
            playTone(500,20,Config.Volume);
406
        }
407
 
408
        if (get_key_press (1 << KEY_ENTER))
409
          {
410
 
411
            return Value;
412
          }
413
      }
414
    while (!get_key_press (1 << KEY_ESC));
415
 
416
    get_key_press(KEY_ALL);
417
    edit = 0;
418
    return Pre;
419
 
420
}
421
 
422
//--------------------------------------------------------------
423
uint8_t ChangeWi_SV2(uint8_t Value)
424
{
425
        Pre = Value;
426
        lcd_cls();
427
 
428
        lcd_puts_at(0, 1, strGet(CONNECT1), 0);
429
        lcd_puts_at(0, 2, strGet(CONNECT2), 0);
430
 
431
        if(Config.UseWi == false)
432
        {
433
                lcd_puts_at(0, 1, strGet(CONNECT1), 0);
434
                lcd_puts_at(0, 2, strGet(CONNECT4), 0);
435
                lcd_puts_at(0, 1, strGet(CONNECT5), 0);
436
                lcd_puts_at(0, 2, strGet(CONNECT6), 0);
437
                lcd_puts_at(0, 1, strGet(CONNECT7), 0);
438
                lcd_puts_at(0, 2, strGet(CONNECT8), 0);
439
                lcd_puts_at(0, 1, strGet(CONNECT9), 0);
440
 
441
 
442
//              lcd_printp_at (12, 7, PSTR("Ende"), 0);
443
                  lcd_puts_at(12, 7, strGet(ENDE), 0);
444
                while (!get_key_press (1 << KEY_ESC));
445
                get_key_press(KEY_ALL);
446
                edit = 0;
447
                return Pre;
448
        }
449
        else
450
        {
451
                switch (Value)
452
                {
453
                        case    0x0 :lcd_printp_at (14, 2, PSTR("Wi232"), 0);
454
                                break;
455
                        case    0x1 : lcd_puts_at(14, 2, strGet(KABEL), 0);
456
 
457
                        //lcd_printp_at (14, 2, PSTR("Kabel"), 0);
458
 
459
                                break;
460
                        break;
461
                }
462
//              lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0);
463
                lcd_puts_at(0, 7, strGet(KEYLINE2), 0);
464
 
465
                do
466
                {
467
                        if(Config.UseWi == true)
468
                        {
469
                                if ((get_key_press (1 << KEY_PLUS)) && (Value == 0))
470
                                {
471
                                        edit = 1;
472
                                        Value = 1;
473
//                                      lcd_printp_at (14, 2, PSTR("Kabel"), 0);
474
                                        lcd_puts_at(14, 2, strGet(KABEL), 0);
475
                                        Change_Output(Uart02FC);
476
                                }
477
 
478
                                if ((get_key_press (1 << KEY_MINUS)) && (Value == 1))
479
                                {
480
                                        edit = 1;
481
                                        Value = 0;
482
                                        lcd_printp_at (14, 2, PSTR("Wi232"), 0);
483
                                        Change_Output(Uart02Wi);
484
                                }
485
 
486
                                if (get_key_press (1 << KEY_ENTER))
487
                                {
488
//                                      lcd_printp_at (0, 4, PSTR("Sie müssen das PKT"), 0);
489
//                                      lcd_printp_at (0, 5, PSTR("jetzt neu starten!"), 0);
490
                                       lcd_puts_at(0, 4, strGet(CONNECT10), 0);
491
                                       lcd_puts_at(0, 5, strGet(CONNECT11), 0);
492
                                        lcd_cls_line (0, 7, 18);
493
                                        while (!get_key_press (1 << KEY_ENTER));
494
                                        return Value;
495
                                }
496
                        }
497
                }
498
                while (!get_key_press (1 << KEY_ESC));
499
        }
500
                get_key_press(KEY_ALL);
501
                edit = 0;
502
                return Pre;
503
}
504
 
505
 
506
//--------------------------------------------------------------
507
uint8_t Edit_DisplayHelligkeit(uint8_t Value, uint8_t min, uint8_t max, uint8_t Text)
508
{
509
        float ValCorr = 2.55;  // (Value * ValCorr) maximal 255
510
        Pre = Value;
511
        OCR2A = Value * ValCorr;
512
 
513
        lcd_cls();
514
//      lcd_printp_at (0, 2, Text, 0);
515
        lcd_puts_at(0, 2, strGet(Text), 0);
516
        write_ndigit_number_u (16, 2, Value, 3, 0,0);
517
        lcd_printp_at (17, 2, PSTR("%"), 0);
518
//      lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0);
519
        lcd_puts_at(0, 7, strGet(KEYLINE2), 0);
520
 
521
        do
522
        {
523
                write_ndigit_number_u (16, 2,Value, 3, 0,0);
524
                lcd_frect ((8*0), (8*4), (Value * (16*8) / 100), 6, 1);
525
 
526
                if ((get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 3)) && (Value < max))
527
                {
528
                        Value++;
529
 
530
                        if (Value >= max)
531
                        {
532
                                Value = max;
533
                                set_beep ( 200, 0x0080, BeepNormal);
534
                        }
535
                        else
536
                                OCR2A = Value * ValCorr;
537
 
538
                }
539
 
540
                if ((get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 3)) && (Value > min))
541
                {
542
                        lcd_frect (((Value - 1) * (16*8) / 100), (8*4), (16*8), 6, 0);
543
                        Value--;
544
 
545
                        if (Value == min)
546
                        {
547
                                Value = min;
548
                                set_beep ( 200, 0x0080, BeepNormal);
549
                        }
550
                        else
551
                                OCR2A = Value * ValCorr;
552
 
553
                }
554
 
555
                if (get_key_press (1 << KEY_ENTER))
556
                {
557
                        edit = 1;
558
                        OCR2A = Value * ValCorr;
559
                        Config.LCD_Helligkeit = Value;
560
//                      WriteParameter();
561
                        edit = 0;
562
                        return Value;
563
                }
564
        }
565
 
566
        while (!get_key_press (1 << KEY_ESC));
567
        {
568
                get_key_press(KEY_ALL);
569
                edit = 0;
570
                OCR2A = Pre * ValCorr;
571
                Config.LCD_Helligkeit = Pre;
572
//              WriteParameter();
573
                return Pre;
574
        }
575
}
576
 
577
 
578
//--------------------------------------------------------------
579
void Reset_EEprom(void)
580
{
581
        lcd_cls();
582
        get_key_press(KEY_ALL);
583
//      lcd_printp_at (0, 2, PSTR(" EEProm wirklich"), 0);
584
//     lcd_printp_at (0, 3, PSTR(" löschen?"), 0);
585
//     lcd_printp_at (12, 7, PSTR("Ende   OK"), 0);
586
        lcd_puts_at(0, 2, strGet(EEPROM1), 0);
587
        lcd_puts_at(0, 3, strGet(EEPROM2), 0);
588
        lcd_puts_at(12, 7, strGet(ENDOK), 0);
589
 
590
 
591
        do
592
        {
593
 
594
                if (get_key_press (1 << KEY_ENTER))
595
                {
596
                        Delete_EEPROM();
597
                        clr_V_On();
598
                        return;
599
                }
600
        }
601
        while (!get_key_press (1 << KEY_ESC));
602
        get_key_press(KEY_ALL);
603
}
604
 
605
 
606
//--------------------------------------------------------------
607
void PKT_Setup (void)
608
{
609
//      uint8_t ii = 0;
610
//      uint8_t Offset = 0;
611
//      uint8_t size = 0;
612
 
613
//      uint8_t dmode = 0;
614
        uint8_t target_pos=1;
615
//      uint8_t val;
616
 
617
        lcd_cls ();
618
        mmode = 0;
619
        edit= 0;
620
        val = 0;
621
 
622
        while(1)
623
        {
624
                size = ITEMS_PKT;
625
                lcd_cls ();
626
                lcd_printp_at (0, 0, PSTR(" PKT-Setup           "), 2);
627
//              lcd_printp_at (0, 7, PSTR(KEY_LINE_1), 0);
628
                lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
629
 
630
//              while(1)
631
//              {
632
//                      ii = 0;
633
//
634
//                      if(Offset > 0)
635
//                              lcd_printp_at(1,1, PSTR("\x12"), 0);
636
//
637
//                      for(ii = 0;ii < 6 ; ii++)
638
//                      {
639
//                              if((ii+Offset) < size)
640
//                                      lcd_printp_at(3,ii+1,param_menuitems_pkt[ii+Offset][Config.DisplayLanguage], 0);
641
//
642
//                              if((ii == 5)&&(ii+Offset < (size-1)))
643
//                                      lcd_printp_at(1,6, PSTR("\x13"), 0);
644
//
645
//                      }
646
//
647
//                      if(dmode == 0)
648
//                      {
649
//                              if(Offset == 0)
650
//                              {
651
//                                      if(size > 6)
652
//                                              val = menu_choose2 (1, 5, target_pos,0,1);
653
//                                      else
654
//                                              val = menu_choose2 (1, size, target_pos,0,0);
655
//
656
//                              }
657
//                              else
658
//                                      val = menu_choose2 (2, 5, target_pos,1,1);
659
//
660
//                      }
661
//
662
//                      if(dmode == 1)
663
//                      {
664
//                              if(Offset+7 > size)
665
//                                      val = menu_choose2 (2, 6, target_pos,1,0);
666
//                              else
667
//                                      val = menu_choose2 (2, 5, target_pos,1,1);
668
//
669
//                      }
670
//
671
//                      if(val == 254)
672
//                      {
673
//                              Offset++;
674
//                              dmode = 1;
675
//                              target_pos = 5;
676
//                      }
677
//                      else if(val == 253)
678
//                      {
679
//                              Offset--;
680
//                              dmode = 0;
681
//                              target_pos = 2;
682
//                      }
683
//                      else if(val == 255)
684
//                      {       // Ende mit ESC, speichern
685
//                              if (edit == 1)
686
//                              {
687
//                                      WriteParameter();
688
//                                      edit = 0;
689
//                                      return;
690
//                              }
691
//                              return;
692
//                      }
693
//                      else
694
//                              break;
695
//              }
696
 
697
                val = menu_select(param_menuitems_pkt,size,target_pos);
698
                if (val==255) break;
699
                target_pos = val;
700
 
701
//
702
//                  {"Verbindung zum MK","connection to MK "," connexion a MK " ,"Aansluiting op MK"},
703
//                  {"MK LowBat Warnung","MK LowBat warning","MK LowBat Attent", "MK LoBat alarm   "},
704
//                  {"Anzeige         \x1d","Display         \x1d","d'affichage     \x1d","Display         \x1d"},
705
//                  {"Wi.232          \x1d","Wi.232          \x1d","Wi.232          \x1d","Wi.232          \x1d"},
706
//                  {"BTM-222         \x1d","BTM-222         \x1d","BTM-222         \x1d","BTM-222         \x1d"},
707
//                  {"Antennen Track. \x1d","antenna tracking\x1d","antenna tracking\x1d","antenna tracking\x1d"},
708
//                  {"OSD             \x1d","OSD             \x1d","OSD             \x1d","OSD             \x1d"},
709
//                  {"GPS             \x1d","GPS             \x1d","GPS             \x1d","GPS             \x1d"},
710
//                   "Follow Me       \x1d"
711
//                  {"PKT-Akku        \x1d","PKT-Accu        \x1d","PKT-Accu        \x1d","PKT-Accu        \x1d"},
712
//                  {"PKT Update       ","PKT Update       ","PKT Mise a jour  ","PKT Update       "},
713
//                  {"Debug PKT        ","Debug PKT        ","Debug PKT        ","Debug PKT        "},
714
//                  {"EEProm Reset     ","EEProm Reset     ","EEProm Reinitiali","EEProm Reset     "},
715
 
716
 
717
 
718
                if((val + offset) == 1)
719
                {
720
#ifdef HWVERSION3_9
721
                    Config.U02SV2 = ChangeWi_SV2(Config.U02SV2);
722
 
723
                        if (edit == 1)
724
                                PKT_Change = 1;
725
 
726
#else
727
                        Show_Error_HW12();
728
#endif
729
                }
730
 
731
 
732
                if((val + offset) == 2) Display_Setup();
733
 
734
                if((val + offset) == 3)
735
                {
736
#if defined HWVERSION3_9 || defined HWVERSION1_2W || defined HWVERSION1_3W
737
                        if(Config.UseWi == false)
738
//                              Wi_Use();
739
                          {
740
                            Config.UseWi = Edit_generic(Config.UseWi,0,1,WI2321,YesNo);
741
                             if (edit==1)
742
                              if (Config.UseWi== true) InitWi232(Config.PKT_Baudrate);
743
                          }
744
 
745
                        else
746
                                Wi_Setup();
747
#else
748
                        Show_Error_HW12();
749
#endif
750
                }
751
 
752
                if((val + offset) == 4)
753
                {
754
#ifdef HWVERSION3_9
755
                        if(Config.UseBT == 0)
756
                          {
757
                            Config.UseBT = Edit_generic(Config.UseBT,0,1,BT1,YesNo);
758
                            if (edit==1)
759
                             if (Config.UseBT == 1)
760
                               {
761
                                 if (bt_init()) Config.BTIsSet = true; else Config.BTIsSet = false;
762
//                               WriteParameter();
763
                                 edit = 0;
764
                               }
765
                          }
766
                        else
767
                                BT_Setup();
768
#else
769
                        Show_Error_HW12();
770
#endif
771
                }
772
 
773
                if((val + offset) == 5) servo_menu();
774
                if((val + offset) == 6) OSD_Setup();
775
#ifdef HWVERSION3_9
776
                if((val + offset) == 7) GPS_Setup();
777
 
778
                if((val + offset) == 8) FollowMe_Setup();
779
                if((val + offset) == 9) Joysticks_Setup();
780
 
781
                if((val + offset) == 10) Accu_Setup();
782
#else
783
                        Show_Error_HW12();
784
#endif
785
                if((val + offset) == 11) Update_PKT();
786
 
787
                if((val + offset) == 12) Config.Debug =  Edit_generic(Config.Debug,0,1,DEBUGPKT,Show_uint3);
788
 
789
                if((val + offset) == 13) Reset_EEprom();
790
 
791
 
792
        }
793
}
794
 
795
 
796
//--------------------------------------------------------------
797
void Display_Setup (void)
798
{
799
//      uint8_t ii = 0;
800
//      uint8_t Offset = 0;
801
//      uint8_t size = 0;
802
 
803
//      uint8_t dmode = 0;
804
        uint8_t target_pos = 1;
805
//      uint8_t val;
806
 
807
        lcd_cls ();
808
        mmode = 0;
809
        edit= 0;
810
        LCD_Change = 0;
811
//      val = 0;
812
 
813
        while(1)
814
        {
815
                size = ITEMS_LCD;
816
                lcd_cls ();
817
                lcd_puts_at(0, 0, strGet(DISPLAY1), 2);
818
                lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
819
 
820
//              while(1)
821
//              {
822
//                      ii = 0;
823
//
824
//                      if(Offset > 0)
825
//                              lcd_printp_at(1, 1, PSTR("\x12"), 0);
826
//
827
//                      for(ii = 0; ii < 6 ; ii++)
828
//                      {
829
//                              if((ii + Offset) < size)
830
//                                      lcd_printp_at(3, ii + 1, param_menuitems_lcd[ii + Offset][Config.DisplayLanguage], 0);
831
//
832
//                              if((ii == 5)&&(ii+Offset < (size - 1)))
833
//                                      lcd_printp_at(1,6, PSTR("\x13"), 0);
834
//
835
//                      }
836
//
837
//                      if(dmode == 0)
838
//                      {
839
//                              if(Offset == 0)
840
//                              {
841
//                                      if(size > 6)
842
//                                              val = menu_choose2 (1, 5, target_pos,0,1);
843
//                                      else
844
//                                              val = menu_choose2 (1, size, target_pos,0,0);
845
//
846
//                              }
847
//                              else
848
//                                      val = menu_choose2 (2, 5, target_pos,1,1);
849
//
850
//                      }
851
//
852
//                      if(dmode == 1)
853
//                      {
854
//                              if(Offset + 7 > size)
855
//                                      val = menu_choose2 (2, 6, target_pos,1,0);
856
//                              else
857
//                                      val = menu_choose2 (2, 5, target_pos,1,1);
858
//
859
//                      }
860
//
861
//                      if(val == 254)
862
//                      {
863
//                              Offset++;
864
//                              dmode = 1;
865
//                              target_pos = 5;
866
//                      }
867
//                      else if(val == 253)
868
//                      {
869
//                              Offset--;
870
//                              dmode = 0;
871
//                              target_pos = 2;
872
//                      }
873
//                      else if(val == 255)
874
//                      {       // Ende mit ESC, speichern
875
//                              if (edit == 1)
876
//                              {
877
//                                      WriteParameter();
878
//                                      edit = 0;
879
//                                      return;
880
//                              }
881
//                              return;
882
//                      }
883
//                      else
884
//                              break;
885
//              }
886
 
887
                val = menu_select(param_menuitems_lcd,size,target_pos);
888
                if (val==255) break;
889
                target_pos = val;
890
 
891
                if((val + offset) == 1)
892
                  Config.PKT_StartInfo = Edit_generic(Config.PKT_StartInfo,0,2,DISPLAY2,OnOff);
893
                if((val + offset) == 2)
894
                  Config.OSD_RCErrorbeep = Edit_generic(Config.OSD_RCErrorbeep,0,2,DISPLAY9,OnOff);
895
 
896
                if((val + offset) == 3)
897
                  Config.DisplayLanguage = Edit_generic(Config.DisplayLanguage,0,2,DISPLAY3,Language);
898
 
899
 
900
                if((val + offset) == 4)
901
                  Config.DisplayTimeout = Edit_generic(Config.DisplayTimeout,0,254,DISPLAY4,Show_uint3);
902
 
903
                if((val + offset) == 5)
904
                  {
905
                      if (Config.HWSound==0)
906
                        {
907
                          Config.LCD_Helligkeit =  Edit_DisplayHelligkeit(Config.LCD_Helligkeit,0,100,DISPLAY5);
908
                        if (edit == 1)
909
                                if(!LCD_Change)
910
                                        LCD_Change =1;
911
                        }
912
 
913
 
914
                  }
915
 
916
 
917
                if((val + offset) == 6)
918
                  Config.LCD_Kontrast =  Edit_generic(Config.LCD_Kontrast,0,63,DISPLAY6,Kontrast);
919
                        if (edit == 1)
920
                                if(!LCD_Change)
921
                                        LCD_Change =1;
922
 
923
                if((val + offset) == 7)
924
                {
925
                    Config.LCD_DisplayMode = Edit_generic(Config.LCD_DisplayMode,0,4,DISPLAY7,NormRev);
926
                        if (edit == 1)
927
                                if(!LCD_Change)
928
                                        LCD_Change =1;
929
                }
930
 
931
                if((val + offset) == 8)
932
                {
933
                    Config.LCD_ORIENTATION = Edit_generic(Config.LCD_ORIENTATION,0,4,DISPLAY8,NormRev);
934
                        if (edit == 1)
935
                                if(!LCD_Change)
936
                                        LCD_Change =1;
937
                }
938
                if((val + offset) == 9)
939
                {
940
                    Config.HWSound = Edit_generic(Config.HWSound,0,1,HWSOUND,YesNo);
941
 
942
                }
943
                if((val + offset) == 10)
944
                {
945
                    Config.HWBeeper = Edit_generic(Config.HWBeeper,0,1,HWBEEPER,YesNo);
946
 
947
                }
948
                if((val + offset) == 11)
949
                  Config.Volume = Edit_generic(Config.Volume,0,50,VOLUME,Show_uint3);
950
 
951
 
952
        }
953
}
954
 
955
 
956
//--------------------------------------------------------------
957
void Wi_Setup (void)
958
{
959
//      uint8_t ii = 0;
960
//      uint8_t Offset = 0;
961
//      uint8_t size = 0;
962
 
963
//      uint8_t dmode = 0;
964
        uint8_t target_pos = 1;
965
//      uint8_t val = 0;
966
 
967
        mmode = 0;
968
        edit = 0;
969
//      WiIsSet = true;
970
 
971
        lcd_cls ();
972
 
973
        while(1)
974
        {
975
                size = ITEMS_WI;
976
                lcd_cls ();
977
                lcd_printp_at (0, 0, PSTR(" Wi.232 Setup        "), 2);
978
                lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
979
 
980
//              while(1)
981
//              {
982
//                      ii = 0;
983
//
984
//                      if(Offset > 0)
985
//                              lcd_printp_at(1, 1, PSTR("\x12"), 0);
986
//
987
//                      for(ii = 0; ii < 6; ii++)
988
//                      {
989
//                              if((ii + Offset) < size)
990
//                                      lcd_printp_at(3, ii+1, param_menuitems_wi[ii+Offset][Config.DisplayLanguage], 0);
991
//
992
//                              if((ii == 5)&&(ii + Offset < (size - 1)))
993
//                                      lcd_printp_at(1, 6, PSTR("\x13"), 0);
994
//
995
//                      }
996
//
997
//                      if(dmode == 0)
998
//                      {
999
//                              if(Offset == 0)
1000
//                              {
1001
//                                      if(size > 6)
1002
//                                              val = menu_choose2 (1, 5, target_pos,0,1);
1003
//                                      else
1004
//                                              val = menu_choose2 (1, size, target_pos,0,0);
1005
//
1006
//                              }
1007
//                              else
1008
//                                      val = menu_choose2 (2, 5, target_pos,1,1);
1009
//
1010
//                      }
1011
//
1012
//                      if(dmode == 1)
1013
//                      {
1014
//                              if(Offset + 7 > size)
1015
//                                      val = menu_choose2 (2, 6, target_pos, 1, 0);
1016
//                              else
1017
//                                      val = menu_choose2 (2, 5, target_pos, 1, 1);
1018
//
1019
//                      }
1020
//
1021
//                      if(val == 254)
1022
//                      {
1023
//                              Offset++;
1024
//                              dmode = 1;
1025
//                              target_pos = 5;
1026
//                      }
1027
//                      else if(val == 253)
1028
//                      {
1029
//                              Offset--;
1030
//                              dmode = 0;
1031
//                              target_pos = 2;
1032
//                      }
1033
//                      else if(val == 255)
1034
//                      {       // Ende mit ESC, speichern
1035
//                              if (edit == 1)
1036
//                              {
1037
//                                  if (Config.UseWi==true) InitWi232(Config.PKT_Baudrate);
1038
//                                  //Old_Baudrate = PKT_Baudrate;
1039
//                                  WriteParameter();
1040
//                                  edit = 0;
1041
//                              }
1042
//
1043
//                              return;
1044
//                      }
1045
//                      else
1046
//
1047
//                              break;
1048
//              }
1049
 
1050
                val = menu_select(param_menuitems_wi,size,target_pos);
1051
                if (val==255)
1052
                  {
1053
                   if (edit == 1)
1054
                      {
1055
                          if (Config.UseWi==true) InitWi232(Config.PKT_Baudrate);
1056
                          //Old_Baudrate = PKT_Baudrate;
1057
//                          WriteParameter();
1058
                          edit = 0;
1059
                      }
1060
                  break;
1061
                  }
1062
 
1063
                target_pos = val;
1064
 
1065
                if((val + offset) == 1)
1066
                  {
1067
                    Config.UseWi = Edit_generic(Config.UseWi,0,1,WI2321,YesNo);
1068
                  }
1069
 
1070
                if((val + offset) == 2)
1071
                {
1072
                    Config.WiTXRXChannel = Edit_generic(Config.WiTXRXChannel, 0, 5,WITXRX,Show_uint3);
1073
 
1074
                }
1075
 
1076
                if((val + offset) == 3)
1077
                {
1078
                    Config.WiNetworkGroup = Edit_generic(Config.WiNetworkGroup, 0, 127, WINETWG,Show_uint3);
1079
 
1080
 
1081
                }
1082
 
1083
                if((val + offset) == 4)
1084
                {
1085
                    Config.WiNetworkMode = Edit_generic(Config.WiNetworkMode,0,1,WINETWM,Wi_Netmode);
1086
 
1087
 
1088
                }
1089
 
1090
                if((val + offset) == 5)
1091
                {
1092
                    Config.WiTXTO = Edit_generic(Config.WiTXTO,0,127,WITIMEOUT,Show_uint3);
1093
 
1094
 
1095
                }
1096
 
1097
                if((val + offset) == 6)
1098
                {
1099
                    Config.WiUartMTU = Edit_generic(Config.WiUartMTU,0,127,WIUART,Show_uint3);
1100
 
1101
 
1102
                }
1103
 
1104
                if((val + offset) == 7)
1105
                {
1106
                        Old_Baudrate = Config.PKT_Baudrate;
1107
                        Config.PKT_Baudrate = Edit_generic(Config.PKT_Baudrate,1,6,PKT_BAUDRATE,Baudrate);
1108
                        Wi232_New_Baudrate = Config.PKT_Baudrate;
1109
                        BT_New_Baudrate = Config.PKT_Baudrate;
1110
                        if (edit==1)
1111
                          { if (Config.UseBT==true) { set_BTOn(); bt_setbaud(BT_New_Baudrate); set_BTOff();}
1112
                            if (Config.UseWi==true) InitWi232(Wi232_New_Baudrate);
1113
//                            WriteParameter();
1114
                            Old_Baudrate = Config.PKT_Baudrate;
1115
                            edit = 0;
1116
                          }
1117
 
1118
 
1119
                }
1120
 
1121
 
1122
 
1123
                if((val + offset) == 8)
1124
                        InitWi232(Config.PKT_Baudrate);
1125
                if((val + offset) == 9)
1126
                        Port_USB2CFG_Wi();
1127
        }
1128
}
1129
 
1130
 
1131
 
1132
 
1133
uint8_t Edit_String(const char *data, const uint8_t length, uint8_t type, const char *Text)
1134
{
1135
        uint8_t y = 1;
1136
        uint8_t x = 1;
1137
        uint8_t I = 0;
1138
 
1139
        lcd_cls();
1140
        lcd_printp_at (0, 0, Text, 2);
1141
 
1142
        for (uint8_t i = 0; i < length; i++)
1143
                {
1144
                        lcd_putc (y++, 3, data[i], 0);
1145
                        lcd_printp_at (y++, 3, PSTR(" "), 0);
1146
 
1147
                        EditString[i] = data[i];
1148
                }
1149
 
1150
        lcd_rect ((x*6)-3, (8*3)-2, 10, 10, 1);
1151
        lcd_printp_at (0, 6, PSTR("             C"), 0);
1152
        lcd_printp_at (0, 7, PSTR(" \x17     \x16     \x19    OK"), 0);
1153
 
1154
        do
1155
        {
1156
                if (type == 1)  // Name
1157
                {
1158
                        for (uint8_t i = bt_name_length; i > 0; i--)
1159
                        {
1160
                                if (EditString[i - 1] != ' ')
1161
                                {
1162
                                        bt_name_len = i;
1163
                                        break;
1164
                                }
1165
                        }
1166
 
1167
                        if ((get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 2)) && EditString[I] < 'z')
1168
                        {
1169
                                EditString[I]++;
1170
 
1171
                                if (EditString[I] >= 0x00 && EditString[I] < ' ')
1172
                                        EditString[I] = ' ';
1173
 
1174
                                if (EditString[I] > ' ' && EditString[I] < '0')
1175
                                        EditString[I] = '0';
1176
 
1177
                                if (EditString[I] > '9' && EditString[I] < 'A')
1178
                                        EditString[I] = 'A';
1179
 
1180
                                if (EditString[I] > 'Z' && EditString[I] < 'a')
1181
                                        EditString[I] = 'a';
1182
 
1183
                                lcd_putc (x, 3, EditString[I], 0);
1184
                                edit = 1;
1185
                        }
1186
 
1187
                        if ((get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 2)) && EditString[I] > ' ')
1188
                        {
1189
                                EditString[I]--;
1190
 
1191
                                if (EditString[I] < 'a' && EditString[I] > 'Z')
1192
                                        EditString[I] = 'Z';
1193
 
1194
                                if (EditString[I] < 'A' && EditString[I] > '9')
1195
                                        EditString[I] = '9';
1196
 
1197
                                if (EditString[I] < '0' && EditString[I] > ' ')
1198
                                        EditString[I] = ' ';
1199
 
1200
                                lcd_putc (x, 3, EditString[I], 0);
1201
                                edit = 1;
1202
                        }
1203
                }
1204
                else if (type == 2)  // PIN
1205
                {
1206
                        if ((get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 1)) && (EditString[I] < '9'))
1207
                        {
1208
                                EditString[I]++;
1209
 
1210
                                if (EditString[I] >= 0x00 && EditString[I] < ' ')
1211
                                        EditString[I] = ' ';
1212
 
1213
                                if (EditString[I] > ' ' && EditString[I] < '0')
1214
                                        EditString[I] = '0';
1215
 
1216
                                lcd_putc (x, 3, EditString[I], 0);
1217
                                edit = 1;
1218
                        }
1219
 
1220
                        if ((get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 1)) && (EditString[I] > '0'))
1221
                        {
1222
                                EditString[I]--;
1223
 
1224
                                if (EditString[I] < 'A' && EditString[I] > '9')
1225
                                        EditString[I] = '9';
1226
 
1227
                                lcd_putc (x, 3, EditString[I], 0);
1228
                                edit = 1;
1229
                        }
1230
                }
1231
 
1232
                if (get_key_long (1 << KEY_ESC))
1233
                {
1234
                        if (type == 1)  // Name
1235
                                EditString[I] = ' ';  // Zeichen l�schen
1236
                        else if (type == 2)  // Pin
1237
                                EditString[I] = '0';  // Zeichen setzen
1238
                        lcd_putc (x, 3, EditString[I], 0);
1239
                        edit = 1;
1240
                }
1241
 
1242
                if (get_key_short (1 << KEY_ESC))
1243
                {
1244
                        if (type == 1)
1245
                                length_tmp = bt_name_length;
1246
                        else if (type == 2)
1247
                                length_tmp = bt_pin_length;
1248
 
1249
                        if ((x / 2) + 2 > length_tmp)
1250
                        {
1251
                                lcd_rect ((x*6)-3, (8*3)-2, 10, 10, 0);
1252
                                x = 1;
1253
                                lcd_rect ((x*6)-3, (8*3)-2, 10, 10, 1);
1254
                                I = 0;
1255
                        }
1256
                        else
1257
                        {
1258
                                lcd_rect ((x*6)-3, (8*3)-2, 10, 10, 0);
1259
                                x++;
1260
                                x++;
1261
                                lcd_rect ((x*6)-3, (8*3)-2, 10, 10, 1);
1262
                                I++;  //Zeiger auf Zeichen
1263
                        }
1264
                }
1265
        }
1266
        while (!get_key_press (1 << KEY_ENTER));
1267
        {
1268
                return 1;
1269
        }
1270
}
1271
 
1272
 
1273
void BT_SelectDevice (void)
1274
{
1275
        uint8_t ii = 0;
1276
        uint8_t Offset = 0;
1277
        uint8_t size = 0;
1278
 
1279
 
1280
        uint8_t dmode = 0;
1281
        uint8_t target_pos = 1;
1282
        uint8_t val = 0;
1283
 
1284
        mmode = 0;
1285
        edit = 0;
1286
 
1287
 
1288
        lcd_cls ();
1289
 
1290
        while(1)
1291
        {
1292
                size = bt_devicecount;
1293
                lcd_cls ();
1294
                lcd_printp_at (0, 0, PSTR(" BT select Device    "), 2);
1295
                lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
1296
 
1297
                while(1)
1298
                {
1299
                        ii = 0;
1300
 
1301
                        if(Offset > 0)
1302
                                lcd_printp_at(1, 1, PSTR("\x12"), 0);
1303
 
1304
                        for(ii = 0; ii < 6; ii++)
1305
                        {
1306
                                if((ii + Offset) < size)
1307
                                  {
1308
                                     if (strncmp (device_list[ii + Offset].mac, Config.gps_UsedMac, 14) == 0)
1309
                                     {
1310
                                         lcd_puts_at(3, ii+1, device_list[ii + Offset].DevName, 2);
1311
//                                         lcd_puts_at(3, 4, strGet(KEYLINE1), 0);
1312
                                     }
1313
                                         else
1314
                                           {
1315
                                            lcd_puts_at(3, ii+1, device_list[ii + Offset].DevName, 0);
1316
//                                              lcd_puts_at(3, 5, strGet(KEYLINE1), 0);
1317
                                           }
1318
                                  }
1319
 
1320
                                if((ii == 5)&&(ii + Offset < (size - 1)))
1321
                                        lcd_printp_at(1, 6, PSTR("\x13"), 0);
1322
 
1323
                        }
1324
 
1325
                        if(dmode == 0)
1326
                        {
1327
                                if(Offset == 0)
1328
                                {
1329
                                        if(size > 6)
1330
                                                val = menu_choose2 (1, 5, target_pos,0,1);
1331
                                        else
1332
                                                val = menu_choose2 (1, size, target_pos,0,0);
1333
 
1334
                                }
1335
                                else
1336
                                        val = menu_choose2 (2, 5, target_pos,1,1);
1337
 
1338
                        }
1339
 
1340
                        if(dmode == 1)
1341
                        {
1342
                                if(Offset + 7 > size)
1343
                                        val = menu_choose2 (2, 6, target_pos, 1, 0);
1344
                                else
1345
                                        val = menu_choose2 (2, 5, target_pos, 1, 1);
1346
 
1347
                        }
1348
 
1349
                        if(val == 254)
1350
                        {
1351
                                Offset++;
1352
                                dmode = 1;
1353
                                target_pos = 5;
1354
                        }
1355
                        else if(val == 253)
1356
                        {
1357
                                Offset--;
1358
                                dmode = 0;
1359
                                target_pos = 2;
1360
                        }
1361
                        else if(val == 255)
1362
                        {       // Ende mit ESC, speichern
1363
                                if (edit == 1)
1364
                                {
1365
//                                  WriteParameter();
1366
                                   edit = 0;
1367
                                }
1368
 
1369
                                return;
1370
                        }
1371
                        else
1372
 
1373
                                break;
1374
                }
1375
                target_pos = val;
1376
 
1377
                if(val > 0 )
1378
                  {
1379
                    for(uint8_t i = 0; i < 14; i++)
1380
                      {
1381
                        Config.gps_UsedMac[i] = device_list[val-1].mac[i];
1382
                      }
1383
                    for(uint8_t i = 0; i < 20; i++)
1384
                      {
1385
                        Config.gps_UsedDevName[i] = device_list[val-1].DevName[i];
1386
                      }
1387
                    edit = 1;
1388
                  }
1389
        }
1390
}
1391
 
1392
 
1393
//--------------------------------------------------------------
1394
//
1395
void BT_Setup (void)
1396
{
1397
//      uint8_t ii = 0;
1398
        uint8_t z = 0;
1399
//      uint8_t Offset = 0;
1400
//      uint8_t size = 0;
1401
 
1402
//      uint8_t dmode = 0;
1403
        uint8_t target_pos = 1;
1404
//      uint8_t val;
1405
        char string[20];
1406
 
1407
        mmode = 0;
1408
        edit = 0;
1409
//      val = 0;
1410
//      BTIsSet = true;
1411
 
1412
        lcd_cls ();
1413
 
1414
        while(1)
1415
        {
1416
                size = ITEMS_BT;
1417
                lcd_cls ();
1418
                lcd_puts_at(0, 0, strGet(BT1), 2);
1419
                lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
1420
 
1421
//              while(1)
1422
//              {
1423
//                      ii = 0;
1424
//
1425
//                      if(Offset > 0)
1426
//                                      lcd_printp_at(1,1, PSTR("\x12"), 0);
1427
//
1428
//                      for(ii = 0; ii < 6; ii++)
1429
//                      {
1430
//                              if((ii + Offset) < size)
1431
//                                {
1432
//                                 lcd_printp_at(3, ii + 1, param_menuitems_bt[ii+Offset][Config.DisplayLanguage], 0);
1433
//                                 if ((ii+Offset)==5)
1434
//                                   {
1435
//                                          for (uint8_t i = 0; i < RE_ID_length; i++)
1436
//                                          {
1437
//                                             lcd_putc (10+i, ii+1, Config.RE_ID[i], 0);
1438
//
1439
//                                          }
1440
//                                   }
1441
//                                }
1442
//
1443
//
1444
//                              if((ii == 5) && (ii + Offset < (size - 1)))
1445
//                                      lcd_printp_at(1,6, PSTR("\x13"), 0);
1446
//
1447
//                      }
1448
//
1449
//                      if(dmode == 0)
1450
//                      {
1451
//                              if(Offset == 0)
1452
//                              {
1453
//                                      if(size > 6)
1454
//                                              val = menu_choose2 (1, 5, target_pos, 0, 1);
1455
//                                      else
1456
//                                              val = menu_choose2 (1, size, target_pos, 0, 0);
1457
//
1458
//                              }
1459
//                              else
1460
//                                      val = menu_choose2 (2, 5, target_pos, 1, 1);
1461
//
1462
//                      }
1463
//
1464
//                      if(dmode == 1)
1465
//                      {
1466
//                              if(Offset + 7 > size)
1467
//                                      val = menu_choose2 (2, 6, target_pos, 1, 0);
1468
//                              else
1469
//                                      val = menu_choose2 (2, 5, target_pos, 1, 1);
1470
//                      }
1471
//
1472
//                      if(val == 254)
1473
//                      {
1474
//                              Offset++;
1475
//                              dmode = 1;
1476
//                              target_pos = 5;
1477
//                      }
1478
//                      else if(val == 253)
1479
//                      {
1480
//                              Offset--;
1481
//                              dmode = 0;
1482
//                              target_pos = 2;
1483
//                      }
1484
//                      else if(val == 255)
1485
//                      {       // Ende mit ESC, speichern
1486
//                              if (edit == 1)
1487
//                              {
1488
//                                  if (Config.UseBT == 1);
1489
//                                   if (bt_init()) Config.BTIsSet = true; else Config.BTIsSet = false;
1490
//                                   WriteParameter();
1491
//                                   return;
1492
//                              }
1493
//                              return;
1494
//                      }
1495
//                      else
1496
//              break;
1497
//              }
1498
                val = menu_select(param_menuitems_bt,size,target_pos);
1499
                if (val==255)
1500
                  {
1501
                    if (edit == 1)
1502
                      {
1503
                          if (Config.UseBT == 1);
1504
                           if (bt_init()) Config.BTIsSet = true; else Config.BTIsSet = false;
1505
                      }
1506
                    break;
1507
                  }
1508
                target_pos = val;
1509
                  if((val + offset) == 1)
1510
 
1511
                    Config.UseBT = Edit_generic(Config.UseBT,0,1,BT4,YesNo);
1512
 
1513
                  if((val + offset) == 2)
1514
                  {
1515
                    for (uint8_t i = 0; i < bt_name_length; i++)
1516
                    {
1517
                            string[i] = Config.bt_name[i];
1518
                    }
1519
                    string[bt_name_length] = 0;
1520
                    Edit_String(string, bt_name_length, 1, PSTR(" Bluetooth Name      "));
1521
                    if (edit == 1)
1522
                    {
1523
                      for (uint8_t i = 0; i < bt_name_len; i++)
1524
                      {
1525
                          Config.bt_name[i] = EditString[i];
1526
//                        WriteParameter();
1527
                      }
1528
 
1529
                      if (bt_name_len < 10)
1530
                      {
1531
                        for (uint8_t i = bt_name_len; i < 10; i++)
1532
                        {
1533
                            Config.bt_name[i] = ' ';
1534
//                          WriteParameter();
1535
                        }
1536
                      }
1537
                    }
1538
                  }
1539
 
1540
                  if((val + offset) == 3)
1541
                  {
1542
                    for (uint8_t i = 0; i < bt_pin_length; i++)
1543
                    {
1544
                            string[i] = Config.bt_pin[i];
1545
                    }
1546
                    string[bt_pin_length] = 0;
1547
                    Edit_String(string, bt_pin_length, 2, PSTR(" Bluetooth Pin       "));
1548
                    if (edit == 1)
1549
                    {
1550
                            for (uint8_t i = 0; i < bt_pin_length; i++)
1551
                            {
1552
                                Config.bt_pin[i] = EditString[i];
1553
//                                    WriteParameter();
1554
                            }
1555
                    }
1556
                  }
1557
 
1558
                  if((val + offset) == 4)
1559
                  {
1560
//                                      if (edit == 1)
1561
//                                              if(BTIsSet)
1562
//                                                      BTIsSet = false;
1563
 
1564
                      if (bt_init() == true)
1565
                      {
1566
                              lcd_printp_at (0, 3, PSTR("BT Init ok"), 0);
1567
                              WriteBTInitFlag();
1568
                      }
1569
                      else
1570
                      {
1571
                              lcd_printp_at (0, 3, PSTR("BT Init Error"), 0);
1572
                              Config.BTIsSet = false;
1573
                              set_beep ( 1000, 0x0040, BeepNormal);
1574
 
1575
                      }
1576
                  }
1577
 
1578
 
1579
                  if((val + offset) == 5)
1580
                    {
1581
                      lcd_cls ();
1582
                      lcd_printp_at (0, 0, PSTR(" BTM-222 MAC-Adresse "), 2);
1583
                      lcd_puts_at(18, 7, strGet(OK), 0);
1584
                      lcd_printp_at (0, 4, PSTR("MAC:"), 0);
1585
                      z = 0;
1586
                      for(uint8_t i = 0; i < 13; i++)
1587
                       {
1588
                          lcd_putc (z, 5, Config.bt_Mac[i],0);
1589
                          if ((i%2==1)&&(i<11))
1590
                             {
1591
                              z++;
1592
                              lcd_printp_at(z, 5, PSTR(":"),0);
1593
                             }
1594
                          z++;
1595
                       }
1596
 
1597
                      while (!get_key_press (1 << KEY_ENTER));
1598
 
1599
                    }
1600
 
1601
                  if((val + offset) == 6)
1602
                  {
1603
                    for (uint8_t i = 0; i < RE_ID_length; i++)
1604
                    {
1605
                            string[i] = Config.RE_ID[i];
1606
                    }
1607
                    string[RE_ID_length] = 0;
1608
                    Edit_String(string, RE_ID_length, 2, PSTR(" RE-ID Notiz         "));
1609
                    if (edit == 1)
1610
                    {
1611
                            for (uint8_t i = 0; i < RE_ID_length; i++)
1612
                            {
1613
                                Config.RE_ID[i] = EditString[i];
1614
//                                    WriteParameter();
1615
                            }
1616
                    }
1617
                  }
1618
 
1619
 
1620
 
1621
 
1622
 
1623
                  if((val + offset) == 7)
1624
                          Port_FC2CFG_BT();
1625
 
1626
 
1627
        }
1628
}
1629
 
1630
 
1631
void GPS_Setup (void)
1632
{
1633
//        uint8_t ii = 0;
1634
//        uint8_t Offset = 0;
1635
//        uint8_t size = 0;
1636
 
1637
//        uint8_t dmode = 0;
1638
        uint8_t target_pos = 1;
1639
//        uint8_t val;
1640
        uint8_t BT_WhasOn = 0;
1641
        uint8_t status;
1642
//        uint16_t uart_bytes;
1643
 
1644
        mmode = 0;
1645
        edit = 0;
1646
        val = 0;
1647
        lcd_cls ();
1648
 
1649
        while(1)
1650
        {
1651
                size = ITEMS_GPS;
1652
                lcd_cls ();
1653
                lcd_puts_at(0, 0, strGet(GPS1), 2);
1654
                lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
1655
 
1656
//                while(1)
1657
//                {
1658
//                        ii = 0;
1659
//
1660
//                        if(Offset > 0)
1661
//                                        lcd_printp_at(1,1, PSTR("\x12"), 0);
1662
//
1663
//                        for(ii = 0; ii < 6; ii++)
1664
//                        {
1665
//                                if((ii + Offset) < size)
1666
//                                        lcd_printp_at(3, ii + 1, param_menuitems_GPS[ii+Offset][Config.DisplayLanguage], 0);
1667
//
1668
//                                if((ii == 5) && (ii + Offset < (size - 1)))
1669
//                                        lcd_printp_at(1,6, PSTR("\x13"), 0);
1670
//
1671
//                        }
1672
//
1673
//                        if(dmode == 0)
1674
//                        {
1675
//                                if(Offset == 0)
1676
//                                {
1677
//                                        if(size > 6)
1678
//                                                val = menu_choose2 (1, 5, target_pos, 0, 1);
1679
//                                        else
1680
//                                                val = menu_choose2 (1, size, target_pos, 0, 0);
1681
//
1682
//                                }
1683
//                                else
1684
//                                        val = menu_choose2 (2, 5, target_pos, 1, 1);
1685
//
1686
//                        }
1687
//
1688
//                        if(dmode == 1)
1689
//                        {
1690
//                                if(Offset + 7 > size)
1691
//                                        val = menu_choose2 (2, 6, target_pos, 1, 0);
1692
//                                else
1693
//                                        val = menu_choose2 (2, 5, target_pos, 1, 1);
1694
//                        }
1695
//
1696
//                        if(val == 254)
1697
//                        {
1698
//                                Offset++;
1699
//                                dmode = 1;
1700
//                                target_pos = 5;
1701
//                        }
1702
//                        else if(val == 253)
1703
//                        {
1704
//                                Offset--;
1705
//                                dmode = 0;
1706
//                                target_pos = 2;
1707
//                        }
1708
//                        else if(val == 255)
1709
//                        {       // Ende mit ESC, speichern
1710
//                                if (edit == 1)
1711
//                                {
1712
//                                        WriteParameter();
1713
//                                    if (BT_WhasOn)
1714
//                                      {
1715
//                                      set_BTOn();
1716
////                                      bt_set_mode(SLAVE);
1717
//                                      bt_init();
1718
//                                      set_BTOff();
1719
//                                      }
1720
//
1721
//                                        return;
1722
//                                }
1723
//                                return;
1724
//                        }
1725
//                        else
1726
//                                break;
1727
//                }
1728
 
1729
                val = menu_select(param_menuitems_GPS,size,target_pos);
1730
                if (val==255)
1731
                  {
1732
                    if (edit == 1)
1733
                      {
1734
//                              WriteParameter();
1735
                          if (BT_WhasOn)
1736
                            {
1737
                            set_BTOn();
1738
//                                      bt_set_mode(SLAVE);
1739
                            bt_init();
1740
                            set_BTOff();
1741
                            }
1742
                      }
1743
                    break;
1744
                  }
1745
 
1746
                target_pos = val;
1747
//
1748
//                {"Suche GPS Maus   ","search GPS mouse ","search GPS mouse ","search GPS mouse "},
1749
//                {"GPS Maus Typ     ","GPS mouse typ    ","GPS mouse typ    ","GPS mouse typ    "},
1750
//                {"GPS Maus aktiv?  ","GPS mouse activ? ","GPS mouse activ? ","GPS mouse activ? "},
1751
//                {"Zeige GPS Device ","show GPS device  ","show GPS device  ","show GPS device  "},
1752
//
1753
 
1754
                if((val + offset) == 1)
1755
                  {
1756
                    if (bt_devicecount ==0)
1757
                      {
1758
                       lcd_cls ();
1759
                       lcd_printp_at (0, 0, PSTR("wähle BT Device"), 0);
1760
                       set_BTOn();
1761
                       BT_WhasOn = true;
1762
//                       _delay_ms(2000);
1763
                       bt_downlink_init();
1764
                       bt_searchDevice();
1765
                       set_BTOff();
1766
                       BT_SelectDevice();
1767
                      }
1768
                    else
1769
                     BT_SelectDevice();
1770
//                if (edit == 1) WriteParameter();
1771
                  }
1772
 
1773
 
1774
 
1775
 
1776
 
1777
                if((val + offset) == 2)
1778
                   {
1779
                     lcd_cls ();
1780
                     lcd_printp_at (0, 0, PSTR("suche BT Device"), 0);
1781
                     set_BTOn();
1782
                     BT_WhasOn = true;
1783
                     bt_downlink_init();
1784
                     bt_searchDevice();
1785
                     set_BTOff();
1786
                     BT_SelectDevice();
1787
                    }
1788
 
1789
 
1790
                if((val + offset) == 3)
1791
                  {
1792
                    Config.gps_UsedGPSMouse  =  Edit_generic(Config.gps_UsedGPSMouse,0,1,GPS_MOUSETYP,GPSMOUSE);
1793
                      if (edit == 1) {
1794
//                                       WriteParameter();
1795
                                        edit = 0;
1796
                                     }
1797
 
1798
                  }
1799
 
1800
 
1801
 
1802
                if((val + offset) == 4)
1803
                  {
1804
                    Config.gps_UseGPS = Edit_generic(Config.gps_UseGPS,0,1,GPS3,YesNo);
1805
                    if (edit == 1) {
1806
//                        WriteParameter();
1807
                        edit = 0;
1808
                    }
1809
                  }
1810
 
1811
                if((val + offset) == 5)
1812
                  {
1813
                    lcd_cls ();
1814
                    lcd_puts_at(0, 0, strGet(GPS2), 2);
1815
                    lcd_puts_at(18, 7, strGet(OK), 0);
1816
                    lcd_printp_at (0, 1, PSTR("Device:"), 0);
1817
                    lcd_printp_at (0, 4, PSTR("MAC:"), 0);
1818
 
1819
                    lcd_puts_at (0, 2,Config.gps_UsedDevName, 0);
1820
 
1821
                    for(uint8_t i = 0; i < 12; i++)
1822
                     {
1823
                        lcd_putc (i, 5, Config.gps_UsedMac[i],0);
1824
                     }
1825
 
1826
                    while (!get_key_press (1 << KEY_ENTER));
1827
 
1828
                  }
1829
 
1830
 
1831
                if((val + offset) == 6)
1832
                  {
1833
                    get_key_press(KEY_ALL);
1834
                    lcd_cls ();
1835
                    lcd_puts_at(18, 7, strGet(OK), 0);
1836
                    lcd_puts_at (0, 0,Config.gps_UsedDevName, 2);
1837
                    set_BTOn();
1838
                    BT_WhasOn = true;
1839
                    if (Config.BTIsSlave==true)
1840
                      {
1841
                        bt_downlink_init();
1842
                      }
1843
                      lcd_printp_at (0, 1, PSTR("try to connect"), 0);
1844
                      status = bt_connect(Config.gps_UsedMac);
1845
 
1846
                      lcd_printp_at (0, 2, PSTR("connect status"), 0);
1847
                      write_ndigit_number_u (14, 2, status, 2, 0,0);
1848
 
1849
 
1850
 
1851
 
1852
                    if (status==true)
1853
                      {
1854
                      lcd_printp_at (0, 1, PSTR("connected     "), 0);
1855
                      receiveNMEA = true;
1856
                      }
1857
                    else
1858
                      {
1859
                        lcd_printp_at (0, 2, PSTR("connect Error"), 0);
1860
                        write_ndigit_number_u (14, 2, status, 2, 0,0);
1861
 
1862
                      }
1863
//---OG:BEGIN---
1864
                    if (receiveNMEA==true)
1865
                      {
1866
                        lcd_cls();
1867
 
1868
                        // BT-Device Name
1869
                        lcd_puts_at(0, 0,Config.gps_UsedDevName, 2);
1870
 
1871
                        // Labels
1872
                        lcd_printp_at( 0, 1, PSTR("Sat: "), 0);
1873
                        lcd_printp_at(11, 1, PSTR("XErr: "), 0);
1874
 
1875
                        lcd_printp_at( 0, 2, PSTR("Fix: "), 0);
1876
                        lcd_printp_at(11, 2, PSTR("HDOP: "), 0);
1877
 
1878
                        lcd_printp_at( 0, 3, PSTR(" Latitude   Longitude"), 2);
1879
 
1880
                        lcd_printp_at( 0, 6, PSTR("Alt: "), 0);
1881
 
1882
                        // Bottom-Line: OK
1883
                        lcd_puts_at(18, 7, strGet(OK), 0);
1884
 
1885
                        bt_rx_ready = 0;
1886
                        do
1887
                        {
1888
                           CheckGPS = true;
1889
                           if (!bt_receiveNMEA()){ receiveNMEA = false; break;}
1890
 
1891
                            Tracking_NMEA();
1892
 
1893
                            //---------------------------------------------------------------------
1894
 
1895
                            // Line 1 L: Sat-Anzahl
1896
                            write_ndigit_number_u (5, 1,  NMEAsatsInUse, 2, 0,0);
1897
 
1898
                            // Line 1 R: BT RX Error's
1899
                            write_ndigit_number_u (17, 1,  bt_rxerror, 4, 0,0);
1900
 
1901
                            //---------------------------------------------------------------------
1902
 
1903
                            // Line 2 L: Fix
1904
                            write_ndigit_number_u (5, 2,  posfix, 2, 0,0);
1905
 
1906
                            // Line 2 R: HDOP
1907
                            if( HDOP == 0 )
1908
                              lcd_printp_at(16, 2, PSTR("  ---"), 0);
1909
                            else
1910
                              write_ndigit_number_u_10th (16, 2, HDOP, 4, 0,0);
1911
 
1912
                            //---------------------------------------------------------------------
1913
 
1914
                            // Line 4 L: Latitude
1915
                            write_ndigit_number_u (1, 4, (uint16_t)(NMEAlatitude/10000000), 2, 0,0);
1916
                            lcd_printp_at (3, 4, PSTR("."), 0);
1917
                            write_ndigit_number_u (4, 4, (uint16_t)((NMEAlatitude/1000) % 10000), 4, 1,0);
1918
                            write_ndigit_number_u (8, 4, (uint16_t)((NMEAlatitude/10) % 100), 2, 1,0);
1919
 
1920
                            // Line 4 R: Longitude
1921
                            write_ndigit_number_u (12, 4, (uint16_t)(NMEAlongitude/10000000), 2, 0,0);
1922
                            lcd_printp_at (14, 4, PSTR("."), 0);
1923
                            write_ndigit_number_u (15, 4, (uint16_t)((NMEAlongitude/1000) % 10000), 4, 1,0);
1924
                            write_ndigit_number_u (19, 4, (uint16_t)((NMEAlongitude/10) % 100), 2, 1,0);
1925
 
1926
                            //---------------------------------------------------------------------
1927
 
1928
                            // Line 6 L: Altitude
1929
                            write_ndigit_number_u_10th (5, 6,  NMEAaltitude, 5, 0,0);
1930
                            lcd_printp_at (11, 6, PSTR("m"), 0);
1931
 
1932
                            // Line 6 R: GPS Time
1933
                            lcd_puts_at (13, 6, NMEAtime, 0);
1934
 
1935
                            //---------------------------------------------------------------------
1936
 
1937
                        } while (!get_key_press (1 << KEY_ENTER) || !receiveNMEA==true);
1938
 
1939
                        CheckGPS = false;
1940
 
1941
                        lcd_cls();
1942
 
1943
                        if (!receiveNMEA) {
1944
                                           lcd_printp_at (0, 1, PSTR("lost BT data"), 0);
1945
                                           set_beep ( 400, 0x0080, BeepNormal);
1946
                                          }
1947
                        lcd_printp_at (0, 3, PSTR("GPS trennen"), 0);
1948
                        lcd_printp_at (0, 4, PSTR("bitte warten..."), 0);
1949
                      }
1950
                    else
1951
                      {
1952
                        lcd_printp_at (0, 3, PSTR("Error connecting!"), 0);
1953
                        while (!get_key_press (1 << KEY_ENTER));
1954
                      }
1955
                    receiveNMEA = false;
1956
                    CheckGPS = false;
1957
                    if  (!bt_disconnect()) lcd_printp_at (0, 3, PSTR("Error disconnecting!"), 0);
1958
//---OG:END---
1959
 
1960
//                    if (receiveNMEA==true)
1961
//                      {
1962
//                        lcd_printp_at (0, 3, PSTR(" Latitude   Longitude"), 2);
1963
//                        bt_rx_ready = 0;
1964
//                        do
1965
//                          {
1966
//                           CheckGPS = true;
1967
//                           if (!bt_receiveNMEA()){ receiveNMEA = false; break;}
1968
//
1969
//
1970
//                            Tracking_NMEA();
1971
//
1972
//
1973
//                            write_ndigit_number_u (1, 4, (uint16_t)(NMEAlatitude/10000000), 2, 0,0);
1974
//                            lcd_printp_at (3, 4, PSTR("."), 0);
1975
//                            write_ndigit_number_u (4, 4, (uint16_t)((NMEAlatitude/1000) % 10000), 4, 1,0);
1976
//                            write_ndigit_number_u (8, 4, (uint16_t)((NMEAlatitude/10) % 100), 2, 1,0);
1977
//
1978
//
1979
//                            write_ndigit_number_u (12, 4, (uint16_t)(NMEAlongitude/10000000), 2, 0,0);
1980
//                            lcd_printp_at (14, 4, PSTR("."), 0);
1981
//                            write_ndigit_number_u (15, 4, (uint16_t)((NMEAlongitude/1000) % 10000), 4, 1,0);
1982
//                            write_ndigit_number_u (19, 4, (uint16_t)((NMEAlongitude/10) % 100), 2, 1,0);
1983
//                            lcd_printp_at (0, 2, PSTR("GPS Time: "), 0);
1984
//                            lcd_puts_at (10, 2, NMEAtime, 0);
1985
//                            lcd_printp_at (0, 6, PSTR("Satellite: "), 0);
1986
//                            write_ndigit_number_u (11, 6,  NMEAsatsInUse, 2, 1,0);
1987
//                            lcd_printp_at (0, 5, PSTR("Fix: "), 0);
1988
//                            write_ndigit_number_u (5, 5,  posfix, 1, 1,0);
1989
//                            lcd_printp_at (8, 5, PSTR("HDOP: "), 0);
1990
//                            write_ndigit_number_u_10th (14, 5,  HDOP, 4, 0,0);
1991
//                            lcd_printp_at (0, 7, PSTR("Alitude: "), 0);
1992
//                            write_ndigit_number_u_10th (9, 7,  NMEAaltitude, 5, 0,0);
1993
//                            lcd_printp_at (15, 7, PSTR("m"), 0);
1994
//                            lcd_printp_at (0, 1, PSTR(" BT RX Error: "), 0);
1995
//                            write_ndigit_number_u (13, 1,  bt_rxerror, 3, 1,0);
1996
////                            write_ndigit_number_u (13, 1,  UART1_RxError, 5, 1,0);
1997
//
1998
////                            uart_bytes =  uart1_available();
1999
////                            lcd_printp_at (0, 1, PSTR(" UartAvail: "), 0);
2000
////                            write_ndigit_number_u (13, 1,uart_bytes , 4, 1,0);
2001
//                          }
2002
//
2003
//
2004
//                        while (!get_key_press (1 << KEY_ENTER) || !receiveNMEA==true);
2005
//
2006
//                        CheckGPS = false;
2007
//                        lcd_cls_line(0,1,21);
2008
//                        lcd_cls_line(0,2,21);
2009
//                        lcd_cls_line(0,3,21);
2010
//                        lcd_cls_line(0,4,21);
2011
//                        lcd_cls_line(0,5,21);
2012
//                        lcd_cls_line(0,6,21);
2013
//                        lcd_cls_line(0,7,21);
2014
//                        if (!receiveNMEA) lcd_printp_at (0, 2, PSTR("lost BT data"), 0);
2015
//                        lcd_printp_at (0, 3, PSTR("GPS trennen"), 0);
2016
//                        lcd_printp_at (0, 4, PSTR("bitte warten"), 0);
2017
//                      }
2018
//                    else
2019
//                      {
2020
//                        lcd_printp_at (0, 4, PSTR("Error at connecting"), 0);
2021
//                        while (!get_key_press (1 << KEY_ENTER));
2022
//                      }
2023
//                    receiveNMEA = false;
2024
//                    CheckGPS = false;
2025
//                    if  (!bt_disconnect()) lcd_printp_at (0, 3, PSTR("Fehler beim Trennen"), 0);
2026
 
2027
                    set_BTOff();
2028
 
2029
                  }
2030
 
2031
 
2032
        }
2033
}
2034
 
2035
 
2036
 
2037
 
2038
//--------------------------------------------------------------
2039
uint8_t Edit_PKT_Accu(uint8_t Value, uint8_t min, uint8_t max)
2040
{
2041
        Pre = Value;
2042
        lcd_cls();
2043
//        lcd_printp_at (0, 2, Text, 0);
2044
        lcd_puts_at(0, 2, strGet(LIPO2), 0);
2045
        switch (Value)
2046
        {
2047
                case    false :lcd_printp_at (15, 2, PSTR("LiIo"), 0);
2048
                        break;
2049
                case    true :lcd_printp_at (15, 2, PSTR("LiPo"), 0);
2050
                        break;
2051
                break;
2052
        }
2053
 
2054
        lcd_puts_at(0, 7, strGet(KEYLINE2), 0);
2055
 
2056
        do
2057
        {
2058
                if ((get_key_press (1 << KEY_PLUS)) && (Value == 0))
2059
                {
2060
                        Value = 1;
2061
                        lcd_printp_at (15, 2, PSTR("LiPo"), 0);
2062
                }
2063
 
2064
                if ((get_key_press (1 << KEY_MINUS)) && (Value == 1))
2065
                {
2066
                        Value = 0;
2067
                        lcd_printp_at (15, 2, PSTR("LiIo"), 0);
2068
                }
2069
 
2070
                if (get_key_press (1 << KEY_ENTER))
2071
                {
2072
                        edit = 1;
2073
 
2074
                        Config.PKT_Accutyp = Value;
2075
 
2076
 
2077
                        return Value;
2078
                }
2079
        }
2080
 
2081
        while (!get_key_press (1 << KEY_ESC));
2082
        {
2083
                get_key_press(KEY_ALL);
2084
                edit = 0;
2085
                Config.PKT_Accutyp = Pre;
2086
                return Pre;
2087
        }
2088
 
2089
}
2090
 
2091
//--------------------------------------------------------------
2092
uint16_t Edit_LipoOffset(uint16_t Value, uint16_t min, uint16_t max)
2093
{
2094
        lcd_cls();
2095
        lcd_puts_at(0, 2, strGet(LIPO3), 0);
2096
        lcd_puts_at(0, 5, strGet(LIPO5), 0);
2097
        lcd_puts_at(0, 6, strGet(LIPO6), 0);
2098
        Pre16 = Value;
2099
        write_ndigit_number_u (16, 2, Value, 4, 0,0);
2100
        lcd_puts_at(0, 7, strGet(KEYLINE2), 0);
2101
 
2102
        do
2103
        {
2104
                if ((get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 2)) && (Value < max-10))
2105
                {
2106
                        edit = 1;
2107
                        Value = Value +10;
2108
                        Config.Lipo_UOffset = Value;
2109
                        write_ndigit_number_u (16, 2,Value, 4, 0,0);
2110
 
2111
                }
2112
 
2113
                if ((get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 2)) && (Value > min))
2114
                {
2115
                        edit = 1;
2116
                        Value=Value -10;
2117
                        Config.Lipo_UOffset = Value;
2118
                        write_ndigit_number_u (16, 2,Value, 4, 0,0);
2119
                }
2120
 
2121
                if (get_key_press (1 << KEY_ENTER))
2122
                        return Value;
2123
                show_Lipo();
2124
                write_ndigit_number_u_100th(8, 3, volt_avg, 0, 0);
2125
                lcd_printp_at(3, 3, PSTR("Volt"), 0);
2126
 
2127
        }
2128
        while (!get_key_press (1 << KEY_ESC));
2129
        {
2130
                get_key_press(KEY_ALL);
2131
                edit = 0;
2132
                Config.Lipo_UOffset = Pre16;
2133
                return Pre16;
2134
        }
2135
}
2136
 
2137
//--------------------------------------------------------------
2138
void Accu_Setup (void)
2139
{
2140
//        uint8_t ii = 0;
2141
//        uint8_t Offset = 0;
2142
//        uint8_t size = 0;
2143
 
2144
//        uint8_t dmode = 0;
2145
        uint8_t target_pos = 1;
2146
//        uint8_t val;
2147
 
2148
        mmode = 0;
2149
        edit = 0;
2150
        val = 0;
2151
        lcd_cls ();
2152
 
2153
        while(1)
2154
        {
2155
                size = ITEMS_Accu;
2156
                lcd_cls ();
2157
                lcd_puts_at(0, 0, strGet(LIPO1), 2);
2158
                lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
2159
 
2160
//                while(1)
2161
//                {
2162
//                        ii = 0;
2163
//
2164
//                        if(Offset > 0)
2165
//                                        lcd_printp_at(1,1, PSTR("\x12"), 0);
2166
//
2167
//                        for(ii = 0; ii < 6; ii++)
2168
//                        {
2169
//                                if((ii + Offset) < size)
2170
//                                        lcd_printp_at(3, ii + 1, param_menuitems_Accu[ii+Offset][Config.DisplayLanguage], 0);
2171
//
2172
//                                if((ii == 5) && (ii + Offset < (size - 1)))
2173
//                                        lcd_printp_at(1,6, PSTR("\x13"), 0);
2174
//
2175
//                        }
2176
//
2177
//                        if(dmode == 0)
2178
//                        {
2179
//                                if(Offset == 0)
2180
//                                {
2181
//                                        if(size > 6)
2182
//                                                val = menu_choose2 (1, 5, target_pos, 0, 1);
2183
//                                        else
2184
//                                                val = menu_choose2 (1, size, target_pos, 0, 0);
2185
//
2186
//                                }
2187
//                                else
2188
//                                        val = menu_choose2 (2, 5, target_pos, 1, 1);
2189
//
2190
//                        }
2191
//
2192
//                        if(dmode == 1)
2193
//                        {
2194
//                                if(Offset + 7 > size)
2195
//                                        val = menu_choose2 (2, 6, target_pos, 1, 0);
2196
//                                else
2197
//                                        val = menu_choose2 (2, 5, target_pos, 1, 1);
2198
//                        }
2199
//
2200
//                        if(val == 254)
2201
//                        {
2202
//                                Offset++;
2203
//                                dmode = 1;
2204
//                                target_pos = 5;
2205
//                        }
2206
//                        else if(val == 253)
2207
//                        {
2208
//                                Offset--;
2209
//                                dmode = 0;
2210
//                                target_pos = 2;
2211
//                        }
2212
//                        else if(val == 255)
2213
//                        {       // Ende mit ESC, speichern
2214
//                                if (edit == 1)
2215
//                                {
2216
//                                        WriteParameter();
2217
//                                        edit = 0;
2218
//                                        return;
2219
//                                }
2220
//                                return;
2221
//                        }
2222
//                        else
2223
//                                break;
2224
//                }
2225
                val = menu_select(param_menuitems_Accu,size,target_pos);
2226
                if (val==255) break;
2227
                target_pos = val;
2228
                if((val + offset) == 1)
2229
                  {
2230
                    Config.PKT_Accutyp= Edit_PKT_Accu(Config.PKT_Accutyp,0,1);
2231
                  if (edit == 1)           {
2232
//                      WriteParameter();
2233
                      edit = 0;
2234
                  }
2235
                  }
2236
 
2237
                if((val + offset) == 2)
2238
                  {
2239
                    Config.Lipo_UOffset = Edit_LipoOffset(Config.Lipo_UOffset,0,9999);
2240
                    if (edit == 1) {
2241
//                        WriteParameter();
2242
                        edit = 0;
2243
                    }
2244
                  }
2245
 
2246
        }
2247
}
2248
 
2249
 
2250
//--------------------------------------------------------------
2251
uint8_t Edit_LED_Form (uint8_t Value,  uint8_t min, uint8_t max, uint8_t Text)
2252
{
2253
        Pre = Value;
2254
        lcd_cls();
2255
        lcd_puts_at(0, 2, strGet(Text), 0);
2256
 
2257
        switch (Value)
2258
        {
2259
                case    0x1:
2260
                        lcd_circle  (14 * 6 + 5, 2 * 8 + 3, 3, 1);   // kreis
2261
 
2262
                        lcd_fcircle (16 * 6 + 5, 2 * 8 + 3, 3, 0);   // löschen
2263
                        lcd_circle  (16 * 6 + 5, 2 * 8 + 3, 3, 1);   // kreis
2264
                        lcd_fcircle (16 * 6 + 5, 2 * 8 + 3, 1, 1);   // plus
2265
                        break;
2266
                case    0x3 :
2267
                        lcd_circle  (14 * 6 + 5, 2 * 8 + 3, 3, 1);   // kreis
2268
 
2269
                        lcd_fcircle (16 * 6 + 5, 2 * 8 + 3, 3, 1);   // schwarz
2270
                        break;
2271
                break;
2272
        }
2273
 
2274
        lcd_puts_at(0, 7, strGet(KEYLINE2), 0);
2275
 
2276
        do
2277
        {
2278
                if ((get_key_press (1 << KEY_PLUS)) && (Value == 1))
2279
                {
2280
                        Value = 3;
2281
                        lcd_circle  (14 * 6 + 5, 2 * 8 + 3, 3, 1);   // kreis
2282
 
2283
                        lcd_fcircle (16 * 6 + 5, 2 * 8 + 3, 3, 1);   // schwarz
2284
                }
2285
 
2286
                if ((get_key_press (1 << KEY_MINUS)) && (Value == 3))
2287
                {
2288
                        Value = 1;
2289
                        lcd_circle  (14 * 6 + 5, 2 * 8 + 3, 3, 1);   // kreis
2290
 
2291
                        lcd_fcircle (16 * 6 + 5, 2 * 8 + 3, 3, 0);   // löschen
2292
                        lcd_circle  (16 * 6 + 5, 2 * 8 + 3, 3, 1);   // kreis
2293
                        lcd_fcircle (16 * 6 + 5, 2 * 8 + 3, 1, 1);   // plus
2294
                }
2295
 
2296
                if (get_key_press (1 << KEY_ENTER))
2297
                {
2298
                        edit = 1;
2299
                        Config.OSD_LEDform = Value;
2300
//                      WriteParameter();
2301
                        edit = 0;
2302
                        return Value;
2303
                }
2304
        }
2305
 
2306
        while (!get_key_press (1 << KEY_ESC));
2307
        {
2308
                get_key_press(KEY_ALL);
2309
                edit = 0;
2310
                Config.OSD_LEDform = Pre;
2311
                return Pre;
2312
        }
2313
}
2314
 
2315
 
2316
//--------------------------------------------------------------
2317
void OSD_Setup (void)
2318
{
2319
//        uint8_t ii = 0;
2320
//        uint8_t Offset = 0;
2321
//        uint8_t size = 0;
2322
 
2323
//        uint8_t dmode = 0;
2324
        uint8_t target_pos = 1;
2325
//        uint8_t val;
2326
 
2327
        mmode = 0;
2328
        edit = 0;
2329
        val = 0;
2330
        lcd_cls ();
2331
 
2332
        while(1)
2333
        {
2334
                size = ITEMS_OSD;
2335
                lcd_cls ();
2336
                lcd_puts_at(0, 0, strGet(OSD_Screen), 2);
2337
                lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
2338
 
2339
//                while(1)
2340
//                {
2341
//                        ii = 0;
2342
//
2343
//                        if(Offset > 0)
2344
//                                        lcd_printp_at(1,1, PSTR("\x12"), 0);
2345
//
2346
//                        for(ii = 0; ii < 6; ii++)
2347
//                        {
2348
//                                if((ii + Offset) < size)
2349
//                                        lcd_printp_at(3, ii + 1, param_menuitems_OSD[ii+Offset][Config.DisplayLanguage], 0);
2350
//
2351
//                                if((ii == 5) && (ii + Offset < (size - 1)))
2352
//                                        lcd_printp_at(1,6, PSTR("\x13"), 0);
2353
//
2354
//                        }
2355
//
2356
//                        if(dmode == 0)
2357
//                        {
2358
//                                if(Offset == 0)
2359
//                                {
2360
//                                        if(size > 6)
2361
//                                                val = menu_choose2 (1, 5, target_pos, 0, 1);
2362
//                                        else
2363
//                                                val = menu_choose2 (1, size, target_pos, 0, 0);
2364
//
2365
//                                }
2366
//                                else
2367
//                                        val = menu_choose2 (2, 5, target_pos, 1, 1);
2368
//
2369
//                        }
2370
//
2371
//                        if(dmode == 1)
2372
//                        {
2373
//                                if(Offset + 7 > size)
2374
//                                        val = menu_choose2 (2, 6, target_pos, 1, 0);
2375
//                                else
2376
//                                        val = menu_choose2 (2, 5, target_pos, 1, 1);
2377
//                        }
2378
//
2379
//                        if(val == 254)
2380
//                        {
2381
//                                Offset++;
2382
//                                dmode = 1;
2383
//                                target_pos = 5;
2384
//                        }
2385
//                        else if(val == 253)
2386
//                        {
2387
//                                Offset--;
2388
//                                dmode = 0;
2389
//                                target_pos = 2;
2390
//                        }
2391
//                        else if(val == 255)
2392
//                        {       // Ende mit ESC, speichern
2393
//                                if (edit == 1)
2394
//                                {
2395
//                                        WriteParameter();
2396
//                                        edit = 0;
2397
//                                        return;
2398
//                                }
2399
//                                return;
2400
//                        }
2401
//                        else
2402
//                                break;
2403
//                }
2404
                val = menu_select(param_menuitems_OSD,size,target_pos);
2405
                if (val==255) break;
2406
                target_pos = val;
2407
//4.3.13 CB                if((val + Offset) == 1) Config.OSD_ScreenMode = Edit_generic(Config.OSD_ScreenMode, 0, OSD_MaxScreen, OSD_SCREENMODE,Show_uint);
2408
                if((val + offset) == 1) Config.OSD_LEDform = Edit_LED_Form(Config.OSD_LEDform, 1, 3, OSD_LED_Form);
2409
                if((val + offset) == 2) Config.OSD_InvertOut = Edit_generic(Config.OSD_InvertOut, 0, 1, OSD_Invert_Out,YesNo);
2410
                if((val + offset) == 3) Config.OSD_SendOSD = Edit_generic(Config.OSD_SendOSD, 0, 1,OSD_Send_OSD ,YesNo);
2411
                if((val + offset) == 4) Config.OSD_Fallspeed = Edit_generic(Config.OSD_Fallspeed,0,247,FALLSPEED,Show_uint10th);
2412
                if((val + offset) == 5) Config.OSD_VarioBeep = Edit_generic(Config.OSD_VarioBeep,0,1,OSD_VARIOBEEP,YesNo);
2413
                if((val + offset) == 6) Config.OSD_HomeMKView = Edit_generic(Config.OSD_HomeMKView,0,1,OSD_HOMEMKVIEW,YesNo);
2414
                if((val + offset) == 7) Config.MK_LowBat = Edit_generic(Config.MK_LowBat,32,247,LOWBAT,Show_uint10th);
2415
                if((val + offset) == 8) Config.OSD_mAh_Warning = Edit_generic(Config.OSD_mAh_Warning,0,30000,OSD_MAHWARNING, Show_uint5);
2416
                if((val + offset) == 9)Config.OSD_LipoBar = Edit_generic(Config.OSD_LipoBar, 0, 1, OSD_LIPOBAR,YesNo);
2417
 
2418
 
2419
        }
2420
}
2421
//--------------------------------------------------------------
2422
void FollowMe_Setup (void)
2423
{
2424
//        uint8_t ii = 0;
2425
//        uint8_t Offset = 0;
2426
//        uint8_t size = 0;
2427
//        uint8_t dmode = 0;
2428
        uint8_t target_pos = 1;
2429
//        uint8_t val;
2430
 
2431
        mmode = 0;
2432
        edit = 0;
2433
        val = 0;
2434
        lcd_cls ();
2435
 
2436
        while(1)
2437
        {
2438
                size = ITEMS_FOLLOWME;
2439
                lcd_cls ();
2440
                lcd_puts_at(0, 0, strGet(FOLLOWME_0), 2);
2441
                lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
2442
 
2443
//                while(1)
2444
//                {
2445
//                        ii = 0;
2446
//
2447
//                        if(Offset > 0)
2448
//                                        lcd_printp_at(1,1, PSTR("\x12"), 0);
2449
//
2450
//                        for(ii = 0; ii < 6; ii++)
2451
//                        {
2452
//                                if((ii + Offset) < size)
2453
//                                        lcd_printp_at(3, ii + 1, param_menuitems_FOLLOWME[ii+Offset][Config.DisplayLanguage], 0);
2454
//
2455
//                                if((ii == 5) && (ii + Offset < (size - 1)))
2456
//                                        lcd_printp_at(1,6, PSTR("\x13"), 0);
2457
//
2458
//                        }
2459
//
2460
//                        if(dmode == 0)
2461
//                        {
2462
//                                if(Offset == 0)
2463
//                                {
2464
//                                        if(size > 6)
2465
//                                                val = menu_choose2 (1, 5, target_pos, 0, 1);
2466
//                                        else
2467
//                                                val = menu_choose2 (1, size, target_pos, 0, 0);
2468
//
2469
//                                }
2470
//                                else
2471
//                                        val = menu_choose2 (2, 5, target_pos, 1, 1);
2472
//
2473
//                        }
2474
//
2475
//                        if(dmode == 1)
2476
//                        {
2477
//                                if(Offset + 7 > size)
2478
//                                        val = menu_choose2 (2, 6, target_pos, 1, 0);
2479
//                                else
2480
//                                        val = menu_choose2 (2, 5, target_pos, 1, 1);
2481
//                        }
2482
//
2483
//                        if(val == 254)
2484
//                        {
2485
//                                Offset++;
2486
//                                dmode = 1;
2487
//                                target_pos = 5;
2488
//                        }
2489
//                        else if(val == 253)
2490
//                        {
2491
//                                Offset--;
2492
//                                dmode = 0;
2493
//                                target_pos = 2;
2494
//                        }
2495
//                        else if(val == 255)
2496
//                        {       // Ende mit ESC, speichern
2497
//                                if (edit == 1)
2498
//                                {
2499
//                                        WriteParameter();
2500
//                                        edit = 0;
2501
//                                        return;
2502
//                                }
2503
//                                return;
2504
//                        }
2505
//                        else
2506
//                                break;
2507
//                }
2508
                val = menu_select(param_menuitems_FOLLOWME,size,target_pos);
2509
                if (val==255) break;
2510
                target_pos = val;
2511
                if((val + offset) == 1) Config.FM_Refresh = Edit_generic(Config.FM_Refresh, 250, 60000, FOLLOWME_1, Show_uint3);
2512
                if((val + offset) == 2) Config.FM_Speed = Edit_generic(Config.FM_Speed, 0, 100, FOLLOWME_2, Show_uint3);
2513
                if((val + offset) == 3) Config.FM_Radius = Edit_generic(Config.FM_Radius, 1,20, FOLLOWME_3, Show_uint3);
2514
 
2515
        }
2516
}
2517
 
2518