Use the AMS_LOWMEM define to indicate memory size as the .lds files do in config...
[kugel-rb.git] / apps / plugins / stats.c
blob976fd262f86f387e64a029ab6c8b5b0b350e7a99
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 Jonas Haggqvist
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "plugin.h"
23 PLUGIN_HEADER
25 static int files, dirs, musicfiles, largestdir;
26 static int lasttick;
27 static bool abort;
29 #if CONFIG_KEYPAD == PLAYER_PAD
30 #define STATS_STOP BUTTON_STOP
32 #elif (CONFIG_KEYPAD == RECORDER_PAD) \
33 || (CONFIG_KEYPAD == ONDIO_PAD) \
34 || (CONFIG_KEYPAD == ARCHOS_AV300_PAD)
35 #define STATS_STOP BUTTON_OFF
37 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) \
38 || (CONFIG_KEYPAD == IRIVER_H300_PAD)
39 #define STATS_STOP BUTTON_OFF
40 #define STATS_STOP_REMOTE BUTTON_RC_STOP
42 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
43 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
44 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
45 #define STATS_STOP BUTTON_MENU
47 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
48 #define STATS_STOP BUTTON_PLAY
50 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
51 #define STATS_STOP BUTTON_POWER
52 #define STATS_STOP_REMOTE BUTTON_RC_PLAY
54 #elif CONFIG_KEYPAD == GIGABEAT_PAD
55 #define STATS_STOP BUTTON_POWER
57 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
58 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
59 (CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
60 (CONFIG_KEYPAD == SANSA_M200_PAD)
61 #define STATS_STOP BUTTON_POWER
63 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
64 #define STATS_STOP BUTTON_HOME
66 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
67 #define STATS_STOP BUTTON_POWER
69 #elif CONFIG_KEYPAD == MROBE500_PAD
70 #define STATS_STOP BUTTON_POWER
71 #define STATS_STOP_REMOTE BUTTON_RC_DOWN
73 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
74 #define STATS_STOP BUTTON_BACK
76 #elif CONFIG_KEYPAD == MROBE100_PAD
77 #define STATS_STOP BUTTON_POWER
79 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
80 #define STATS_STOP BUTTON_REC
81 #define STATS_STOP_REMOTE BUTTON_RC_REC
83 #elif CONFIG_KEYPAD == COWOND2_PAD
84 #define STATS_STOP BUTTON_POWER
86 #elif CONFIG_KEYPAD == IAUDIO67_PAD
87 #define STATS_STOP BUTTON_POWER
89 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
90 #define STATS_STOP BUTTON_BACK
92 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
93 #define STATS_STOP BUTTON_POWER
95 #elif CONFIG_KEYPAD == ONDAVX747_PAD
96 #define STATS_STOP BUTTON_POWER
98 #else
99 #error No keymap defined!
100 #endif
102 /* TODO: Better get the exts from the filetypes var in tree.c */
103 const char *music_exts[] = {"mp3","mp2","mp1","mpa","ogg",
104 "wav","flac","ac3","a52","mpc","wv","m4a","m4b","mp4",
105 "shn","aif","aiff","wma","wmv","spx","ape","adx",
106 "sid","mod","nsf","nsfe","spc","asf","mac"};
108 void prn(const char *str, int y)
110 rb->lcd_puts(0,y,str);
111 #ifdef HAVE_REMOTE_LCD
112 rb->lcd_remote_puts(0,y,str);
113 #endif
116 void update_screen(void)
118 char buf[32];
120 rb->lcd_clear_display();
121 #ifdef HAVE_REMOTE_LCD
122 rb->lcd_remote_clear_display();
123 #endif
125 #ifdef HAVE_LCD_BITMAP
126 rb->snprintf(buf, sizeof(buf), "Files: %d", files);
127 prn(buf,0);
128 rb->snprintf(buf, sizeof(buf), "Music: %d", musicfiles);
129 prn(buf,1);
130 rb->snprintf(buf, sizeof(buf), "Dirs: %d", dirs);
131 prn(buf,2);
132 rb->snprintf(buf, sizeof(buf), "Max files in Dir: %d", largestdir);
133 prn(buf,3);
134 #else
135 rb->snprintf(buf, sizeof(buf), "Files:%5d", files);
136 prn(buf,0);
137 rb->snprintf(buf, sizeof(buf), "Dirs: %5d", dirs);
138 prn(buf,1);
139 #endif
141 rb->lcd_update();
142 #ifdef HAVE_REMOTE_LCD
143 rb->lcd_remote_update();
144 #endif
147 void traversedir(char* location, char* name)
149 int button;
150 struct dirent *entry;
151 DIR* dir;
152 char fullpath[MAX_PATH];
153 int files_in_dir = 0;
155 rb->snprintf(fullpath, sizeof(fullpath), "%s/%s", location, name);
156 dir = rb->opendir(fullpath);
157 if (dir) {
158 entry = rb->readdir(dir);
159 while (entry) {
160 if (abort == true)
161 break;
162 /* Skip .. and . */
163 if (rb->strcmp(entry->d_name, ".") && rb->strcmp(entry->d_name, ".."))
165 if (entry->attribute & ATTR_DIRECTORY) {
166 traversedir(fullpath, entry->d_name);
167 dirs++;
169 else {
170 char *ptr = rb->strrchr(entry->d_name,'.');
171 files++; files_in_dir++;
172 /* Might want to only count .mp3, .ogg etc. */
173 if(ptr){
174 unsigned i;
175 ptr++;
176 for(i=0;i<sizeof(music_exts)/sizeof(char*);i++)
177 if(!rb->strcasecmp(ptr,music_exts[i])){
178 musicfiles++; break;
184 if (*rb->current_tick - lasttick > (HZ/2)) {
185 update_screen();
186 lasttick = *rb->current_tick;
187 button = rb->button_get(false);
188 if (button == STATS_STOP
189 #ifdef HAVE_REMOTE_LCD
190 || button == STATS_STOP_REMOTE
191 #endif
193 abort = true;
194 break;
198 entry = rb->readdir(dir);
200 rb->closedir(dir);
202 if (largestdir < files_in_dir)
203 largestdir = files_in_dir;
206 enum plugin_status plugin_start(const void* parameter)
208 int button;
210 (void)parameter;
212 files = 0;
213 dirs = 0;
214 musicfiles = 0;
215 largestdir = 0;
216 abort = false;
218 rb->splash(HZ, "Counting...");
219 update_screen();
220 lasttick = *rb->current_tick;
222 traversedir("", "");
223 if (abort == true) {
224 rb->splash(HZ, "Aborted");
225 return PLUGIN_OK;
227 update_screen();
228 #ifdef HAVE_REMOTE_LCD
229 rb->remote_backlight_on();
230 #endif
231 rb->backlight_on();
232 rb->splash(HZ, "Done");
233 update_screen();
234 while (1) {
235 button = rb->button_get(true);
236 switch (button) {
237 #ifdef HAVE_REMOTE_LCD
238 case STATS_STOP_REMOTE:
239 #endif
240 case STATS_STOP:
241 return PLUGIN_OK;
242 break;
243 default:
244 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) {
245 return PLUGIN_USB_CONNECTED;
247 break;
250 return PLUGIN_OK;