Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1053 - 1
/*****************************************************************************
2
 *   Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de                  *
3
 *   Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net                  *
4
 *   Copyright (C) 2010 Sebastian Boehm, seb@exse.net                            *
5
 *                                                                           *
6
 *   This program is free software; you can redistribute it and/or modify    *
7
 *   it under the terms of the GNU General Public License as published by    *
8
 *   the Free Software Foundation; either version 2 of the License.          *
9
 *                                                                           *
10
 *   This program is distributed in the hope that it will be useful,         *
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
13
 *   GNU General Public License for more details.                            *
14
 *                                                                           *
15
 *   You should have received a copy of the GNU General Public License       *
16
 *   along with this program; if not, write to the                           *
17
 *   Free Software Foundation, Inc.,                                         *
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.               *
19
 *                                                                           *
20
 *****************************************************************************/
21
 
22
#include <avr/io.h>
23
#include <avr/pgmspace.h>
24
#include <util/delay.h>
25
#include <string.h>
26
#include <stdlib.h>
27
 
28
#include "main.h"
29
#include "lcd.h"
30
#include "timer.h"
31
#include "usart.h"
32
#include "mk-data-structs.h"
33
#include "parameter.h"
34
#include "menu.h"
35
#include "eeprom.h"
36
 
37
#define LANGUAGE_INT
38
 
39
#ifdef LANGUAGE_INT
40
#include "parameter_names.h"
41
#endif
42
 
43
#ifdef LANGUAGE_DE
44
#include "parameter_names_de.h"
45
#endif
46
 
47
#ifdef LANGUAGE_FR
48
#include "parameter_names_fr.h"
49
#endif
50
 
51
#ifdef LANGUAGE_EN
52
#include "parameter_names_en.h"
53
#endif
54
 
55
 
56
#define TIMEOUT 500     // 5 sec
57
 
58
uint8_t display_settings_menu (void);
59
uint8_t display_param_menu (uint8_t);
60
uint8_t load_setting (uint8_t);
61
uint8_t write_setting (uint8_t);
62
uint8_t display_section_menu(void);
63
void edit_param(uint8_t);
64
void copy_setting(void);
65
 
66
 
67
 
68
 
69
 
70
mk_param_struct_t *mk_param_struct;
71
 
72
uint8_t ii;
73
volatile uint8_t offset = 0;
74
volatile uint8_t dmode = 0;
75
volatile uint8_t target_pos = 1;
76
 
77
volatile uint8_t offset2 = 0;
78
volatile uint8_t pmode = 0;
79
volatile uint8_t target_pos2 = 1;
80
 
81
uint8_t changes = 0;
82
 
83
#define OFFSETOF(type, field)    ((unsigned int) &(((type *) 0)->field))
84
 
85
#define MKOSO(field) (uint8_t)OFFSETOF(mk_param_struct_t, field)
86
 
