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 MAX_LOGF_ENTRY (29) bytes per entry in a circular buffer. Each
24 * logged string is space- padded for easier and faster output on screen. Just
25 * output MAX_LOGF_ENTRY characters on each line. MAX_LOGF_ENTRY bytes fit
26 * nicely on the iRiver remote LCD (128 pixels with an 8x6 pixels font).
28 * When the length of log exceeds MAX_LOGF_ENTRY bytes, dividing into the
29 * string of length is MAX_LOGF_ENTRY-1 bytes.
33 * |<- MAX_LOGF_ENTRY bytes ->|1|
36 * T : log terminate flag
37 * == LOGF_TERMINATE_ONE_LINE(0x00) : log data end (one line)
38 * == LOGF_TERMINATE_CONTINUE_LINE(0x01) : log data continues
39 * == LOGF_TERMINATE_MULTI_LINE(0x02) : log data end (multi line)
46 #include "lcd-remote.h"
52 #include "usbstack/usb_serial.h"
55 /* Only provide all this if asked to */
56 #ifdef ROCKBOX_HAS_LOGF
59 unsigned char logfbuffer
[MAX_LOGF_LINES
][MAX_LOGF_ENTRY
+1];
64 #ifdef HAVE_REMOTE_LCD
65 static void displayremote(void)
67 /* TODO: we should have a debug option that enables/disables this! */
74 lcd_remote_getstringsize("A", &w
, &h
);
75 lines
= LCD_REMOTE_HEIGHT
/h
;
76 columns
= LCD_REMOTE_WIDTH
/w
;
77 lcd_remote_clear_display();
80 for(i
= lines
-1; i
>=0; i
--) {
81 unsigned char buffer
[columns
+1];
85 index
= MAX_LOGF_LINES
-1;
90 memcpy(buffer
, logfbuffer
[index
], columns
);
92 lcd_remote_puts(0, i
, buffer
);
97 #define displayremote()
101 void _logf(const char *format
, ...)
105 va_start(ap
, format
);
107 vsnprintf(buf
, sizeof buf
, format
, ap
);
108 printf("DEBUG: %s\n", buf
);
111 static void check_logfindex(void)
113 if(logfindex
>= MAX_LOGF_LINES
) {
120 void _logf(const char *format
, ...)
124 unsigned char buf
[MAX_LOGF_ONE_LINE_SIZE
];
127 bool multiline
= false;
129 va_start(ap
, format
);
130 vsnprintf(buf
, MAX_LOGF_ONE_LINE_SIZE
, format
, ap
);
134 #if defined(HAVE_SERIAL) && !defined(SIMULATOR)
139 usb_serial_send(buf
, len
);
140 usb_serial_send("\r\n", 2);
145 while(len
> MAX_LOGF_ENTRY
)
147 ptr
= logfbuffer
[logfindex
];
148 strncpy(ptr
, buf
+ tlen
, MAX_LOGF_ENTRY
-1);
149 ptr
[MAX_LOGF_ENTRY
] = LOGF_TERMINATE_CONTINUE_LINE
;
152 len
-= MAX_LOGF_ENTRY
-1;
153 tlen
+= MAX_LOGF_ENTRY
-1;
156 ptr
= logfbuffer
[logfindex
];
157 strcpy(ptr
, buf
+ tlen
);
159 if(len
< MAX_LOGF_ENTRY
)
160 /* pad with spaces up to the MAX_LOGF_ENTRY byte border */
161 memset(ptr
+len
, ' ', MAX_LOGF_ENTRY
-len
);
162 ptr
[MAX_LOGF_ENTRY
] = (multiline
)?LOGF_TERMINATE_MULTI_LINE
:LOGF_TERMINATE_ONE_LINE
;
164 logfindex
++; /* leave it where we write the next time */