Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
112 | mikeljo | 1 | |
2 | #include <avr/io.h> |
||
3 | #include <inttypes.h> |
||
4 | #include <stdlib.h> |
||
5 | #include <avr/pgmspace.h> |
||
6 | |||
7 | #include "main.h" |
||
8 | #include "lcd.h" |
||
9 | #include "rs232.h" |
||
10 | #include "base64.h" |
||
11 | #include "parameter.h" |
||
12 | #include "menu.h" |
||
13 | |||
14 | uint8_t array[8]; |
||
15 | |||
16 | prog_uchar p_menus[12][11]= |
||
17 | { |
||
18 | "Config ", |
||
19 | "Channels ", |
||
20 | "Stick ", |
||
21 | "Hoehe ", |
||
22 | "Gyro ", |
||
23 | "Looping ", |
||
24 | "Camera ", |
||
25 | "Sonstiges ", |
||
26 | "User ", |
||
27 | "Coupling ", |
||
28 | "Config(2) ", |
||
29 | "Loopingset" |
||
30 | }; |
||
31 | |||
32 | |||
33 | // Diese Tabelle ordnet die eingelesenen Parameter den Menü-Seiten zu |
||
34 | |||
35 | prog_uchar p_menu_number[67]= |
||
36 | { |
||
37 | 2,2,2,2,2,2,2,2, // Die ersten 8 Parameter werden auf Menüseite 2 angezeigt (=Kanalzuordnungen) |
||
38 | 0,4,4,4,4,4,4,3, |
||
39 | 3,3,8,8,8,8,5,5, |
||
40 | 8,8,8,0,5,9,9,9, |
||
41 | 9,7,7,7,7,7,7,6, |
||
42 | 6,6,10,10,6,6,5,5, |
||
43 | 5,9,9,9,9,0,7,11, |
||
44 | 11,11,11,12,12, 12, |
||
45 | 12,12,12,12,12 |
||
46 | |||
47 | }; |
||
48 | |||
49 | prog_uchar p_limits[199]= // Limits für die Parameter |
||
50 | { |
||
51 | 1,8,2, // 2:Nick (3) |
||
52 | 1,8,2, // 2:Roll (4) |
||
53 | 1,8,2, // 2:Gas (2) |
||
54 | 1,8,2, // 2:Gier (1) |
||
55 | 1,8,2, // 2:Poti1 (6) |
||
56 | 1,8,2, // 2:Poti2 (6) |
||
57 | 1,8,2, // 2:Poti3 (7) |
||
58 | 1,8,2, // 2:Poti4 (5) |
||
59 | 0,0,0, // 1:Config |
||
60 | 0,255,4, // 4:Höhe MinGas (30) |
||
61 | 0,255,4, // 4:Luftdruck_D (30) |
||
62 | 0,255,4, // 4:MaxHöhe (Setpoint?) (Poti4) |
||
63 | 0,255,4, // 4:Höhe_P (10) |
||
64 | 0,50,4, // 4:Höhe Verstärkung (3) |
||
65 | 0,255,4, // 4:Höhe Z-acc (30) |
||
66 | 0,6,3, // 3:Nick/Roll P (3) |
||
67 | 0,64,3, // 3:Nick/Roll D (4) |
||
68 | 0,20,3, // 3:Gier_P (6) |
||
69 | 0,32,8, // 8:Min.Gas (15) |
||
70 | 33,250,8, // 8:Max.Gas (250) |
||
71 | 0,50,8, // 5:Gyro-Acc Faktor (30) |
||
72 | 0,255,8, // 8:Kompass-Wirkung (128) |
||
73 | 0,0,5, // 5:Gyro-P (80) |
||
74 | 0,0,5, // 5:Gyro-I (120) |
||
75 | 0,250,8, // 8:Unterspannung (94) |
||
76 | 0,250,8, // 8:Not-Gas Zeit (20) |
||
77 | 0,250,8, // 8:Not-Gas (35) |
||
78 | 0,1,0, // Ufo-Ausrichtung (X +) |
||
79 | 0,255,5, // I-Faktor (32) |
||
80 | 0,255,9, // 9:User1 (80) |
||
81 | 0,255,9, // 9:User2 (0) |
||
82 | 0,255,9, // 9:User3 |
||
83 | 0,255,9, // 9:User4 |
||
84 | 0,255,7, // 7:Servo Nick Control (100) |
||
85 | 0,250,7, // 7:Servo Nick Compensation (40) |
||
86 | 0,250,7, // 7:Servo Nick min (50) |
||
87 | 0,250,7, // 7:Servo Nick max (150) |
||
88 | 0,25,7, // 7:Servo Nick refrsh (5) |
||
89 | 0,255,6, // 6:Loop Gas Limit (50) |
||
90 | 0,250,6, // 6:Loop Ansprechschwelle (90) |
||
91 | 0,250,6, // 6:Loop Hysterese (50) |
||
92 | 0,255,10, // 10:Achskopplung (90) |
||
93 | 0,255,10, // 10:Achsgegenkopplung (5) |
||
94 | 0,250,6, // 6:Turnover Nick (100) |
||
95 | 0,250,6, // 6:Turnover Roll (100) |
||
96 | 0,250,5, // 5: Gyro-Abgleich (Comp.) (32) |
||
97 | 0,250,5, // 5: Drift (4) |
||
98 | 0,255,5, // 5: Dynamic stability (75) |
||
99 | 0,255,9, // 9:User5 |
||
100 | 0,255,9, // 9:User6 |
||
101 | 0,255,9, // 9:User7 |
||
102 | 0,255,9, // 9:User8 (0) |
||
103 | |||
104 | 0,0,1, // 6:Loop Config (0) |
||
105 | 0,1,7 // 7:Servo Nick Compensation Invert (0) |
||
106 | |||
107 | }; |
||
108 | |||
109 | prog_char bin_parameter[12][16] = // Die binär kodierten Parametern werden getrennt behandelt. |
||
110 | { |
||
111 | "Loop up ", |
||
112 | "Loop down ", |
||
113 | "Loop left ", |
||
114 | "Loop right ", |
||
115 | "Höhenregler ", // 8 |
||
116 | "Höhenschalter ", |
||
117 | "Headhold ", |
||
118 | "Kompass ", |
||
119 | "KompassFix ", |
||
120 | "GPS ", |
||
121 | "Achsenkopplung ", |
||
122 | "Drehrate " |
||
123 | }; |
||
124 | |||
125 | prog_char parameter[54][16]= |
||
126 | { |
||
127 | "Nick ", // 0 (3) |
||
128 | "Roll ", // 1 (4) |
||
129 | "Gas ", // (2) |
||
130 | "Gier ", // (1) |
||
131 | "Poti1 ", // (6) |
||
132 | "Poti2 ", // (6) |
||
133 | "Poti3 ", // (7) |
||
134 | "Poti4 ", // 7 (5) |
||
135 | "Config ", // 8 |
||
136 | "Hoehe_MinGas ", // 9 (30) |
||
137 | "Luftdruck_D ", // 10 Wert : 0-250 (30) |
||
138 | "MaxHoehe ", // 11 Wert : 0-250 251 -> Poti1 (Poti4) |
||
139 | "Hoehe_P ", // 12 Wert : 0-32 (10) |
||
140 | "Hoehe_Verstaerk", // 13 Wert : 0-50 |
||
141 | "Hoehe_ACC_Wirk.", // 14 Wert : 0-250 (30) |
||
142 | "Stick_P ", // 15 Wert : 1-6 |
||
143 | "Stick_D ", // 16 Wert : 0-64 |
||
144 | "Gier_P ", // 17 Wert : 1-20 POTI(?) |
||
145 | "Gas_Min ", // 17 Wert : 0-32 |
||
146 | "Gas_Max ", // 18 Wert : 33-250 |
||
147 | "GyroAccFaktor ", // 19 Wert : 1-64 |
||
148 | "KompassWirkung ", // 20 Wert : 0-250 |
||
149 | "Gyro_P ", // 21 Wert : 0-250 |
||
150 | "Gyro_I ", // 22 Wert : 0-250 |
||
151 | "Unterspannung ", // 23 Wert : 0-250 |
||
152 | "NotGas ", // 24 Wert : 0-250 // Gaswert bei Empangsverlust |
||
153 | "NotGasZeit ", // 25 Wert : 0-250 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
||
154 | "UfoAusrichtung ", // 26 X oder + Formation |
||
155 | "I_Faktor ", // 27 = 32; |
||
156 | "UserParam1 ", // 28 = 32 * 4; //zur freien Verwendung |
||
157 | "UserParam2 ", // 29 zur freien Verwendung |
||
158 | "UserParam3 ", // 30 zur freien Verwendung |
||
159 | "UserParam4 ", // 31 zur freien Verwendung |
||
160 | "ServoNickCtrl ", // 32 Wert : 0-250 // Stellung des Servos |
||
161 | "ServoNickComp ", // 33 Wert : 0-250 // Einfluss Gyro/Servo |
||
162 | "ServoNickMin ", // 34 Wert : 0-250 // Anschlag |
||
163 | "ServoNickMax ", // 35 Wert : 0-250 // Anschlag |
||
164 | "ServoNickRefrsh", // 36 |
||
165 | "LoopGasLimit ", // 37 |
||
166 | "LoopThreshold ", // 38 Wert: 0-250 Schwelle für Stickausschlag |
||
167 | "LoopHysterese ", // 39 |
||
168 | "AchsKopplung ", // 40 |
||
169 | "AchsGegenKoppl.", // 41 |
||
170 | "WinklUmschlNick", // 42 |
||
171 | "WinklUmschlRoll", // 43 |
||
172 | "GyroAccAbgleich", // 44 1/k |
||
173 | "Driftkomp ", // 45 |
||
174 | "DynamicStabilit", // 47 |
||
175 | "UserParam5 ", // 48 zur freien Verwendung |
||
176 | "UserParam6 ", // 49 zur freien Verwendung |
||
177 | "UserParam7 ", // 50 zur freien Verwendung |
||
178 | "UserParam8 ", // 51 zur freien Verwendung |
||
179 | "LoopConfig ", // 52 Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts / wird getrennt behandelt |
||
180 | "ServoNickCompIn" // 53 Wert : 0-250 // Richtung Einfluss Gyro/Servo |
||
181 | // "Name " // 54 |
||
182 | }; |
||
183 | |||
184 | |||
185 | // Parameter lesen, editieren und zurückschreiben |
||
186 | |||
187 | uint8_t read_parameter (uint8_t number) // Number = Parameter-Set# |
||
188 | { |
||
189 | uint8_t timeout; |
||
190 | |||
191 | timeout = 0; |
||
192 | |||
193 | p_buffer[0] = '#'; // Parameter anfordern |
||
194 | p_buffer[1] = 'a'; |
||
195 | p_buffer[2] = 'q'; |
||
196 | p_buffer[3] = number; |
||
197 | p_buffer[4] = 0; |
||
198 | p_buffer[5] = 0; |
||
199 | base64_send(6); |
||
200 | |||
201 | do // warten, bis die Parameter gesendet werden |
||
202 | { |
||
203 | if (get_message() == 1) // Fehler bei der Übertragung? |
||
204 | timeout = 30; // Timeout sofort auf Endwert setzen |
||
205 | timeout ++; |
||
206 | } |
||
207 | while (((r_buffer[1] < 'L') || (r_buffer[1] > 'P')) && (timeout < 30)); // warten, bis Parameter empfangen wurden oder ein Timeout auftrat |
||
208 | |||
209 | if (timeout >= 30) // Wenn ein Timeout (=Fehler) auftrat, eine 1 zurückgeben, ansonsten 0 |
||
210 | return 1; |
||
211 | else |
||
212 | return 0; |
||
213 | } |
||
214 | |||
215 | void write_parameter(uint8_t number) // Schreibe Parameter-Satz |
||
216 | { |
||
217 | uint8_t i; |
||
218 | |||
219 | if (number <= 5) |
||
220 | { |
||
221 | |||
222 | for (i=0;i<71;i++) // Den gesamten Parameter-Puffer um 3 Bytes nach hinten verschieben |
||
223 | p_buffer[(70-i)+3] = p_buffer[70-i]; |
||
224 | |||
225 | p_buffer[0] = '#'; // Befehl zum Schreiben der Parameter |
||
226 | p_buffer[1] = 'a'; |
||
227 | p_buffer[2] = number + 'k'; // Nummer des Parameters |
||
228 | p_buffer[74] = 0; |
||
229 | base64_send(75); // Parameter in base64 kodieren und senden, 75 Bytes |
||
230 | } |
||
231 | } |
||
232 | |||
233 | void binary (uint8_t data, uint8_t *feld) // Wandelt eine 8-Bit Zahl in eine Binärzahl um (Array mit 8 Elementen) |
||
234 | { // Wird für die Flags (Loop + Grundkonfiguration) benötigt |
||
235 | uint8_t i; |
||
236 | |||
237 | i=0; |
||
238 | for (i=0;i<8;i++) |
||
239 | { |
||
240 | if ((1<<i) & data) |
||
241 | feld[i] = 1; |
||
242 | else |
||
243 | feld[i] = 0; |
||
244 | } |
||
245 | } |
||
246 | |||
247 | uint8_t bindec (uint8_t *feld) // wandelt eine Binärzahl (im Array) in eine 8-Bit Zahl |
||
248 | { // Wird für die Flags (Loop + Grundkonfiguration) benötigt |
||
249 | uint8_t i; |
||
250 | uint8_t result; |
||
251 | |||
252 | result = 0; |
||
253 | for (i=0;i<8;i++) |
||
254 | { |
||
255 | if (feld[i] == 1) |
||
256 | result += 1<<i; |
||
257 | } |
||
258 | return result; |
||
259 | } |
||
260 | |||
261 | |||
262 | |||
263 | |||
264 | void decimal (uint8_t data, uint8_t *text) // wandelt Wert in rechtsbündigen Text um |
||
265 | { // (schneller/kleiner als printf()) |
||
266 | text[0] = data/100; |
||
267 | data -= (text[0] * 100); |
||
268 | text[1] = data/10; |
||
269 | data -= (text[1] *10); |
||
270 | text[2] = data + 0x30; |
||
271 | text[0] += 0x30; |
||
272 | text[1] += 0x30; |
||
273 | |||
274 | if (text[0] == 0x30) |
||
275 | { |
||
276 | text[0] = 0x20; |
||
277 | if (text[1] == 0x30) |
||
278 | text[1] = 0x20; |
||
279 | } |
||
280 | text[3] = 0x00; |
||
281 | } |
||
282 | |||
283 | uint8_t show_parameter (uint8_t number) // Zeigt eine Parameter-Seite an und gibt die ausgewählte Zeile zurück |
||
284 | { |
||
285 | uint8_t i; |
||
286 | uint8_t line; |
||
287 | uint8_t text[25]; |
||
288 | uint8_t bin[8]; |
||
289 | |||
290 | line = 0; |
||
291 | |||
292 | if (number > 1) |
||
293 | { |
||
294 | for (i = 0; i<66; i++) |
||
295 | { |
||
296 | if (pgm_read_byte(p_limits+i*3+2) == number) |
||
297 | { |
||
298 | array[line] = i; |
||
299 | decimal(p_buffer[i],text); |
||
300 | lcd_print_at(0,line,text,0); |
||
301 | lcd_print_atp(5,line,parameter[i],0); |
||
302 | if (line <= 7) |
||
303 | line++; |
||
304 | } |
||
305 | } |
||
306 | } |
||
307 | else |
||
308 | { // Sonderfälle: Binäre Eingabe |
||
309 | if (number == 1) |
||
310 | { |
||
311 | binary(p_buffer[52],bin); // Loop-Config |
||
312 | text[1] = 0x00; |
||
313 | for (i=0;i<4;i++) |
||
314 | { |
||
315 | text[0] = bin[i] + 0x30; |
||
316 | lcd_print_at(0,i,text,0); |
||
317 | lcd_print_atp(5,i,bin_parameter[i],0); |
||
318 | } |
||
319 | |||
320 | } |
||
321 | if (number == 0) |
||
322 | { |
||
323 | binary(p_buffer[8],bin); // Config |
||
324 | text[1] = 0x00; |
||
325 | for (i=0;i<8;i++) |
||
326 | { |
||
327 | text[0] = bin[i] + 0x30; |
||
328 | lcd_print_at(0,i,text,0); |
||
329 | lcd_print_atp(5,i,bin_parameter[i+4],0); |
||
330 | } |
||
331 | } |
||
332 | |||
333 | |||
334 | } |
||
335 | return line; |
||
336 | } |
||
337 | |||
338 | void edit_parameter2 (uint8_t page, uint8_t lines) // Ändern der Parameter einer Seite |
||
339 | { |
||
340 | uint8_t line; |
||
341 | uint8_t par; |
||
342 | uint8_t min; |
||
343 | uint8_t max; |
||
344 | uint8_t text[10]; |
||
345 | uint8_t bin[8]; |
||
346 | |||
347 | if (page > 1) // "normale" Parameter-Seiten |
||
348 | { |
||
349 | line = menu_choose(0,lines-1,4); |
||
350 | if (line != 255) // Wenn line == 255, wurde Escape gedrückt |
||
351 | { |
||
352 | par = p_buffer[array[line]]; |
||
353 | min = pgm_read_byte(p_limits + par * 3); |
||
354 | max = pgm_read_byte(p_limits + par * 3 + 1); |
||
355 | |||
356 | lcd_print_atp(4,line,PSTR("-"),0); |
||
357 | |||
358 | while (key != key_nokey); |
||
359 | |||
360 | do |
||
361 | { |
||
362 | if (key == key_minus) |
||
363 | { |
||
364 | //if (par > min) // Überprüfung der Parameter auf Bereichsüberschreitung derzeit deaktiviert |
||
365 | par --; |
||
366 | } |
||
367 | if (key == key_plus) |
||
368 | { |
||
369 | //if (par < max) |
||
370 | par ++; |
||
371 | } |
||
372 | |||
373 | decimal(par,text); |
||
374 | lcd_print_at(0,line,text,0); |
||
375 | |||
376 | timer = 20; |
||
377 | while (timer > 0); |
||
378 | } |
||
379 | while ((key != 0x04) && (key != 0x08)); |
||
380 | |||
381 | if (key == 0x08) |
||
382 | p_buffer[array[line]] = par; |
||
383 | } |
||
384 | } |
||
385 | |||
386 | if (page == 1) // Spezialfall: Loop-Config (einzelne Bits setzen / löschen) |
||
387 | { |
||
388 | binary(p_buffer[52],bin); |
||
389 | text[1] = 0x00; |
||
390 | |||
391 | line = menu_choose(0,3,4); |
||
392 | if (line != 255) // Wenn line == 255, wurde Escape gedrückt |
||
393 | { |
||
394 | par = bin[line]; |
||
395 | |||
396 | lcd_print_atp(4,line,PSTR("-"),0); |
||
397 | |||
398 | do |
||
399 | { |
||
400 | |||
401 | if (key == key_minus) |
||
402 | { |
||
403 | par = 0x00; |
||
404 | } |
||
405 | if (key == key_plus) |
||
406 | { |
||
407 | par = 0x01; |
||
408 | } |
||
409 | |||
410 | text[0] = par+0x30; |
||
411 | lcd_print_at(0,line,text,0); |
||
412 | timer = 20; |
||
413 | while (timer > 0); |
||
414 | |||
415 | |||
416 | } |
||
417 | while ((key != key_enter) && (key != key_esc)); |
||
418 | |||
419 | if (key == key_enter) |
||
420 | { |
||
421 | bin[line] = par; |
||
422 | p_buffer[52] = bindec(bin); |
||
423 | } |
||
424 | |||
425 | lcd_cls(); |
||
426 | decimal(p_buffer[52],text); |
||
427 | lcd_print(text,0); |
||
428 | timer = 200; |
||
429 | while(timer > 0); |
||
430 | } |
||
431 | } |
||
432 | if (page == 0) // Spezialfall: Allgemeine Konfiguration (einzelne Bits setzen/löschen) |
||
433 | { |
||
434 | binary(p_buffer[8],bin); |
||
435 | text[1] = 0x00; |
||
436 | |||
437 | line = menu_choose(0,7,4); |
||
438 | if (line != 255) // Wenn line == 255, wurde Escape gedrückt |
||
439 | { |
||
440 | par = bin[line]; |
||
441 | |||
442 | lcd_print_atp(4,line,PSTR("-"),0); |
||
443 | |||
444 | do |
||
445 | { |
||
446 | |||
447 | if (key == key_minus) |
||
448 | { |
||
449 | par = 0x00; |
||
450 | } |
||
451 | if (key == key_plus) |
||
452 | { |
||
453 | par = 0x01; |
||
454 | } |
||
455 | |||
456 | text[0] = par+0x30; |
||
457 | lcd_print_at(0,line,text,0); |
||
458 | timer = 20; |
||
459 | while (timer > 0); |
||
460 | |||
461 | |||
462 | } |
||
463 | while ((key != key_enter) && (key != key_esc)); |
||
464 | |||
465 | if (key == key_enter) |
||
466 | { |
||
467 | bin[line] = par; |
||
468 | p_buffer[8] = bindec(bin); |
||
469 | } |
||
470 | |||
471 | lcd_cls(); |
||
472 | decimal(p_buffer[8],text); |
||
473 | lcd_print(text,0); |
||
474 | timer = 200; |
||
475 | while(timer > 0); |
||
476 | } |
||
477 | } |
||
478 | } |
||
479 | |||
480 | |||
481 | void edit_parameter (void) // Blättert die Parameter seitenweise durch, Einsprung vom Hauptmenü |
||
482 | { |
||
483 | uint8_t page; // 12 Pages |
||
484 | uint8_t text[15]; |
||
485 | uint8_t lines; |
||
486 | uint8_t parameter; |
||
487 | |||
488 | lcd_cls(); |
||
489 | |||
490 | lcd_printp(PSTR("Lade Parameter\r\n"),0); |
||
491 | lcd_printp(PSTR(" 1:\r\n"),0); |
||
492 | lcd_printp(PSTR(" 2:\r\n"),0); |
||
493 | lcd_printp(PSTR(" 3:\r\n"),0); |
||
494 | lcd_printp(PSTR(" 4:\r\n"),0); |
||
495 | lcd_printp(PSTR(" 5:\r\n"),0); |
||
496 | |||
497 | parameter = menu_choose(1,5,0); |
||
498 | |||
499 | page = 2; |
||
500 | if (read_parameter(parameter) == 1) |
||
501 | { |
||
502 | lcd_print_atp(0,6,PSTR("Timeout"),0); |
||
503 | } |
||
504 | else |
||
505 | { |
||
506 | do |
||
507 | { |
||
508 | lcd_cls(); |
||
509 | utoa(page,text,10); |
||
510 | lcd_print(text,0); |
||
511 | timer = 50; |
||
512 | |||
513 | while (timer > 0); |
||
514 | |||
515 | lcd_cls(); |
||
516 | |||
517 | lines = show_parameter(page); |
||
518 | |||
519 | while (key == key_nokey); |
||
520 | if (key == key_plus) |
||
521 | page++; |
||
522 | if (key == key_minus) |
||
523 | page--; |
||
524 | |||
525 | if (page == 255) |
||
526 | page = 12; |
||
527 | |||
528 | if (page > 12) |
||
529 | page = 0; |
||
530 | |||
531 | if (key == key_enter) |
||
532 | edit_parameter2(page,lines); |
||
533 | |||
534 | } |
||
535 | while (key != key_esc); |
||
536 | |||
537 | lcd_cls(); |
||
538 | lcd_printp(PSTR("Parameter speichern?\r\n ja\r\n nein"),0); |
||
539 | |||
540 | lines = menu_choose(1,2,0); |
||
541 | |||
542 | if (lines == 1 ) |
||
543 | { |
||
544 | lcd_printp(PSTR("\r\n--->"),0); |
||
545 | write_parameter(5); // Sicherheitshalber wird derzeit ausschließlich auf Parametersatz 5 gesichert. |
||
546 | lcd_printp(PSTR("\r\nParameter gespeichert"),0); |
||
547 | } |
||
548 | else |
||
549 | { |
||
550 | lcd_printp(PSTR("\r\nNicht gespeichert"),0); |
||
551 | } |
||
552 | } |
||
553 | timer = 100; |
||
554 | while(timer > 0); |
||
555 | |||
556 | } |