87
// Typ(1=mit Poti,0=ohne Poti,2=bitfield,3=serCh,4=LEDmask,5 Angle,6 Empfaenger ),
88
// min,
89
// max,
90
// struct-name,
91
// default1,
92
// default2,
93
// default3+4+5
94
prog_uchar  param_config[8*PARAM_COUNT]=
95
{
96
         // group 0 (kanaele) 15
97
         0,0,1,12  ,MKOSO(Kanalbelegung)+2,1,1,1, //   gas
98
         0,0,1,12  ,MKOSO(Kanalbelegung)+3,2,2,2, //   gier
99
         0,0,1,12  ,MKOSO(Kanalbelegung),3,3,3,   //   nick
100
         0,0,1,12  ,MKOSO(Kanalbelegung)+1,4,4,4, //   roll
101
         0,3,1,25  ,MKOSO(Kanalbelegung)+4,5,5,5, //   poti1
102
         0,3,1,25  ,MKOSO(Kanalbelegung)+5,6,6,6, //   poti2
103
         0,3,1,25  ,MKOSO(Kanalbelegung)+6,7,7,7, //   poti3
104
         0,3,1,25  ,MKOSO(Kanalbelegung)+7,8,8,8, //   poti4
105
         0,3,1,25  ,MKOSO(Kanalbelegung)+8,9,9,9, //   poti5
106
         0,3,1,25  ,MKOSO(Kanalbelegung)+9,10,10,10, //   poti6
107
         0,3,1,25  ,MKOSO(Kanalbelegung)+10,11,11,11, //   poti7
108
         0,3,1,25  ,MKOSO(Kanalbelegung)+11,12,12,12, //   poti8
109
         //26.3.2011 0.82 CB
110
         0,0,0,12  ,MKOSO(MotorSafetySwitch),0,0,0, //   Motor Sicherungsswitch
111
         //
112
         0,2,0,0x04,MKOSO(ExtraConfig),0,0,0, //erweiterte signal pruefung
113
         0,6,0,5   ,MKOSO(Receiver),1,1,1,
114
 
115
         // group 1 (main) 8
116
 
117
         1,2,0,0x01,MKOSO(GlobalConfig),0,0,1, //hoehenregler
118
         1,2,0,0x20,MKOSO(GlobalConfig),1,1,1, //gps
119
         1,2,0,0x08,MKOSO(GlobalConfig),1,1,1, //kompass 
120
         1,2,0,0x10,MKOSO(GlobalConfig),0,0,0, //feste ausrichtung
121
         1,2,0,0x04,MKOSO(ExtraConfig),0,0,0, //erweiterte signal pruefung
122
         1,2,0,0x40,MKOSO(GlobalConfig),1,1,1, //achsentkopplung
123
         1,2,0,0x80,MKOSO(GlobalConfig),0,0,0, //drehratenbregrenzung
124
         1,2,0,0x04,MKOSO(GlobalConfig),0,0,0, //heading hold
125
 
126
         // group 2 (stick) 4
127
         2,0,0,20  ,MKOSO(Stick_P),8,8,8,
128
         2,0,0,20  ,MKOSO(Stick_D),16,16,16,
129
         2,1,0,247 ,MKOSO(Gier_P),6,6,6,
130
         2,1,0,247 ,MKOSO(ExternalControl),0,0,0,
131
 
132
 
133
 
134
         // group3 : looping 9
135
 
136
         3,2,0,0x01,MKOSO(BitConfig),0,0,0, //oben
137
         3,2,0,0x02,MKOSO(BitConfig),0,0,0, //unten
138
         3,2,0,0x04,MKOSO(BitConfig),0,0,0, //links
139
         3,2,0,0x08,MKOSO(BitConfig),0,0,0, //rechts
140
         3,1,0,247 ,MKOSO(LoopGasLimit),50,50,50,
141
         3,0,0,247 ,MKOSO(LoopThreshold),90,90,90,
142
         3,0,0,247 ,MKOSO(LoopHysterese),50,50,50,
143
         3,0,0,247 ,MKOSO(WinkelUmschlagNick),78,78,78,
144
         3,0,0,247 ,MKOSO(WinkelUmschlagRoll),78,78,78,
145
 
146
 
147
 
148
 
149
         // group 4 (hoehe) 13
150
 
151
         4,2,0,0x01,MKOSO(GlobalConfig),1,1,1, //hoehenrelger
152
         4,2,0,0x01,MKOSO(ExtraConfig),0,0,0, //vario oder hoeenbergenzung
153
         4,2,0,0x02,MKOSO(GlobalConfig),1,1,1, //hoehenschalter
154
         4,2,0,0x02,MKOSO(ExtraConfig),1,1,1, //variobeep
155
         4,1,0,247 ,MKOSO(MaxHoehe),255,255,255,
156
         4,0,0,247 ,MKOSO(Hoehe_MinGas),30,30,30,        
157
         4,1,0,247 ,MKOSO(Hoehe_P),15,15,15,    
158
         4,1,0,247 ,MKOSO(Luftdruck_D),30,30,30,        
159
         4,1,0,247 ,MKOSO(Hoehe_ACC_Wirkung),0,0,0,      
160
         4,0,0,247 ,MKOSO(Hoehe_Verstaerkung),15,15,15,          
161
         4,0,0,247 ,MKOSO(Hoehe_HoverBand),8,8,8,        
162
         4,1,0,247 ,MKOSO(Hoehe_GPS_Z),64,64,64,        
163
         4,0,0,247 ,MKOSO(Hoehe_StickNeutralPoint),0,0,0,
164
 
165
         // Typ(1=mit Poti,0=ohne Poti,2=bitfield,3=serCh,4=LEDmask,5 Angle,6 Empfaenger),
166
         // min,
167
         // max,
168
         // struct-name,
169
         // default1,
170
         // default2,
171
         // default3+4+5
172
 
173
         // group 5 : kamera 16
174
 
175
         5,1,0,247,MKOSO(ServoNickControl),100,100,100,
176
         5,0,0,247,MKOSO(ServoNickComp),40,40,40,
177
         5,2,0,0x01,MKOSO(ServoCompInvert),1,1,1,
178
         5,0,0,247,MKOSO(ServoNickMin),0,0,0,
179
         5,0,0,247,MKOSO(ServoNickMax),247,247,247,
180
 
181
         5,1,0,247,MKOSO(ServoRollControl),100,100,100,
182
         5,0,0,247,MKOSO(ServoRollComp),40,40,40,
183
         5,2,0,0x01,MKOSO(ServoCompInvert),0,0,0,
184
         5,0,0,247,MKOSO(ServoRollMin),0,0,0,
185
         5,0,0,247,MKOSO(ServoRollMax),247,247,247,
186
 
187
 
188
         5,0,2,8  ,MKOSO(ServoNickRefresh),6,6,6,
189
         //26.3.2011 0.82 CB
190
         5,0,0,247 ,MKOSO(ServoManualControlSpeed),40,40,40,
191
         5,5,0,247 ,MKOSO(CamOrientation),0,0,0,
192
         //
193
         5,1,0,247,MKOSO(Servo3),125,125,125,
194
         5,1,0,247,MKOSO(Servo4),125,125,125,
195
         5,1,0,247,MKOSO(Servo5),125,125,125,
196
 
197
 
198
         // group 6 : navictrl 17
199
 
200
    6,2,0,0x20,MKOSO(GlobalConfig),1,1,1, //gps
201
        6,1,0,247,MKOSO(NaviGpsModeControl),254,254,254,
202
        6,1,0,247,MKOSO(NaviGpsGain),100,100,100,
203
        6,0,0,247,MKOSO(NaviStickThreshold),8,8,8,
204
        6,0,0,247,MKOSO(NaviGpsMinSat),6,6,6,
205
        6,1,0,247,MKOSO(NaviGpsP),90,90,90,
206
        6,1,0,247,MKOSO(NaviGpsI),90,90,90,
207
        6,1,0,247,MKOSO(NaviGpsD),90,90,90,
208
        6,1,0,247,MKOSO(NaviGpsPLimit),75,75,75,
209
        6,1,0,247,MKOSO(NaviGpsILimit),75,75,75,
210
        6,1,0,247,MKOSO(NaviGpsDLimit),75,75,75,
211
        6,1,0,247,MKOSO(NaviGpsACC),0,0,0,
212
//
213
        6,1,0,247,MKOSO(NaviWindCorrection),90,90,90,
214
        6,1,0,247,MKOSO(NaviSpeedCompensation),30,30,30,
215
        6,1,0,247,MKOSO(NaviOperatingRadius),100,100,100,
216
        6,1,0,247,MKOSO(NaviAngleLimitation),100,100,100,
217
        6,0,0,247,MKOSO(NaviPH_LoginTime),2,2,2,
218
 
219
 
220
 
221
         // group 7 : ausgaenge 9
222
 
223
     7,4,0,255,MKOSO(J16Bitmask),95,95,95,
224
     7,1,0,247,MKOSO(J16Timing),30,30,30,
225
     7,4,0,255,MKOSO(J17Bitmask),243,243,243,
226
     7,1,0,247,MKOSO(J17Timing),30,30,30,
227
     7,2,0,0x10,MKOSO(BitConfig),0,0,0,//CFG_MOTOR_BLINK
228
     7,4,0,255,MKOSO(WARN_J16_Bitmask),170,170,170,
229
     7,2,0,0x20,MKOSO(BitConfig),1,1,1,//CFG_MOTOR_OFF_LED1
230
     7,4,0,255,MKOSO(WARN_J17_Bitmask),170,170,170,
231
     7,2,0,0x40,MKOSO(BitConfig),1,1,1,//CFG_MOTOR_OFF_LED2
232
 
233
 
234
 
235
         // group 8 : versch. 7
236
 
237
     8,0,0,247,MKOSO(Gas_Min),8,8,8,
238
     8,0,0,247,MKOSO(Gas_Max),230,230,230,
239
     8,1,0,247,MKOSO(KompassWirkung),128,128,128,
240
     8,1,0,247,MKOSO(OrientationModeControl),0,0,0,
241
     8,0,0,247,MKOSO(UnterspannungsWarnung),33,33,33,
242
     8,0,0,247,MKOSO(NotGasZeit),90,90,90,
243
     8,0,0,247,MKOSO(NotGas),45,45,45,
244
 
245
 
246
         // group 9 : gyro 12
247
 
248
         9,1,0,247,MKOSO(Gyro_P),100,100,100,
249
         9,1,0,247,MKOSO(Gyro_I),120,120,120,
250
         9,1,0,247,MKOSO(Gyro_D),10,10,10,
251
         9,1,0,247,MKOSO(Gyro_Gier_P),100,100,100,
252
         9,1,0,247,MKOSO(Gyro_Gier_I),120,120,120,
253
         9,1,0,247,MKOSO(DynamicStability),70,70,70,
254
         9,2,0,0x80,MKOSO(GlobalConfig),0,0,0, //drehratenbregrenzung
255
         9,0,0,247,MKOSO(GyroAccFaktor),27,27,27,
256
         9,0,0,247,MKOSO(GyroAccAbgleich),32,32,32,
257
         9,1,0,247,MKOSO(I_Faktor),16,16,16,
258
         9,0,0,247,MKOSO(Driftkomp),0,0,0,
259
         9,0,0,8,MKOSO(Gyro_Stability),100,100,100,
260
 
261
 
262
         // group 10: benutzer 8
263
 
264
         10,1,0,247,MKOSO(UserParam1),0,0,0,
265
         10,1,0,247,MKOSO(UserParam2),0,0,0,
266
         10,1,0,247,MKOSO(UserParam3),0,0,0,
267
         10,1,0,247,MKOSO(UserParam4),0,0,0,
268
         10,1,0,247,MKOSO(UserParam5),0,0,0,
269
         10,1,0,247,MKOSO(UserParam6),0,0,0,
270
         10,1,0,247,MKOSO(UserParam7),0,0,0,
271
         10,1,0,247,MKOSO(UserParam8),0,0,0,
272
 
273
 
274
         // group 11: achskoppl 4
275
 
276
         11,2,0,0x40,MKOSO(GlobalConfig),0,0,0, //achsentkopplung
277
         11,1,0,247,MKOSO(AchsKopplung1),90,90,90,
278
         11,1,0,247,MKOSO(AchsKopplung2),80,80,80,
279
         11,1,0,247,MKOSO(CouplingYawCorrection),70,70,70,
280
 
281
 
282
 
283
         // group 12: mixer
284
 
285
         12,5,0,23,MKOSO(OrientationAngle),0,0,0,
286
 
287
};
288
 
