Make the statusbar setting use a temp variable so it doesnt look wierd when changing it
[Rockbox.git] / firmware / logf.c
blob2056db5cc4c164c0e28de3fa8f458b15784e6741
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 "config.h"
31 #include "lcd-remote.h"
32 #include "logf.h"
33 #include "serial.h"
35 /* Only provide all this if asked to */
36 #ifdef ROCKBOX_HAS_LOGF
38 #ifndef __PCTOOL__
39 unsigned char logfbuffer[MAX_LOGF_LINES][MAX_LOGF_ENTRY];
40 int logfindex;
41 bool logfwrap;
42 #endif
44 #ifdef HAVE_REMOTE_LCD
45 static void displayremote(void)
47 /* TODO: we should have a debug option that enables/disables this! */
48 int w, h;
49 int lines;
50 int columns;
51 int i;
52 int index;
54 lcd_remote_getstringsize("A", &w, &h);
55 lines = LCD_REMOTE_HEIGHT/h;
56 columns = LCD_REMOTE_WIDTH/w;
57 lcd_remote_setmargins(0, 0);
58 lcd_remote_clear_display();
60 index = logfindex;
61 for(i = lines-1; i>=0; i--) {
62 unsigned char buffer[columns+1];
64 if(--index < 0) {
65 if(logfwrap)
66 index = MAX_LOGF_LINES-1;
67 else
68 break; /* done */
71 memcpy(buffer, logfbuffer[index], columns);
72 buffer[columns]=0;
73 lcd_remote_puts(0, i, buffer);
75 lcd_remote_update();
77 #else
78 #define displayremote()
79 #endif
81 #ifdef __PCTOOL__
82 void _logf(const char *format, ...)
84 char buf[1024];
85 va_list ap;
86 va_start(ap, format);
88 vsnprintf(buf, sizeof buf, format, ap);
89 printf("DEBUG: %s\n", buf);
91 #else
92 void _logf(const char *format, ...)
94 int len;
95 unsigned char *ptr;
96 va_list ap;
97 va_start(ap, format);
99 if(logfindex >= MAX_LOGF_LINES) {
100 /* wrap */
101 logfwrap = true;
102 logfindex = 0;
104 ptr = logfbuffer[logfindex];
105 len = vsnprintf(ptr, MAX_LOGF_ENTRY, format, ap);
106 #ifdef HAVE_SERIAL
107 serial_tx(ptr);
108 serial_tx("\r\n");
109 #endif
110 va_end(ap);
111 if(len < MAX_LOGF_ENTRY)
112 /* pad with spaces up to the MAX_LOGF_ENTRY byte border */
113 memset(ptr+len, ' ', MAX_LOGF_ENTRY-len);
115 logfindex++; /* leave it where we write the next time */
117 displayremote();
119 #endif
121 #endif