1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Björn Stenberg
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 ****************************************************************************/
25 #include "backlight.h"
28 #ifdef HAVE_REMOTE_LCD
29 #include "lcd-remote.h"
35 #include "mp3_playback.h"
37 #if defined(HAVE_USBSTACK)
40 #include "usbstack/usb_hid.h"
50 #include "powermgmt.h"
59 #include "statusbar.h"
60 #include "screen_access.h"
66 #include "appevents.h"
67 #include "statusbar.h"
69 #ifdef HAVE_LCD_BITMAP
70 #include "bitmaps/usblogo.h"
73 #ifdef HAVE_REMOTE_LCD
74 #include "bitmaps/remote_usblogo.h"
77 #if (CONFIG_STORAGE & STORAGE_MMC)
80 #if CONFIG_CODEC == SWCODEC
84 /* only used in set_time screen */
85 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
86 static int clamp_value_wrap(int value
, int max
, int min
)
97 static int handle_usb_events(void)
99 #if (CONFIG_STORAGE & STORAGE_MMC)
101 #endif /* STORAGE_MMC */
103 #ifdef HAVE_TOUCHSCREEN
104 enum touchscreen_mode old_mode
= touchscreen_get_mode();
106 /* TODO: Paint buttons on screens OR switch to point mode and use
107 * touchscreen as a touchpad to move the host's mouse cursor */
108 touchscreen_set_mode(TOUCHSCREEN_BUTTON
);
111 /* Don't return until we get SYS_USB_DISCONNECTED or SYS_TIMEOUT */
115 #if defined(HAVE_USBSTACK) && defined(USB_ENABLE_HID)
116 bool hid_enabled
= usb_core_driver_enabled(USB_DRIVER_HID
);
120 int id
= HID_CONSUMER_USAGE_UNASSIGNED
;
121 button
= get_action(CONTEXT_USB_HID
, HZ
/2);
125 case ACTION_USB_HID_PLAY
:
126 id
= HID_CONSUMER_USAGE_PLAY_PAUSE
;
128 case ACTION_USB_HID_STOP
:
129 id
= HID_CONSUMER_USAGE_STOP
;
131 case ACTION_USB_HID_SKIPPREV
:
132 id
= HID_CONSUMER_USAGE_SCAN_PREVIOUS_TRACK
;
134 case ACTION_USB_HID_SKIPNEXT
:
135 id
= HID_CONSUMER_USAGE_SCAN_NEXT_TRACK
;
137 case ACTION_USB_HID_VOLDOWN
:
138 id
= HID_CONSUMER_USAGE_VOLUME_DECREMENT
;
140 case ACTION_USB_HID_VOLUP
:
141 id
= HID_CONSUMER_USAGE_VOLUME_INCREMENT
;
143 case ACTION_USB_HID_MUTE
:
144 id
= HID_CONSUMER_USAGE_MUTE
;
148 if (id
!= HID_CONSUMER_USAGE_UNASSIGNED
)
149 usb_hid_send(HID_USAGE_PAGE_CONSUMER
, id
);
154 button
= button_get_w_tmo(HZ
/2);
155 /* hid emits the event in get_action */
156 send_event(GUI_EVENT_ACTIONUPDATE
, NULL
);
161 case SYS_USB_DISCONNECTED
:
162 usb_acknowledge(SYS_USB_DISCONNECTED_ACK
);
168 #if (CONFIG_STORAGE & STORAGE_MMC) /* USB-MMC bridge can report activity */
169 if(TIME_AFTER(current_tick
,next_update
))
172 led(mmc_usb_active(HZ
));
174 next_update
=current_tick
+HZ
/2;
176 #endif /* STORAGE_MMC */
179 #ifdef HAVE_TOUCHSCREEN
180 touchscreen_set_mode(old_mode
);
186 void usb_screen(void)
192 int usb_bars
= VP_SB_ALLSCREENS
; /* force statusbars */
193 int old_bars
= viewportmanager_get_statusbar();
197 screens
[i
].backdrop_show(BACKDROP_MAIN
);
198 screens
[i
].backlight_on();
199 screens
[i
].clear_display();
200 #ifdef HAVE_REMOTE_LCD
201 if (i
== SCREEN_REMOTE
)
203 screens
[i
].bitmap(remote_usblogo
,
204 (LCD_REMOTE_WIDTH
-BMPWIDTH_remote_usblogo
),
205 (LCD_REMOTE_HEIGHT
-BMPHEIGHT_remote_usblogo
)/2,
206 BMPWIDTH_remote_usblogo
, BMPHEIGHT_remote_usblogo
);
211 #ifdef HAVE_LCD_BITMAP
212 screens
[i
].transparent_bitmap(usblogo
,
213 (LCD_WIDTH
-BMPWIDTH_usblogo
),
214 (LCD_HEIGHT
-BMPHEIGHT_usblogo
)/2,
215 BMPWIDTH_usblogo
, BMPHEIGHT_usblogo
);
217 screens
[i
].double_height(false);
218 screens
[i
].puts_scroll(0, 0, "[USB Mode]");
219 status_set_param(false);
220 status_set_audio(false);
221 status_set_usb(true);
222 #endif /* HAVE_LCD_BITMAP */
226 /* force statusbar by ignoring the setting */
227 usb_bars
|= VP_SB_IGNORE_SETTING(i
);
230 viewportmanager_set_statusbar(usb_bars
);
235 if (button_get_w_tmo(HZ
/2))
237 send_event(GUI_EVENT_ACTIONUPDATE
, NULL
);
240 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
241 while (handle_usb_events());
242 #endif /* SIMULATOR */
243 #ifdef HAVE_LCD_CHARCELLS
244 status_set_usb(false);
245 #endif /* HAVE_LCD_CHARCELLS */
248 screens
[i
].backlight_on();
250 viewportmanager_set_statusbar(old_bars
);
251 send_event(GUI_EVENT_REFRESH
, NULL
);
253 #endif /* USB_NONE */
256 #if (CONFIG_STORAGE & STORAGE_MMC)
257 int mmc_remove_request(void)
259 struct queue_event ev
;
262 screens
[i
].clear_display();
263 splash(0, ID2P(LANG_REMOVE_MMC
));
267 queue_wait_w_tmo(&button_queue
, &ev
, HZ
/2);
270 case SYS_HOTSWAP_EXTRACTED
:
271 return SYS_HOTSWAP_EXTRACTED
;
273 case SYS_USB_DISCONNECTED
:
274 return SYS_USB_DISCONNECTED
;
280 /* the charging screen is only used for archos targets */
281 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
283 #ifdef HAVE_LCD_BITMAP
284 static void charging_display_info(bool animate
)
286 unsigned char charging_logo
[36];
287 const int pox_x
= (LCD_WIDTH
- sizeof(charging_logo
)) / 2;
288 const int pox_y
= 32;
289 static unsigned phase
= 3;
294 #ifdef NEED_ATA_POWER_BATT_MEASURE
295 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
298 int battv
= battery_voltage();
299 snprintf(buf
, 32, " Batt: %d.%02dV %d%% ", battv
/ 1000,
300 (battv
% 1000) / 10, battery_level());
304 #ifdef ARCHOS_RECORER
305 snprintf(buf
, 32, "Charge mode:");
308 if (charge_state
== CHARGING
)
309 snprintf(buf
, 32, str(LANG_BATTERY_CHARGE
));
310 else if (charge_state
== TOPOFF
)
311 snprintf(buf
, 32, str(LANG_BATTERY_TOPOFF_CHARGE
));
312 else if (charge_state
== TRICKLE
)
313 snprintf(buf
, 32, str(LANG_BATTERY_TRICKLE_CHARGE
));
315 snprintf(buf
, 32, "not charging");
318 if (!charger_enabled())
320 #endif /* ARCHOS_RECORER */
323 memset(charging_logo
+3, 0x00, 32);
324 charging_logo
[0] = 0x3C;
325 charging_logo
[1] = 0x24;
326 charging_logo
[2] = charging_logo
[35] = 0xFF;
329 { /* draw the outline */
331 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8,
332 sizeof(charging_logo
), 8);
333 lcd_set_drawmode(DRMODE_FG
);
335 charging_logo
[0] = charging_logo
[1] = 0x00;
336 memset(charging_logo
+2, 0x80, 34);
337 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
, sizeof(charging_logo
), 8);
339 memset(charging_logo
+2, 0x01, 34);
340 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 16,
341 sizeof(charging_logo
), 8);
342 lcd_set_drawmode(DRMODE_SOLID
);
345 { /* animate the middle part */
346 for (i
= 3; i
<MIN(sizeof(charging_logo
)-1, phase
); i
++)
348 if ((i
-phase
) % 8 == 0)
349 { /* draw a "bubble" here */
351 bitpos
= (phase
+ i
/8) % 15; /* "bounce" effect */
353 bitpos
= 14 - bitpos
;
354 charging_logo
[i
] = BIT_N(bitpos
);
357 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8,
358 sizeof(charging_logo
), 8);
363 #else /* not HAVE_LCD_BITMAP */
365 static unsigned long logo_chars
[4];
366 static const unsigned char logo_pattern
[] = {
367 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
368 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
369 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
370 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
373 static void logo_lock_patterns(bool on
)
379 for (i
= 0; i
< 4; i
++)
380 logo_chars
[i
] = lcd_get_locked_pattern();
384 for (i
= 0; i
< 4; i
++)
385 lcd_unlock_pattern(logo_chars
[i
]);
389 static void charging_display_info(bool animate
)
393 static unsigned phase
= 3;
396 battv
= battery_voltage();
397 snprintf(buf
, sizeof(buf
), " %d.%02dV", battv
/ 1000, (battv
% 1000) / 10);
400 memcpy(buf
, logo_pattern
, 32); /* copy logo patterns */
402 if (!animate
) /* build the screen */
404 lcd_double_height(false);
405 lcd_puts(0, 0, "[Charging]");
406 for (i
= 0; i
< 4; i
++)
407 lcd_putc(i
, 1, logo_chars
[i
]);
409 else /* animate the logo */
411 for (i
= 3; i
< MIN(19, phase
); i
++)
413 if ((i
- phase
) % 5 == 0)
414 { /* draw a "bubble" here */
415 ypos
= (phase
+ i
/5) % 9; /* "bounce" effect */
418 buf
[5 - ypos
+ 8 * (i
/5)] |= 0x10u
>> (i
%5);
424 for (i
= 0; i
< 4; i
++)
425 lcd_define_pattern(logo_chars
[i
], buf
+ 8 * i
);
429 #endif /* (not) HAVE_LCD_BITMAP */
431 /* blocks while charging, returns on event:
432 1 if charger cable was removed
433 2 if Off/Stop key was pressed
434 3 if On key was pressed
435 4 if USB was connected */
437 int charging_screen(void)
442 ide_power_enable(false); /* power down the disk, else would be spinning */
445 backlight_set_timeout(global_settings
.backlight_timeout
);
446 #ifdef HAVE_REMOTE_LCD
447 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
449 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
451 #ifdef HAVE_LCD_CHARCELLS
452 logo_lock_patterns(true);
454 charging_display_info(false);
458 gui_syncstatusbar_draw(&statusbars
, false);
459 charging_display_info(true);
460 button
= get_action(CONTEXT_STD
,HZ
/3);
461 if (button
== ACTION_STD_OK
)
463 else if (usb_detect() == USB_INSERTED
)
465 else if (!charger_inserted())
469 #ifdef HAVE_LCD_CHARCELLS
470 logo_lock_patterns(false);
474 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
477 void charging_splash(void)
479 splash(2*HZ
, str(LANG_BATTERY_CHARGE
));
480 button_clear_queue();
485 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
487 /* little helper function for voice output */
488 static void say_time(int cursorpos
, const struct tm
*tm
)
493 if (!global_settings
.talk_menu
)
511 value
= tm
->tm_year
+ 1900;
518 if (cursorpos
== 4) /* month */
519 talk_id(LANG_MONTH_JANUARY
+ tm
->tm_mon
, false);
521 talk_value(value
, unit
, false);
528 #define SEPARATOR ":"
529 bool set_time_screen(const char* title
, struct tm
*tm
)
533 unsigned int i
, j
, s
;
535 unsigned int realyear
;
537 unsigned int min
, max
;
538 unsigned int statusbar_height
= 0;
539 unsigned int separator_width
, weekday_width
;
540 unsigned int prev_line_height
;
541 static unsigned char daysinmonth
[] =
542 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
543 unsigned char buffer
[20];
544 struct viewport vp
[NB_SCREENS
];
547 /* 6 possible cursor possitions, 2 values stored for each: x, y */
548 unsigned int cursor
[6][2];
551 unsigned char *ptr
[6];
553 if(global_settings
.statusbar
)
554 statusbar_height
= STATUSBAR_HEIGHT
;
556 /* speak selection when screen is entered */
557 say_time(cursorpos
, tm
);
560 /* for easy acess in the drawing loop */
561 ptr
[0] = buffer
; /* hours */
562 ptr
[1] = buffer
+ 3; /* minutes */
563 ptr
[2] = buffer
+ 6; /* seconds */
564 ptr
[3] = buffer
+ 9; /* year */
565 ptr
[4] = str(LANG_MONTH_JANUARY
+ tm
->tm_mon
); /* monthname */
566 ptr
[5] = buffer
+ 14; /* day of month */
568 /* calculate the number of days in febuary */
569 realyear
= tm
->tm_year
+ 1900;
570 if((realyear
% 4 == 0 && !(realyear
% 100 == 0)) || realyear
% 400 == 0)
575 /* fix day if month or year changed */
576 if (tm
->tm_mday
> daysinmonth
[tm
->tm_mon
])
577 tm
->tm_mday
= daysinmonth
[tm
->tm_mon
];
579 /* calculate day of week */
582 /* put all the numbers we want from the tm struct into
583 an easily printable buffer */
584 snprintf(buffer
, sizeof(buffer
),
585 "%02d " "%02d " "%02d " "%04d " "%02d",
586 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
,
587 tm
->tm_year
+1900, tm
->tm_mday
);
589 /* convert spaces in the buffer to '\0' to make it possible to work
590 directly on the buffer */
591 for(i
=0; i
< sizeof(buffer
); i
++)
599 viewport_set_defaults(&vp
[s
], s
);
600 screens
[s
].set_viewport(&vp
[s
]);
601 nb_lines
= viewport_get_nb_lines(&vp
[s
]);
603 /* minimum lines needed is 2 + title line */
606 vp
[s
].font
= FONT_SYSFIXED
;
607 nb_lines
= viewport_get_nb_lines(&vp
[s
]);
610 /* recalculate the positions and offsets */
612 screens
[s
].getstringsize(title
, NULL
, &prev_line_height
);
614 prev_line_height
= 0;
616 screens
[s
].getstringsize(SEPARATOR
, &separator_width
, NULL
);
619 screens
[s
].getstringsize(str(LANG_WEEKDAY_SUNDAY
+ tm
->tm_wday
),
620 &weekday_width
, NULL
);
621 screens
[s
].getstringsize(" ", &separator_width
, NULL
);
623 for(i
=0, j
=0; i
< 6; i
++)
625 if(i
==3) /* second row */
627 j
= weekday_width
+ separator_width
;
628 prev_line_height
*= 2;
630 screens
[s
].getstringsize(ptr
[i
], &width
, NULL
);
631 cursor
[i
][INDEX_Y
] = prev_line_height
+ statusbar_height
;
632 cursor
[i
][INDEX_X
] = j
;
633 j
+= width
+ separator_width
;
636 /* draw the screen */
637 screens
[s
].set_viewport(&vp
[s
]);
638 screens
[s
].clear_viewport();
639 /* display the screen title */
640 screens
[s
].puts_scroll(0, 0, title
);
642 /* these are not selectable, so we draw them outside the loop */
643 /* name of the week day */
644 screens
[s
].putsxy(0, cursor
[3][INDEX_Y
],
645 str(LANG_WEEKDAY_SUNDAY
+ tm
->tm_wday
));
647 /* draw the selected item with drawmode set to
648 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
649 items with drawmode DRMODE_SOLID */
652 if (cursorpos
== (int)i
)
653 vp
[s
].drawmode
= (DRMODE_SOLID
|DRMODE_INVERSEVID
);
655 screens
[s
].putsxy(cursor
[i
][INDEX_X
],
656 cursor
[i
][INDEX_Y
], ptr
[i
]);
658 vp
[s
].drawmode
= DRMODE_SOLID
;
660 screens
[s
].putsxy(cursor
[i
/4 +1][INDEX_X
] - separator_width
,
661 cursor
[0][INDEX_Y
], SEPARATOR
);
664 /* print help text */
666 screens
[s
].puts(0, 4, str(LANG_TIME_SET_BUTTON
));
668 screens
[s
].puts(0, 5, str(LANG_TIME_REVERT
));
669 screens
[s
].update_viewport();
670 screens
[s
].set_viewport(NULL
);
673 /* set the most common numbers */
676 /* calculate the minimum and maximum for the number under cursor */
680 valptr
= &tm
->tm_hour
;
683 valptr
= &tm
->tm_min
;
686 valptr
= &tm
->tm_sec
;
691 valptr
= &tm
->tm_year
;
695 valptr
= &tm
->tm_mon
;
699 max
= daysinmonth
[tm
->tm_mon
];
700 valptr
= &tm
->tm_mday
;
704 #ifdef HAVE_TOUCHSCREEN
705 enum touchscreen_mode old_mode
= touchscreen_get_mode();
707 touchscreen_set_mode(TOUCHSCREEN_BUTTON
);
709 button
= get_action(CONTEXT_SETTINGS_TIME
, TIMEOUT_BLOCK
);
710 #ifdef HAVE_TOUCHSCREEN
711 touchscreen_set_mode(old_mode
);
714 case ACTION_STD_PREV
:
715 cursorpos
= clamp_value_wrap(--cursorpos
, 5, 0);
716 say_time(cursorpos
, tm
);
718 case ACTION_STD_NEXT
:
719 cursorpos
= clamp_value_wrap(++cursorpos
, 5, 0);
720 say_time(cursorpos
, tm
);
722 case ACTION_SETTINGS_INC
:
723 case ACTION_SETTINGS_INCREPEAT
:
724 *valptr
= clamp_value_wrap(++(*valptr
), max
, min
);
725 say_time(cursorpos
, tm
);
727 case ACTION_SETTINGS_DEC
:
728 case ACTION_SETTINGS_DECREPEAT
:
729 *valptr
= clamp_value_wrap(--(*valptr
), max
, min
);
730 say_time(cursorpos
, tm
);
737 case ACTION_STD_CANCEL
:
743 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
750 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
752 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
753 bool shutdown_screen(void)
757 long time_entered
= current_tick
;
761 splash(0, str(LANG_CONFIRM_SHUTDOWN
));
763 while(!done
&& TIME_BEFORE(current_tick
,time_entered
+HZ
*2))
765 button
= get_action(CONTEXT_STD
,HZ
);
768 case ACTION_STD_CANCEL
:
772 /* do nothing here, because ACTION_NONE might be caused
773 * by timeout or button release. In case of timeout the loop
774 * is terminated by TIME_BEFORE */
779 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
789 static const int id3_headers
[]=
794 LANG_ID3_ALBUMARTIST
,
805 #if CONFIG_CODEC == SWCODEC
812 struct id3view_info
{
813 struct mp3entry
* id3
;
815 int info_id
[ARRAYLEN(id3_headers
)];
818 static const char* id3_get_info(int selected_item
, void* data
,
819 char *buffer
, size_t buffer_len
)
821 struct id3view_info
*info
= (struct id3view_info
*)data
;
822 struct mp3entry
* id3
=info
->id3
;
823 int info_no
=selected_item
/2;
824 if(!(selected_item
%2))
826 return(str(id3_headers
[info
->info_id
[info_no
]]));
832 switch(info
->info_id
[info_no
])
834 case 0:/*LANG_ID3_TITLE*/
837 case 1:/*LANG_ID3_ARTIST*/
840 case 2:/*LANG_ID3_ALBUM*/
843 case 3:/*LANG_ID3_ALBUMARTIST*/
844 val
=id3
->albumartist
;
846 case 4:/*LANG_ID3_GROUPING*/
849 case 5:/*LANG_ID3_DISCNUM*/
850 if (id3
->disc_string
)
851 val
= id3
->disc_string
;
852 else if (id3
->discnum
)
854 snprintf(buffer
, buffer_len
, "%d", id3
->discnum
);
858 case 6:/*LANG_ID3_TRACKNUM*/
859 if (id3
->track_string
)
860 val
= id3
->track_string
;
861 else if (id3
->tracknum
)
863 snprintf(buffer
, buffer_len
, "%d", id3
->tracknum
);
867 case 7:/*LANG_ID3_COMMENT*/
870 case 8:/*LANG_ID3_GENRE*/
871 val
= id3
->genre_string
;
873 case 9:/*LANG_ID3_YEAR*/
874 if (id3
->year_string
)
875 val
= id3
->year_string
;
878 snprintf(buffer
, buffer_len
, "%d", id3
->year
);
882 case 10:/*LANG_ID3_LENGTH*/
883 format_time(buffer
, buffer_len
, id3
->length
);
886 case 11:/*LANG_ID3_PLAYLIST*/
887 snprintf(buffer
, buffer_len
, "%d/%d",
888 playlist_get_display_index(), playlist_amount());
891 case 12:/*LANG_ID3_BITRATE*/
892 snprintf(buffer
, buffer_len
, "%d kbps%s", id3
->bitrate
,
893 id3
->vbr
? str(LANG_ID3_VBR
) : (const unsigned char*) "");
896 case 13:/*LANG_ID3_FREQUENCY*/
897 snprintf(buffer
, buffer_len
, "%ld Hz", id3
->frequency
);
900 #if CONFIG_CODEC == SWCODEC
901 case 14:/*LANG_ID3_TRACK_GAIN*/
902 val
=id3
->track_gain_string
;
904 case 15:/*LANG_ID3_ALBUM_GAIN*/
905 val
=id3
->album_gain_string
;
907 case 16:/*LANG_ID3_PATH*/
909 case 14:/*LANG_ID3_PATH*/
914 return val
&& *val
? val
: NULL
;
918 bool browse_id3(void)
920 struct gui_synclist id3_lists
;
921 struct mp3entry
* id3
= audio_current_track();
924 struct id3view_info info
;
927 for (i
= 0; i
< ARRAYLEN(id3_headers
); i
++)
931 if (id3_get_info((i
*2)+1, &info
, temp
, 8) != NULL
)
932 info
.info_id
[info
.count
++] = i
;
935 gui_synclist_init(&id3_lists
, &id3_get_info
, &info
, true, 2, NULL
);
936 gui_synclist_set_nb_items(&id3_lists
, info
.count
*2);
937 gui_synclist_draw(&id3_lists
);
939 key
= get_action(CONTEXT_LIST
,HZ
/2);
940 if(key
!=ACTION_NONE
&& key
!=ACTION_UNKNOWN
941 && !gui_synclist_do_button(&id3_lists
, &key
,LIST_WRAP_UNLESS_HELD
))
943 return(default_event_handler(key
) == SYS_USB_CONNECTED
);
948 static const char* runtime_get_data(int selected_item
, void* data
,
949 char* buffer
, size_t buffer_len
)
953 switch (selected_item
)
955 case 0: return str(LANG_RUNNING_TIME
);
956 case 1: t
= global_status
.runtime
; break;
957 case 2: return str(LANG_TOP_TIME
);
958 case 3: t
= global_status
.topruntime
; break;
963 snprintf(buffer
, buffer_len
, "%dh %dm %ds",
964 t
/ 3600, (t
% 3600) / 60, t
% 60);
968 static int runtime_speak_data(int selected_item
, void* data
)
972 (selected_item
< 2) ? LANG_RUNNING_TIME
: LANG_TOP_TIME
,
973 TALK_ID((selected_item
< 2) ? global_status
.runtime
974 : global_status
.topruntime
, UNIT_TIME
));
979 bool view_runtime(void)
981 static const char *lines
[]={ID2P(LANG_CLEAR_TIME
)};
982 static const struct text_message message
={lines
, 1};
984 struct gui_synclist lists
;
986 gui_synclist_init(&lists
, runtime_get_data
, NULL
, false, 2, NULL
);
987 #if !defined(HAVE_LCD_CHARCELLS)
988 gui_synclist_set_title(&lists
, str(LANG_RUNNING_TIME
), NOICON
);
990 gui_synclist_set_title(&lists
, NULL
, NOICON
);
992 if(global_settings
.talk_menu
)
993 gui_synclist_set_voice_callback(&lists
, runtime_speak_data
);
994 gui_synclist_set_icon_callback(&lists
, NULL
);
995 gui_synclist_set_nb_items(&lists
, 4);
996 gui_synclist_speak_item(&lists
);
1000 if (charger_inserted())
1002 global_status
.runtime
= 0;
1007 global_status
.runtime
+= ((current_tick
- lasttime
) / HZ
);
1009 lasttime
= current_tick
;
1010 gui_synclist_draw(&lists
);
1011 list_do_action(CONTEXT_STD
, HZ
,
1012 &lists
, &action
, LIST_WRAP_UNLESS_HELD
);
1013 if(action
== ACTION_STD_CANCEL
)
1015 if(action
== ACTION_STD_OK
) {
1016 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
1018 if (!(gui_synclist_get_sel_pos(&lists
)/2))
1019 global_status
.runtime
= 0;
1021 global_status
.topruntime
= 0;
1022 gui_synclist_speak_item(&lists
);
1025 if(default_event_handler(action
) == SYS_USB_CONNECTED
)
1031 #ifdef HAVE_TOUCHSCREEN
1032 static int get_sample(struct touchscreen_calibration
*cal
, int x
, int y
, int i
,
1033 struct screen
* screen
)
1039 screen
->drawline(x
- 10, y
, x
- 2, y
);
1040 screen
->drawline(x
+ 2, y
, x
+ 10, y
);
1041 screen
->drawline(x
, y
- 10, x
, y
- 2);
1042 screen
->drawline(x
, y
+ 2, x
, y
+ 10);
1045 /* Wait for a touchscreen press */
1048 action
= get_action(CONTEXT_STD
, TIMEOUT_BLOCK
);
1049 if(action
== ACTION_TOUCHSCREEN
)
1051 if(action_get_touchscreen_press(&ts_x
, &ts_y
) == BUTTON_REL
)
1054 else if(action
== ACTION_STD_CANCEL
)
1058 cal
->x
[i
][0] = ts_x
;
1059 cal
->y
[i
][0] = ts_y
;
1069 short points
[3][2] = {
1070 {LCD_WIDTH
/10, LCD_HEIGHT
/10},
1071 {7*LCD_WIDTH
/8, LCD_HEIGHT
/2},
1072 {LCD_WIDTH
/2, 7*LCD_HEIGHT
/8}
1074 struct screen
* screen
= &screens
[SCREEN_MAIN
];
1075 enum touchscreen_mode old_mode
= touchscreen_get_mode();
1076 struct touchscreen_calibration cal
;
1078 int statusbar
= global_settings
.statusbar
; /* hide the statusbar */
1079 global_settings
.statusbar
= STATUSBAR_OFF
;
1081 touchscreen_disable_mapping(); /* set raw mode */
1082 touchscreen_set_mode(TOUCHSCREEN_POINT
);
1085 screen
->clear_display();
1087 if(get_sample(&cal
, points
[i
][0], points
[i
][1], i
, screen
))
1095 touchscreen_calibrate(&cal
);
1097 touchscreen_reset_mapping();
1098 memcpy(&global_settings
.ts_calibration_data
, &calibration_parameters
, sizeof(struct touchscreen_parameter
));
1099 touchscreen_set_mode(old_mode
);
1100 global_settings
.statusbar
= statusbar
;
1105 int reset_mapping(void)
1107 touchscreen_reset_mapping();
1108 memcpy(&global_settings
.ts_calibration_data
, &calibration_parameters
, sizeof(struct touchscreen_parameter
));