Daniel Stenberg | e2c4a6c | 2005-05-24 14:26:23 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2005 Daniel Stenberg |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 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. |
Daniel Stenberg | e2c4a6c | 2005-05-24 14:26:23 +0000 | [diff] [blame] | 16 | * |
| 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 Stenberg | edc0792 | 2005-05-30 13:00:43 +0000 | [diff] [blame] | 22 | |
| 23 | #ifdef ROCKBOX_HAS_LOGF |
Daniel Stenberg | c95319f | 2005-06-01 13:07:37 +0000 | [diff] [blame] | 24 | #include <file.h> |
| 25 | #include <sprintf.h> |
Daniel Stenberg | e2c4a6c | 2005-05-24 14:26:23 +0000 | [diff] [blame] | 26 | #include <timefuncs.h> |
| 27 | #include <string.h> |
| 28 | #include <kernel.h> |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 29 | #include <action.h> |
Daniel Stenberg | e2c4a6c | 2005-05-24 14:26:23 +0000 | [diff] [blame] | 30 | |
| 31 | #include <lcd.h> |
| 32 | #include "menu.h" |
| 33 | #include "logf.h" |
Barry Wardell | d727f5d | 2007-09-10 19:29:53 +0000 | [diff] [blame] | 34 | #include "settings.h" |
Bertrik Sikken | a5d3029 | 2008-04-28 10:22:05 +0000 | [diff] [blame] | 35 | #include "logfdisp.h" |
Daniel Stenberg | e2c4a6c | 2005-05-24 14:26:23 +0000 | [diff] [blame] | 36 | |
| 37 | #ifdef HAVE_LCD_BITMAP |
| 38 | bool logfdisplay(void) |
| 39 | |
| 40 | { |
| 41 | int w, h; |
| 42 | int lines; |
Michiel Van Der Kolk | 65ff219 | 2005-06-30 15:14:08 +0000 | [diff] [blame] | 43 | int columns; |
Daniel Stenberg | e2c4a6c | 2005-05-24 14:26:23 +0000 | [diff] [blame] | 44 | int i; |
Daniel Stenberg | e2c4a6c | 2005-05-24 14:26:23 +0000 | [diff] [blame] | 45 | |
| 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 Kolk | 65ff219 | 2005-06-30 15:14:08 +0000 | [diff] [blame] | 57 | columns = (lcd? |
| 58 | #ifdef HAVE_REMOTE_LCD |
| 59 | LCD_REMOTE_WIDTH |
| 60 | #else |
| 61 | 0 |
| 62 | #endif |
| 63 | :LCD_WIDTH)/w; |
Brandon Low | 16ee416 | 2006-04-11 22:19:47 +0000 | [diff] [blame] | 64 | |
| 65 | if (columns > MAX_LOGF_ENTRY) |
| 66 | columns = MAX_LOGF_ENTRY; |
Michiel Van Der Kolk | 65ff219 | 2005-06-30 15:14:08 +0000 | [diff] [blame] | 67 | |
Daniel Stenberg | e2c4a6c | 2005-05-24 14:26:23 +0000 | [diff] [blame] | 68 | if(!lines) |
| 69 | return false; |
| 70 | |
Daniel Stenberg | e2c4a6c | 2005-05-24 14:26:23 +0000 | [diff] [blame] | 71 | lcd_clear_display(); |
| 72 | |
| 73 | do { |
| 74 | index = logfindex; |
| 75 | for(i = lines-1; i>=0; i--) { |
Michiel Van Der Kolk | 65ff219 | 2005-06-30 15:14:08 +0000 | [diff] [blame] | 76 | unsigned char buffer[columns + 1]; |
Daniel Stenberg | e2c4a6c | 2005-05-24 14:26:23 +0000 | [diff] [blame] | 77 | |
| 78 | if(--index < 0) { |
| 79 | if(logfwrap) |
| 80 | index = MAX_LOGF_LINES-1; |
| 81 | else |
| 82 | break; /* done */ |
| 83 | } |
| 84 | |
Michiel Van Der Kolk | 65ff219 | 2005-06-30 15:14:08 +0000 | [diff] [blame] | 85 | memcpy(buffer, logfbuffer[index], columns); |
| 86 | buffer[columns]=0; |
Daniel Stenberg | e2c4a6c | 2005-05-24 14:26:23 +0000 | [diff] [blame] | 87 | lcd_puts(0, i, buffer); |
| 88 | } |
| 89 | lcd_update(); |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 90 | } while(!action_userabort(HZ)); |
Daniel Stenberg | e2c4a6c | 2005-05-24 14:26:23 +0000 | [diff] [blame] | 91 | |
| 92 | return false; |
| 93 | } |
Daniel Stenberg | edc0792 | 2005-05-30 13:00:43 +0000 | [diff] [blame] | 94 | #else /* HAVE_LCD_BITMAP */ |
| 95 | bool logfdisplay(void) |
| 96 | |
| 97 | { |
| 98 | /* TODO: implement a browser for charcell bitmaps */ |
| 99 | return false; |
| 100 | } |
| 101 | #endif /* HAVE_LCD_BITMAP */ |
| 102 | |
Daniel Stenberg | c95319f | 2005-06-01 13:07:37 +0000 | [diff] [blame] | 103 | /* 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 */ |
| 106 | bool logfdump(void) |
| 107 | { |
| 108 | int fd; |
| 109 | |
| 110 | if(!logfindex && !logfwrap) |
| 111 | /* nothing is logged just yet */ |
| 112 | return false; |
| 113 | |
Nils Wallménius | 04b3435 | 2007-09-10 09:46:36 +0000 | [diff] [blame] | 114 | fd = open(ROCKBOX_DIR "/logf.txt", O_CREAT|O_WRONLY|O_TRUNC); |
Daniel Stenberg | c95319f | 2005-06-01 13:07:37 +0000 | [diff] [blame] | 115 | if(-1 != fd) { |
Daniel Stenberg | 6ebdbe8 | 2005-06-01 13:21:20 +0000 | [diff] [blame] | 116 | unsigned char buffer[MAX_LOGF_ENTRY +1]; |
Daniel Stenberg | c95319f | 2005-06-01 13:07:37 +0000 | [diff] [blame] | 117 | 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 Stenberg | 6ebdbe8 | 2005-06-01 13:21:20 +0000 | [diff] [blame] | 129 | memcpy(buffer, logfbuffer[index], MAX_LOGF_ENTRY); |
| 130 | buffer[MAX_LOGF_ENTRY]=0; |
Daniel Stenberg | c95319f | 2005-06-01 13:07:37 +0000 | [diff] [blame] | 131 | fdprintf(fd, "%s\n", buffer); |
| 132 | index--; |
| 133 | } |
| 134 | close(fd); |
| 135 | } |
| 136 | return false; |
| 137 | } |
| 138 | |
Daniel Stenberg | edc0792 | 2005-05-30 13:00:43 +0000 | [diff] [blame] | 139 | #endif /* ROCKBOX_HAS_LOGF */ |