289
 
290
 
291
 
292
 
293
 
294
void edit_parameter (void)
295
{
296
        SwitchToFC();
297
 
298
 
299
        uint8_t setting;
300
 
301
 
302
        setting = display_settings_menu();
303
 
304
        if(setting == 6)
305
        {
306
                copy_setting();
307
                return;
308
        }
309
 
310
 
311
                if(setting == 255) return;
312
                uint8_t setting_loaded =  load_setting(setting);
313
                if(setting_loaded == 255) return;
314
 
315
                offset = 0;
316
                dmode = 0;
317
                target_pos = 1;
318
                changes =0;
319
 
320
 
321
                        uint8_t group =0;
322
                        do
323
                        {
324
 
325
                                group = display_section_menu();
326
 
327
                                if(group != 255)
328
                                {
329
                                        offset2 = 0;
330
                                        pmode = 0;
331
                                        target_pos2 = 1;
332
                                        uint8_t param;
333
                                        do
334
                                        {
335
                                                param = display_param_menu(group);
336
 
337
                                                if(param != 255)
338
                                                {
339
                                                        edit_param(param);
340
                                                }
341
 
342
                                        }
343
                                        while(param != 255);
344
                                }
345
 
346
 
347
                        }
348
                        while(group != 255);
349
 
350
                if(changes == 1)
351
                {
352
                        lcd_cls();
353
                        lcd_printp_at (0, 0, PSTR("Save Setting x?"), 0);
354
                        write_ndigit_number_u(13,0,setting, 1,0);
355
                        lcd_printp_at (3, 1, PSTR("yes"), 0);
356
                        lcd_printp_at (3, 2, PSTR("no"), 0);
357
                        lcd_printpns_at (0, 7, PSTR(" \x1a    \x1b     Exit   \x0c"), 0);
358
 
359
                        uint8_t val = menu_choose2 (1, 2, 2,0,0);
360
 
361
                        if(val == 1)
362
                        {
363
                                uint8_t setting_written = write_setting(setting);
364
 
365
                                if(setting_written == setting)
366
                                {
367
                                        lcd_printp_at (0, 4, PSTR("saved and"), 0);
368
                                        lcd_printp_at (0, 5, PSTR("activated"), 0);
369
                                }
370
                                else
371
                                {
372
                                        lcd_printp_at (0, 4, PSTR("ERROR"), 0);
373
                                }
374
                                timer = 100;
375
                                while (timer > 0);
376
 
377
                        }
378
 
379
                }
380
 
381
 
382
 
383
 
384
}
385
 
386
 
387
void copy_setting(void)
388
{
389
        uint8_t fromsetting = 3;
390
        uint8_t tosetting = 5;
391
 
392
        lcd_cls();
393
 
394
        lcd_printp_at (0, 0, PSTR("Copy Setting:"), 0);
395
        lcd_printp_at (3, 2, PSTR("From Setting:"), 0);
396
        lcd_printp_at (3, 3, PSTR("  To Setting:"), 0);
397
 
398
        //                           123456789012345678901
399
        //                               x     x    x
400
        lcd_printpns_at (0, 7, PSTR("From   To  Back   Do"), 0);
401
 
402
 
403
        do
404
        {
405
                write_ndigit_number_u(17,2,fromsetting, 1,0);
406
                write_ndigit_number_u(17,3,tosetting, 1,0);
407
 
408
                if(get_key_press (1 << KEY_MINUS))
409
                {
410
                        fromsetting++;
411
                        if(fromsetting == 6) fromsetting = 1;
412
                }
413
                if(get_key_press (1 << KEY_PLUS))
414
                {
415
                        tosetting++;
416
                        if(tosetting == 6) tosetting = 1;
417
                }
418
                if(get_key_press (1 << KEY_ENTER))
419
                {                                                          
420
                        lcd_printp_at (0, 5, PSTR("Really want to copy?"), 0);
421
                        do
422
                        {
423
 
424
                        if(get_key_press (1 << KEY_ENTER))
425
                        {
426
                                uint8_t loaded = load_setting(fromsetting);
427
                                if(loaded == fromsetting)
428
                                {
429
                                        uint8_t written = write_setting(tosetting);
430
                                        if(written == tosetting)
431
                                        {
432
                                                lcd_printp_at (0, 5, PSTR("written and activated"), 0);
433
 
434
                                        }
435
                                        else
436
                                        {
437
                                                lcd_printp_at (0, 5, PSTR("ERROR               "), 0);
438
                                        }
439
                                }
440
                                else
441
                                {
442
                                        lcd_printp_at (0, 5, PSTR("ERROR               "), 0);
443
                                }
444
                                timer = 100;
445
                                while (timer > 0);
446
                                return;
447
                        }
448
 
449
 
450
                        }while (!get_key_short (1 << KEY_ESC));
451
                        lcd_printp_at (0, 5, PSTR("                    "), 0);
452
 
453
                }
454
 
455
 
456
 
457
        }
458
        while (!get_key_short (1 << KEY_ESC));
459
}
460
 
