Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

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