blob: bfe37bc3fb239ce26ef323e958204ab53498a9b9 [file] [log] [blame]
Daniel Stenberge2c4a6c2005-05-24 14:26:23 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 Daniel Stenberg
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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.
Daniel Stenberge2c4a6c2005-05-24 14:26:23 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "config.h"
Daniel Stenbergedc07922005-05-30 13:00:43 +000022
23#ifdef ROCKBOX_HAS_LOGF
Daniel Stenbergc95319f2005-06-01 13:07:37 +000024#include <file.h>
25#include <sprintf.h>
Daniel Stenberge2c4a6c2005-05-24 14:26:23 +000026#include <timefuncs.h>
27#include <string.h>
28#include <kernel.h>
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +000029#include <action.h>
Daniel Stenberge2c4a6c2005-05-24 14:26:23 +000030
31#include <lcd.h>
32#include "menu.h"
33#include "logf.h"
Barry Wardelld727f5d2007-09-10 19:29:53 +000034#include "settings.h"
Bertrik Sikkena5d30292008-04-28 10:22:05 +000035#include "logfdisp.h"
Daniel Stenberge2c4a6c2005-05-24 14:26:23 +000036
37#ifdef HAVE_LCD_BITMAP
38bool logfdisplay(void)
39
40{
41 int w, h;
42 int lines;
Michiel Van Der Kolk65ff2192005-06-30 15:14:08 +000043 int columns;
Daniel Stenberge2c4a6c2005-05-24 14:26:23 +000044 int i;
Daniel Stenberge2c4a6c2005-05-24 14:26:23 +000045
46 bool lcd = false; /* fixed atm */
47 int index;
48
49 lcd_getstringsize("A", &w, &h);
50 lines = (lcd?
51#ifdef HAVE_REMOTE_LCD
52 LCD_REMOTE_HEIGHT
53#else
54 0
55#endif
56 :LCD_HEIGHT)/h;
Michiel Van Der Kolk65ff2192005-06-30 15:14:08 +000057 columns = (lcd?
58#ifdef HAVE_REMOTE_LCD
59 LCD_REMOTE_WIDTH
60#else
61 0
62#endif
63 :LCD_WIDTH)/w;
Brandon Low16ee4162006-04-11 22:19:47 +000064
65 if (columns > MAX_LOGF_ENTRY)
66 columns = MAX_LOGF_ENTRY;
Michiel Van Der Kolk65ff2192005-06-30 15:14:08 +000067
Daniel Stenberge2c4a6c2005-05-24 14:26:23 +000068 if(!lines)
69 return false;
70
Daniel Stenberge2c4a6c2005-05-24 14:26:23 +000071 lcd_clear_display();
72
73 do {
74 index = logfindex;
75 for(i = lines-1; i>=0; i--) {
Michiel Van Der Kolk65ff2192005-06-30 15:14:08 +000076 unsigned char buffer[columns + 1];
Daniel Stenberge2c4a6c2005-05-24 14:26:23 +000077
78 if(--index < 0) {
79 if(logfwrap)
80 index = MAX_LOGF_LINES-1;
81 else
82 break; /* done */
83 }
84
Michiel Van Der Kolk65ff2192005-06-30 15:14:08 +000085 memcpy(buffer, logfbuffer[index], columns);
86 buffer[columns]=0;
Daniel Stenberge2c4a6c2005-05-24 14:26:23 +000087 lcd_puts(0, i, buffer);
88 }
89 lcd_update();
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +000090 } while(!action_userabort(HZ));
Daniel Stenberge2c4a6c2005-05-24 14:26:23 +000091
92 return false;
93}
Daniel Stenbergedc07922005-05-30 13:00:43 +000094#else /* HAVE_LCD_BITMAP */
95bool logfdisplay(void)
96
97{
98 /* TODO: implement a browser for charcell bitmaps */
99 return false;
100}
101#endif /* HAVE_LCD_BITMAP */
102
Daniel Stenbergc95319f2005-06-01 13:07:37 +0000103/* Store the logf log to logf.txt in the .rockbox directory. The order of the
104 * entries will be "reversed" so that the most recently logged entry is on the
105 * top of the file */
106bool logfdump(void)
107{
108 int fd;
109
110 if(!logfindex && !logfwrap)
111 /* nothing is logged just yet */
112 return false;
113
Nils Wallménius04b34352007-09-10 09:46:36 +0000114 fd = open(ROCKBOX_DIR "/logf.txt", O_CREAT|O_WRONLY|O_TRUNC);
Daniel Stenbergc95319f2005-06-01 13:07:37 +0000115 if(-1 != fd) {
Daniel Stenberg6ebdbe82005-06-01 13:21:20 +0000116 unsigned char buffer[MAX_LOGF_ENTRY +1];
Daniel Stenbergc95319f2005-06-01 13:07:37 +0000117 int index = logfindex-1;
118 int stop = logfindex;
119
120
121 while(index != stop) {
122 if(index < 0) {
123 if(logfwrap)
124 index = MAX_LOGF_LINES-1;
125 else
126 break; /* done */
127 }
128
Daniel Stenberg6ebdbe82005-06-01 13:21:20 +0000129 memcpy(buffer, logfbuffer[index], MAX_LOGF_ENTRY);
130 buffer[MAX_LOGF_ENTRY]=0;
Daniel Stenbergc95319f2005-06-01 13:07:37 +0000131 fdprintf(fd, "%s\n", buffer);
132 index--;
133 }
134 close(fd);
135 }
136 return false;
137}
138
Daniel Stenbergedc07922005-05-30 13:00:43 +0000139#endif /* ROCKBOX_HAS_LOGF */