2005-05-24 14:26:23 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 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-24 14:26:23 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "config.h"
|
2005-05-30 13:00:43 +00:00
|
|
|
|
|
|
|
#ifdef ROCKBOX_HAS_LOGF
|
2005-06-01 13:07:37 +00:00
|
|
|
#include <file.h>
|
2005-05-24 14:26:23 +00:00
|
|
|
#include <timefuncs.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <kernel.h>
|
2006-08-15 12:27:07 +00:00
|
|
|
#include <action.h>
|
2005-05-24 14:26:23 +00:00
|
|
|
|
|
|
|
#include <lcd.h>
|
2009-08-21 22:54:23 +00:00
|
|
|
#include <font.h>
|
2005-05-24 14:26:23 +00:00
|
|
|
#include "menu.h"
|
|
|
|
#include "logf.h"
|
2007-09-10 19:29:53 +00:00
|
|
|
#include "settings.h"
|
2008-04-28 10:22:05 +00:00
|
|
|
#include "logfdisp.h"
|
2009-04-19 15:48:26 +00:00
|
|
|
#include "action.h"
|
2009-11-23 00:19:22 +00:00
|
|
|
#include "splash.h"
|
2005-05-24 14:26:23 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2009-08-21 22:54:23 +00:00
|
|
|
int compute_nb_lines(int w, struct font* font)
|
2005-05-24 14:26:23 +00:00
|
|
|
{
|
2009-08-21 22:54:23 +00:00
|
|
|
int i, nb_lines;
|
|
|
|
int cur_x, delta_x;
|
|
|
|
|
|
|
|
if(logfindex == 0 && !logfwrap)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(logfwrap)
|
|
|
|
i = logfindex;
|
|
|
|
else
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
cur_x = 0;
|
|
|
|
nb_lines = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if(logfbuffer[i] == '\0')
|
|
|
|
{
|
|
|
|
cur_x = 0;
|
|
|
|
nb_lines++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* does character fit on this line ? */
|
|
|
|
delta_x = font_get_width(font, logfbuffer[i]);
|
|
|
|
|
|
|
|
if(cur_x + delta_x > w)
|
|
|
|
{
|
|
|
|
cur_x = 0;
|
|
|
|
nb_lines++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update pointer */
|
|
|
|
cur_x += delta_x;
|
|
|
|
}
|
2005-05-24 14:26:23 +00:00
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
i++;
|
|
|
|
if(i >= MAX_LOGF_SIZE)
|
|
|
|
i = 0;
|
|
|
|
} while(i != logfindex);
|
|
|
|
|
|
|
|
return nb_lines;
|
|
|
|
}
|
2006-04-11 22:19:47 +00:00
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
bool logfdisplay(void)
|
|
|
|
{
|
|
|
|
int action;
|
|
|
|
int w, h, i, index;
|
|
|
|
int fontnr;
|
|
|
|
int cur_x, cur_y, delta_y, delta_x;
|
|
|
|
struct font* font;
|
|
|
|
int user_index;/* user_index will be number of the first line to display (warning: line!=logf entry) */
|
|
|
|
char buf[2];
|
|
|
|
|
|
|
|
fontnr = lcd_getfont();
|
|
|
|
font = font_get(fontnr);
|
|
|
|
|
|
|
|
/* get the horizontal size of each line */
|
|
|
|
font_getstringsize("A", NULL, &delta_y, fontnr);
|
|
|
|
|
|
|
|
buf[1] = '\0';
|
|
|
|
w = LCD_WIDTH;
|
|
|
|
h = LCD_HEIGHT;
|
|
|
|
/* start at the end of the log */
|
|
|
|
user_index = compute_nb_lines(w, font) - h/delta_y -1; /* if negative, will be set 0 to zero later */
|
2005-05-24 14:26:23 +00:00
|
|
|
|
|
|
|
do {
|
2009-04-19 15:48:26 +00:00
|
|
|
lcd_clear_display();
|
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
if(user_index < 0)
|
|
|
|
user_index = 0;
|
2005-05-24 14:26:23 +00:00
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
if(logfwrap)
|
|
|
|
i = logfindex;
|
|
|
|
else
|
|
|
|
i = 0;
|
2008-12-31 17:01:00 +00:00
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
index = 0;
|
|
|
|
cur_x = 0;
|
|
|
|
cur_y = 0;
|
|
|
|
|
|
|
|
/* nothing to print ? */
|
|
|
|
if(logfindex == 0 && !logfwrap)
|
|
|
|
goto end_print;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if(logfbuffer[i] == '\0')
|
|
|
|
{
|
|
|
|
/* should be display a newline ? */
|
|
|
|
if(index >= user_index)
|
|
|
|
cur_y += delta_y;
|
|
|
|
cur_x = 0;
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* does character fit on this line ? */
|
|
|
|
delta_x = font_get_width(font, logfbuffer[i]);
|
|
|
|
|
|
|
|
if(cur_x + delta_x > w)
|
|
|
|
{
|
|
|
|
/* should be display a newline ? */
|
|
|
|
if(index >= user_index)
|
|
|
|
cur_y += delta_y;
|
|
|
|
cur_x = 0;
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* should we print character ? */
|
|
|
|
if(index >= user_index)
|
|
|
|
{
|
|
|
|
buf[0] = logfbuffer[i];
|
|
|
|
lcd_putsxy(cur_x, cur_y, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update pointer */
|
|
|
|
cur_x += delta_x;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* did we fill the screen ? */
|
|
|
|
if(cur_y > h)
|
|
|
|
break;
|
|
|
|
|
|
|
|
i++;
|
|
|
|
if(i >= MAX_LOGF_SIZE)
|
|
|
|
i = 0;
|
|
|
|
} while(i != logfindex);
|
|
|
|
|
|
|
|
end_print:
|
2005-05-24 14:26:23 +00:00
|
|
|
lcd_update();
|
2009-04-19 15:48:26 +00:00
|
|
|
|
|
|
|
action = get_action(CONTEXT_STD, HZ);
|
2009-08-21 22:54:23 +00:00
|
|
|
switch( action )
|
2009-04-19 15:48:26 +00:00
|
|
|
{
|
2009-08-21 22:54:23 +00:00
|
|
|
case ACTION_STD_NEXT:
|
|
|
|
case ACTION_STD_NEXTREPEAT:
|
|
|
|
user_index++;
|
|
|
|
break;
|
|
|
|
case ACTION_STD_PREV:
|
|
|
|
case ACTION_STD_PREVREPEAT:
|
|
|
|
user_index--;
|
|
|
|
break;
|
|
|
|
case ACTION_STD_OK:
|
|
|
|
user_index = 0;
|
|
|
|
break;
|
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
case ACTION_TOUCHSCREEN:
|
2009-04-19 15:48:26 +00:00
|
|
|
{
|
2009-08-21 22:54:23 +00:00
|
|
|
short x, y;
|
|
|
|
static int prev_y;
|
2009-04-19 15:48:26 +00:00
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
action = action_get_touchscreen_press(&x, &y);
|
|
|
|
|
|
|
|
if(action & BUTTON_REL)
|
|
|
|
prev_y = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(prev_y != 0)
|
|
|
|
user_index += (prev_y - y) / delta_y;
|
|
|
|
|
|
|
|
prev_y = y;
|
|
|
|
}
|
2009-04-19 15:48:26 +00:00
|
|
|
}
|
|
|
|
#endif
|
2009-08-21 22:54:23 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-04-19 15:48:26 +00:00
|
|
|
} while(action != ACTION_STD_CANCEL);
|
2005-05-24 14:26:23 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2005-05-30 13:00:43 +00:00
|
|
|
#else /* HAVE_LCD_BITMAP */
|
|
|
|
bool logfdisplay(void)
|
|
|
|
|
|
|
|
{
|
|
|
|
/* TODO: implement a browser for charcell bitmaps */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_LCD_BITMAP */
|
|
|
|
|
2005-06-01 13:07:37 +00:00
|
|
|
/* Store the logf log to logf.txt in the .rockbox directory. The order of the
|
|
|
|
* entries will be "reversed" so that the most recently logged entry is on the
|
|
|
|
* top of the file */
|
|
|
|
bool logfdump(void)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
2009-11-23 00:19:22 +00:00
|
|
|
splashf(HZ, "Log File Dumped");
|
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
/* nothing to print ? */
|
|
|
|
if(logfindex == 0 && !logfwrap)
|
2005-06-01 13:07:37 +00:00
|
|
|
/* nothing is logged just yet */
|
|
|
|
return false;
|
|
|
|
|
2010-05-06 17:35:13 +00:00
|
|
|
fd = open(ROCKBOX_DIR "/logf.txt", O_CREAT|O_WRONLY|O_TRUNC, 0666);
|
2005-06-01 13:07:37 +00:00
|
|
|
if(-1 != fd) {
|
2009-08-21 22:54:23 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if(logfwrap)
|
|
|
|
i = logfindex;
|
|
|
|
else
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if(logfbuffer[i]=='\0')
|
|
|
|
fdprintf(fd, "\n");
|
|
|
|
else
|
|
|
|
fdprintf(fd, "%c", logfbuffer[i]);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
if(i >= MAX_LOGF_SIZE)
|
|
|
|
i = 0;
|
|
|
|
} while(i != logfindex);
|
2005-06-01 13:07:37 +00:00
|
|
|
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-05-30 13:00:43 +00:00
|
|
|
#endif /* ROCKBOX_HAS_LOGF */
|