461
 
462
//      write_ndigit_number_u (0,0, *(((uint8_t*)mk_param_struct) + OFFSETOF(mk_param_struct_t, GlobalConfig)) , 6, 0);//evtl. den cast auf uint16_t machen
463
 
464
  //  lcd_printp_at (pos, before, PSTR(" "), 0);
465
  //
466
  // oben  \x1a   unten \x1b
467
   //      lcd_printp_at (pos, line, PSTR("\x1D"), 0);
468
 
469
 
470
void edit_param(uint8_t param)
471
{
472
        lcd_cls();
473
        uint8_t type = pgm_read_byte(param_config+(8*param)+1);
474
        lcd_printp_at (0, 0, PSTR("Edit Setting:"), 0);
475
        if (type != 6) lcd_printp_at(0,2,param_names[param][DisplayLanguage], 0);
476
 
477
 
478
 
479
        if(type == 2)// ja/nein
480
        {
481
                lcd_printpns_at (0, 7, PSTR(" \x1a    \x1b     Back   \x0c"), 0);
482
                lcd_printp_at (3, 4, PSTR("Y"), 0);
483
                lcd_printp_at (3, 5, PSTR("N"), 0);
484
 
485
                uint8_t value = *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4));
486
                uint8_t defaultvalue =  pgm_read_byte(param_config+(8*param)+5);
487
                uint8_t bitmap = pgm_read_byte(param_config+(8*param)+3);
488
                uint8_t newvalue = value;
489
 
490
                if(defaultvalue == 1) lcd_printp_at (4, 4, PSTR("*"), 0);
491
                if(defaultvalue == 0) lcd_printp_at (4, 5, PSTR("*"), 0);
492
 
493
                do
494
                {
495
 
496
                        if(newvalue & bitmap)
497
                        {
498
                                lcd_printp_at (1, 4, PSTR("\x1D"), 0);
499
                        lcd_printp_at (1, 5, PSTR(" "), 0);
500
                        }
501
                        else
502
                        {
503
                        lcd_printp_at (1, 4, PSTR(" "), 0);
504
                                lcd_printp_at (1, 5, PSTR("\x1D"), 0);
505
                        }
506
 
507
 
508
                        if(get_key_press (1 << KEY_MINUS))
509
                        {
510
                                newvalue ^= bitmap;
511
                        }
512
 
513
                        if(get_key_press (1 << KEY_PLUS))
514
                        {
515
                                newvalue ^= bitmap;
516
                        }
517
 
518
                        if(get_key_press (1 << KEY_ENTER))
519
                        {
520
                                if(newvalue != value)
521
                                {
522
                                        *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4)) = newvalue;
523
                                        changes=1;
524
                                }
525
                                break;
526
 
527
                        }
528
 
529
                        if(get_key_long (1 << KEY_ESC))
530
                        {
531
                                if(defaultvalue == 1)
532
                                {
533
                                        newvalue |= bitmap;
534
                                }
535
                                else
536
                                {
537
                                        newvalue &= ~bitmap;
538
                                }
539
                        }
540
 
541
 
542
                }while (!get_key_short (1 << KEY_ESC));
543
        }
544
        if(type == 0)// ohne poti
545
        {
546
                lcd_printpns_at (0, 7, PSTR(" \x18    \x19     Back   \x0c"), 0);
547
                uint8_t value = *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4));
548
                uint8_t min   =pgm_read_byte(param_config+(8*param)+2);
549
                uint8_t max   = pgm_read_byte(param_config+(8*param)+3);
550
                uint8_t defaultvalue   = pgm_read_byte(param_config+(8*param)+5);
551
                lcd_printpns_at (4, 4, PSTR("(   -   ) (d:   )"), 0);
552
                write_ndigit_number_u (5, 4, min, 3, 0);
553
                write_ndigit_number_u (9, 4, max, 3, 0);
554
                write_ndigit_number_u (17, 4, defaultvalue, 3, 0);
555
 
556
 
557
                uint8_t newvalue = value;
558
 
559
                do
560
                {
561
                        write_ndigit_number_u (0, 4, newvalue, 3, 0);
562
                        lcd_frect ((8*0), (8*5), (newvalue * (16*8)) / max, 6, 1);
563
 
564
 
565
                        if(get_key_press (1 << KEY_PLUS) || get_key_rpt (1 << KEY_PLUS))
566
                        {
567
                                if((newvalue+1) <= max)
568
                                {
569
                                        newvalue++;
570
                                        //lcd_frect ((8*0), (8*5), (newvalue * (16*8)) / max, 6, 1);
571
                                }
572
                        }
573
 
574
                        if(get_key_press (1 << KEY_MINUS) || get_key_rpt (1 << KEY_MINUS))
575
                        {
576
                                if((newvalue-1)>=min)
577
                                {
578
                                        lcd_frect ((8*0), (8*5), (newvalue * (16*8)) / max, 6, 0);
579
                                        newvalue--;
580
                                        //lcd_frect ((8*0), (8*5), (newvalue * (16*8)) / max, 6, 1);
581
                                }
582
                        }
583
 
584
 
585
                        if(get_key_press (1 << KEY_ENTER))
586
                        {
587
                                if(newvalue != value)
588
                                {
589
                                        *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4)) = newvalue;
590
                                        changes=1;
591
                                }
592
                                break;
593
 
594
                        }
595
                        if(get_key_long (1 << KEY_ESC))
596
                        {
597
                                lcd_frect ((8*0), (8*5), (newvalue * (16*8)) / max, 6, 0);
598
                                newvalue = defaultvalue;
599
                                //lcd_frect ((8*0), (8*5), (newvalue * (16*8)) / max, 6, 1);
600
 
601
                        }
602
 
603
                }while (!get_key_short (1 << KEY_ESC));
604
        }
605
 
606
        if(type == 1)// mit poti
607
        {
608
                lcd_printpns_at (0, 7, PSTR(" \x18    \x19     Back  \x0c\x0c"), 0);
609
                uint8_t value = *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4));
610
                uint8_t min   =pgm_read_byte(param_config+(8*param)+2);
611
                uint8_t max   = pgm_read_byte(param_config+(8*param)+3);
612
                uint8_t defaultvalue   = pgm_read_byte(param_config+(8*param)+5);
613
                lcd_printpns_at (4, 4, PSTR("(   -   ) (d:Po )"), 0);
614
                write_ndigit_number_u (5, 4, min, 3, 0);
