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"
67 #ifdef HAVE_LCD_BITMAP
68 #include "bitmaps/usblogo.h"
71 #ifdef HAVE_REMOTE_LCD
72 #include "bitmaps/remote_usblogo.h"
75 #if (CONFIG_STORAGE & STORAGE_MMC)
78 #if CONFIG_CODEC == SWCODEC
82 /* only used in set_time screen */
83 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
84 static int clamp_value_wrap(int value
, int max
, int min
)
95 static int handle_usb_events(void)
98 #ifdef HAVE_TOUCHSCREEN
99 enum touchscreen_mode old_mode
= touchscreen_get_mode();
101 /* TODO: Paint buttons on screens OR switch to point mode and use
102 * touchscreen as a touchpad to move the host's mouse cursor */
103 touchscreen_set_mode(TOUCHSCREEN_BUTTON
);
106 /* Don't return until we get SYS_USB_DISCONNECTED or SYS_TIMEOUT */
110 #if defined(HAVE_USBSTACK) && defined(USB_ENABLE_HID)
111 bool hid_enabled
= usb_core_driver_enabled(USB_DRIVER_HID
);
115 int id
= HID_CONSUMER_USAGE_UNASSIGNED
;
116 button
= get_action(CONTEXT_USB_HID
, HZ
/4);
120 case ACTION_USB_HID_PLAY
:
121 id
= HID_CONSUMER_USAGE_PLAY_PAUSE
;
123 case ACTION_USB_HID_STOP
:
124 id
= HID_CONSUMER_USAGE_STOP
;
126 case ACTION_USB_HID_SKIPPREV
:
127 id
= HID_CONSUMER_USAGE_SCAN_PREVIOUS_TRACK
;
129 case ACTION_USB_HID_SKIPNEXT
:
130 id
= HID_CONSUMER_USAGE_SCAN_NEXT_TRACK
;
132 case ACTION_USB_HID_VOLDOWN
:
133 id
= HID_CONSUMER_USAGE_VOLUME_DECREMENT
;
135 case ACTION_USB_HID_VOLUP
:
136 id
= HID_CONSUMER_USAGE_VOLUME_INCREMENT
;
138 case ACTION_USB_HID_MUTE
:
139 id
= HID_CONSUMER_USAGE_MUTE
;
143 if (id
!= HID_CONSUMER_USAGE_UNASSIGNED
)
144 usb_hid_send(HID_USAGE_PAGE_CONSUMER
, id
);
148 button
= button_get_w_tmo(HZ
/4);
152 case SYS_USB_DISCONNECTED
:
153 usb_acknowledge(SYS_USB_DISCONNECTED_ACK
);
159 if(TIME_AFTER(current_tick
,next_update
))
162 #if (CONFIG_STORAGE & STORAGE_MMC) /* USB-MMC bridge can report activity */
163 led(mmc_usb_active(HZ
));
164 #endif /* STORAGE_MMC */
165 gui_syncstatusbar_draw(&statusbars
, false);
167 next_update
=current_tick
+HZ
/2;
171 #ifdef HAVE_TOUCHSCREEN
172 touchscreen_set_mode(old_mode
);
178 void usb_screen(void)
184 bool statusbar
= global_settings
.statusbar
; /* force the statusbar */
185 global_settings
.statusbar
= true;
188 screens
[i
].backdrop_show(BACKDROP_MAIN
);
189 screens
[i
].backlight_on();
190 screens
[i
].clear_display();
192 if (i
== SCREEN_REMOTE
)
194 screens
[i
].bitmap(remote_usblogo
,
195 (LCD_REMOTE_WIDTH
-BMPWIDTH_remote_usblogo
),
196 (LCD_REMOTE_HEIGHT
-BMPHEIGHT_remote_usblogo
)/2,
197 BMPWIDTH_remote_usblogo
, BMPHEIGHT_remote_usblogo
);
202 #ifdef HAVE_LCD_BITMAP
203 screens
[i
].transparent_bitmap(usblogo
,
204 (LCD_WIDTH
-BMPWIDTH_usblogo
),
205 (LCD_HEIGHT
-BMPHEIGHT_usblogo
)/2,
206 BMPWIDTH_usblogo
, BMPHEIGHT_usblogo
);
208 screens
[i
].double_height(false);
209 screens
[i
].puts_scroll(0, 0, "[USB Mode]");
210 status_set_param(false);
211 status_set_audio(false);
212 status_set_usb(true);
213 #endif /* HAVE_LCD_BITMAP */
221 while (button_get(true) & BUTTON_REL
);
223 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
224 while (handle_usb_events());
225 #endif /* SIMULATOR */
226 #ifdef HAVE_LCD_CHARCELLS
227 status_set_usb(false);
228 #endif /* HAVE_LCD_CHARCELLS */
230 screens
[i
].backlight_on();
231 global_settings
.statusbar
= statusbar
;
232 #endif /* USB_NONE */
235 #if (CONFIG_STORAGE & STORAGE_MMC)
236 int mmc_remove_request(void)
238 struct queue_event ev
;
241 screens
[i
].clear_display();
242 splash(0, ID2P(LANG_REMOVE_MMC
));
246 queue_wait_w_tmo(&button_queue
, &ev
, HZ
/2);
249 case SYS_HOTSWAP_EXTRACTED
:
250 return SYS_HOTSWAP_EXTRACTED
;
252 case SYS_USB_DISCONNECTED
:
253 return SYS_USB_DISCONNECTED
;
259 /* the charging screen is only used for archos targets */
260 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
262 #ifdef HAVE_LCD_BITMAP
263 static void charging_display_info(bool animate
)
265 unsigned char charging_logo
[36];
266 const int pox_x
= (LCD_WIDTH
- sizeof(charging_logo
)) / 2;
267 const int pox_y
= 32;
268 static unsigned phase
= 3;
273 #ifdef NEED_ATA_POWER_BATT_MEASURE
274 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
277 int battv
= battery_voltage();
278 snprintf(buf
, 32, " Batt: %d.%02dV %d%% ", battv
/ 1000,
279 (battv
% 1000) / 10, battery_level());
283 #ifdef ARCHOS_RECORER
284 snprintf(buf
, 32, "Charge mode:");
287 if (charge_state
== CHARGING
)
288 snprintf(buf
, 32, str(LANG_BATTERY_CHARGE
));
289 else if (charge_state
== TOPOFF
)
290 snprintf(buf
, 32, str(LANG_BATTERY_TOPOFF_CHARGE
));
291 else if (charge_state
== TRICKLE
)
292 snprintf(buf
, 32, str(LANG_BATTERY_TRICKLE_CHARGE
));
294 snprintf(buf
, 32, "not charging");
297 if (!charger_enabled())
299 #endif /* ARCHOS_RECORER */
302 memset(charging_logo
+3, 0x00, 32);
303 charging_logo
[0] = 0x3C;
304 charging_logo
[1] = 0x24;
305 charging_logo
[2] = charging_logo
[35] = 0xFF;
308 { /* draw the outline */
310 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8,
311 sizeof(charging_logo
), 8);
312 lcd_set_drawmode(DRMODE_FG
);
314 charging_logo
[0] = charging_logo
[1] = 0x00;
315 memset(charging_logo
+2, 0x80, 34);
316 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
, sizeof(charging_logo
), 8);
318 memset(charging_logo
+2, 0x01, 34);
319 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 16,
320 sizeof(charging_logo
), 8);
321 lcd_set_drawmode(DRMODE_SOLID
);
324 { /* animate the middle part */
325 for (i
= 3; i
<MIN(sizeof(charging_logo
)-1, phase
); i
++)
327 if ((i
-phase
) % 8 == 0)
328 { /* draw a "bubble" here */
330 bitpos
= (phase
+ i
/8) % 15; /* "bounce" effect */
332 bitpos
= 14 - bitpos
;
333 charging_logo
[i
] = BIT_N(bitpos
);
336 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8,
337 sizeof(charging_logo
), 8);
342 #else /* not HAVE_LCD_BITMAP */
344 static unsigned long logo_chars
[4];
345 static const unsigned char logo_pattern
[] = {
346 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
347 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
348 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
349 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
352 static void logo_lock_patterns(bool on
)
358 for (i
= 0; i
< 4; i
++)
359 logo_chars
[i
] = lcd_get_locked_pattern();
363 for (i
= 0; i
< 4; i
++)
364 lcd_unlock_pattern(logo_chars
[i
]);
368 static void charging_display_info(bool animate
)
372 static unsigned phase
= 3;
375 battv
= battery_voltage();
376 snprintf(buf
, sizeof(buf
), " %d.%02dV", battv
/ 1000, (battv
% 1000) / 10);
379 memcpy(buf
, logo_pattern
, 32); /* copy logo patterns */
381 if (!animate
) /* build the screen */
383 lcd_double_height(false);
384 lcd_puts(0, 0, "[Charging]");
385 for (i
= 0; i
< 4; i
++)
386 lcd_putc(i
, 1, logo_chars
[i
]);
388 else /* animate the logo */
390 for (i
= 3; i
< MIN(19, phase
); i
++)
392 if ((i
- phase
) % 5 == 0)
393 { /* draw a "bubble" here */
394 ypos
= (phase
+ i
/5) % 9; /* "bounce" effect */
397 buf
[5 - ypos
+ 8 * (i
/5)] |= 0x10u
>> (i
%5);
403 for (i
= 0; i
< 4; i
++)
404 lcd_define_pattern(logo_chars
[i
], buf
+ 8 * i
);
408 #endif /* (not) HAVE_LCD_BITMAP */
410 /* blocks while charging, returns on event:
411 1 if charger cable was removed
412 2 if Off/Stop key was pressed
413 3 if On key was pressed
414 4 if USB was connected */
416 int charging_screen(void)
421 ide_power_enable(false); /* power down the disk, else would be spinning */
424 backlight_set_timeout(global_settings
.backlight_timeout
);
425 #ifdef HAVE_REMOTE_LCD
426 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
428 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
430 #ifdef HAVE_LCD_CHARCELLS
431 logo_lock_patterns(true);
433 charging_display_info(false);
437 gui_syncstatusbar_draw(&statusbars
, false);
438 charging_display_info(true);
439 button
= get_action(CONTEXT_STD
,HZ
/3);
440 if (button
== ACTION_STD_OK
)
442 else if (usb_detect() == USB_INSERTED
)
444 else if (!charger_inserted())
448 #ifdef HAVE_LCD_CHARCELLS
449 logo_lock_patterns(false);
453 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
456 void charging_splash(void)
458 splash(2*HZ
, str(LANG_BATTERY_CHARGE
));
459 button_clear_queue();
464 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
466 /* little helper function for voice output */
467 static void say_time(int cursorpos
, const struct tm
*tm
)
472 if (!global_settings
.talk_menu
)
490 value
= tm
->tm_year
+ 1900;
497 if (cursorpos
== 4) /* month */
498 talk_id(LANG_MONTH_JANUARY
+ tm
->tm_mon
, false);
500 talk_value(value
, unit
, false);
507 #define SEPARATOR ":"
508 bool set_time_screen(const char* title
, struct tm
*tm
)
512 unsigned int i
, j
, s
;
514 unsigned int julianday
;
515 unsigned int realyear
;
517 unsigned int min
, max
;
518 unsigned int statusbar_height
= 0;
519 unsigned int separator_width
, weekday_width
;
520 unsigned int prev_line_height
;
521 int daysinmonth
[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
522 unsigned char buffer
[20];
523 struct viewport vp
[NB_SCREENS
];
526 /* 6 possible cursor possitions, 2 values stored for each: x, y */
527 unsigned int cursor
[6][2];
530 unsigned char *ptr
[6];
532 if(global_settings
.statusbar
)
533 statusbar_height
= STATUSBAR_HEIGHT
;
535 /* speak selection when screen is entered */
536 say_time(cursorpos
, tm
);
539 /* for easy acess in the drawing loop */
540 ptr
[0] = buffer
; /* hours */
541 ptr
[1] = buffer
+ 3; /* minutes */
542 ptr
[2] = buffer
+ 6; /* seconds */
543 ptr
[3] = buffer
+ 9; /* year */
544 ptr
[4] = str(LANG_MONTH_JANUARY
+ tm
->tm_mon
); /* monthname */
545 ptr
[5] = buffer
+ 14; /* day of month */
547 /* calculate the number of days in febuary */
548 realyear
= tm
->tm_year
+ 1900;
549 if((realyear
% 4 == 0 && !(realyear
% 100 == 0)) || realyear
% 400 == 0)
554 /* fix day if month or year changed */
555 if (tm
->tm_mday
> daysinmonth
[tm
->tm_mon
])
556 tm
->tm_mday
= daysinmonth
[tm
->tm_mon
];
558 /* calculate day of week */
559 julianday
= tm
->tm_mday
;
560 for(i
= 0; (int)i
< tm
->tm_mon
; i
++) {
561 julianday
+= daysinmonth
[i
];
564 tm
->tm_wday
= (realyear
+ julianday
+ (realyear
- 1) / 4 -
565 (realyear
- 1) / 100 + (realyear
- 1) / 400 + 7 - 1) % 7;
567 /* put all the numbers we want from the tm struct into
568 an easily printable buffer */
569 snprintf(buffer
, sizeof(buffer
),
570 "%02d " "%02d " "%02d " "%04d " "%02d",
571 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
,
572 tm
->tm_year
+1900, tm
->tm_mday
);
574 /* convert spaces in the buffer to '\0' to make it possible to work
575 directly on the buffer */
576 for(i
=0; i
< sizeof(buffer
); i
++)
584 viewport_set_defaults(&vp
[s
], s
);
585 screens
[s
].set_viewport(&vp
[s
]);
586 nb_lines
= viewport_get_nb_lines(&vp
[s
]);
588 /* minimum lines needed is 2 + title line */
591 vp
[s
].font
= FONT_SYSFIXED
;
592 nb_lines
= viewport_get_nb_lines(&vp
[s
]);
595 /* recalculate the positions and offsets */
597 screens
[s
].getstringsize(title
, NULL
, &prev_line_height
);
599 prev_line_height
= 0;
601 screens
[s
].getstringsize(SEPARATOR
, &separator_width
, NULL
);
604 screens
[s
].getstringsize(str(LANG_WEEKDAY_SUNDAY
+ tm
->tm_wday
),
605 &weekday_width
, NULL
);
606 screens
[s
].getstringsize(" ", &separator_width
, NULL
);
608 for(i
=0, j
=0; i
< 6; i
++)
610 if(i
==3) /* second row */
612 j
= weekday_width
+ separator_width
;
613 prev_line_height
*= 2;
615 screens
[s
].getstringsize(ptr
[i
], &width
, NULL
);
616 cursor
[i
][INDEX_Y
] = prev_line_height
+ statusbar_height
;
617 cursor
[i
][INDEX_X
] = j
;
618 j
+= width
+ separator_width
;
621 /* draw the screen */
622 screens
[s
].set_viewport(&vp
[s
]);
623 screens
[s
].clear_viewport();
624 /* display the screen title */
625 screens
[s
].puts_scroll(0, 0, title
);
627 /* these are not selectable, so we draw them outside the loop */
628 /* name of the week day */
629 screens
[s
].putsxy(0, cursor
[3][INDEX_Y
],
630 str(LANG_WEEKDAY_SUNDAY
+ tm
->tm_wday
));
632 /* draw the selected item with drawmode set to
633 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
634 items with drawmode DRMODE_SOLID */
637 if (cursorpos
== (int)i
)
638 vp
[s
].drawmode
= (DRMODE_SOLID
|DRMODE_INVERSEVID
);
640 screens
[s
].putsxy(cursor
[i
][INDEX_X
],
641 cursor
[i
][INDEX_Y
], ptr
[i
]);
643 vp
[s
].drawmode
= DRMODE_SOLID
;
645 screens
[s
].putsxy(cursor
[i
/4 +1][INDEX_X
] - separator_width
,
646 cursor
[0][INDEX_Y
], SEPARATOR
);
649 /* print help text */
651 screens
[s
].puts(0, 4, str(LANG_TIME_SET_BUTTON
));
653 screens
[s
].puts(0, 5, str(LANG_TIME_REVERT
));
654 screens
[s
].update_viewport();
655 screens
[s
].set_viewport(NULL
);
658 /* set the most common numbers */
661 /* calculate the minimum and maximum for the number under cursor */
665 valptr
= &tm
->tm_hour
;
668 valptr
= &tm
->tm_min
;
671 valptr
= &tm
->tm_sec
;
676 valptr
= &tm
->tm_year
;
680 valptr
= &tm
->tm_mon
;
684 max
= daysinmonth
[tm
->tm_mon
];
685 valptr
= &tm
->tm_mday
;
689 #ifdef HAVE_TOUCHSCREEN
690 enum touchscreen_mode old_mode
= touchscreen_get_mode();
692 touchscreen_set_mode(TOUCHSCREEN_BUTTON
);
694 button
= get_action(CONTEXT_SETTINGS_TIME
, TIMEOUT_BLOCK
);
695 #ifdef HAVE_TOUCHSCREEN
696 touchscreen_set_mode(old_mode
);
699 case ACTION_STD_PREV
:
700 cursorpos
= clamp_value_wrap(--cursorpos
, 5, 0);
701 say_time(cursorpos
, tm
);
703 case ACTION_STD_NEXT
:
704 cursorpos
= clamp_value_wrap(++cursorpos
, 5, 0);
705 say_time(cursorpos
, tm
);
707 case ACTION_SETTINGS_INC
:
708 case ACTION_SETTINGS_INCREPEAT
:
709 *valptr
= clamp_value_wrap(++(*valptr
), max
, min
);
710 say_time(cursorpos
, tm
);
712 case ACTION_SETTINGS_DEC
:
713 case ACTION_SETTINGS_DECREPEAT
:
714 *valptr
= clamp_value_wrap(--(*valptr
), max
, min
);
715 say_time(cursorpos
, tm
);
722 case ACTION_STD_CANCEL
:
728 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
735 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
737 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
738 bool shutdown_screen(void)
742 long time_entered
= current_tick
;
746 splash(0, str(LANG_CONFIRM_SHUTDOWN
));
748 while(!done
&& TIME_BEFORE(current_tick
,time_entered
+HZ
*2))
750 button
= get_action(CONTEXT_STD
,HZ
);
753 case ACTION_STD_CANCEL
:
757 /* do nothing here, because ACTION_NONE might be caused
758 * by timeout or button release. In case of timeout the loop
759 * is terminated by TIME_BEFORE */
764 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
774 static const int id3_headers
[]=
779 LANG_ID3_ALBUMARTIST
,
790 #if CONFIG_CODEC == SWCODEC
796 struct id3view_info
{
797 struct mp3entry
* id3
;
799 int info_id
[sizeof(id3_headers
)/sizeof(id3_headers
[0])];
801 static char * id3_get_info(int selected_item
, void* data
,
802 char *buffer
, size_t buffer_len
)
804 struct id3view_info
*info
= (struct id3view_info
*)data
;
805 struct mp3entry
* id3
=info
->id3
;
806 int info_no
=selected_item
/2;
807 if(!(selected_item
%2))
809 return( str(id3_headers
[info
->info_id
[info_no
]]));
815 switch(info
->info_id
[info_no
])
817 case 0:/*LANG_ID3_TITLE*/
820 case 1:/*LANG_ID3_ARTIST*/
823 case 2:/*LANG_ID3_ALBUM*/
826 case 3:/*LANG_ID3_ALBUMARTIST*/
827 val
=id3
->albumartist
;
829 case 4:/*LANG_ID3_GROUPING*/
832 case 5:/*LANG_ID3_DISCNUM*/
833 if (id3
->disc_string
)
834 val
= id3
->disc_string
;
835 else if (id3
->discnum
)
837 snprintf(buffer
, buffer_len
, "%d", id3
->discnum
);
841 case 6:/*LANG_ID3_TRACKNUM*/
842 if (id3
->track_string
)
843 val
= id3
->track_string
;
844 else if (id3
->tracknum
)
846 snprintf(buffer
, buffer_len
, "%d", id3
->tracknum
);
850 case 7:/*LANG_ID3_COMMENT*/
853 case 8:/*LANG_ID3_GENRE*/
854 val
= id3
->genre_string
;
856 case 9:/*LANG_ID3_YEAR*/
857 if (id3
->year_string
)
858 val
= id3
->year_string
;
861 snprintf(buffer
, buffer_len
, "%d", id3
->year
);
865 case 10:/*LANG_ID3_LENGTH*/
866 format_time(buffer
, buffer_len
, id3
->length
);
869 case 11:/*LANG_ID3_PLAYLIST*/
870 snprintf(buffer
, buffer_len
, "%d/%d",
871 playlist_get_display_index(), playlist_amount());
874 case 12:/*LANG_ID3_BITRATE*/
875 snprintf(buffer
, buffer_len
, "%d kbps%s", id3
->bitrate
,
876 id3
->vbr
? str(LANG_ID3_VBR
) : (const unsigned char*) "");
879 case 13:/*LANG_ID3_FREQUENCY*/
880 snprintf(buffer
, buffer_len
, "%ld Hz", id3
->frequency
);
883 #if CONFIG_CODEC == SWCODEC
884 case 14:/*LANG_ID3_TRACK_GAIN*/
885 val
=id3
->track_gain_string
;
887 case 15:/*LANG_ID3_ALBUM_GAIN*/
888 val
=id3
->album_gain_string
;
890 case 16:/*LANG_ID3_PATH*/
892 case 14:/*LANG_ID3_PATH*/
897 return val
&& *val
? val
: NULL
;
901 bool browse_id3(void)
903 struct gui_synclist id3_lists
;
904 struct mp3entry
* id3
= audio_current_track();
907 struct id3view_info info
;
910 for (i
=0; i
<sizeof(id3_headers
)/sizeof(id3_headers
[0]); i
++)
914 if (id3_get_info((i
*2)+1, &info
, temp
, 8) != NULL
)
915 info
.info_id
[info
.count
++] = i
;
918 gui_synclist_init(&id3_lists
, &id3_get_info
, &info
, true, 2, NULL
);
919 gui_synclist_set_nb_items(&id3_lists
, info
.count
*2);
920 gui_synclist_draw(&id3_lists
);
922 key
= get_action(CONTEXT_LIST
,HZ
/2);
923 if(key
!=ACTION_NONE
&& key
!=ACTION_UNKNOWN
924 && !gui_synclist_do_button(&id3_lists
, &key
,LIST_WRAP_UNLESS_HELD
))
926 return(default_event_handler(key
) == SYS_USB_CONNECTED
);
931 static char* runtime_get_data(int selected_item
, void* data
,
932 char* buffer
, size_t buffer_len
)
936 switch (selected_item
)
938 case 0: return str(LANG_RUNNING_TIME
);
939 case 1: t
= global_status
.runtime
; break;
940 case 2: return str(LANG_TOP_TIME
);
941 case 3: t
= global_status
.topruntime
; break;
946 snprintf(buffer
, buffer_len
, "%dh %dm %ds",
947 t
/ 3600, (t
% 3600) / 60, t
% 60);
951 static int runtime_speak_data(int selected_item
, void* data
)
955 (selected_item
< 2) ? LANG_RUNNING_TIME
: LANG_TOP_TIME
,
956 TALK_ID((selected_item
< 2) ? global_status
.runtime
957 : global_status
.topruntime
, UNIT_TIME
));
962 bool view_runtime(void)
964 static const char *lines
[]={ID2P(LANG_CLEAR_TIME
)};
965 static const struct text_message message
={lines
, 1};
967 struct gui_synclist lists
;
969 gui_synclist_init(&lists
, runtime_get_data
, NULL
, false, 2, NULL
);
970 #if !defined(HAVE_LCD_CHARCELLS)
971 gui_synclist_set_title(&lists
, str(LANG_RUNNING_TIME
), NOICON
);
973 gui_synclist_set_title(&lists
, NULL
, NOICON
);
975 if(global_settings
.talk_menu
)
976 gui_synclist_set_voice_callback(&lists
, runtime_speak_data
);
977 gui_synclist_set_icon_callback(&lists
, NULL
);
978 gui_synclist_set_nb_items(&lists
, 4);
979 gui_synclist_speak_item(&lists
);
983 if (charger_inserted())
985 global_status
.runtime
= 0;
990 global_status
.runtime
+= ((current_tick
- lasttime
) / HZ
);
992 lasttime
= current_tick
;
993 gui_synclist_draw(&lists
);
994 list_do_action(CONTEXT_STD
, HZ
,
995 &lists
, &action
, LIST_WRAP_UNLESS_HELD
);
996 if(action
== ACTION_STD_CANCEL
)
998 if(action
== ACTION_STD_OK
) {
999 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
1001 if (!(gui_synclist_get_sel_pos(&lists
)/2))
1002 global_status
.runtime
= 0;
1004 global_status
.topruntime
= 0;
1005 gui_synclist_speak_item(&lists
);
1008 if(default_event_handler(action
) == SYS_USB_CONNECTED
)
1014 #ifdef HAVE_TOUCHSCREEN
1015 static int get_sample(struct touchscreen_calibration
*cal
, int x
, int y
, int i
,
1016 struct screen
* screen
)
1022 screen
->drawline(x
- 10, y
, x
- 2, y
);
1023 screen
->drawline(x
+ 2, y
, x
+ 10, y
);
1024 screen
->drawline(x
, y
- 10, x
, y
- 2);
1025 screen
->drawline(x
, y
+ 2, x
, y
+ 10);
1028 /* Wait for a touchscreen press */
1031 action
= get_action(CONTEXT_STD
, TIMEOUT_BLOCK
);
1032 if(action
== ACTION_TOUCHSCREEN
)
1034 if(action_get_touchscreen_press(&ts_x
, &ts_y
) == BUTTON_REL
)
1037 else if(action
== ACTION_STD_CANCEL
)
1041 cal
->x
[i
][0] = ts_x
;
1042 cal
->y
[i
][0] = ts_y
;
1052 short points
[3][2] = {
1053 {LCD_WIDTH
/10, LCD_HEIGHT
/10},
1054 {7*LCD_WIDTH
/8, LCD_HEIGHT
/2},
1055 {LCD_WIDTH
/2, 7*LCD_HEIGHT
/8}
1057 struct screen
* screen
= &screens
[SCREEN_MAIN
];
1058 enum touchscreen_mode old_mode
= touchscreen_get_mode();
1059 struct touchscreen_calibration cal
;
1061 bool statusbar
= global_settings
.statusbar
; /* hide the statusbar */
1063 global_settings
.statusbar
= false;
1064 touchscreen_disable_mapping(); /* set raw mode */
1065 touchscreen_set_mode(TOUCHSCREEN_POINT
);
1068 screen
->clear_display();
1070 if(get_sample(&cal
, points
[i
][0], points
[i
][1], i
, screen
))
1078 touchscreen_calibrate(&cal
);
1080 touchscreen_reset_mapping();
1081 memcpy(&global_settings
.ts_calibration_data
, &calibration_parameters
, sizeof(struct touchscreen_parameter
));
1082 touchscreen_set_mode(old_mode
);
1083 global_settings
.statusbar
= statusbar
;
1088 int reset_mapping(void)
1090 touchscreen_reset_mapping();
1091 memcpy(&global_settings
.ts_calibration_data
, &calibration_parameters
, sizeof(struct touchscreen_parameter
));