very minor code police. also fix a possible but unlikely missed cpu_boost(false)
[Rockbox.git] / firmware / logf.c
blob9599547907345db247b041f0c5bb90e03961c8cf
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 (21) 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).
29 #include <string.h>
30 #include <stdio.h>
31 #include <stdarg.h>
32 #include "config.h"
33 #include "lcd-remote.h"
34 #include "logf.h"
35 #include "serial.h"
37 #ifdef HAVE_USBSTACK
38 #include "usb_core.h"
39 #include "usbstack/usb_serial.h"
40 #endif
42 /* Only provide all this if asked to */
43 #ifdef ROCKBOX_HAS_LOGF
45 #ifndef __PCTOOL__
46 unsigned char logfbuffer[MAX_LOGF_LINES][MAX_LOGF_ENTRY];
47 int logfindex;
48 bool logfwrap;
49 #endif
51 #ifdef HAVE_REMOTE_LCD
52 static void displayremote(void)
54 /* TODO: we should have a debug option that enables/disables this! */
55 int w, h;
56 int lines;
57 int columns;
58 int i;
59 int index;
61 lcd_remote_getstringsize("A", &w, &h);
62 lines = LCD_REMOTE_HEIGHT/h;
63 columns = LCD_REMOTE_WIDTH/w;
64 lcd_remote_clear_display();
66 index = logfindex;
67 for(i = lines-1; i>=0; i--) {
68 unsigned char buffer[columns+1];
70 if(--index < 0) {
71 if(logfwrap)
72 index = MAX_LOGF_LINES-1;
73 else
74 break; /* done */
77 memcpy(buffer, logfbuffer[index], columns);
78 buffer[columns]=0;
79 lcd_remote_puts(0, i, buffer);
81 lcd_remote_update();
83 #else
84 #define displayremote()
85 #endif
87 #ifdef __PCTOOL__
88 void _logf(const char *format, ...)
90 char buf[1024];
91 va_list ap;
92 va_start(ap, format);
94 vsnprintf(buf, sizeof buf, format, ap);
95 printf("DEBUG: %s\n", buf);
97 #else
98 void _logf(const char *format, ...)
100 int len;
101 unsigned char *ptr;
102 va_list ap;
103 va_start(ap, format);
105 if(logfindex >= MAX_LOGF_LINES) {
106 /* wrap */
107 logfwrap = true;
108 logfindex = 0;
110 ptr = logfbuffer[logfindex];
111 len = vsnprintf(ptr, MAX_LOGF_ENTRY, format, ap);
112 #ifdef HAVE_SERIAL
113 serial_tx(ptr);
114 serial_tx("\r\n");
115 #endif
116 #ifdef USB_SERIAL
117 usb_serial_send(ptr,len);
118 usb_serial_send("\r\n",2);
119 #endif
121 va_end(ap);
122 if(len < MAX_LOGF_ENTRY)
123 /* pad with spaces up to the MAX_LOGF_ENTRY byte border */
124 memset(ptr+len, ' ', MAX_LOGF_ENTRY-len);
126 logfindex++; /* leave it where we write the next time */
128 displayremote();
130 #endif
132 #endif