615
                write_ndigit_number_u (9, 4, max, 3, 0);
616
                if(defaultvalue > 247)
617
                {
618
                        write_ndigit_number_u (19, 4, 256-defaultvalue, 1, 0);
619
                }
620
                else
621
                {
622
                        write_ndigit_number_u (17, 4, defaultvalue, 3, 0);
623
                }
624
 
625
 
626
                uint8_t newvalue = value;
627
 
628
                uint8_t mode = 0;
629
                if(value > 247)
630
                {
631
                        mode=1;
632
                }
633
                else
634
                {
635
                }
636
 
637
                uint8_t tempv = 255;
638
 
639
                do
640
                {
641
 
642
                        if(get_key_long (1 << KEY_ENTER))
643
                        {
644
                                if(mode == 0)
645
                                {
646
                                        mode = 1;
647
                                        lcd_frect ((8*0), (8*5), 128, 6, 0);
648
                                        tempv = newvalue;
649
                                        newvalue = 255;
650
                                }
651
                                else
652
                                {
653
                                        mode = 0;
654
                                        if(tempv == 255)
655
                                        {
656
                                                if (defaultvalue > 247)
657
                                                {
658
                                                        newvalue = min;
659
                                                }
660
                                                else
661
                                                {
662
                                                        newvalue = defaultvalue;
663
                                                }
664
                                        }
665
                                        else
666
                                        {
667
                                                newvalue = tempv;
668
                                        }
669
                                }
670
                        }
671
 
672
 
673
                        if(mode==0)
674
                        {
675
 
676
                                write_ndigit_number_u (0, 4, newvalue, 3, 0);
677
                                lcd_frect ((8*0), (8*5), (newvalue * (16*8)) / max, 6, 1);
678
 
679
 
680
 
681
                                if(get_key_press (1 << KEY_PLUS) || get_key_rpt (1 << KEY_PLUS))
682
                                {
683
                                        if((newvalue+1) <= max)
684
                                        {
685
                                                newvalue++;
686
                                                //lcd_frect ((8*0), (8*5), (newvalue * (16*8)) / max, 6, 1);
687
                                        }
688
                                }
689
 
690
                                if(get_key_press (1 << KEY_MINUS) || get_key_rpt (1 << KEY_MINUS))
691
                                {
692
                                        if((newvalue-1)>=min)
693
                                        {
694
                                                lcd_frect ((8*0), (8*5), (newvalue * (16*8)) / max, 6, 0);
695
                                                newvalue--;
696
                                                //lcd_frect ((8*0), (8*5), (newvalue * (16*8)) / max, 6, 1);
697
                                        }
698
                                }
699
                        }
700
                        else
701
                        {
702
                                lcd_printpns_at (0, 4, PSTR("Po"), 0);
703
                                write_ndigit_number_u (2, 4, 256-newvalue, 1, 0);
704
                                if(get_key_press (1 << KEY_PLUS))
705
                                {
706
                                        if(newvalue > 248)
707
                                        {
708
                                                newvalue--;
709
                                        }
710
                                }
711
 
712
                                if(get_key_press (1 << KEY_MINUS))
713
                                {
714
                                        if(newvalue < 255)
715
                                        {
716
                                                newvalue++;
717
                                        }
718
                                }
719
                        }
720
 
721
 
722
                        if(get_key_short (1 << KEY_ENTER))
723
                        {
724
                                if(newvalue != value)
725
                                {
726
                                        *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4)) = newvalue;
727
                                        changes=1;
728
                                }
729
                                break;
730
 
731
                        }
732
                        if(get_key_long (1 << KEY_ESC))
733
                        {
734
                                lcd_frect ((8*0), (8*5), (newvalue * (16*8)) / max, 6, 0);
735
                                newvalue = defaultvalue;
736
                                if(newvalue > 247)
737
                                {
738
                                        mode =1;
739
                                }
740
                                else
741
                                {
742
                                        //lcd_frect ((8*0), (8*5), (newvalue * (16*8)) / max, 6, 1);
743
                                        mode =0;
744
                                }
745
 
746
 
747
                        }
748
 
749
                }while (!get_key_short (1 << KEY_ESC));
750
        }
751
 
752
        if(type == 3)// serCH
753
        {
754
                lcd_printpns_at (0, 7, PSTR(" \x18    \x19     Back   \x0c"), 0);
755
                uint8_t value = *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4));
756
                uint8_t min   =pgm_read_byte(param_config+(8*param)+2);
757
                uint8_t max   = pgm_read_byte(param_config+(8*param)+3);
758
                uint8_t defaultvalue   = pgm_read_byte(param_config+(8*param)+5);
759
                lcd_printpns_at (4, 4, PSTR("(1-S12/W) (d:   )"), 0);
760
//              write_ndigit_number_u (5, 4, min, 3, 0);
761
//              write_ndigit_number_u (9, 4, max, 3, 0);
762
                write_ndigit_number_u (17, 4, defaultvalue, 3, 0);
763
 
764
 
765
                uint8_t newvalue = value;
766
 
767
                do
768
                {
769
                        if (newvalue<=(max-13))
770
                        {
771
                        write_ndigit_number_u (0, 4, newvalue, 3, 0);
772
                        }
773
                else
774
                    if (newvalue<=(max-1))
775
                         {
776
                          lcd_printpns_at (0, 4, PSTR("S"), 0);
777
                          write_ndigit_number_u (1, 4, (newvalue-12), 2, 0);
778
                         }
779
                   if (newvalue==max)
780
                   {
781
                          lcd_printpns_at (0, 4, PSTR("WPE"), 0);
782
                   }
783
 
784
                          lcd_frect ((8*0), (8*5), (newvalue * (16*8)) / max, 6, 1);
785
 
786
 
787
                        if(get_key_press (1 << KEY_PLUS) || get_key_rpt (1 << KEY_PLUS))
788
                        {
789
                                if((newvalue+1) <= max)
790
                                {
791
                                        newvalue++;
792
                                        //lcd_frect ((8*0), (8*5), (newvalue * (16*8)) / max, 6, 1);
793
                                }
794
                        }
795
 
796
                        if(get_key_press (1 << KEY_MINUS) || get_key_rpt (1 << KEY_MINUS))
797
                        {
798
                                if((newvalue-1)>=min)
799
                                {
800
                                        lcd_frect ((8*0), (8*5), (newvalue * (16*8)) / max, 6, 0);
801
                                        newvalue--;
802
                                        //lcd_frect ((8*0), (8*5), (newvalue * (16*8)) / max, 6, 1);
803
                                }
804
                        }
805
 
806
 
807
                        if(get_key_press (1 << KEY_ENTER))
808
                        {
809
                                if(newvalue != value)
810
                                {
811
                                        *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4)) = newvalue;
812
                                        changes=1;
813
                                }
