1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2005 by Daniel Stenberg
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 ****************************************************************************/
23 * logf() logs entries in a circular buffer. Each logged string is null-terminated.
25 * When the length of log exceeds MAX_LOGF_SIZE bytes, the buffer wraps.
35 #ifdef HAVE_REMOTE_LCD
36 #include "lcd-remote.h"
44 #include "usbstack/usb_serial.h"
47 /* Only provide all this if asked to */
48 #ifdef ROCKBOX_HAS_LOGF
51 unsigned char logfbuffer
[MAX_LOGF_SIZE
];
56 #ifdef HAVE_REMOTE_LCD
57 static void displayremote(void)
59 /* TODO: we should have a debug option that enables/disables this! */
62 int cur_x
, cur_y
, delta_y
, delta_x
;
66 /* Memorize the pointer to the beginning of the last ... lines
67 I assume delta_y >= 6 to avoid wasting memory and allocating memory dynamically
68 I hope there is no font with height < 6 ! */
69 const int NB_ENTRIES
=LCD_REMOTE_HEIGHT
/ 6;
70 int line_start_ptr
[NB_ENTRIES
];
72 fontnr
= lcd_getfont();
73 font
= font_get(fontnr
);
75 /* get the horizontal size of each line */
76 font_getstringsize("A", NULL
, &delta_y
, fontnr
);
78 /* font too small ? */
81 /* nothing to print ? */
82 if(logfindex
== 0 && !logfwrap
)
86 h
= LCD_REMOTE_HEIGHT
;
96 line_start_ptr
[0] = i
;
100 if(logfbuffer
[i
] == '\0')
102 line_start_ptr
[++nb_lines
% NB_ENTRIES
] = i
+1;
107 /* does character fit on this line ? */
108 delta_x
= font_get_width(font
, logfbuffer
[i
]);
110 if(cur_x
+ delta_x
> w
)
113 line_start_ptr
[++nb_lines
% NB_ENTRIES
] = i
;
119 if(i
>= MAX_LOGF_SIZE
)
121 } while(i
!= logfindex
);
123 lcd_remote_clear_display();
125 i
= line_start_ptr
[ MAX(nb_lines
- h
/ delta_y
, 0) % NB_ENTRIES
];
131 if(logfbuffer
[i
] == '\0')
138 /* does character fit on this line ? */
139 delta_x
= font_get_width(font
, logfbuffer
[i
]);
141 if(cur_x
+ delta_x
> w
)
147 buf
[0] = logfbuffer
[i
];
148 lcd_remote_putsxy(cur_x
, cur_y
, buf
);
153 if(i
>= MAX_LOGF_SIZE
)
155 } while(i
!= logfindex
);
160 #define displayremote()
164 void _logf(const char *format
, ...)
168 va_start(ap
, format
);
170 vsnprintf(buf
, sizeof buf
, format
, ap
);
171 printf("DEBUG: %s\n", buf
);
174 static void check_logfindex(void)
176 if(logfindex
>= MAX_LOGF_SIZE
)
184 static int logf_push(void *userp
, unsigned char c
)
188 logfbuffer
[logfindex
++] = c
;
191 #if defined(HAVE_SERIAL) && !defined(SIMULATOR) && defined(LOGF_SERIAL)
204 void _logf(const char *fmt
, ...)
206 #ifdef USB_ENABLE_SERIAL
207 int old_logfindex
= logfindex
;
213 #if (CONFIG_PLATFORM & PLATFORM_HOSTED)
215 vsnprintf(buf
, sizeof buf
, fmt
, ap
);
217 /* restart va_list otherwise the result if undefined when vuprintf is called */
222 vuprintf(logf_push
, NULL
, fmt
, ap
);
225 /* add trailing zero */
226 logf_push(NULL
, '\0');
228 #if defined(HAVE_SERIAL) && !defined(SIMULATOR) && defined(LOGF_SERIAL)
231 #ifdef USB_ENABLE_SERIAL
233 if(logfindex
< old_logfindex
)
235 usb_serial_send(logfbuffer
+ old_logfindex
, MAX_LOGF_SIZE
- old_logfindex
);
236 usb_serial_send(logfbuffer
, logfindex
- 1);
239 usb_serial_send(logfbuffer
+ old_logfindex
, logfindex
- old_logfindex
- 1);
240 usb_serial_send("\r\n", 2);