diff options
author | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2009-08-21 22:54:23 +0000 |
---|---|---|
committer | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2009-08-21 22:54:23 +0000 |
commit | 20b0dd2788794521ac7f3eec1065b7de99e4a5aa (patch) | |
tree | ef44f6d28e4674e6a4dda8e36187e9723186cb2e /apps | |
parent | 249392c2d33130b86e39ad36d99cc2673842e37d (diff) | |
download | rockbox-20b0dd2788794521ac7f3eec1065b7de99e4a5aa.tar.gz rockbox-20b0dd2788794521ac7f3eec1065b7de99e4a5aa.zip |
A new implementation of logf, logfdisplay and logfdump.
Flyspray: FS#10528
Author: Amaury Pouly
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22462 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/logfdisp.c | 293 |
1 files changed, 171 insertions, 122 deletions
diff --git a/apps/logfdisp.c b/apps/logfdisp.c index da711bf1d3..41cb109efd 100644 --- a/apps/logfdisp.c +++ b/apps/logfdisp.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <action.h> | 29 | #include <action.h> |
30 | 30 | ||
31 | #include <lcd.h> | 31 | #include <lcd.h> |
32 | #include <font.h> | ||
32 | #include "menu.h" | 33 | #include "menu.h" |
33 | #include "logf.h" | 34 | #include "logf.h" |
34 | #include "settings.h" | 35 | #include "settings.h" |
@@ -36,90 +37,174 @@ | |||
36 | #include "action.h" | 37 | #include "action.h" |
37 | 38 | ||
38 | #ifdef HAVE_LCD_BITMAP | 39 | #ifdef HAVE_LCD_BITMAP |
39 | bool logfdisplay(void) | 40 | int compute_nb_lines(int w, struct font* font) |
40 | { | 41 | { |
41 | int w, h; | 42 | int i, nb_lines; |
42 | int lines; | 43 | int cur_x, delta_x; |
43 | int columns; | 44 | |
44 | int i; | 45 | if(logfindex == 0 && !logfwrap) |
45 | int action; | 46 | return 0; |
46 | 47 | ||
47 | bool lcd = false; /* fixed atm */ | 48 | if(logfwrap) |
48 | int index, user_index=0; | 49 | i = logfindex; |
50 | else | ||
51 | i = 0; | ||
52 | |||
53 | cur_x = 0; | ||
54 | nb_lines = 0; | ||
55 | |||
56 | do { | ||
57 | if(logfbuffer[i] == '\0') | ||
58 | { | ||
59 | cur_x = 0; | ||
60 | nb_lines++; | ||
61 | } | ||
62 | else | ||
63 | { | ||
64 | /* does character fit on this line ? */ | ||
65 | delta_x = font_get_width(font, logfbuffer[i]); | ||
66 | |||
67 | if(cur_x + delta_x > w) | ||
68 | { | ||
69 | cur_x = 0; | ||
70 | nb_lines++; | ||
71 | } | ||
72 | |||
73 | /* update pointer */ | ||
74 | cur_x += delta_x; | ||
75 | } | ||
49 | 76 | ||
50 | lcd_getstringsize("A", &w, &h); | 77 | i++; |
51 | lines = (lcd? | 78 | if(i >= MAX_LOGF_SIZE) |
52 | #ifdef HAVE_REMOTE_LCD | 79 | i = 0; |
53 | LCD_REMOTE_HEIGHT | 80 | } while(i != logfindex); |
54 | #else | 81 | |
55 | 0 | 82 | return nb_lines; |
56 | #endif | 83 | } |
57 | :LCD_HEIGHT)/h; | ||
58 | columns = (lcd? | ||
59 | #ifdef HAVE_REMOTE_LCD | ||
60 | LCD_REMOTE_WIDTH | ||
61 | #else | ||
62 | 0 | ||
63 | #endif | ||
64 | :LCD_WIDTH)/w; | ||
65 | 84 | ||
66 | if (columns > MAX_LOGF_ENTRY+1) | 85 | bool logfdisplay(void) |
67 | columns = MAX_LOGF_ENTRY+1; | 86 | { |
68 | 87 | int action; | |
69 | if(!lines) | 88 | int w, h, i, index; |
70 | return false; | 89 | int fontnr; |
90 | int cur_x, cur_y, delta_y, delta_x; | ||
91 | struct font* font; | ||
92 | int user_index;/* user_index will be number of the first line to display (warning: line!=logf entry) */ | ||
93 | char buf[2]; | ||
94 | |||
95 | fontnr = lcd_getfont(); | ||
96 | font = font_get(fontnr); | ||
97 | |||
98 | /* get the horizontal size of each line */ | ||
99 | font_getstringsize("A", NULL, &delta_y, fontnr); | ||
100 | |||
101 | buf[1] = '\0'; | ||
102 | w = LCD_WIDTH; | ||
103 | h = LCD_HEIGHT; | ||
104 | /* start at the end of the log */ | ||
105 | user_index = compute_nb_lines(w, font) - h/delta_y -1; /* if negative, will be set 0 to zero later */ | ||
71 | 106 | ||
72 | do { | 107 | do { |
73 | lcd_clear_display(); | 108 | lcd_clear_display(); |
74 | 109 | ||
75 | index = logfindex + user_index; | 110 | if(user_index < 0) |
76 | for(i = lines-1; i>=0; i--) { | 111 | user_index = 0; |
77 | unsigned char buffer[columns + 1]; | ||
78 | |||
79 | if(--index < 0) { | ||
80 | if(logfwrap) | ||
81 | index = MAX_LOGF_LINES-1; | ||
82 | else | ||
83 | break; /* done */ | ||
84 | } | ||
85 | 112 | ||
86 | memcpy(buffer, logfbuffer[index], columns); | 113 | if(logfwrap) |
87 | if (logfbuffer[index][MAX_LOGF_ENTRY] == LOGF_TERMINATE_CONTINUE_LINE) | 114 | i = logfindex; |
88 | buffer[columns-1] = '>'; | 115 | else |
89 | else if (logfbuffer[index][MAX_LOGF_ENTRY] == LOGF_TERMINATE_MULTI_LINE) | 116 | i = 0; |
90 | buffer[columns-1] = '\0'; | ||
91 | buffer[columns] = '\0'; | ||
92 | 117 | ||
93 | lcd_puts(0, i, buffer); | 118 | index = 0; |
94 | } | 119 | cur_x = 0; |
120 | cur_y = 0; | ||
121 | |||
122 | /* nothing to print ? */ | ||
123 | if(logfindex == 0 && !logfwrap) | ||
124 | goto end_print; | ||
125 | |||
126 | do { | ||
127 | if(logfbuffer[i] == '\0') | ||
128 | { | ||
129 | /* should be display a newline ? */ | ||
130 | if(index >= user_index) | ||
131 | cur_y += delta_y; | ||
132 | cur_x = 0; | ||
133 | index++; | ||
134 | } | ||
135 | else | ||
136 | { | ||
137 | /* does character fit on this line ? */ | ||
138 | delta_x = font_get_width(font, logfbuffer[i]); | ||
139 | |||
140 | if(cur_x + delta_x > w) | ||
141 | { | ||
142 | /* should be display a newline ? */ | ||
143 | if(index >= user_index) | ||
144 | cur_y += delta_y; | ||
145 | cur_x = 0; | ||
146 | index++; | ||
147 | } | ||
148 | |||
149 | /* should we print character ? */ | ||
150 | if(index >= user_index) | ||
151 | { | ||
152 | buf[0] = logfbuffer[i]; | ||
153 | lcd_putsxy(cur_x, cur_y, buf); | ||
154 | } | ||
155 | |||
156 | /* update pointer */ | ||
157 | cur_x += delta_x; | ||
158 | } | ||
159 | |||
160 | /* did we fill the screen ? */ | ||
161 | if(cur_y > h) | ||
162 | break; | ||
163 | |||
164 | i++; | ||
165 | if(i >= MAX_LOGF_SIZE) | ||
166 | i = 0; | ||
167 | } while(i != logfindex); | ||
168 | |||
169 | end_print: | ||
95 | lcd_update(); | 170 | lcd_update(); |
96 | 171 | ||
97 | action = get_action(CONTEXT_STD, HZ); | 172 | action = get_action(CONTEXT_STD, HZ); |
98 | if(action == ACTION_STD_NEXT) | 173 | switch( action ) |
99 | user_index++; | ||
100 | else if(action == ACTION_STD_PREV) | ||
101 | user_index--; | ||
102 | else if(action == ACTION_STD_OK) | ||
103 | user_index = 0; | ||
104 | #ifdef HAVE_TOUCHSCREEN | ||
105 | else if(action == ACTION_TOUCHSCREEN) | ||
106 | { | 174 | { |
107 | short x, y; | 175 | case ACTION_STD_NEXT: |
108 | static int prev_y; | 176 | case ACTION_STD_NEXTREPEAT: |
109 | 177 | user_index++; | |
110 | action = action_get_touchscreen_press(&x, &y); | 178 | break; |
111 | 179 | case ACTION_STD_PREV: | |
112 | if(action & BUTTON_REL) | 180 | case ACTION_STD_PREVREPEAT: |
113 | prev_y = 0; | 181 | user_index--; |
114 | else | 182 | break; |
183 | case ACTION_STD_OK: | ||
184 | user_index = 0; | ||
185 | break; | ||
186 | #ifdef HAVE_TOUCHSCREEN | ||
187 | case ACTION_TOUCHSCREEN: | ||
115 | { | 188 | { |
116 | if(prev_y != 0) | 189 | short x, y; |
117 | user_index += (prev_y - y) / h; | 190 | static int prev_y; |
118 | 191 | ||
119 | prev_y = y; | 192 | action = action_get_touchscreen_press(&x, &y); |
193 | |||
194 | if(action & BUTTON_REL) | ||
195 | prev_y = 0; | ||
196 | else | ||
197 | { | ||
198 | if(prev_y != 0) | ||
199 | user_index += (prev_y - y) / delta_y; | ||
200 | |||
201 | prev_y = y; | ||
202 | } | ||
120 | } | 203 | } |
121 | } | ||
122 | #endif | 204 | #endif |
205 | default: | ||
206 | break; | ||
207 | } | ||
123 | } while(action != ACTION_STD_CANCEL); | 208 | } while(action != ACTION_STD_CANCEL); |
124 | 209 | ||
125 | return false; | 210 | return false; |
@@ -140,67 +225,31 @@ bool logfdump(void) | |||
140 | { | 225 | { |
141 | int fd; | 226 | int fd; |
142 | 227 | ||
143 | if(!logfindex && !logfwrap) | 228 | /* nothing to print ? */ |
229 | if(logfindex == 0 && !logfwrap) | ||
144 | /* nothing is logged just yet */ | 230 | /* nothing is logged just yet */ |
145 | return false; | 231 | return false; |
146 | 232 | ||
147 | fd = open(ROCKBOX_DIR "/logf.txt", O_CREAT|O_WRONLY|O_TRUNC); | 233 | fd = open(ROCKBOX_DIR "/logf.txt", O_CREAT|O_WRONLY|O_TRUNC); |
148 | if(-1 != fd) { | 234 | if(-1 != fd) { |
149 | unsigned char buffer[MAX_LOGF_ONE_LINE_SIZE +1]; | 235 | int i; |
150 | unsigned char *ptr; | 236 | |
151 | int index = logfindex-1; | 237 | if(logfwrap) |
152 | int stop = logfindex; | 238 | i = logfindex; |
153 | int tindex; | 239 | else |
154 | bool dumpwrap = false; | 240 | i = 0; |
155 | bool multiline; | 241 | |
156 | 242 | do { | |
157 | while(!dumpwrap || (index >= stop)) { | 243 | if(logfbuffer[i]=='\0') |
158 | if(index < 0) { | 244 | fdprintf(fd, "\n"); |
159 | if(logfwrap) | 245 | else |
160 | { | 246 | fdprintf(fd, "%c", logfbuffer[i]); |
161 | index = MAX_LOGF_LINES-1; | 247 | |
162 | dumpwrap = true; | 248 | i++; |
163 | } | 249 | if(i >= MAX_LOGF_SIZE) |
164 | else | 250 | i = 0; |
165 | break; /* done */ | 251 | } while(i != logfindex); |
166 | } | ||
167 | |||
168 | multiline = false; | ||
169 | if (logfbuffer[index][MAX_LOGF_ENTRY] == LOGF_TERMINATE_MULTI_LINE) | ||
170 | { | ||
171 | multiline = true; | ||
172 | do { | ||
173 | index--; | ||
174 | if(index < 0) { | ||
175 | if(logfwrap) | ||
176 | { | ||
177 | index = MAX_LOGF_LINES-1; | ||
178 | dumpwrap = true; | ||
179 | } | ||
180 | else | ||
181 | goto end_loop; | ||
182 | } | ||
183 | } while(logfbuffer[index][MAX_LOGF_ENTRY] == LOGF_TERMINATE_CONTINUE_LINE); | ||
184 | index++; | ||
185 | if (index >= MAX_LOGF_LINES) | ||
186 | index = 0; | ||
187 | } | ||
188 | |||
189 | tindex = index-1; | ||
190 | ptr = buffer; | ||
191 | do { | ||
192 | tindex++; | ||
193 | memcpy(ptr, logfbuffer[tindex], MAX_LOGF_ENTRY); | ||
194 | ptr += MAX_LOGF_ENTRY; | ||
195 | if (tindex >= MAX_LOGF_LINES) | ||
196 | tindex = 0; | ||
197 | } while(logfbuffer[tindex][MAX_LOGF_ENTRY] == LOGF_TERMINATE_CONTINUE_LINE); | ||
198 | *ptr = '\0'; | ||
199 | 252 | ||
200 | fdprintf(fd, "%s\n", buffer); | ||
201 | index--; | ||
202 | } | ||
203 | end_loop: | ||
204 | close(fd); | 253 | close(fd); |
205 | } | 254 | } |
206 | return false; | 255 | return false; |