814
                                break;
815
 
816
                        }
817
                        if(get_key_long (1 << KEY_ESC))
818
                        {
819
                                lcd_frect ((8*0), (8*5), (newvalue * (16*8)) / max, 6, 0);
820
                                newvalue = defaultvalue;
821
                                //lcd_frect ((8*0), (8*5), (newvalue * (16*8)) / max, 6, 1);
822
 
823
                        }
824
 
825
                }while (!get_key_short (1 << KEY_ESC));
826
        }
827
 
828
 
829
        if(type == 4) // led bitfeld
830
        {
831
                lcd_printpns_at (0, 7, PSTR(" \x19   Set    Back   \x0c"), 0);
832
                uint8_t value = *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4));
833
                uint8_t defaultvalue   = pgm_read_byte(param_config+(8*param)+5);
834
 
835
 
836
 
837
                uint8_t pos = 0;
838
                uint8_t newvalue = value;
839
                do
840
                {
841
 
842
                        for(ii=0;ii<8;ii++)
843
                        {
844
                                if(newvalue & (1 << ii))
845
                                {
846
                                        lcd_printpns_at (8-ii, 4,PSTR("X"),0);
847
                                }
848
                                else
849
                                {
850
                                        lcd_printpns_at (8-ii, 4,PSTR("O"),0);
851
                                }
852
                        }
853
                        lcd_printpns_at (pos+1, 5,PSTR("\x1a"),0);
854
                        if(get_key_press (1 << KEY_MINUS))
855
                        {
856
                                lcd_printpns_at (pos+1, 5,PSTR(" "),0);
857
                                pos++;
858
                                if(pos == 8) pos = 0;
859
                        }
860
                        if(get_key_press (1 << KEY_PLUS))
861
                        {
862
                                newvalue ^= (1<<(7-pos));
863
                        }
864
                        if(get_key_press (1 << KEY_ENTER))
865
                        {
866
                                if(newvalue != value)
867
                                {
868
                                        *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4)) = newvalue;
869
                                        changes=1;
870
                                }
871
                                break;
872
                        }
873
 
874
                        if(get_key_long (1 << KEY_ESC))
875
                        {
876
                                newvalue = defaultvalue;
877
                        }
878
 
879
 
880
                }while (!get_key_short (1 << KEY_ESC));
881
        }
882
 
883
        if(type == 6) // receiver
884
        {
885
                lcd_printpns_at (0, 7, PSTR(" \x1a    \x1b     Back   \x0c"), 0);
886
                uint8_t value = *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4));
887
                uint8_t defaultvalue   = pgm_read_byte(param_config+(8*param)+5);
888
 
889
                lcd_printpns_at (3, 1,PSTR("PPM"),0);
890
                lcd_printpns_at (3, 2,PSTR("Spektrum"),0);
891
                lcd_printpns_at (3, 3,PSTR("Spektrum HiRes"),0);
892
                lcd_printpns_at (3, 4,PSTR("Spektrum LoRes"),0);
893
                lcd_printpns_at (3, 5,PSTR("Jeti"),0);
894
                lcd_printpns_at (3, 6,PSTR("ACT DSL"),0);
895
 
896
                uint8_t newvalue = value;
897
                do
898
                {
899
 
900
                        for(ii=0;ii<6;ii++)
901
                        {
902
                                if(newvalue == ii)
903
                                {
904
                                        lcd_printpns_at (1, ii+1,PSTR(">"),0);
905
                                }
906
                                else
907
                                {
908
                                        lcd_printpns_at (1, ii+1,PSTR(" "),0);
909
                                }
910
 
911
 
912
                        }
913
 
914
                        if(get_key_press (1 << KEY_PLUS))
915
                        {
916
                                newvalue++;
917
                                if(newvalue == 6) newvalue = 0;
918
                        }
919
                        if(get_key_press (1 << KEY_MINUS))
920
                        {
921
                                if(newvalue == 0) newvalue = 6;
922
                                newvalue--;
923
                        }
924
                        if(get_key_press (1 << KEY_ENTER))
925
                        {
926
                                if(newvalue != value)
927
                                {
928
                                        *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4)) = newvalue;
929
                                        changes=1;
930
                                }
931
                                break;
932
                        }
933
 
934
                        if(get_key_long (1 << KEY_ESC))
935
                        {
936
                                newvalue = defaultvalue;
937
                        }
938
 
939
 
940
                }while (!get_key_short (1 << KEY_ESC));
941
        }
942
 
943
        if(type == 5) // Angle
944
        {
945
                lcd_printpns_at (0, 7, PSTR(" \x1a    \x1b     Back   \x0c"), 0);
946
                uint8_t value = *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4));
947
                uint8_t defaultvalue   = pgm_read_byte(param_config+(8*param)+5);
948
 
949
                lcd_ecircle(102, 35, 16, 1);
950
 
951
                uint8_t newvalue = value;
952
                uint8_t oldvalue = newvalue;
953
                do
954
                {
955
 
956
                        if(oldvalue != newvalue) lcd_ecirc_line (102, 35, 15, oldvalue*15, 0);
957
                        oldvalue = newvalue;
958
                        lcd_ecirc_line (102, 35, 15, newvalue*15, 1);
959
 
960
 
961
                        if(get_key_press (1 << KEY_PLUS))
962
                        {
963
                                newvalue++;
964
                                if(newvalue == 24) newvalue = 0;
965
                        }
966
                        if(get_key_press (1 << KEY_MINUS))
967
                        {
968
                                if(newvalue == 0) newvalue = 24;
969
                                newvalue--;
970
                        }
971
                        if(get_key_press (1 << KEY_ENTER))
972
                        {
973
                                if(newvalue != value)
974
                                {
975
                                        *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*param)+4)) = newvalue;
976
                                        changes=1;
977
                                }
978
                                break;
979
                        }
980
 
981
                        if(get_key_long (1 << KEY_ESC))
982
                        {
983
                                newvalue = defaultvalue;
984
                        }
985
 
986
 
987
                }while (!get_key_short (1 << KEY_ESC));
988
        }
989
 
990
 
991
 
992
 
993
//      while (!get_key_press (1 << KEY_ESC));
994
}      
995
 
996
 
997
 
998
 
