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 mkdebugdata.c |
||
36 | //# |
||
37 | //# 04.06.2014 OG |
||
38 | //# komplett neues Layout |
||
39 | //# - chg: MK_DebugData(), GetAnalogNames() umgestellt auf PKT_Message_Datenverlust() |
||
40 | //# - chg: GetAnalogNames() Timeout reduziert |
||
41 | //# - add: #include "../lipo/lipo.h" |
||
42 | //# - add: #include "../pkt/pkt.h" |
||
43 | //# - add: #include <stdbool.h> |
||
44 | //# |
||
45 | //# 29.01.2014 OG |
||
46 | //# - chg: ehemals display_debug() jetzt MK_DebugData() |
||
47 | //# - chg: ehemals 'debug.c' jetzt 'mk/mkdebugdata.c' |
||
48 | //# |
||
49 | //# 03.04.2013 OG |
||
50 | //# - chg: define 'analognames' zu define 'USE_MKDEBUGDATA' |
||
51 | //# - add: Benutzer kann GetAnalogNames() via KEY_ESC abbrechen |
||
52 | //# - chg: Screen-Layout GetAnalogNames() |
||
53 | //# - chg: SwitchToNC/FC Reihenfolge |
||
54 | //# |
||
55 | //# 27.03.2013 OG |
||
56 | //# - chg: auf malloc umgestellt |
||
57 | //# - fix: diverse Anzeigefehler |
||
58 | //# - chg: teilweise redunten Code entfernt |
||
59 | //############################################################################ |
||
60 | |||
61 | |||
62 | #include "../cpu.h" |
||
63 | #include <avr/io.h> |
||
64 | #include <stdlib.h> |
||
65 | #include <avr/pgmspace.h> |
||
66 | #include <util/delay.h> |
||
67 | #include <stdbool.h> |
||
68 | #include <string.h> |
||
69 | #include "../main.h" |
||
70 | |||
71 | #ifdef USE_MKDEBUGDATA |
||
72 | |||
73 | #include "../lcd/lcd.h" |
||
74 | #include "../pkt/pkt.h" |
||
75 | #include "../lipo/lipo.h" |
||
76 | #include "../uart/usart.h" |
||
77 | #include "mkdebugdata.h" |
||
78 | #include "../timer/timer.h" |
||
79 | #include "../messages.h" |
||
80 | #include "../mk-data-structs.h" |
||
81 | |||
82 | |||
83 | //-------------------------------------------------------------- |
||
84 | |||
85 | |||
86 | #define PAGELINES 5 // Anzahl der Zeilen pro Anzeigescreens |
||
87 | #define XOFFS 4 |
||
88 | #define YOFFS 12 |
||
89 | |||
90 | #define TIMEOUT 200 // 2 sec |
||
91 | #define ANALOGTIME 20 // 200 ms |
||
92 | |||
93 | #define MKDD_ANALOGNAME_SIZE 2*32*17 // MALLOC: 32 names, 16 characters + 1 0x00 |
||
94 | |||
95 | // WARNING: this work for NC & FC only |
||
96 | // if current_hardware == MK3MAG or MKGPS the access is outside of the array... |
||
97 | //uint8_t AnalogNames[2][32][16 + 1]; // 32 names, 16 characters + 1 0x00 |
||
98 | uint8_t *AnalogNames; // MALLOC: MKDD_ANALOGNAME_SIZE - 32 names, 16 characters + 1 0x00 |
||
99 | |||
100 | uint8_t AnalogNamesRead[2] = {0,0}; |
||
101 | |||
102 | static const char strFC[] PROGMEM = "FC"; |
||
103 | static const char strNC[] PROGMEM = "NC"; |
||
104 | |||
105 | |||
106 | //-------------------------------------------------------------- |
||
107 | // Speicher wieder freigeben |
||
108 | //-------------------------------------------------------------- |
||
109 | void MKDD_MemFree( void ) |
||
110 | { |
||
111 | free( AnalogNames ); |
||
112 | } |
||
113 | |||
114 | |||
115 | //-------------------------------------------------------------- |
||
116 | //-------------------------------------------------------------- |
||
117 | void showTitle( void ) |
||
118 | { |
||
119 | lcdx_printf_at_P( 0, 0, MINVERS, 0,0, PSTR(" %2S %16S"), (current_hardware==FC ? strFC : strNC), strGet(STR_DATA) ); // Titelzeile |
||
120 | show_Lipo(); |
||
121 | } |
||
122 | |||
123 | |||
124 | |||
125 | //-------------------------------------------------------------- |
||
126 | // lOk = GetAnalogNames() |
||
127 | // |
||
128 | // Return: |
||
129 | // true = OK |
||
130 | // false = User-Abort (KEY_ESC) |
||
131 | //-------------------------------------------------------------- |
||
132 | uint8_t GetAnalogNames( void ) |
||
133 | { |
||
134 | uint8_t i = AnalogNamesRead[current_hardware - 1]; |
||
135 | uint8_t t = 0; |
||
136 | uint8_t lOk = TRUE; |
||
137 | int8_t yoffs = -2; // yoffs der Progress-Bar |
||
138 | |||
139 | lcd_cls (); |
||
140 | showTitle(); // Titel |
||
141 | lcdx_printf_center_P( 3, MNORMAL, 0,0, PSTR("%S %S %S"), strGet(STR_READING), (current_hardware==FC ? strFC : strNC), strGet(STR_LABELS) ); |
||
142 | |||
143 | lcd_rect_round( 13, 40+yoffs, 102, 6, 1, R1); // Rahmen fuer Progress |
||
144 | lcd_printp_at(12, 7, strGet(ENDE), MNORMAL); // Keyline |
||
145 | |||
146 | |||
147 | mode = 'A'; // read Names |
||
148 | _delay_ms(200); |
||
149 | rxd_buffer_locked = FALSE; |
||
150 | |||
151 | timer = ANALOGTIME; |
||
152 | |||
153 | while( (i < 32) && lOk ) |
||
154 | { |
||
155 | SendOutData ('a', ADDRESS_ANY, 1, &i, 1); |
||
156 | |||
157 | while( !rxd_buffer_locked && timer && lOk) |
||
158 | lOk = !get_key_press (1 << KEY_ESC); |
||
159 | |||
160 | if( timer ) |
||
161 | { |
||
162 | Decode64 (); |
||
163 | if( i == *pRxData ) |
||
164 | { |
||
165 | lcd_frect( 16, 42+yoffs, (i+1)*3, 2, 1); // Progress |
||
166 | |||
167 | memcpy( (uint8_t *) (AnalogNames+((current_hardware-1)*32*17)+(i*17)), (uint8_t *) pRxData + 1, 16); |
||
168 | *(AnalogNames+((current_hardware-1)*32*17)+(i*17)+16) = 0; |
||
169 | i++; |
||
170 | t = 0; |
||
171 | } |
||
172 | else |
||
173 | { |
||
174 | _delay_ms(100); |
||
175 | } |
||
176 | |||
177 | timer = ANALOGTIME; |
||
178 | rxd_buffer_locked = FALSE; |
||
179 | } |
||
180 | else if( lOk ) |
||
181 | { // timeout occured |
||
182 | t++; |
||
183 | timer = ANALOGTIME; |
||
184 | |||
185 | if( t >= 15 ) // timeout? |
||
186 | { |
||
187 | //PKT_Message_Datenverlust( timeout, beep) |
||
188 | PKT_Message_Datenverlust( 500, true); // 500 = 5 Sekunden |
||
189 | break; |
||
190 | } |
||
191 | } |
||
192 | else |
||
193 | { |
||
194 | lOk = !get_key_press( 1 << KEY_ESC ); |
||
195 | } |
||
196 | } |
||
197 | |||
198 | if(lOk) AnalogNamesRead[current_hardware - 1] = i; |
||
199 | |||
200 | //_delay_ms(4000); // DEBUG |
||
201 | |||
202 | return lOk; |
||
203 | } |
||
204 | |||
205 | |||
206 | |||
207 | //-------------------------------------------------------------- |
||
208 | //-------------------------------------------------------------- |
||
209 | void showLabels( uint8_t page) |
||
210 | { |
||
211 | uint8_t i = 0; |
||
212 | |||
213 | for( i = 0; i < PAGELINES; i++ ) |
||
214 | { |
||
215 | if( (i + (page * PAGELINES)) >= 32 ) |
||
216 | { |
||
217 | //lcdx_cls_rowwidth( y, width, mode, xoffs, yoffs ) |
||
218 | lcdx_cls_rowwidth( i, 20, MNORMAL, XOFFS,YOFFS ); |
||
219 | } |
||
220 | else |
||
221 | { |
||
222 | lcdx_print_at( 0, i, AnalogNames+((current_hardware-1)*32*17)+(i + page * PAGELINES)*17, MNORMAL, XOFFS,YOFFS); |
||
223 | } |
||
224 | } |
||
225 | } |
||
226 | |||
227 | |||
228 | //-------------------------------------------------------------- |
||
229 | // |
||
230 | //-------------------------------------------------------------- |
||
231 | void MK_DebugData(void) |
||
232 | { |
||
233 | uint8_t tmp_dat; |
||
234 | uint8_t i = 0; |
||
235 | uint8_t page = 0; |
||
236 | uint8_t pagemax = (32/PAGELINES); |
||
237 | uint8_t redraw = 2; |
||
238 | |||
239 | DebugData_t *DebugData; |
||
240 | |||
241 | |||
242 | // alloc ram |
||
243 | AnalogNames = malloc( MKDD_ANALOGNAME_SIZE ); |
||
244 | |||
245 | if( !AnalogNames ) |
||
246 | { |
||
247 | Show_PKTError_NoRAM(); |
||
248 | return; |
||
249 | } |
||
250 | |||
251 | memset( AnalogNames, 0, MKDD_ANALOGNAME_SIZE ); // init: AnalogNames |
||
252 | AnalogNamesRead[0] = 0; |
||
253 | AnalogNamesRead[1] = 0; |
||
254 | |||
255 | SwitchToFC(); |
||
256 | |||
257 | timer = TIMEOUT; |
||
258 | |||
259 | if( AnalogNamesRead[current_hardware - 1] < 32 ) |
||
260 | { |
||
261 | if( !GetAnalogNames() ) |
||
262 | { |
||
263 | MKDD_MemFree(); |
||
264 | return; |
||
265 | } |
||
266 | } |
||
267 | |||
268 | if( !timer ) |
||
269 | { |
||
270 | MKDD_MemFree(); |
||
271 | return; |
||
272 | } |
||
273 | |||
274 | mode = 'D'; // Debug Data |
||
275 | rxd_buffer_locked = FALSE; |
||
276 | timer = TIMEOUT; |
||
277 | timer1 = 0; |
||
278 | |||
279 | tmp_dat = 10; |
||
280 | SendOutData( 'd', ADDRESS_ANY, 1, &tmp_dat, 1); |
||
281 | abo_timer = ABO_TIMEOUT; |
||
282 | |||
283 | |||
284 | do |
||
285 | { |
||
286 | //------------------------------------------ |
||
287 | //------------------------------------------ |
||
288 | if( redraw ) |
||
289 | { |
||
290 | if( redraw==2 ) lcd_cls(); |
||
291 | |||
292 | showTitle(); // Titelzeile |
||
293 | lcd_rect_round( 0, (1*8)+1, 127, (6*8)-4, 1, R2); // Rahmen fuer 5 Zeilen Display |
||
294 | |||
295 | showLabels( page ); |
||
296 | |||
297 | lcd_printp_at( 0, 7, strGet(KEYLINE3), 0); |
||
298 | |||
299 | lcd_write_number_u_at (5, 7, page + 1); |
||
300 | lcd_printp_at( (current_hardware==FC ? 3 : 19), 7, strFC, 0); |
||
301 | lcd_printp_at( (current_hardware==FC ? 19 : 3), 7, strNC, 0); |
||
302 | |||
303 | redraw = false; |
||
304 | } |
||
305 | |||
306 | |||
307 | if( rxd_buffer_locked ) |
||
308 | { |
||
309 | Decode64(); |
||
310 | DebugData = (DebugData_t *) pRxData; |
||
311 | |||
312 | if( !timer1 ) |
||
313 | { |
||
314 | for( i = 0; i < PAGELINES && (i + (page * PAGELINES)) < 32; i++) |
||
315 | { |
||
316 | writex_ndigit_number_s( 21-6, i, DebugData->Analog[i + page * PAGELINES], 5, 0, MNORMAL, XOFFS,YOFFS); |
||
317 | } |
||
318 | timer1 = 25; // Anzeigeverzoegerung damit es nicht flackert |
||
319 | } |
||
320 | |||
321 | rxd_buffer_locked = FALSE; |
||
322 | |||
323 | timer = TIMEOUT; |
||
324 | } |
||
325 | |||
326 | |||
327 | if( !abo_timer ) |
||
328 | { // renew abo every ... sec |
||
329 | tmp_dat = 10; |
||
330 | SendOutData( 'd', ADDRESS_ANY, 1, &tmp_dat, 1); |
||
331 | abo_timer = ABO_TIMEOUT; |
||
332 | } |
||
333 | |||
334 | |||
335 | //------------------------------------------ |
||
336 | // PKT LiPo anzeigen |
||
337 | //------------------------------------------ |
||
338 | show_Lipo(); |
||
339 | |||
340 | |||
341 | //------------------------------------------ |
||
342 | // Pruefe PKT Update oder andere PKT-Aktion |
||
343 | //------------------------------------------ |
||
344 | if( PKT_CtrlHook() ) // Update vom Updatetool angefordert? |
||
345 | { |
||
346 | redraw = 2; |
||
347 | timer = TIMEOUT; |
||
348 | } |
||
349 | |||
350 | |||
351 | //------------------------------------------ |
||
352 | // Tasten |
||
353 | //------------------------------------------ |
||
354 | if( get_key_press(1 << KEY_MINUS) ) |
||
355 | { |
||
356 | page--; |
||
357 | if( page > pagemax ) page = pagemax; |
||
358 | redraw = true; |
||
359 | } |
||
360 | |||
361 | if( get_key_press(1 << KEY_PLUS) ) |
||
362 | { |
||
363 | page++; |
||
364 | if( page > pagemax ) page = 0; |
||
365 | redraw = true; |
||
366 | } |
||
367 | |||
368 | if( (hardware == NC) && get_key_press (1 << KEY_ENTER) ) |
||
369 | { |
||
370 | if( current_hardware == NC ) SwitchToFC(); |
||
371 | else SwitchToNC(); |
||
372 | |||
373 | if( AnalogNamesRead[current_hardware - 1] < 32 ) |
||
374 | { |
||
375 | if( !GetAnalogNames() ) |
||
376 | { |
||
377 | MKDD_MemFree(); |
||
378 | return; |
||
379 | } |
||
380 | } |
||
381 | |||
382 | mode = 'D'; // Debug Data |
||
383 | rxd_buffer_locked = FALSE; |
||
384 | timer = TIMEOUT; |
||
385 | |||
386 | tmp_dat = 10; |
||
387 | SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1); |
||
388 | |||
389 | //page = 0; |
||
390 | redraw = true; |
||
391 | } |
||
392 | } |
||
393 | while (!get_key_press(1 << KEY_ESC) && timer); // Taste: Ende oder Timeout |
||
394 | |||
395 | |||
396 | clear_key_all(); |
||
397 | |||
398 | tmp_dat = 0; |
||
399 | SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1); // Request Debugdata abschalten |
||
400 | |||
401 | mode = 0; |
||
402 | rxd_buffer_locked = FALSE; |
||
403 | |||
404 | if( !timer ) |
||
405 | { // timeout occured |
||
406 | //PKT_Message_Datenverlust( timeout, beep) |
||
407 | PKT_Message_Datenverlust( 500, true); // 500 = 5 Sekunden |
||
408 | } |
||
409 | |||
410 | //SwitchToNC(); |
||
411 | |||
412 | // free ram |
||
413 | MKDD_MemFree(); |
||
414 | } |
||
415 | |||
416 | #endif // end: #ifdef USE_MKDEBUGDATA |