"Mosaic" is in fact spelled "Mosaique". Just change the name for now.
[Rockbox.git] / firmware / logf.c
blobf61797b2892f7ec1ae47f8528a02066de5ee09d1
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 by Daniel Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
21 * logf() logs MAX_LOGF_ENTRY (21) bytes per entry in a circular buffer. Each
22 * logged string is space- padded for easier and faster output on screen. Just
23 * output MAX_LOGF_ENTRY characters on each line. MAX_LOGF_ENTRY bytes fit
24 * nicely on the iRiver remote LCD (128 pixels with an 8x6 pixels font).
27 #include <string.h>
28 #include <stdio.h>
29 #include <stdarg.h>
30 #include <sprintf.h>
31 #include "config.h"
32 #include "lcd-remote.h"
33 #include "logf.h"
35 /* Only provide all this if asked to */
36 #ifdef ROCKBOX_HAS_LOGF
38 unsigned char logfbuffer[MAX_LOGF_LINES][MAX_LOGF_ENTRY];
39 int logfindex;
40 bool logfwrap;
42 #ifdef HAVE_REMOTE_LCD
43 static void displayremote(void)
45 /* TODO: we should have a debug option that enables/disables this! */
46 int w, h;
47 int lines;
48 int columns;
49 int i;
50 int index;
52 lcd_remote_getstringsize("A", &w, &h);
53 lines = LCD_REMOTE_HEIGHT/h;
54 columns = LCD_REMOTE_WIDTH/w;
55 lcd_remote_setmargins(0, 0);
56 lcd_remote_clear_display();
58 index = logfindex;
59 for(i = lines-1; i>=0; i--) {
60 unsigned char buffer[columns+1];
62 if(--index < 0) {
63 if(logfwrap)
64 index = MAX_LOGF_LINES-1;
65 else
66 break; /* done */
69 memcpy(buffer, logfbuffer[index], columns);
70 buffer[columns]=0;
71 lcd_remote_puts(0, i, buffer);
73 lcd_remote_update();
75 #else
76 #define displayremote()
77 #endif
79 void logf(const char *format, ...)
81 int len;
82 unsigned char *ptr;
83 va_list ap;
84 va_start(ap, format);
86 if(logfindex >= MAX_LOGF_LINES) {
87 /* wrap */
88 logfwrap = true;
89 logfindex = 0;
91 ptr = logfbuffer[logfindex];
92 len = vsnprintf(ptr, MAX_LOGF_ENTRY, format, ap);
93 va_end(ap);
94 if(len < MAX_LOGF_ENTRY)
95 /* pad with spaces up to the MAX_LOGF_ENTRY byte border */
96 memset(ptr+len, ' ', MAX_LOGF_ENTRY-len);
98 logfindex++; /* leave it where we write the next time */
100 displayremote();
103 #endif