add a bit more debug info for skins... show the subimage id in the display image...
[kugel-rb.git] / apps / gui / skin_engine / wps_debug.c
blob64a68b05d64bb146ef9f431252e0bcb9570b363c
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 Nicolas Pennequin, Dan Everton, Matthias Mohr
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #if defined(DEBUG) || defined(SIMULATOR)
24 #include <stdio.h>
25 #include <string.h>
26 #include "wps.h"
27 #include "wps_internals.h"
28 #include "skin_buffer.h"
29 #ifdef __PCTOOL__
30 #ifdef WPSEDITOR
31 #include "proxy.h"
32 #else
33 #define DEBUGF printf
34 #endif
35 #else
36 #include "debug.h"
37 #endif
39 #if defined(SIMULATOR) || defined(__PCTOOL__)
40 extern bool debug_wps;
41 extern int wps_verbose_level;
42 #endif
44 static char *next_str(bool next) {
45 return next ? "next " : "";
48 static char *get_token_desc(struct wps_token *token, char *buf,
49 int bufsize, struct wps_data *data)
51 bool next = token->next;
53 switch(token->type)
55 case WPS_NO_TOKEN:
56 snprintf(buf, bufsize, "No token");
57 break;
59 case WPS_TOKEN_UNKNOWN:
60 snprintf(buf, bufsize, "Unknown token");
61 break;
63 case WPS_TOKEN_CHARACTER:
64 if (token->value.c == '\n')
65 snprintf(buf, bufsize, "Character '\\n'");
66 else
67 snprintf(buf, bufsize, "Character '%c'",
68 token->value.c);
69 break;
71 case WPS_TOKEN_STRING:
72 snprintf(buf, bufsize, "String '%s'",
73 (char*)token->value.data);
74 break;
76 #ifdef HAVE_LCD_BITMAP
77 case WPS_TOKEN_ALIGN_LEFT:
78 snprintf(buf, bufsize, "align left");
79 break;
81 case WPS_TOKEN_ALIGN_CENTER:
82 snprintf(buf, bufsize, "align center");
83 break;
85 case WPS_TOKEN_ALIGN_RIGHT:
86 snprintf(buf, bufsize, "align right");
87 break;
88 #endif
90 case WPS_TOKEN_SUBLINE_TIMEOUT:
91 snprintf(buf, bufsize, "subline timeout value: %d",
92 token->value.i);
93 break;
95 case WPS_TOKEN_CONDITIONAL:
96 snprintf(buf, bufsize, "conditional, %d options",
97 token->value.i);
98 break;
100 case WPS_TOKEN_CONDITIONAL_START:
101 snprintf(buf, bufsize, "conditional start, next cond: %d",
102 token->value.i);
103 break;
105 case WPS_TOKEN_CONDITIONAL_OPTION:
106 snprintf(buf, bufsize, "conditional option, next cond: %d",
107 token->value.i);
108 break;
110 case WPS_TOKEN_CONDITIONAL_END:
111 snprintf(buf, bufsize, "conditional end");
112 break;
114 #ifdef HAVE_LCD_BITMAP
115 case WPS_TOKEN_IMAGE_PRELOAD:
116 snprintf(buf, bufsize, "preload image");
117 break;
119 case WPS_TOKEN_IMAGE_PRELOAD_DISPLAY:
121 char subimage = '\0';
122 char label = token->value.i&0xFF;
123 struct gui_img *img = find_image(label, data);
124 if (img && img->num_subimages > 1)
125 subimage = 'a' + (token->value.i>>8);
126 snprintf(buf, bufsize, "display preloaded image '%c%c'",
127 label, subimage);
129 break;
131 case WPS_TOKEN_IMAGE_DISPLAY:
132 snprintf(buf, bufsize, "display image");
133 break;
134 #endif
136 #ifdef HAS_BUTTON_HOLD
137 case WPS_TOKEN_MAIN_HOLD:
138 snprintf(buf, bufsize, "mode hold");
139 break;
140 #endif
142 #ifdef HAS_REMOTE_BUTTON_HOLD
143 case WPS_TOKEN_REMOTE_HOLD:
144 snprintf(buf, bufsize, "mode remote hold");
145 break;
146 #endif
148 case WPS_TOKEN_REPEAT_MODE:
149 snprintf(buf, bufsize, "mode repeat");
150 break;
152 case WPS_TOKEN_PLAYBACK_STATUS:
153 snprintf(buf, bufsize, "mode playback");
154 break;
156 case WPS_TOKEN_RTC_DAY_OF_MONTH:
157 snprintf(buf, bufsize, "rtc: day of month (01..31)");
158 break;
159 case WPS_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED:
160 snprintf(buf, bufsize,
161 "rtc: day of month, blank padded ( 1..31)");
162 break;
163 case WPS_TOKEN_RTC_HOUR_24_ZERO_PADDED:
164 snprintf(buf, bufsize, "rtc: hour (00..23)");
165 break;
166 case WPS_TOKEN_RTC_HOUR_24:
167 snprintf(buf, bufsize, "rtc: hour ( 0..23)");
168 break;
169 case WPS_TOKEN_RTC_HOUR_12_ZERO_PADDED:
170 snprintf(buf, bufsize, "rtc: hour (01..12)");
171 break;
172 case WPS_TOKEN_RTC_HOUR_12:
173 snprintf(buf, bufsize, "rtc: hour ( 1..12)");
174 break;
175 case WPS_TOKEN_RTC_MONTH:
176 snprintf(buf, bufsize, "rtc: month (01..12)");
177 break;
178 case WPS_TOKEN_RTC_MINUTE:
179 snprintf(buf, bufsize, "rtc: minute (00..59)");
180 break;
181 case WPS_TOKEN_RTC_SECOND:
182 snprintf(buf, bufsize, "rtc: second (00..59)");
183 break;
184 case WPS_TOKEN_RTC_YEAR_2_DIGITS:
185 snprintf(buf, bufsize,
186 "rtc: last two digits of year (00..99)");
187 break;
188 case WPS_TOKEN_RTC_YEAR_4_DIGITS:
189 snprintf(buf, bufsize, "rtc: year (1970...)");
190 break;
191 case WPS_TOKEN_RTC_AM_PM_UPPER:
192 snprintf(buf, bufsize,
193 "rtc: upper case AM or PM indicator");
194 break;
195 case WPS_TOKEN_RTC_AM_PM_LOWER:
196 snprintf(buf, bufsize,
197 "rtc: lower case am or pm indicator");
198 break;
199 case WPS_TOKEN_RTC_WEEKDAY_NAME:
200 snprintf(buf, bufsize,
201 "rtc: abbreviated weekday name (Sun..Sat)");
202 break;
203 case WPS_TOKEN_RTC_MONTH_NAME:
204 snprintf(buf, bufsize,
205 "rtc: abbreviated month name (Jan..Dec)");
206 break;
207 case WPS_TOKEN_RTC_DAY_OF_WEEK_START_MON:
208 snprintf(buf, bufsize,
209 "rtc: day of week (1..7); 1 is Monday");
210 break;
211 case WPS_TOKEN_RTC_DAY_OF_WEEK_START_SUN:
212 snprintf(buf, bufsize,
213 "rtc: day of week (0..6); 0 is Sunday");
214 break;
216 #if (CONFIG_CODEC == SWCODEC)
217 case WPS_TOKEN_CROSSFADE:
218 snprintf(buf, bufsize, "crossfade");
219 break;
221 case WPS_TOKEN_REPLAYGAIN:
222 snprintf(buf, bufsize, "replaygain");
223 break;
224 #endif
226 #ifdef HAVE_ALBUMART
227 case WPS_TOKEN_ALBUMART_DISPLAY:
228 snprintf(buf, bufsize, "album art display");
229 break;
231 case WPS_TOKEN_ALBUMART_FOUND:
232 snprintf(buf, bufsize, "%strack album art conditional",
233 next_str(next));
234 break;
235 #endif
237 #ifdef HAVE_LCD_BITMAP
238 case WPS_TOKEN_IMAGE_BACKDROP:
239 snprintf(buf, bufsize, "backdrop image");
240 break;
242 case WPS_TOKEN_IMAGE_PROGRESS_BAR:
243 snprintf(buf, bufsize, "progressbar bitmap");
244 break;
246 case WPS_TOKEN_PEAKMETER:
247 snprintf(buf, bufsize, "peakmeter");
248 break;
249 #endif
251 case WPS_TOKEN_PROGRESSBAR:
252 snprintf(buf, bufsize, "progressbar");
253 break;
255 #ifdef HAVE_LCD_CHARCELLS
256 case WPS_TOKEN_PLAYER_PROGRESSBAR:
257 snprintf(buf, bufsize, "full line progressbar");
258 break;
259 #endif
261 case WPS_TOKEN_TRACK_TIME_ELAPSED:
262 snprintf(buf, bufsize, "time elapsed in track");
263 break;
265 case WPS_TOKEN_TRACK_ELAPSED_PERCENT:
266 snprintf(buf, bufsize, "played percentage of track");
267 break;
269 case WPS_TOKEN_PLAYLIST_ENTRIES:
270 snprintf(buf, bufsize, "number of entries in playlist");
271 break;
273 case WPS_TOKEN_PLAYLIST_NAME:
274 snprintf(buf, bufsize, "playlist name");
275 break;
277 case WPS_TOKEN_PLAYLIST_POSITION:
278 snprintf(buf, bufsize, "position in playlist");
279 break;
281 case WPS_TOKEN_TRACK_TIME_REMAINING:
282 snprintf(buf, bufsize, "time remaining in track");
283 break;
285 case WPS_TOKEN_PLAYLIST_SHUFFLE:
286 snprintf(buf, bufsize, "playlist shuffle mode");
287 break;
289 case WPS_TOKEN_TRACK_LENGTH:
290 snprintf(buf, bufsize, "track length");
291 break;
293 case WPS_TOKEN_VOLUME:
294 snprintf(buf, bufsize, "volume");
295 break;
297 case WPS_TOKEN_METADATA_ARTIST:
298 snprintf(buf, bufsize, "%strack artist",
299 next_str(next));
300 break;
302 case WPS_TOKEN_METADATA_COMPOSER:
303 snprintf(buf, bufsize, "%strack composer",
304 next_str(next));
305 break;
307 case WPS_TOKEN_METADATA_ALBUM:
308 snprintf(buf, bufsize, "%strack album",
309 next_str(next));
310 break;
312 case WPS_TOKEN_METADATA_GROUPING:
313 snprintf(buf, bufsize, "%strack grouping",
314 next_str(next));
315 break;
317 case WPS_TOKEN_METADATA_GENRE:
318 snprintf(buf, bufsize, "%strack genre",
319 next_str(next));
320 break;
322 case WPS_TOKEN_METADATA_DISC_NUMBER:
323 snprintf(buf, bufsize, "%strack disc", next_str(next));
324 break;
326 case WPS_TOKEN_METADATA_TRACK_NUMBER:
327 snprintf(buf, bufsize, "%strack number",
328 next_str(next));
329 break;
331 case WPS_TOKEN_METADATA_TRACK_TITLE:
332 snprintf(buf, bufsize, "%strack title",
333 next_str(next));
334 break;
336 case WPS_TOKEN_METADATA_VERSION:
337 snprintf(buf, bufsize, "%strack ID3 version",
338 next_str(next));
339 break;
341 case WPS_TOKEN_METADATA_ALBUM_ARTIST:
342 snprintf(buf, bufsize, "%strack album artist",
343 next_str(next));
344 break;
346 case WPS_TOKEN_METADATA_COMMENT:
347 snprintf(buf, bufsize, "%strack comment",
348 next_str(next));
349 break;
351 case WPS_TOKEN_METADATA_YEAR:
352 snprintf(buf, bufsize, "%strack year", next_str(next));
353 break;
355 #ifdef HAVE_TAGCACHE
356 case WPS_TOKEN_DATABASE_PLAYCOUNT:
357 snprintf(buf, bufsize, "track playcount (database)");
358 break;
360 case WPS_TOKEN_DATABASE_RATING:
361 snprintf(buf, bufsize, "track rating (database)");
362 break;
364 case WPS_TOKEN_DATABASE_AUTOSCORE:
365 snprintf(buf, bufsize, "track autoscore (database)");
366 break;
367 #endif
369 case WPS_TOKEN_BATTERY_PERCENT:
370 snprintf(buf, bufsize, "battery percentage");
371 break;
373 case WPS_TOKEN_BATTERY_VOLTS:
374 snprintf(buf, bufsize, "battery voltage");
375 break;
377 case WPS_TOKEN_BATTERY_TIME:
378 snprintf(buf, bufsize, "battery time left");
379 break;
381 case WPS_TOKEN_BATTERY_CHARGER_CONNECTED:
382 snprintf(buf, bufsize, "battery charger connected");
383 break;
385 case WPS_TOKEN_BATTERY_CHARGING:
386 snprintf(buf, bufsize, "battery charging");
387 break;
389 case WPS_TOKEN_BATTERY_SLEEPTIME:
390 snprintf(buf, bufsize, "sleep timer");
391 break;
393 case WPS_TOKEN_FILE_BITRATE:
394 snprintf(buf, bufsize, "%sfile bitrate", next_str(next));
395 break;
397 case WPS_TOKEN_FILE_CODEC:
398 snprintf(buf, bufsize, "%sfile codec", next_str(next));
399 break;
401 case WPS_TOKEN_FILE_FREQUENCY:
402 snprintf(buf, bufsize, "%sfile audio frequency in Hz",
403 next_str(next));
404 break;
406 case WPS_TOKEN_FILE_FREQUENCY_KHZ:
407 snprintf(buf, bufsize, "%sfile audio frequency in KHz",
408 next_str(next));
409 break;
411 case WPS_TOKEN_FILE_NAME:
412 snprintf(buf, bufsize, "%sfile name", next_str(next));
413 break;
415 case WPS_TOKEN_FILE_NAME_WITH_EXTENSION:
416 snprintf(buf, bufsize, "%sfile name with extension",
417 next_str(next));
418 break;
420 case WPS_TOKEN_FILE_PATH:
421 snprintf(buf, bufsize, "%sfile path", next_str(next));
422 break;
424 case WPS_TOKEN_FILE_SIZE:
425 snprintf(buf, bufsize, "%sfile size", next_str(next));
426 break;
428 case WPS_TOKEN_FILE_VBR:
429 snprintf(buf, bufsize, "%sfile is vbr", next_str(next));
430 break;
432 case WPS_TOKEN_FILE_DIRECTORY:
433 snprintf(buf, bufsize, "%sfile directory, level: %d",
434 next_str(next), token->value.i);
435 break;
437 #if (CONFIG_CODEC != MAS3507D)
438 case WPS_TOKEN_SOUND_PITCH:
439 snprintf(buf, bufsize, "pitch value");
440 break;
441 #endif
443 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
444 case WPS_TOKEN_VLED_HDD:
445 snprintf(buf, bufsize, "display virtual HDD LED");
446 break;
447 #endif
448 case WPS_VIEWPORT_ENABLE:
449 snprintf(buf, bufsize, "enable VP:%d",
450 token->value.i);
451 break;
452 case WPS_TOKEN_BUTTON_VOLUME:
453 snprintf(buf, bufsize, "Volume button timeout:%d",
454 token->value.i);
455 break;
456 default:
457 snprintf(buf, bufsize, "FIXME (code: %d)",
458 token->type);
459 break;
462 return buf;
465 #if defined(SIMULATOR) || defined(__PCTOOL__)
466 static void dump_wps_tokens(struct wps_data *data)
468 struct wps_token *token;
469 int i, j;
470 int indent = 0;
471 char buf[64];
473 /* Dump parsed WPS */
474 for (i = 0, token = data->tokens; i < data->num_tokens; i++, token++)
476 get_token_desc(token, buf, sizeof(buf), data);
478 switch(token->type)
481 case WPS_TOKEN_CONDITIONAL_START:
482 indent++;
483 break;
485 case WPS_TOKEN_CONDITIONAL_END:
486 indent--;
487 break;
489 default:
490 break;
493 if (wps_verbose_level > 2)
495 for(j = 0; j < indent; j++) {
496 DEBUGF("\t");
499 DEBUGF("[%3d] = (%2d) %s\n", i, token->type, buf);
504 static void print_line_info(struct wps_data *data)
506 struct skin_line *line;
507 struct skin_subline *subline;
508 if (wps_verbose_level > 0)
510 struct skin_token_list *viewport_list;
511 for (viewport_list = data->viewports;
512 viewport_list; viewport_list = viewport_list->next)
514 struct skin_viewport *v =
515 (struct skin_viewport *)viewport_list->token->value.data;
516 DEBUGF("vp Label:'%c' Hidden flags:%x\n", v->label, v->hidden_flags);
518 DEBUGF("Number of tokens : %d\n", data->num_tokens);
519 DEBUGF("\n");
522 if (wps_verbose_level > 1)
524 int line_number = 0;
525 struct skin_token_list *viewport_list;
526 for (viewport_list = data->viewports;
527 viewport_list; viewport_list = viewport_list->next)
529 struct skin_viewport *v =
530 (struct skin_viewport *)viewport_list->token->value.data;
531 DEBUGF("Viewport '%c' - +%d+%d (%dx%d)\n",v->label, v->vp.x, v->vp.y,
532 v->vp.width, v->vp.height);
533 for (line = v->lines; line; line = line->next, line_number++)
535 DEBUGF("Line %2d\n", line_number);
536 int subline_number = 0;
537 subline = &line->sublines;
538 while (subline)
540 DEBUGF(" Subline %d: first_token=%3d, last_token=%3d",
541 subline_number, subline->first_token_idx,subline->last_token_idx);
543 if (subline->line_type & WPS_REFRESH_SCROLL)
544 DEBUGF(", scrolled");
545 else if (subline->line_type & WPS_REFRESH_PLAYER_PROGRESS)
546 DEBUGF(", progressbar");
547 else if (subline->line_type & WPS_REFRESH_PEAK_METER)
548 DEBUGF(", peakmeter");
550 DEBUGF("\n");
551 subline = subline->next;
552 subline_number++;
557 DEBUGF("\n");
560 #endif
562 void print_debug_info(struct wps_data *data, enum wps_parse_error fail, int line)
564 #if defined(SIMULATOR) || defined(__PCTOOL__)
565 if (debug_wps && wps_verbose_level)
567 dump_wps_tokens(data);
568 print_line_info(data);
570 #endif /* SIMULATOR */
572 if (data->num_tokens >= WPS_MAX_TOKENS - 1) {
573 DEBUGF("Warning: Max number of tokens was reached (%d)\n",
574 WPS_MAX_TOKENS - 1);
577 if (fail != PARSE_OK)
579 char buf[64];
581 DEBUGF("ERR: Failed parsing on line %d : ", line);
582 switch (fail)
584 case PARSE_OK:
585 break;
587 case PARSE_FAIL_UNCLOSED_COND:
588 DEBUGF("ERR: Unclosed conditional");
589 break;
591 case PARSE_FAIL_INVALID_CHAR:
592 DEBUGF("ERR: Unexpected conditional char after token %d: \"%s\"",
593 data->num_tokens-1,
594 get_token_desc(&data->tokens[data->num_tokens-1], buf, sizeof(buf), data)
596 break;
598 case PARSE_FAIL_COND_SYNTAX_ERROR:
599 DEBUGF("ERR: Conditional syntax error after token %d: \"%s\"",
600 data->num_tokens-1,
601 get_token_desc(&data->tokens[data->num_tokens-1], buf, sizeof(buf), data)
603 break;
605 case PARSE_FAIL_COND_INVALID_PARAM:
606 DEBUGF("ERR: Invalid parameter list for token %d: \"%s\"",
607 data->num_tokens,
608 get_token_desc(&data->tokens[data->num_tokens], buf, sizeof(buf), data)
610 break;
612 case PARSE_FAIL_LIMITS_EXCEEDED:
613 DEBUGF("ERR: Limits exceeded");
614 break;
616 DEBUGF("\n");
620 void debug_skin_usage(void)
622 if (wps_verbose_level > 1)
623 DEBUGF("Skin buffer usage: %lu/%lu\n", (unsigned long)skin_buffer_usage(),
624 (unsigned long)(skin_buffer_usage() + skin_buffer_freespace()));
628 #endif /* DEBUG || SIMULATOR */