999
uint8_t display_param_menu(uint8_t group)
1000
{
1001
        uint8_t items[20];
1002
 
1003
        uint8_t size=0;
1004
        for(ii = 0;ii < PARAM_COUNT; ii++)
1005
        {
1006
                if(pgm_read_byte(param_config+(8*ii)) == (group-1))
1007
                {
1008
                        items[size] = ii;
1009
                        size++;
1010
                }
1011
        }
1012
 
1013
 
1014
//      offset2=0;
1015
//      target_pos2=1;
1016
//      pmode =0;
1017
 
1018
        uint8_t val =0 ;
1019
 
1020
 
1021
 
1022
        while(1)
1023
        {
1024
                lcd_cls ();
1025
                lcd_printp_at (0, 0, PSTR("Choose Parameter:"), 0);
1026
                lcd_printpns_at (0, 7, PSTR(" \x1a    \x1b     Back   \x0c"), 0);
1027
 
1028
                ii = 0;
1029
                if(offset2 > 0)
1030
                {
1031
                        lcd_printp_at(1,1, PSTR("\x1a"), 0);
1032
                }
1033
                for(ii = 0;ii < 6 ; ii++)
1034
                {
1035
                        if((ii+offset2) < size)
1036
                        {
1037
                                lcd_printp_at(3,ii+1,param_names[items[ii+offset2]][DisplayLanguage], 0);
1038
                                // this reads the the offset in the struct from the pgm configuration table and then reads the value from the struct
1039
 
1040
                                uint8_t type = pgm_read_byte(param_config+(8*items[ii+offset2])+1);
1041
 
1042
                                if(type == 0)
1043
                                {
1044
                                        write_ndigit_number_u (18, ii+1, *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*items[ii+offset2])+4)), 3, 0);
1045
                                }
1046
                                if(type == 1)
1047
                                {
1048
                                        uint8_t value = *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*items[ii+offset2])+4));
1049
 
1050
                                        if(value < 248)
1051
                                                write_ndigit_number_u (18, ii+1, value, 3, 0);
1052
                                        if(value >= 248)
1053
                                        {
1054
                                                lcd_printp_at (18, ii+1, PSTR(" P"), 0);
1055
                                                write_ndigit_number_u (20, ii+1, 256-value, 1, 0);
1056
                                        }
1057
                                }
1058
                                if(type == 2)
1059
                                {
1060
 
1061
                                        uint8_t value = *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*items[ii+offset2])+4));
1062
                                        uint8_t bitmap = pgm_read_byte(param_config+(8*items[ii+offset2])+3);
1063
                                        if(value & bitmap)
1064
                                        {
1065
                                                lcd_printp_at (18, ii+1, PSTR("  Y"), 0);
1066
                                        }
1067
                                        else
1068
                                        {
1069
                                                lcd_printp_at (18, ii+1, PSTR("  N"), 0);
1070
                                        }
1071
                                }
1072
                                if(type == 3)
1073
                                {
1074
                                        uint8_t value = *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*items[ii+offset2])+4));
1075
                                        if (value<=12)
1076
//                                      write_ndigit_number_u (18, ii+1, *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*items[ii+offset2])+4)), 3, 0);
1077
                                        write_ndigit_number_u (18, ii+1, value, 3, 0);
1078
                                else
1079
                                    if (value<=(24))
1080
                                         {
1081
                                          lcd_printpns_at (18, ii+1, PSTR("S"), 0);
1082
                                          write_ndigit_number_u (19, ii+1, (value-12), 2, 0);
1083
                                         }
1084
                           if (value==25)
1085
                                   lcd_printpns_at (18, ii+1, PSTR("WPE"), 0);
1086
                                }
1087
 
1088
 
1089
 
1090
                                if(type == 4)
1091
                                {
1092
                                        write_ndigit_number_u (18, ii+1, *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*items[ii+offset2])+4)), 3, 0);
1093
                                }
1094
                                if(type == 5)
1095
                                {
1096
                                        write_ndigit_number_u (18, ii+1, (*(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*items[ii+offset2])+4)))*15, 3, 0);
1097
                                }
1098
                                if(type == 6)
1099
                                {
1100
                                        uint8_t value = *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*items[ii+offset2])+4));
1101
                                        if(value == 0)
1102
                                        {
1103
                                                lcd_printp_at (18, ii+1, PSTR("PPM"), 0);
1104
                                        }
1105
                                        else if(value == 1)
1106
                                        {
1107
                                                lcd_printp_at (18, ii+1, PSTR(" SP"), 0);
1108
                                        }
1109
                                        else if(value == 2)
1110
                                        {
1111
                                                lcd_printp_at (18, ii+1, PSTR("SPh"), 0);
1112
                                        }
1113
                                        else if(value == 3)
1114
                                        {
1115
                                                lcd_printp_at (18, ii+1, PSTR("SPl"), 0);
1116
                                        }
1117
                                        else if(value == 4)
1118
                                        {
1119
                                                lcd_printp_at (18, ii+1, PSTR("Jet"), 0);
1120
                                        }
1121
                                        else if(value == 5)
1122
                                        {
1123
                                                lcd_printp_at (18, ii+1, PSTR("ACT"), 0);
1124
                                        }
1125
                                        else
1126
                                        {
1127
                                                write_ndigit_number_u (18, ii+1, *(((uint8_t*)mk_param_struct) + pgm_read_byte(param_config+(8*items[ii+offset2])+4)), 3, 0);
1128
                                        }
1129
                                }
1130
 
1131
                        }
1132
                        if((ii == 5)&&(ii+offset2 < (size-1)))
1133
                        {
1134
                                lcd_printp_at(1,6, PSTR("\x1b"), 0);
1135
                        }
1136
 
1137
                }
1138
 
1139
/*              write_ndigit_number_u (0, 0,offset2, 3, 0);
1140
                write_ndigit_number_u (4, 0,target_pos2, 3, 0);
1141
                write_ndigit_number_u (7, 0,pmode, 3, 0);
1142
                write_ndigit_number_u (10, 0,size, 3, 0);
1143
                write_ndigit_number_u (14, 0,val, 3, 0);
1144
                write_ndigit_number_u (17, 0,group, 3, 0);
1145
*/
1146
 
1147
                if(pmode == 0)
1148
                {
1149
                        if(offset2 == 0)
1150
                        {
1151
                                if(size > 6)
1152
                                {
1153
                                        val = menu_choose2 (1, 5, target_pos2,0,1);
1154
                                }
1155
                                else
1156
                                {
1157
                                        val = menu_choose2 (1, size, target_pos2,0,0);
1158
                                }
1159
 
1160
                        }
1161
                        else
1162
                        {
1163
                                val = menu_choose2 (2, 5, target_pos2,1,1);
1164
                        }
1165
                }
1166
                if(pmode == 1)
1167
                {
1168
                        if(offset2+7 > size)
1169
                        {
1170
                                val = menu_choose2 (2, 6, target_pos2,1,0);
1171
                        }
1172
                        else
1173
                        {
1174
                                val = menu_choose2 (2, 5, target_pos2,1,1);
1175
                        }
1176
                }
1177
 
1178
                if(val == 254)
1179
                {
1180
                        offset2++;
1181
                        pmode = 1;
1182
                        target_pos2 = 5;
1183
                }else if(val == 253)
