summaryrefslogtreecommitdiff
path: root/apps/status.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/status.c')
-rw-r--r--apps/status.c278
1 files changed, 2 insertions, 276 deletions
diff --git a/apps/status.c b/apps/status.c
index 00f8c5e1fe..e678c76674 100644
--- a/apps/status.c
+++ b/apps/status.c
@@ -28,6 +28,7 @@
28#include "audio.h" 28#include "audio.h"
29#include "gwps.h" 29#include "gwps.h"
30#include "abrepeat.h" 30#include "abrepeat.h"
31#include "statusbar.h"
31#ifdef HAVE_RTC 32#ifdef HAVE_RTC
32#include "timefuncs.h" 33#include "timefuncs.h"
33#endif 34#endif
@@ -54,27 +55,6 @@ bool battery_state = true;
54int battery_charge_step = 0; 55int battery_charge_step = 0;
55#endif 56#endif
56 57
57struct status_info {
58 int battlevel;
59 int volume;
60 int hour;
61 int minute;
62 int playmode;
63 int repeat;
64 bool inserted;
65 bool shuffle;
66 bool keylock;
67 bool battery_safe;
68 bool redraw_volume; /* true if the volume gauge needs updating */
69#if CONFIG_LED == LED_VIRTUAL
70 bool led; /* disk LED simulation in the status bar */
71#endif
72#ifdef HAVE_USB_POWER
73 bool usb_power;
74#endif
75
76};
77
78void status_init(void) 58void status_init(void)
79{ 59{
80 ff_mode = 0; 60 ff_mode = 0;
@@ -83,7 +63,7 @@ void status_init(void)
83void status_set_ffmode(enum playmode mode) 63void status_set_ffmode(enum playmode mode)
84{ 64{
85 ff_mode = mode; /* Either STATUS_FASTFORWARD or STATUS_FASTBACKWARD */ 65 ff_mode = mode; /* Either STATUS_FASTFORWARD or STATUS_FASTBACKWARD */
86 status_draw(false); 66 gui_syncstatusbar_draw(&statusbars, false);
87} 67}
88 68
89enum playmode status_get_ffmode(void) 69enum playmode status_get_ffmode(void)
@@ -162,257 +142,3 @@ void status_set_usb(bool b)
162} 142}
163 143
164#endif /* HAVE_LCD_CHARCELLS */ 144#endif /* HAVE_LCD_CHARCELLS */
165
166void status_draw(bool force_redraw)
167{
168 /* This is static because we use memcmp() below to check for changes, and
169 the unused bytes (due to struct member alignment) might change if
170 the struct is allocated on the stack. */
171 static struct status_info info;
172
173#ifdef HAVE_LCD_BITMAP
174 static struct status_info lastinfo;
175 struct tm* tm;
176
177 if ( !global_settings.statusbar )
178 return;
179#else
180 (void)force_redraw; /* players always "redraw" */
181#endif
182
183 info.volume = sound_val2phys(SOUND_VOLUME, global_settings.volume);
184 info.inserted = charger_inserted();
185 info.battlevel = battery_level();
186 info.battery_safe = battery_level_safe();
187
188#ifdef HAVE_LCD_BITMAP
189 tm = get_time();
190 info.hour = tm->tm_hour;
191 info.minute = tm->tm_min;
192 info.shuffle = global_settings.playlist_shuffle;
193#if CONFIG_KEYPAD == IRIVER_H100_PAD
194 info.keylock = button_hold();
195#else
196 info.keylock = keys_locked;
197#endif
198 info.repeat = global_settings.repeat_mode;
199 info.playmode = current_playmode();
200#if CONFIG_LED == LED_VIRTUAL
201 info.led = led_read(HZ/2); /* delay should match polling interval */
202#endif
203#ifdef HAVE_USB_POWER
204 info.usb_power = usb_powered();
205#endif
206
207 /* only redraw if forced to, or info has changed */
208 if (force_redraw ||
209 info.inserted ||
210 !info.battery_safe ||
211 info.redraw_volume ||
212 memcmp(&info, &lastinfo, sizeof(struct status_info)))
213 {
214 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
215 lcd_fillrect(0,0,LCD_WIDTH,8);
216 lcd_set_drawmode(DRMODE_SOLID);
217#else
218 /* players always "redraw" */
219 {
220#endif
221
222#ifdef HAVE_CHARGING
223 if (info.inserted) {
224 battery_state = true;
225#if defined(HAVE_CHARGE_CTRL) || CONFIG_BATTERY == BATT_LIION2200
226 /* zero battery run time if charging */
227 if (charge_state > 0) {
228 global_settings.runtime = 0;
229 lasttime = current_tick;
230 }
231
232 /* animate battery if charging */
233 if ((charge_state == 1) ||
234 (charge_state == 2)) {
235#else
236 global_settings.runtime = 0;
237 lasttime = current_tick;
238 {
239#endif
240 /* animate in three steps (34% per step for a better look) */
241 info.battlevel = battery_charge_step * 34;
242 if (info.battlevel > 100)
243 info.battlevel = 100;
244 if(TIME_AFTER(current_tick, switch_tick)) {
245 battery_charge_step=(battery_charge_step+1)%4;
246 switch_tick = current_tick + HZ;
247 }
248 }
249 }
250 else
251#endif /* HAVE_CHARGING */
252 {
253 if (info.battery_safe)
254 battery_state = true;
255 else {
256 /* blink battery if level is low */
257 if(TIME_AFTER(current_tick, switch_tick) &&
258 (info.battlevel > -1)) {
259 switch_tick = current_tick+HZ;
260 battery_state =! battery_state;
261 }
262 }
263 }
264
265#ifdef HAVE_LCD_BITMAP
266 if (battery_state)
267 statusbar_icon_battery(info.battlevel);
268
269 /* draw power plug if charging */
270 if (info.inserted)
271 lcd_mono_bitmap(bitmap_icons_7x8[Icon_Plug], ICON_PLUG_X_POS,
272 STATUSBAR_Y_POS, ICON_PLUG_WIDTH, STATUSBAR_HEIGHT);
273#ifdef HAVE_USB_POWER
274 else if (info.usb_power)
275 lcd_mono_bitmap(bitmap_icons_7x8[Icon_USBPlug], ICON_PLUG_X_POS,
276 STATUSBAR_Y_POS, ICON_PLUG_WIDTH, STATUSBAR_HEIGHT);
277#endif
278
279 info.redraw_volume = statusbar_icon_volume(info.volume);
280 statusbar_icon_play_state(current_playmode() + Icon_Play);
281 switch (info.repeat) {
282#ifdef AB_REPEAT_ENABLE
283 case REPEAT_AB:
284 statusbar_icon_play_mode(Icon_RepeatAB);
285 break;
286#endif
287
288 case REPEAT_ONE:
289 statusbar_icon_play_mode(Icon_RepeatOne);
290 break;
291
292 case REPEAT_ALL:
293 case REPEAT_SHUFFLE:
294 statusbar_icon_play_mode(Icon_Repeat);
295 break;
296 }
297 if (info.shuffle)
298 statusbar_icon_shuffle();
299 if (info.keylock)
300 statusbar_icon_lock();
301#ifdef HAVE_RTC
302 statusbar_time(info.hour, info.minute);
303#endif
304#if CONFIG_LED == LED_VIRTUAL
305 if (info.led)
306 statusbar_led();
307#endif
308 lcd_update_rect(0, 0, LCD_WIDTH, STATUSBAR_HEIGHT);
309 lastinfo = info;
310#endif
311 }
312
313
314#if defined(HAVE_LCD_CHARCELLS)
315 if (info.battlevel > -1)
316 lcd_icon(ICON_BATTERY, battery_state);
317 lcd_icon(ICON_BATTERY_1, info.battlevel > 25);
318 lcd_icon(ICON_BATTERY_2, info.battlevel > 50);
319 lcd_icon(ICON_BATTERY_3, info.battlevel > 75);
320
321 lcd_icon(ICON_VOLUME, true);
322 lcd_icon(ICON_VOLUME_1, info.volume > 10);
323 lcd_icon(ICON_VOLUME_2, info.volume > 30);
324 lcd_icon(ICON_VOLUME_3, info.volume > 50);
325 lcd_icon(ICON_VOLUME_4, info.volume > 70);
326 lcd_icon(ICON_VOLUME_5, info.volume > 90);
327
328 lcd_icon(ICON_PLAY, current_playmode() == STATUS_PLAY);
329 lcd_icon(ICON_PAUSE, current_playmode() == STATUS_PAUSE);
330
331 lcd_icon(ICON_REPEAT, global_settings.repeat_mode != REPEAT_OFF);
332 lcd_icon(ICON_1, global_settings.repeat_mode == REPEAT_ONE);
333
334 lcd_icon(ICON_RECORD, record);
335 lcd_icon(ICON_AUDIO, audio);
336 lcd_icon(ICON_PARAM, param);
337 lcd_icon(ICON_USB, usb);
338#endif
339
340}
341
342#if defined(HAVE_LCD_BITMAP) && (CONFIG_KEYPAD == RECORDER_PAD)
343static void draw_buttonbar_btn(int num, const char* caption)
344{
345 int xpos, ypos, button_width, text_width;
346 int fw, fh;
347
348 lcd_setfont(FONT_SYSFIXED);
349 lcd_getstringsize("M", &fw, &fh);
350
351 button_width = LCD_WIDTH/3;
352 xpos = num * button_width;
353 ypos = LCD_HEIGHT - fh;
354
355 if(caption)
356 {
357 /* center the text */
358 text_width = fw * strlen(caption);
359 lcd_putsxy(xpos + (button_width - text_width)/2, ypos, caption);
360 }
361
362 lcd_set_drawmode(DRMODE_COMPLEMENT);
363 lcd_fillrect(xpos, ypos, button_width - 1, fh);
364 lcd_set_drawmode(DRMODE_SOLID);
365}
366
367static char stored_caption1[8];
368static char stored_caption2[8];
369static char stored_caption3[8];
370
371void buttonbar_set(const char* caption1, const char *caption2,
372 const char *caption3)
373{
374 buttonbar_unset();
375 if(caption1)
376 {
377 strncpy(stored_caption1, caption1, 7);
378 stored_caption1[7] = 0;
379 }
380 if(caption2)
381 {
382 strncpy(stored_caption2, caption2, 7);
383 stored_caption2[7] = 0;
384 }
385 if(caption3)
386 {
387 strncpy(stored_caption3, caption3, 7);
388 stored_caption3[7] = 0;
389 }
390}
391
392void buttonbar_unset(void)
393{
394 stored_caption1[0] = 0;
395 stored_caption2[0] = 0;
396 stored_caption3[0] = 0;
397}
398
399void buttonbar_draw(void)
400{
401 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
402 lcd_fillrect(0, LCD_HEIGHT-8, LCD_WIDTH, 8);
403 lcd_set_drawmode(DRMODE_SOLID);
404 draw_buttonbar_btn(0, stored_caption1);
405 draw_buttonbar_btn(1, stored_caption2);
406 draw_buttonbar_btn(2, stored_caption3);
407}
408
409bool buttonbar_isset(void)
410{
411 /* If all buttons are unset, the button bar is considered disabled */
412 return (global_settings.buttonbar &&
413 ((stored_caption1[0] != 0) ||
414 (stored_caption2[0] != 0) ||
415 (stored_caption3[0] != 0)));
416}
417
418#endif