Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2136 | - | 1 | /***************************************************************************** |
2 | * Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
||
3 | * Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
||
4 | * Copyright (C) 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 | //# HISTORY mksettings.c |
||
36 | //# |
||
37 | //# 14.05.2014 OG |
||
38 | //# - chg: include "mkbase.h" geaendert auf "../mk/mkbase.h" |
||
39 | //# |
||
40 | //# 11.05.2014 OG |
||
41 | //# - chg: MKSettings_Menu() umgestellt auf MenuCtrl_SetTitleFromParentItem() |
||
42 | //# -> die Menues 'erben' damit ihren Titel vom aufrufenden Menuepunkt |
||
43 | //# |
||
44 | //# 29.03.2014 OG |
||
45 | //# - chg: versch. Funktionen: del: MenuCtrl_SetShowBatt() wegen Aenderung |
||
46 | //# des Defaults auf true |
||
47 | //# |
||
48 | //# 26.03.2014 OG |
||
49 | //# - add: etliche Aenderungen in allen Bereichen fuer das erste Release |
||
50 | //# der neuen MK-Settings |
||
51 | //# |
||
52 | //# 27.02.2014 OG |
||
53 | //# - chg: MKSettings_AskAction() Unterstuetzung von param_DUMMY |
||
54 | //# |
||
55 | //# 26.02.2014 OG |
||
56 | //# - chg: MKSettings_Copy() auf KEYLINE2 geaendert |
||
57 | //# |
||
58 | //# 23.02.2014 OG |
||
59 | //# - chg: MKSettings_Menu() Aufruf von MK_Parameters() geaendert |
||
60 | //# |
||
61 | //# 18.02.2014 OG - NEU |
||
62 | //############################################################################ |
||
63 | |||
64 | |||
65 | #include "../cpu.h" |
||
66 | #include <avr/io.h> |
||
67 | #include <inttypes.h> |
||
68 | #include <stdlib.h> |
||
69 | #include <avr/pgmspace.h> |
||
70 | #include <avr/wdt.h> |
||
71 | #include <util/delay.h> |
||
72 | #include <avr/eeprom.h> |
||
73 | #include <util/delay.h> |
||
74 | #include <string.h> |
||
75 | #include <util/atomic.h> |
||
76 | |||
77 | //#include "../lipo/lipo.h" |
||
78 | #include "../main.h" |
||
79 | #include "../lipo/lipo.h" |
||
80 | #include "../lcd/lcd.h" |
||
81 | #include "../uart/usart.h" |
||
82 | #include "../utils/menuctrl.h" |
||
83 | #include "../utils/xutils.h" |
||
84 | |||
85 | #include "../uart/uart1.h" |
||
86 | #include "../mk-data-structs.h" |
||
87 | //#include "../menu.h" |
||
88 | #include "../timer/timer.h" |
||
89 | #include "../eeprom/eeprom.h" |
||
90 | #include "../messages.h" |
||
91 | #include "../pkt/pkt.h" |
||
92 | #include "../mk/mkbase.h" |
||
93 | #include "paramset.h" |
||
94 | #include "mkparameters.h" |
||
95 | #include "mksettings.h" |
||
96 | |||
97 | //--------------------------------------------------------------------------------------------- |
||
98 | |||
99 | #define F_EXIT 0 |
||
100 | #define F_REFRESH 1 |
||
101 | |||
102 | char mksettings_menu_names[6][18]; // befuellt von: MKSettings_read_Names() |
||
103 | |||
104 | |||
105 | //------------------------------------- |
||
106 | //------------------------------------- |
||
107 | typedef struct |
||
108 | { |
||
109 | unsigned char paramsetRevision; // Revision FC-Parameterset fuer die das Temp-Setting gueltig ist |
||
110 | unsigned char *paramset; // malloc: Pointer auf kopierte Parameter-Daten |
||
111 | } MKSetting_TMP_t; |
||
112 | |||
113 | |||
114 | MKSetting_TMP_t MKSetting_TMP; |
||
115 | |||
116 | |||
117 | #define ID_SETTING_COPY 10 // fuer MKSettings_Menu() |
||
118 | #define ID_EDIT 20 // fuer MKSettings_AskAction() |
||
119 | #define ID_ACTIVATE 21 // fuer MKSettings_AskAction() |
||
120 | #define ID_COPY 22 // fuer MKSettings_AskAction() |
||
121 | |||
122 | #define ID_SAVE 30 // fuer MKSettings_AskSaveSetting() |
||
123 | #define ID_DISCARD 31 // fuer MKSettings_AskSaveSetting() |
||
124 | |||
125 | |||
126 | //############################################################################################# |
||
127 | //# |
||
128 | //############################################################################################# |
||
129 | |||
130 | |||
131 | //-------------------------------------------------------------- |
||
132 | // MKSettings_TMP_Init0() |
||
133 | // |
||
134 | // nur fuer main.c |
||
135 | //-------------------------------------------------------------- |
||
136 | void MKSettings_TMP_Init0( void ) |
||
137 | { |
||
138 | memset( &MKSetting_TMP, 0, sizeof(MKSetting_TMP_t) ); |
||
139 | strcpy( mksettings_menu_names[5], "PKT: --empty--"); |
||
140 | } |
||
141 | |||
142 | |||
143 | |||
144 | //-------------------------------------------------------------- |
||
145 | // MKSettings_TMP_Init() |
||
146 | // |
||
147 | // loeschen / initialisieren vom PKT Temp-Setting |
||
148 | //-------------------------------------------------------------- |
||
149 | void MKSettings_TMP_Init( void ) |
||
150 | { |
||
151 | if( MKSetting_TMP.paramset != NULL ) |
||
152 | { |
||
153 | free( MKSetting_TMP.paramset ); |
||
154 | } |
||
155 | MKSettings_TMP_Init0(); |
||
156 | } |
||
157 | |||
158 | |||
159 | |||
160 | //-------------------------------------------------------------- |
||
161 | // from_setting = 6 : von TMP zu einem MK-Setting |
||
162 | // from_setting <= 5: von MK-Setting zu TMP |
||
163 | //-------------------------------------------------------------- |
||
164 | uint8_t MKSettings_TMP_copy( uint8_t to_setting, uint8_t timeout ) |
||
165 | { |
||
166 | uint8_t written; |
||
167 | uint8_t size = paramsetSize(); |
||
168 | |||
169 | if( MKSetting_TMP.paramset == NULL ) |
||
170 | { |
||
171 | MKSetting_TMP.paramset = malloc( size+1 ); // +1 fuer das erste settings-byte |
||
172 | } |
||
173 | |||
174 | if( !MKSetting_TMP.paramset ) |
||
175 | { |
||
176 | //PKT_Message_P( *text, error, timeout, beep, clearscreen ) |
||
177 | PKT_Message_P( PSTR("NO RAM!"), true, 800, true, true ); // FEHLER! (NO RAM) |
||
178 | return 0; // -> EXIT |
||
179 | } |
||
180 | |||
181 | // von MK-Setting 1..5 zu TMP |
||
182 | if( to_setting == 6 ) |
||
183 | { |
||
184 | MKSetting_TMP.paramsetRevision = MKVersion.paramsetRevision; |
||
185 | memcpy( MKSetting_TMP.paramset, (unsigned char *)(pRxData), size+1 ); // memcpy( dst, src, size)) |
||
186 | return 6; |
||
187 | } |
||
188 | |||
189 | // von TMP zu MK-Setting 1..5 |
||
190 | memcpy( (unsigned char *)(pRxData), MKSetting_TMP.paramset , size+1 ); // memcpy( dst, src, size)) |
||
191 | written = MK_Setting_write( to_setting, timeout); |
||
192 | return written; |
||
193 | } |
||
194 | |||
195 | |||
196 | |||
197 | //############################################################################################# |
||
198 | //# |
||
199 | //############################################################################################# |
||
200 | |||
201 | //-------------------------------------------------------------- |
||
202 | //-------------------------------------------------------------- |
||
203 | uint8_t MKSettings_read_Names( void ) |
||
204 | { |
||
205 | uint8_t setting; |
||
206 | |||
207 | // die 5 Settings vom Kopter laden um die |
||
208 | // Setting-Namen zu speichern |
||
209 | for( setting=1; setting <= 5; setting++ ) |
||
210 | { |
||
211 | if( !MK_Setting_load( setting, 20 ) ) |
||
212 | return(0); // Fehler - setting konnte nicht geladen werden (timeout = 20) |
||
213 | xsnprintf( mksettings_menu_names[setting-1], 16, "%1d: %s", setting, paramGet_p(param_Name) ); |
||
214 | } |
||
215 | |||
216 | // TMP-Setting |
||
217 | if( MKSetting_TMP.paramset != NULL ) |
||
218 | { |
||
219 | if( MKSetting_TMP.paramsetRevision != MKVersion.paramsetRevision ) |
||
220 | { |
||
221 | // wenn die FC-Revision vom TMP-Setting abweicht vom zuletzt geladenen |
||
222 | // dann wurde ggf. der Kopter gewechselt -> TMP-Setting verwerfen |
||
223 | MKSettings_TMP_Init(); |
||
224 | } |
||
225 | else |
||
226 | { |
||
227 | // den Namen aus dem TMP-Setting holen |
||
228 | paramsetInit( MKSetting_TMP.paramset ); |
||
229 | xsnprintf( mksettings_menu_names[5], 16, "PKT: %s", paramGet_p(param_Name) ); |
||
230 | } |
||
231 | } |
||
232 | |||
233 | setting = MK_Setting_load( 0xff, 20); // aktuelles MK Setting ermitteln |
||
234 | |||
235 | return setting; |
||
236 | } |
||
237 | |||
238 | |||
239 | |||
240 | //-------------------------------------------------------------- |
||
241 | // wahl = MKSettings_AskAction( setting) |
||
242 | // |
||
243 | // Rueckgabe: |
||
244 | // 0 (==Ende), ID_EDIT, ID_ACTIVATE, ID_COPY |
||
245 | //-------------------------------------------------------------- |
||
246 | uint8_t MKSettings_AskAction( uint8_t setting ) |
||
247 | { |
||
248 | uint8_t wahl = 0; |
||
249 | |||
250 | //----------------- |
||
251 | // Menue erstellen |
||
252 | //----------------- |
||
253 | MenuCtrl_Create(); |
||
254 | MenuCtrl_SetTitle( mksettings_menu_names[setting-1] ); // Menuetitel ist der Settingname |
||
255 | MenuCtrl_ShowLevel(false); |
||
256 | MenuCtrl_SetTopSpace(1); // oben beim Menue eine Leerzeile einfuegen |
||
257 | |||
258 | //----------------- |
||
259 | // Menueeintraege |
||
260 | //----------------- |
||
261 | if( !paramExist(param_DUMMY) ) // param_DUMMY -> das Parameterset wird nicht zum bearbeiten unterstuetzt |
||
262 | MenuCtrl_Push_P( ID_EDIT , MENU_ITEM, NOFUNC, strGet(EDIT_SETTING) ); // "Setting ändern" |
||
263 | |||
264 | if( setting != 6) |
||
265 | MenuCtrl_Push_P( ID_ACTIVATE, MENU_ITEM, NOFUNC, strGet(PARA_AKTIVI) ); // "aktivieren" |
||
266 | |||
267 | MenuCtrl_Push_P( ID_COPY , MENU_ITEM, NOFUNC, strGet(STR_COPY) ); // "kopieren" |
||
268 | |||
269 | //----------------- |
||
270 | // Menue Control |
||
271 | //----------------- |
||
272 | MenuCtrl_Control( MENUCTRL_EVENT ); |
||
273 | |||
274 | if( MenuCtrl_GetKey() != KEY_ESC ) |
||
275 | wahl = MenuCtrl_GetItemId(); // welcher Menu-Punkt (ID_CHANGE, ID_ACTIVATE) |
||
276 | |||
277 | MenuCtrl_Destroy(); |
||
278 | MenuCtrl_ShowLevel(true); |
||
279 | |||
280 | return wahl; // 0=Ende; ID_EDIT; ID_ACTIVATE, ID_COPY |
||
281 | } |
||
282 | |||
283 | |||
284 | |||
285 | //-------------------------------------------------------------- |
||
286 | // wahl = MKSettings_AskSaveSetting( setting) |
||
287 | // |
||
288 | // Rueckgabe: |
||
289 | // 0 (==Ende), ID_SAVE, ID_DISCARD |
||
290 | //-------------------------------------------------------------- |
||
291 | uint8_t MKSettings_AskSaveSetting( uint8_t setting ) |
||
292 | { |
||
293 | uint8_t wahl = 0; |
||
294 | |||
295 | //----------------- |
||
296 | // Menue erstellen |
||
297 | //----------------- |
||
298 | MenuCtrl_Create(); |
||
299 | MenuCtrl_SetTitle( mksettings_menu_names[setting-1] ); // Menuetitel ist der Settingname |
||
300 | MenuCtrl_ShowLevel(false); |
||
301 | MenuCtrl_SetTopSpace(1); // oben beim Menue eine Leerzeile einfuegen |
||
302 | |||
303 | //----------------- |
||
304 | // Menueeintraege |
||
305 | //----------------- |
||
306 | MenuCtrl_Push_P( ID_SAVE , MENU_ITEM, NOFUNC, strGet(STR_SAVE) ); // "speichern" |
||
307 | MenuCtrl_Push_P( ID_DISCARD , MENU_ITEM, NOFUNC, strGet(STR_DISCARD) ); // "verwerfen" |
||
308 | |||
309 | |||
310 | //----------------- |
||
311 | // Menue Control |
||
312 | //----------------- |
||
313 | MenuCtrl_Control( MENUCTRL_EVENT ); |
||
314 | |||
315 | if( MenuCtrl_GetKey() != KEY_ESC ) |
||
316 | wahl = MenuCtrl_GetItemId(); // welcher Menu-Punkt (ID_CHANGE, ID_ACTIVATE) |
||
317 | |||
318 | MenuCtrl_Destroy(); |
||
319 | MenuCtrl_ShowLevel(true); |
||
320 | |||
321 | return wahl; // 0=Ende; ID_EDIT; ID_ACTIVATE, ID_COPY |
||
322 | } |
||
323 | |||
324 | |||
325 | |||
326 | //-------------------------------------------------------------- |
||
327 | //-------------------------------------------------------------- |
||
328 | uint8_t MKSettings_Copy( uint8_t from_setting ) |
||
329 | { |
||
330 | const char *mask = PSTR("%15s"); |
||
331 | uint8_t redraw = true; |
||
332 | uint8_t loaded = 0; |
||
333 | uint8_t to_setting; |
||
334 | uint8_t written; |
||
335 | uint8_t key; |
||
336 | int8_t yoffs; |
||
337 | |||
338 | |||
339 | lcd_cls(); |
||
340 | |||
341 | to_setting = from_setting; |
||
342 | |||
343 | while( true ) |
||
344 | { |
||
345 | //------------------------ |
||
346 | // anzeigen |
||
347 | //------------------------ |
||
348 | if( redraw ) |
||
349 | { |
||
350 | lcd_frect( 0, 0, 127, 7, 1); // Titel: Invers |
||
351 | lcd_printp_at( 1, 0, strGet(PARA_COPY), MINVERS); |
||
352 | |||
353 | yoffs = -1; |
||
354 | lcdx_printp_at( 0, 2, strGet(STR_VON), MNORMAL, 0,yoffs); // "von" |
||
355 | lcdx_printf_at_P( 5, 2, MNORMAL, 3,yoffs, mask, mksettings_menu_names[from_setting-1] ); |
||
356 | |||
357 | yoffs = -7; |
||
358 | lcd_frect( 5*6, 4*8+yoffs, 15*6, 7, 0); |
||
359 | lcdx_printp_at( 0, 4, strGet(STR_NACH), MNORMAL, 0,yoffs); // "nach" |
||
360 | lcdx_printf_at_P( 5, 4, MNORMAL, 3,yoffs, mask, mksettings_menu_names[to_setting-1] ); |
||
361 | |||
362 | lcd_printp_at(0, 7, strGet(KEYLINE2), MNORMAL); // Keyline: <- -> Ende OK |
||
363 | |||
364 | redraw = false; |
||
365 | } |
||
366 | |||
367 | //------------------------ |
||
368 | // Tasten abfragen |
||
369 | //------------------------ |
||
370 | if( get_key_press(1 << KEY_ESC) ) |
||
371 | { |
||
372 | return 99; // nur "ENDE" |
||
373 | } |
||
374 | |||
375 | if( get_key_press(1 << KEY_PLUS) ) |
||
376 | { |
||
377 | if( to_setting == 6 ) to_setting = 1; |
||
378 | else to_setting++; |
||
379 | redraw = true; |
||
380 | } |
||
381 | |||
382 | if( get_key_press(1 << KEY_MINUS) ) |
||
383 | { |
||
384 | if( to_setting == 1 ) to_setting = 6; |
||
385 | else to_setting--; |
||
386 | redraw = true; |
||
387 | } |
||
388 | |||
389 | //------------------------------- |
||
390 | // Taste: OK = Setting kopieren? |
||
391 | //------------------------------- |
||
392 | if( get_key_press(1 << KEY_ENTER) ) |
||
393 | { |
||
394 | lcdx_printp_center( 5, strGet(PARA_COPYQ), MNORMAL, 0,1); // "Wirklich kopieren?" (zentriert) |
||
395 | lcd_rect_round( 0, 5*8-3, 127, 7+7, 1, R2); // Rahmen um die Frage |
||
396 | |||
397 | lcd_frect( 0, 7*8, 127, 7, 0); // Keyline loeschen |
||
398 | lcd_printp_at(12, 7, strGet(NOYES), MNORMAL); // neue Keyline: "Nein Ja" |
||
399 | |||
400 | set_beep( 25, 0xffff, BeepNormal ); // kurzer Beep |
||
401 | |||
402 | key = 0; |
||
403 | while( !key ) // Abfrage: Ja / Nein |
||
404 | { |
||
405 | key = get_key_press(1 << KEY_ENTER) ? KEY_ENTER : key; // => "Ja" (=Setting kopieren) |
||
406 | key = get_key_press(1 << KEY_ESC) ? KEY_ESC : key; // => "Nein" |
||
407 | PKT_CtrlHook(); |
||
408 | } |
||
409 | |||
410 | //--------------------------- |
||
411 | // "Ja" -> Setting kopieren! |
||
412 | //--------------------------- |
||
413 | if( key == KEY_ENTER ) // => "Ja" -> Setting kopieren! |
||
414 | { |
||
415 | if( from_setting != 6 ) // kein PKT TMP-Setting |
||
416 | { |
||
417 | loaded = MK_Setting_load( from_setting, 20 ); // timeout = 20 |
||
418 | |||
419 | if( loaded != from_setting ) // Fehler beim laden - Datenverlust? |
||
420 | { |
||
421 | //PKT_Message_P( *text, error, timeout, beep, clearscreen ) |
||
422 | PKT_Message_P( strGet(ERROR_NODATA), true, 800, true, true ); // "Datenverlust!" (max. 8 Sekunden anzeigen) |
||
423 | return 0; // 0 = Ende/Abbruch |
||
424 | } |
||
425 | } |
||
426 | |||
427 | if( to_setting == 6 ) // von Setting 1..5 nach TMP speichern |
||
428 | { |
||
429 | MKSettings_TMP_copy( 6, 10 ); |
||
430 | return loaded; |
||
431 | } |
||
432 | |||
433 | // Anzeige "speichern..." |
||
434 | lcd_frect( 0, (8*4), 128, (8*4), 0); // Anzeigebereich löschen |
||
435 | lcdx_printp_center( 4, strGet(STR_SAVING), MNORMAL, 0,9); // Text zentriert; String in PROGMEM |
||
436 | lcd_rect_round( 0, 37, 127, 14, 1, R2); // Rahmen |
||
437 | |||
438 | |||
439 | if( from_setting == 6 ) // von TMP nach Setting 1..5 |
||
440 | { |
||
441 | written = MKSettings_TMP_copy( to_setting, 30 ); |
||
442 | return written; |
||
443 | } |
||
444 | |||
445 | |||
446 | if( to_setting <= 5 ) // 'echtes' MK Setting speichern |
||
447 | { |
||
448 | written = MK_Setting_write( to_setting, 30 ); // Timeout = 40 |
||
449 | return written; |
||
450 | } |
||
451 | } |
||
452 | |||
453 | if( key == KEY_ESC ) // => "Nein" -> nicht kopieren |
||
454 | { |
||
455 | lcd_cls(); |
||
456 | redraw = true; |
||
457 | } |
||
458 | |||
459 | } //end: if( get_key_press(1 << KEY_ENTER) ) |
||
460 | |||
461 | |||
462 | //------------------------------------------ |
||
463 | // Pruefe PKT-Update oder andere PKT-Aktion |
||
464 | //------------------------------------------ |
||
465 | if( PKT_CtrlHook() ) // Update vom Updatetool angefordert? |
||
466 | { |
||
467 | lcd_cls(); |
||
468 | redraw = true; |
||
469 | } |
||
470 | |||
471 | } // end: while( true ) |
||
472 | |||
473 | return 0; |
||
474 | } |
||
475 | |||
476 | |||
477 | |||
478 | //-------------------------------------------------------------- |
||
479 | // ret = MKSettings_Menu() |
||
480 | // |
||
481 | // Rueckgabe: |
||
482 | // 0 = Ende/Fehler/Abbruch |
||
483 | // 1 = Refresh |
||
484 | //-------------------------------------------------------------- |
||
485 | uint8_t MKSettings_Menu( void ) |
||
486 | { |
||
487 | uint8_t i; |
||
488 | uint8_t active_setting; |
||
489 | uint8_t setting; |
||
490 | uint8_t wahl; |
||
491 | uint8_t wahl2; |
||
492 | uint8_t changed; |
||
493 | |||
494 | |||
495 | //PKT_Message_P( *text, error, timeout, beep, clearscreen ) |
||
496 | PKT_Message_P( strGet(MSG_LOADSETTINGS), false, 0, true, true ); // "lade Settings..." |
||
497 | |||
498 | |||
499 | active_setting = MKSettings_read_Names(); |
||
500 | |||
501 | if( !active_setting ) // Fehler: settings konnten nicht geladen werden... |
||
502 | { |
||
503 | //PKT_Message_P( *text, error, timeout, beep, clearscreen ) |
||
504 | PKT_Message_P( strGet(ERROR_NODATA), true, 800, true, true ); // "Datenverlust!" (max. 8 Sekunden anzeigen) |
||
505 | return F_EXIT; // F_EXIT = Ende/Abbruch |
||
506 | } |
||
507 | |||
508 | |||
509 | //--------------- |
||
510 | // Create |
||
511 | //--------------- |
||
512 | MenuCtrl_Create(); |
||
513 | |||
514 | //--------------- |
||
515 | // Einstellungen |
||
516 | //--------------- |
||
517 | MenuCtrl_SetTitleFromParentItem(); // "MK Settings" |
||
518 | //MenuCtrl_SetTitle_P( PSTR("MK Settings") ); |
||
519 | //MenuCtrl_SetCycle( false ); |
||
520 | //MenuCtrl_SetShowBatt( true ); |
||
521 | |||
522 | |||
523 | //--------------- |
||
524 | // Menue-Punkte |
||
525 | //--------------- |
||
526 | for( i=0; i< ( MKSetting_TMP.paramset!=NULL ? 6 : 5); i++ ) |
||
527 | { |
||
528 | MenuCtrl_Push( i+1, MENU_SUB, NOFUNC, mksettings_menu_names[i] ); // Setting 1..5 |
||
529 | } |
||
530 | |||
531 | MenuCtrl_ItemSelect( active_setting ); // Menucursor auf aktives Setting setzen |
||
532 | MenuCtrl_ItemMark( active_setting, true); // aktives Setting markieren |
||
533 | |||
534 | |||
535 | //--------------- |
||
536 | // Control |
||
537 | //--------------- |
||
538 | while( true ) |
||
539 | { |
||
540 | MenuCtrl_Control( MENUCTRL_EVENT ); |
||
541 | |||
542 | if( MenuCtrl_GetKey() == KEY_ESC ) // Ende? |
||
543 | { |
||
544 | break; // Ende |
||
545 | } |
||
546 | |||
547 | setting = MenuCtrl_GetItemId(); // welcher Menu-Punkt (ID) |
||
548 | |||
549 | if( setting >=1 && setting <= 6 ) |
||
550 | { |
||
551 | wahl = MKSettings_AskAction( setting ); |
||
552 | |||
553 | //-------------- |
||
554 | // bearbeiten |
||
555 | //-------------- |
||
556 | if( wahl == ID_EDIT ) |
||
557 | { |
||
558 | // TODO: Fehler abfangen! |
||
559 | MK_Setting_load( setting, 25 ); // timeout = 25 |
||
560 | changed = MK_Parameters( setting, mksettings_menu_names[setting-1] ); |
||
561 | |||
562 | if( changed && (setting!=6) ) |
||
563 | { |
||
564 | wahl2 = MKSettings_AskSaveSetting( setting ); |
||
565 | if( wahl2 == ID_SAVE ) |
||
566 | { |
||
567 | lcd_frect( 0, (8*7), 128, 7, 0); // Keyline löschen |
||
568 | lcdx_printp_center( 4, strGet(STR_SAVING), MNORMAL, 0,9); // Text zentriert; String in PROGMEM |
||
569 | lcd_rect_round( 0, 37, 127, 14, 1, R2); // Rahmen |
||
570 | |||
571 | setting = MK_Setting_write( setting, 50); |
||
572 | |||
573 | if( !setting ) |
||
574 | { |
||
575 | //PKT_Message_P( *text, error, timeout, beep, clearscreen ) |
||
576 | PKT_Message_P( strGet(ERROR_NODATA), true, 800, true, true ); // FEHLER! nodata (max. 8 Sekunden anzeigen) |
||
577 | //MenuCtrl_Destroy(); |
||
578 | //return F_EXIT; // F_EXIT = Ende/Abbruch |
||
579 | } |
||
580 | } |
||
581 | } |
||
582 | } |
||
583 | |||
584 | |||
585 | //-------------- |
||
586 | // aktivieren |
||
587 | //-------------- |
||
588 | if( wahl == ID_ACTIVATE ) |
||
589 | { |
||
590 | //PKT_Message_P( *text, error, timeout, beep, clearscreen ) |
||
591 | PKT_Message_P( strGet(MSG_ACTIVATESETTING), false, 0, true, true ); // "aktiviere Setting..." |
||
592 | |||
593 | active_setting = MK_Setting_change( setting ); |
||
594 | |||
595 | if( !active_setting ) |
||
596 | { |
||
597 | //PKT_Message_P( *text, error, timeout, beep, clearscreen ) |
||
598 | PKT_Message_P( strGet(ERROR_NODATA), true, 800, true, true ); // FEHLER! nodata (max. 8 Sekunden anzeigen) |
||
599 | //MenuCtrl_Destroy(); |
||
600 | //return F_EXIT; // F_EXIT = Ende/Abbruch |
||
601 | } |
||
602 | else |
||
603 | { |
||
604 | // neues Setting markieren |
||
605 | for( i=1; i<=5; i++ ) MenuCtrl_ItemMark( i, false); // Markierungen loeschen |
||
606 | MenuCtrl_ItemMark( active_setting, true); // aktives Setting markieren |
||
607 | } |
||
608 | |||
609 | } // end: if( wahl == ID_ACTIVATE ) |
||
610 | |||
611 | |||
612 | //-------------- |
||
613 | // kopieren |
||
614 | //-------------- |
||
615 | if( wahl == ID_COPY ) |
||
616 | { |
||
617 | active_setting = MKSettings_Copy( setting ); |
||
618 | |||
619 | if( !active_setting ) |
||
620 | { |
||
621 | //PKT_Message_P( *text, error, timeout, beep, clearscreen ) |
||
622 | PKT_Message_P( strGet(ERROR_NODATA), true, 800, true, true ); // FEHLER! nodata (max. 8 Sekunden anzeigen) |
||
623 | //MenuCtrl_Destroy(); |
||
624 | //return F_EXIT; // F_EXIT = Ende/Abbruch |
||
625 | } |
||
626 | |||
627 | if( active_setting != 99 ) // =99 bedeutet: User hat die Funktion abgebrochen... |
||
628 | { |
||
629 | MenuCtrl_Destroy(); // ok, kein Abbruch durch den User -> Menue neu aufbauen |
||
630 | return F_REFRESH; // da sich ggf. Settings-Namen geaendert haben |
||
631 | } |
||
632 | } // end: if( wahl == ID_COPY ) |
||
633 | |||
634 | } |
||
635 | |||
636 | } // end: while( true ) |
||
637 | |||
638 | |||
639 | //--------------- |
||
640 | // Destroy |
||
641 | //--------------- |
||
642 | MenuCtrl_Destroy(); |
||
643 | |||
644 | return F_EXIT; |
||
645 | } |
||
646 | |||
647 | |||
648 | |||
649 | //############################################################################################# |
||
650 | //# |
||
651 | //############################################################################################# |
||
652 | |||
653 | |||
654 | //-------------------------------------------------------------- |
||
655 | // das muss ueberarbeitet werden.... |
||
656 | //-------------------------------------------------------------- |
||
657 | static uint8_t check_motorOff(void) |
||
658 | { |
||
659 | NaviData_t *naviData; |
||
660 | |||
661 | if( hardware == NC ) // Prüfung funktioniert nur mit NC |
||
662 | { |
||
663 | SwitchToNC(); |
||
664 | SendOutData( 'o', ADDRESS_NC, 1, 10, 1); |
||
665 | mode = 'O'; |
||
666 | rxd_buffer_locked = FALSE; |
||
667 | timer = 200; |
||
668 | |||
669 | while( !rxd_buffer_locked && timer>0 ); |
||
670 | |||
671 | if( rxd_buffer_locked ) // naviData Ok? |
||
672 | { |
||
673 | // timer = MK_TIMEOUT; |
||
674 | Decode64(); |
||
675 | naviData = (NaviData_t *) pRxData; |
||
676 | |||
677 | if( naviData->FCStatusFlags & FC_STATUS_MOTOR_RUN ) |
||
678 | return false; |
||
679 | else |
||
680 | return true; |
||
681 | } |
||
682 | |||
683 | return false; |
||
684 | } |
||
685 | |||
686 | return true; // hmm, wenn man nur eine FC hat dann wird hier immer gemeldet "Motoren sind aus" ? |
||
687 | } |
||
688 | |||
689 | |||
690 | |||
691 | //-------------------------------------------------------------- |
||
692 | //-------------------------------------------------------------- |
||
693 | void MK_Settings( void ) |
||
694 | { |
||
695 | //MKSettings_TMP_Init(); |
||
696 | |||
697 | //if( true ) |
||
698 | if( !check_motorOff() ) |
||
699 | { |
||
700 | //PKT_Message_P( *text, error, timeout, beep, clearscreen ) |
||
701 | PKT_Message_P( strGet(STR_SWITCHMOTOROFF), false, 400, true, true ); // "Motoren ausschalten!" |
||
702 | return; |
||
703 | } |
||
704 | |||
705 | while( MKSettings_Menu() == F_REFRESH ); |
||
706 | } |
||
707 |