1184
                {
1185
                        offset2--;
1186
                        pmode = 0;
1187
                        target_pos2 = 2;
1188
                }
1189
                else
1190
                {
1191
                        break;
1192
                }
1193
        }
1194
 
1195
        if(val != 255)
1196
        {
1197
                target_pos2=val;       
1198
                return items[val+offset2-1];
1199
        }
1200
        else
1201
        {
1202
                return val;
1203
        }
1204
 
1205
}
1206
 
1207
 
1208
uint8_t display_section_menu(void)
1209
{
1210
        uint8_t size = PAGES;
1211
 
1212
        uint8_t val =0;
1213
 
1214
 
1215
        while(1)
1216
        {
1217
                lcd_cls ();
1218
                lcd_printp_at (0, 0, PSTR("Choose Section:"), 0);
1219
                lcd_printpns_at (0, 7, PSTR(" \x1a    \x1b     Back   \x0c"), 0);
1220
//              write_ndigit_number_u(0,0,dmode,2,0);
1221
//              write_ndigit_number_u(2,0,offset,2,0);
1222
//              write_ndigit_number_u(4,0,target_pos,2,0);
1223
 
1224
                ii = 0;
1225
                if(offset > 0)
1226
                {
1227
                        lcd_printp_at(1,1, PSTR("\x1a"), 0);
1228
                }
1229
                for(ii = 0;ii < 6 ; ii++)
1230
                {
1231
                        if((ii+offset) < size)
1232
                        {
1233
                                lcd_printp_at(3,ii+1,param_pages[ii+offset][DisplayLanguage], 0);
1234
                        }
1235
                        if((ii == 5)&&(ii+offset < (size-1)))
1236
                        {
1237
                                lcd_printp_at(1,6, PSTR("\x1b"), 0);
1238
                        }
1239
 
1240
                }
1241
 
1242
 
1243
 
1244
                if(dmode == 0)
1245
                {
1246
                        if(offset == 0)
1247
                        {
1248
                                if(size > 6)
1249
                                {
1250
                                        val = menu_choose2 (1, 5, target_pos,0,1);
1251
                                }
1252
                                else
1253
                                {
1254
                                        val = menu_choose2 (1, size, target_pos,0,0);
1255
                                }
1256
                        }
1257
                        else
1258
                        {
1259
                                val = menu_choose2 (2, 5, target_pos,1,1);
1260
                        }
1261
                }
1262
                if(dmode == 1)
1263
                {
1264
                        if(offset+7 > size)
1265
                        {
1266
                                val = menu_choose2 (2, 6, target_pos,1,0);
1267
                        }
1268
                        else
1269
                        {
1270
                                val = menu_choose2 (2, 5, target_pos,1,1);
1271
                        }
1272
                }
1273
 
1274
 
1275
 
1276
                if(val == 254)
1277
                {
1278
                        offset++;
1279
                        dmode = 1;
1280
                        target_pos = 5;
1281
                }else if(val == 253)
1282
                {
1283
                        offset--;
1284
                        dmode = 0;
1285
                        target_pos = 2;
1286
                }
1287
                else
1288
                {
1289
                        break;
1290
                }
1291
        }
1292
 
1293
//      write_ndigit_number_u(0,0,val,2,0);
1294
//       menu_choose2 (2, 5, target_pos,1,1);
1295
        if(val != 255)
1296
        {
1297
                target_pos=val;
1298
                return val+offset;
1299
        }
1300
        else
1301
        {
1302
                return val;
1303
        }
1304
 
1305
}
1306
 
1307
 
1308
uint8_t display_settings_menu (void)
1309
{
1310
    uint8_t status;
1311
 
1312
        lcd_cls ();
1313
 
1314
        uint8_t setting = 0;
1315
        lcd_printp_at (0, 0, PSTR("Edit Setting:"), 0);
1316
        lcd_printpns_at (0, 7, PSTR(" \x1a    \x1b     Back   \x0c"), 0);
1317
 
1318
 
1319
        for(setting=1;setting<6;setting++)
1320
        {          
1321
                status = load_setting(setting);
1322
                if(status == 255) return 255;
1323
 
1324
        write_ndigit_number_u (3, setting, status, 1, 0);
1325
        lcd_print_at (5,setting,(uint8_t*)mk_param_struct->Name, 0);
1326
        }
1327
        lcd_printp_at (3, 6, PSTR("Copy Setting"), 0);
1328
 
1329
 
1330
        status = load_setting(0xff);
1331
        if(status == 255) return 255;
1332
 
1333
        setting = menu_choose (1, 6, 1,status);
1334
 
1335
        return setting;
1336
}
1337
 
1338
 
1339
 
1340
uint8_t load_setting(uint8_t setting)
1341
{
1342
        mode = 'Q';     // Settings
1343
        uint8_t timeout = 50;
1344
        rxd_buffer_locked = FALSE;
1345
 
1346
        while (!rxd_buffer_locked && timeout)
1347
        {
1348
                SendOutData ('q', ADDRESS_FC, 1, &setting, 1);
1349
        //      _delay_ms(50);
1350
                timer = 20;
1351
            while (timer > 0);
1352
            timeout--;
1353
        }
1354
 
1355
        if (timeout != 0)
1356
        {
1357
                Decode64 ();
1358
                setting = *pRxData;
1359
            mk_param_struct = (mk_param_struct_t *) (pRxData + 1) ;
1360
        }
1361
        else
1362
        {       // timeout occured
1363
                lcd_printp_at (0, 2, PSTR("ERROR: no data"), 0);
1364
 
1365
                timer = 100;
1366
                while (timer > 0);
1367
                setting = 255;
1368
        }
1369
 
1370
        return setting;
1371
}
1372
 
1373
uint8_t write_setting(uint8_t setting)
1374
{
1375
        mode = 'S';     // Settings
1376
        uint8_t timeout = 50;
1377
        rxd_buffer_locked = FALSE;
1378
 
1379
        while (!rxd_buffer_locked && timeout)
1380
        {
1381
                SendOutData ('s', ADDRESS_FC, 2, &setting, 1, mk_param_struct, sizeof(mk_param_struct_t));
1382
        //      _delay_ms(50);
1383
                timer = 20;
1384
            while (timer > 0);
1385
            timeout--;
1386
        }
1387
 
1388
        if (timeout != 0)
1389
        {
1390
                Decode64 ();
1391
                setting = *pRxData;
1392
        }
1393
        else
1394
        {       // timeout occured
1395
                lcd_printp_at (0, 2, PSTR("ERROR: no data"), 0);
1396
 
1397
                timer = 100;
1398
                while (timer > 0);
1399
                setting = 255;
1400
        }
1401
 
1402
        return setting;
1403
}
1404