2005-05-23 22:47:42 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 by Daniel Stenberg
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2005-05-23 22:47:42 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/*
|
2009-08-21 22:54:23 +00:00
|
|
|
* logf() logs entries in a circular buffer. Each logged string is null-terminated.
|
2008-12-31 17:01:00 +00:00
|
|
|
*
|
2009-08-21 22:54:23 +00:00
|
|
|
* When the length of log exceeds MAX_LOGF_SIZE bytes, the buffer wraps.
|
2008-12-31 17:01:00 +00:00
|
|
|
*
|
2005-05-23 22:47:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include "config.h"
|
2010-05-06 22:17:34 +00:00
|
|
|
#include "system.h"
|
|
|
|
#include "font.h"
|
2005-05-24 14:28:48 +00:00
|
|
|
#include "lcd-remote.h"
|
2005-05-24 14:26:54 +00:00
|
|
|
#include "logf.h"
|
2006-10-12 20:22:16 +00:00
|
|
|
#include "serial.h"
|
2010-05-15 03:47:06 +00:00
|
|
|
#include "format.h"
|
2005-05-23 22:47:42 +00:00
|
|
|
|
2008-03-02 20:45:33 +00:00
|
|
|
#ifdef HAVE_USBSTACK
|
|
|
|
#include "usb_core.h"
|
|
|
|
#include "usbstack/usb_serial.h"
|
|
|
|
#endif
|
|
|
|
|
2005-05-30 13:00:43 +00:00
|
|
|
/* Only provide all this if asked to */
|
|
|
|
#ifdef ROCKBOX_HAS_LOGF
|
|
|
|
|
2006-11-10 08:03:33 +00:00
|
|
|
#ifndef __PCTOOL__
|
2009-08-21 22:54:23 +00:00
|
|
|
unsigned char logfbuffer[MAX_LOGF_SIZE];
|
2005-05-24 14:01:16 +00:00
|
|
|
int logfindex;
|
2005-05-23 22:47:42 +00:00
|
|
|
bool logfwrap;
|
2006-11-10 08:03:33 +00:00
|
|
|
#endif
|
2005-05-23 22:47:42 +00:00
|
|
|
|
2005-05-24 14:26:54 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
static void displayremote(void)
|
|
|
|
{
|
|
|
|
/* TODO: we should have a debug option that enables/disables this! */
|
2009-08-21 22:54:23 +00:00
|
|
|
int w, h, i;
|
|
|
|
int fontnr;
|
|
|
|
int cur_x, cur_y, delta_y, delta_x;
|
|
|
|
struct font* font;
|
|
|
|
int nb_lines;
|
|
|
|
char buf[2];
|
|
|
|
/* Memorize the pointer to the beginning of the last ... lines
|
|
|
|
I assume delta_y >= 6 to avoid wasting memory and allocating memory dynamically
|
|
|
|
I hope there is no font with height < 6 ! */
|
|
|
|
const int NB_ENTRIES=LCD_REMOTE_HEIGHT / 6;
|
|
|
|
int line_start_ptr[NB_ENTRIES];
|
|
|
|
|
|
|
|
fontnr = lcd_getfont();
|
|
|
|
font = font_get(fontnr);
|
|
|
|
|
|
|
|
/* get the horizontal size of each line */
|
|
|
|
font_getstringsize("A", NULL, &delta_y, fontnr);
|
|
|
|
|
|
|
|
/* font too small ? */
|
|
|
|
if(delta_y < 6)
|
|
|
|
return;
|
|
|
|
/* nothing to print ? */
|
|
|
|
if(logfindex == 0 && !logfwrap)
|
|
|
|
return;
|
|
|
|
|
|
|
|
w = LCD_REMOTE_WIDTH;
|
|
|
|
h = LCD_REMOTE_HEIGHT;
|
|
|
|
nb_lines = 0;
|
|
|
|
|
|
|
|
if(logfwrap)
|
|
|
|
i = logfindex;
|
|
|
|
else
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
cur_x = 0;
|
|
|
|
|
|
|
|
line_start_ptr[0] = i;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if(logfbuffer[i] == '\0')
|
|
|
|
{
|
|
|
|
line_start_ptr[++nb_lines % NB_ENTRIES] = i+1;
|
|
|
|
cur_x = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* does character fit on this line ? */
|
|
|
|
delta_x = font_get_width(font, logfbuffer[i]);
|
|
|
|
|
|
|
|
if(cur_x + delta_x > w)
|
|
|
|
{
|
|
|
|
cur_x = 0;
|
|
|
|
line_start_ptr[++nb_lines % NB_ENTRIES] = i;
|
|
|
|
}
|
|
|
|
/* update pointer */
|
|
|
|
cur_x += delta_x;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
if(i >= MAX_LOGF_SIZE)
|
|
|
|
i = 0;
|
|
|
|
} while(i != logfindex);
|
|
|
|
|
2005-05-24 14:26:54 +00:00
|
|
|
lcd_remote_clear_display();
|
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
i = line_start_ptr[ MAX(nb_lines - h / delta_y, 0) % NB_ENTRIES];
|
|
|
|
cur_x = 0;
|
|
|
|
cur_y = 0;
|
|
|
|
buf[1] = '\0';
|
|
|
|
|
|
|
|
do {
|
|
|
|
if(logfbuffer[i] == '\0')
|
|
|
|
{
|
|
|
|
cur_y += delta_y;
|
|
|
|
cur_x = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* does character fit on this line ? */
|
|
|
|
delta_x = font_get_width(font, logfbuffer[i]);
|
|
|
|
|
|
|
|
if(cur_x + delta_x > w)
|
|
|
|
{
|
|
|
|
cur_y += delta_y;
|
|
|
|
cur_x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf[0] = logfbuffer[i];
|
|
|
|
lcd_remote_putsxy(cur_x, cur_y, buf);
|
|
|
|
cur_x += delta_x;
|
2005-05-24 14:26:54 +00:00
|
|
|
}
|
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
i++;
|
|
|
|
if(i >= MAX_LOGF_SIZE)
|
|
|
|
i = 0;
|
|
|
|
} while(i != logfindex);
|
|
|
|
|
2005-05-24 14:26:54 +00:00
|
|
|
lcd_remote_update();
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define displayremote()
|
|
|
|
#endif
|
|
|
|
|
2006-11-10 08:03:33 +00:00
|
|
|
#ifdef __PCTOOL__
|
|
|
|
void _logf(const char *format, ...)
|
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
|
|
|
|
|
|
vsnprintf(buf, sizeof buf, format, ap);
|
|
|
|
printf("DEBUG: %s\n", buf);
|
|
|
|
}
|
|
|
|
#else
|
2009-02-07 19:59:51 +00:00
|
|
|
static void check_logfindex(void)
|
|
|
|
{
|
2009-08-21 22:54:23 +00:00
|
|
|
if(logfindex >= MAX_LOGF_SIZE)
|
|
|
|
{
|
2009-02-07 19:59:51 +00:00
|
|
|
/* wrap */
|
|
|
|
logfwrap = true;
|
|
|
|
logfindex = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
static int logf_push(void *userp, unsigned char c)
|
2005-05-23 22:47:42 +00:00
|
|
|
{
|
2009-08-21 22:54:23 +00:00
|
|
|
(void)userp;
|
|
|
|
|
|
|
|
logfbuffer[logfindex++] = c;
|
|
|
|
check_logfindex();
|
|
|
|
|
|
|
|
#if defined(HAVE_SERIAL) && !defined(SIMULATOR)
|
|
|
|
if(c != '\0')
|
|
|
|
{
|
|
|
|
char buf[2];
|
|
|
|
buf[0] = c;
|
|
|
|
buf[1] = '\0';
|
|
|
|
serial_tx(buf);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _logf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
#ifdef USB_ENABLE_SERIAL
|
|
|
|
int old_logfindex = logfindex;
|
|
|
|
#endif
|
2005-05-23 22:47:42 +00:00
|
|
|
va_list ap;
|
2008-12-31 17:01:00 +00:00
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
va_start(ap, fmt);
|
2009-11-02 15:30:06 +00:00
|
|
|
|
|
|
|
#ifdef SIMULATOR
|
|
|
|
char buf[1024];
|
|
|
|
vsnprintf(buf, sizeof buf, fmt, ap);
|
|
|
|
DEBUGF("%s\n", buf);
|
|
|
|
#endif
|
|
|
|
|
2009-11-03 21:20:09 +00:00
|
|
|
vuprintf(logf_push, NULL, fmt, ap);
|
2008-12-31 17:01:00 +00:00
|
|
|
va_end(ap);
|
2009-08-21 22:54:23 +00:00
|
|
|
|
|
|
|
/* add trailing zero */
|
|
|
|
logf_push(NULL, '\0');
|
|
|
|
|
2009-03-11 16:42:25 +00:00
|
|
|
#if defined(HAVE_SERIAL) && !defined(SIMULATOR)
|
2006-10-12 20:22:16 +00:00
|
|
|
serial_tx("\r\n");
|
|
|
|
#endif
|
2009-05-23 14:30:20 +00:00
|
|
|
#ifdef USB_ENABLE_SERIAL
|
2008-03-02 20:45:33 +00:00
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
if(logfindex < old_logfindex)
|
2008-12-31 17:01:00 +00:00
|
|
|
{
|
2009-08-21 22:54:23 +00:00
|
|
|
usb_serial_send(logfbuffer + old_logfindex, MAX_LOGF_SIZE - old_logfindex);
|
|
|
|
usb_serial_send(logfbuffer, logfindex - 1);
|
2008-12-31 17:01:00 +00:00
|
|
|
}
|
2009-08-21 22:54:23 +00:00
|
|
|
else
|
|
|
|
usb_serial_send(logfbuffer + old_logfindex, logfindex - old_logfindex - 1);
|
|
|
|
usb_serial_send("\r\n", 2);
|
|
|
|
#endif
|
2005-05-24 14:26:54 +00:00
|
|
|
|
|
|
|
displayremote();
|
2005-05-23 22:47:42 +00:00
|
|
|
}
|
2006-11-10 08:03:33 +00:00
|
|
|
#endif
|
2005-05-30 13:00:43 +00:00
|
|
|
|
|
|
|
#endif
|