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)
100 #ifdef HAVE_TOUCHSCREEN
101 enum touchscreen_mode old_mode
= touchscreen_get_mode();
103 /* TODO: Paint buttons on screens OR switch to point mode and use
104 * touchscreen as a touchpad to move the host's mouse cursor */
105 touchscreen_set_mode(TOUCHSCREEN_BUTTON
);
108 /* Don't return until we get SYS_USB_DISCONNECTED or SYS_TIMEOUT */
112 #if defined(HAVE_USBSTACK) && defined(USB_ENABLE_HID)
113 bool hid_enabled
= usb_core_driver_enabled(USB_DRIVER_HID
);
117 int id
= HID_CONSUMER_USAGE_UNASSIGNED
;
118 button
= get_action(CONTEXT_USB_HID
, HZ
/4);
122 case ACTION_USB_HID_PLAY
:
123 id
= HID_CONSUMER_USAGE_PLAY_PAUSE
;
125 case ACTION_USB_HID_STOP
:
126 id
= HID_CONSUMER_USAGE_STOP
;
128 case ACTION_USB_HID_SKIPPREV
:
129 id
= HID_CONSUMER_USAGE_SCAN_PREVIOUS_TRACK
;
131 case ACTION_USB_HID_SKIPNEXT
:
132 id
= HID_CONSUMER_USAGE_SCAN_NEXT_TRACK
;
134 case ACTION_USB_HID_VOLDOWN
:
135 id
= HID_CONSUMER_USAGE_VOLUME_DECREMENT
;
137 case ACTION_USB_HID_VOLUP
:
138 id
= HID_CONSUMER_USAGE_VOLUME_INCREMENT
;
140 case ACTION_USB_HID_MUTE
:
141 id
= HID_CONSUMER_USAGE_MUTE
;
145 if (id
!= HID_CONSUMER_USAGE_UNASSIGNED
)
146 usb_hid_send(HID_USAGE_PAGE_CONSUMER
, id
);
150 button
= button_get_w_tmo(HZ
/4);
154 case SYS_USB_DISCONNECTED
:
155 usb_acknowledge(SYS_USB_DISCONNECTED_ACK
);
161 if(TIME_AFTER(current_tick
,next_update
))
164 #if (CONFIG_STORAGE & STORAGE_MMC) /* USB-MMC bridge can report activity */
165 led(mmc_usb_active(HZ
));
166 #endif /* STORAGE_MMC */
167 gui_syncstatusbar_draw(&statusbars
, false);
169 next_update
=current_tick
+HZ
/2;
173 #ifdef HAVE_TOUCHSCREEN
174 touchscreen_set_mode(old_mode
);
180 void usb_screen(void)
186 int usb_bars
= VP_SB_ALLSCREENS
; /* force statusbars */
187 int old_bars
= viewportmanager_get_statusbar();
191 screens
[i
].backdrop_show(BACKDROP_MAIN
);
192 screens
[i
].backlight_on();
193 screens
[i
].clear_display();
194 #ifdef HAVE_REMOTE_LCD
195 if (i
== SCREEN_REMOTE
)
197 screens
[i
].bitmap(remote_usblogo
,
198 (LCD_REMOTE_WIDTH
-BMPWIDTH_remote_usblogo
),
199 (LCD_REMOTE_HEIGHT
-BMPHEIGHT_remote_usblogo
)/2,
200 BMPWIDTH_remote_usblogo
, BMPHEIGHT_remote_usblogo
);
205 #ifdef HAVE_LCD_BITMAP
206 screens
[i
].transparent_bitmap(usblogo
,
207 (LCD_WIDTH
-BMPWIDTH_usblogo
),
208 (LCD_HEIGHT
-BMPHEIGHT_usblogo
)/2,
209 BMPWIDTH_usblogo
, BMPHEIGHT_usblogo
);
211 screens
[i
].double_height(false);
212 screens
[i
].puts_scroll(0, 0, "[USB Mode]");
213 status_set_param(false);
214 status_set_audio(false);
215 status_set_usb(true);
216 #endif /* HAVE_LCD_BITMAP */
221 usb_bars
|= VP_SB_IGNORE_SETTING(i
);
222 viewportmanager_set_statusbar(usb_bars
);
225 while (button_get(true) & BUTTON_REL
);
227 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
228 while (handle_usb_events());
229 #endif /* SIMULATOR */
230 #ifdef HAVE_LCD_CHARCELLS
231 status_set_usb(false);
232 #endif /* HAVE_LCD_CHARCELLS */
235 screens
[i
].backlight_on();
237 viewportmanager_set_statusbar(old_bars
);
238 send_event(GUI_EVENT_REFRESH
, NULL
);
240 #endif /* USB_NONE */
243 #if (CONFIG_STORAGE & STORAGE_MMC)
244 int mmc_remove_request(void)
246 struct queue_event ev
;
249 screens
[i
].clear_display();
250 splash(0, ID2P(LANG_REMOVE_MMC
));
254 queue_wait_w_tmo(&button_queue
, &ev
, HZ
/2);
257 case SYS_HOTSWAP_EXTRACTED
:
258 return SYS_HOTSWAP_EXTRACTED
;
260 case SYS_USB_DISCONNECTED
:
261 return SYS_USB_DISCONNECTED
;
267 /* the charging screen is only used for archos targets */
268 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
270 #ifdef HAVE_LCD_BITMAP
271 static void charging_display_info(bool animate
)
273 unsigned char charging_logo
[36];
274 const int pox_x
= (LCD_WIDTH
- sizeof(charging_logo
)) / 2;
275 const int pox_y
= 32;
276 static unsigned phase
= 3;
281 #ifdef NEED_ATA_POWER_BATT_MEASURE
282 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
285 int battv
= battery_voltage();
286 snprintf(buf
, 32, " Batt: %d.%02dV %d%% ", battv
/ 1000,
287 (battv
% 1000) / 10, battery_level());
291 #ifdef ARCHOS_RECORER
292 snprintf(buf
, 32, "Charge mode:");
295 if (charge_state
== CHARGING
)
296 snprintf(buf
, 32, str(LANG_BATTERY_CHARGE
));
297 else if (charge_state
== TOPOFF
)
298 snprintf(buf
, 32, str(LANG_BATTERY_TOPOFF_CHARGE
));
299 else if (charge_state
== TRICKLE
)
300 snprintf(buf
, 32, str(LANG_BATTERY_TRICKLE_CHARGE
));
302 snprintf(buf
, 32, "not charging");
305 if (!charger_enabled())
307 #endif /* ARCHOS_RECORER */
310 memset(charging_logo
+3, 0x00, 32);
311 charging_logo
[0] = 0x3C;
312 charging_logo
[1] = 0x24;
313 charging_logo
[2] = charging_logo
[35] = 0xFF;
316 { /* draw the outline */
318 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8,
319 sizeof(charging_logo
), 8);
320 lcd_set_drawmode(DRMODE_FG
);
322 charging_logo
[0] = charging_logo
[1] = 0x00;
323 memset(charging_logo
+2, 0x80, 34);
324 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
, sizeof(charging_logo
), 8);
326 memset(charging_logo
+2, 0x01, 34);
327 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 16,
328 sizeof(charging_logo
), 8);
329 lcd_set_drawmode(DRMODE_SOLID
);
332 { /* animate the middle part */
333 for (i
= 3; i
<MIN(sizeof(charging_logo
)-1, phase
); i
++)
335 if ((i
-phase
) % 8 == 0)
336 { /* draw a "bubble" here */
338 bitpos
= (phase
+ i
/8) % 15; /* "bounce" effect */
340 bitpos
= 14 - bitpos
;
341 charging_logo
[i
] = BIT_N(bitpos
);
344 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8,
345 sizeof(charging_logo
), 8);
350 #else /* not HAVE_LCD_BITMAP */
352 static unsigned long logo_chars
[4];
353 static const unsigned char logo_pattern
[] = {
354 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
355 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
356 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
357 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
360 static void logo_lock_patterns(bool on
)
366 for (i
= 0; i
< 4; i
++)
367 logo_chars
[i
] = lcd_get_locked_pattern();
371 for (i
= 0; i
< 4; i
++)
372 lcd_unlock_pattern(logo_chars
[i
]);
376 static void charging_display_info(bool animate
)
380 static unsigned phase
= 3;
383 battv
= battery_voltage();
384 snprintf(buf
, sizeof(buf
), " %d.%02dV", battv
/ 1000, (battv
% 1000) / 10);
387 memcpy(buf
, logo_pattern
, 32); /* copy logo patterns */
389 if (!animate
) /* build the screen */
391 lcd_double_height(false);
392 lcd_puts(0, 0, "[Charging]");
393 for (i
= 0; i
< 4; i
++)
394 lcd_putc(i
, 1, logo_chars
[i
]);
396 else /* animate the logo */
398 for (i
= 3; i
< MIN(19, phase
); i
++)
400 if ((i
- phase
) % 5 == 0)
401 { /* draw a "bubble" here */
402 ypos
= (phase
+ i
/5) % 9; /* "bounce" effect */
405 buf
[5 - ypos
+ 8 * (i
/5)] |= 0x10u
>> (i
%5);
411 for (i
= 0; i
< 4; i
++)
412 lcd_define_pattern(logo_chars
[i
], buf
+ 8 * i
);
416 #endif /* (not) HAVE_LCD_BITMAP */
418 /* blocks while charging, returns on event:
419 1 if charger cable was removed
420 2 if Off/Stop key was pressed
421 3 if On key was pressed
422 4 if USB was connected */
424 int charging_screen(void)
429 ide_power_enable(false); /* power down the disk, else would be spinning */
432 backlight_set_timeout(global_settings
.backlight_timeout
);
433 #ifdef HAVE_REMOTE_LCD
434 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
436 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
438 #ifdef HAVE_LCD_CHARCELLS
439 logo_lock_patterns(true);
441 charging_display_info(false);
445 gui_syncstatusbar_draw(&statusbars
, false);
446 charging_display_info(true);
447 button
= get_action(CONTEXT_STD
,HZ
/3);
448 if (button
== ACTION_STD_OK
)
450 else if (usb_detect() == USB_INSERTED
)
452 else if (!charger_inserted())
456 #ifdef HAVE_LCD_CHARCELLS
457 logo_lock_patterns(false);
461 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
464 void charging_splash(void)
466 splash(2*HZ
, str(LANG_BATTERY_CHARGE
));
467 button_clear_queue();
472 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
474 /* little helper function for voice output */
475 static void say_time(int cursorpos
, const struct tm
*tm
)
480 if (!global_settings
.talk_menu
)
498 value
= tm
->tm_year
+ 1900;
505 if (cursorpos
== 4) /* month */
506 talk_id(LANG_MONTH_JANUARY
+ tm
->tm_mon
, false);
508 talk_value(value
, unit
, false);
515 #define SEPARATOR ":"
516 bool set_time_screen(const char* title
, struct tm
*tm
)
520 unsigned int i
, j
, s
;
522 unsigned int realyear
;
524 unsigned int min
, max
;
525 unsigned int statusbar_height
= 0;
526 unsigned int separator_width
, weekday_width
;
527 unsigned int prev_line_height
;
528 static unsigned char daysinmonth
[] =
529 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
530 unsigned char buffer
[20];
531 struct viewport vp
[NB_SCREENS
];
534 /* 6 possible cursor possitions, 2 values stored for each: x, y */
535 unsigned int cursor
[6][2];
538 unsigned char *ptr
[6];
540 if(global_settings
.statusbar
)
541 statusbar_height
= STATUSBAR_HEIGHT
;
543 /* speak selection when screen is entered */
544 say_time(cursorpos
, tm
);
547 /* for easy acess in the drawing loop */
548 ptr
[0] = buffer
; /* hours */
549 ptr
[1] = buffer
+ 3; /* minutes */
550 ptr
[2] = buffer
+ 6; /* seconds */
551 ptr
[3] = buffer
+ 9; /* year */
552 ptr
[4] = str(LANG_MONTH_JANUARY
+ tm
->tm_mon
); /* monthname */
553 ptr
[5] = buffer
+ 14; /* day of month */
555 /* calculate the number of days in febuary */
556 realyear
= tm
->tm_year
+ 1900;
557 if((realyear
% 4 == 0 && !(realyear
% 100 == 0)) || realyear
% 400 == 0)
562 /* fix day if month or year changed */
563 if (tm
->tm_mday
> daysinmonth
[tm
->tm_mon
])
564 tm
->tm_mday
= daysinmonth
[tm
->tm_mon
];
566 /* calculate day of week */
569 /* put all the numbers we want from the tm struct into
570 an easily printable buffer */
571 snprintf(buffer
, sizeof(buffer
),
572 "%02d " "%02d " "%02d " "%04d " "%02d",
573 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
,
574 tm
->tm_year
+1900, tm
->tm_mday
);
576 /* convert spaces in the buffer to '\0' to make it possible to work
577 directly on the buffer */
578 for(i
=0; i
< sizeof(buffer
); i
++)
586 viewport_set_defaults(&vp
[s
], s
);
587 screens
[s
].set_viewport(&vp
[s
]);
588 nb_lines
= viewport_get_nb_lines(&vp
[s
]);
590 /* minimum lines needed is 2 + title line */
593 vp
[s
].font
= FONT_SYSFIXED
;
594 nb_lines
= viewport_get_nb_lines(&vp
[s
]);
597 /* recalculate the positions and offsets */
599 screens
[s
].getstringsize(title
, NULL
, &prev_line_height
);
601 prev_line_height
= 0;
603 screens
[s
].getstringsize(SEPARATOR
, &separator_width
, NULL
);
606 screens
[s
].getstringsize(str(LANG_WEEKDAY_SUNDAY
+ tm
->tm_wday
),
607 &weekday_width
, NULL
);
608 screens
[s
].getstringsize(" ", &separator_width
, NULL
);
610 for(i
=0, j
=0; i
< 6; i
++)
612 if(i
==3) /* second row */
614 j
= weekday_width
+ separator_width
;
615 prev_line_height
*= 2;
617 screens
[s
].getstringsize(ptr
[i
], &width
, NULL
);
618 cursor
[i
][INDEX_Y
] = prev_line_height
+ statusbar_height
;
619 cursor
[i
][INDEX_X
] = j
;
620 j
+= width
+ separator_width
;
623 /* draw the screen */
624 screens
[s
].set_viewport(&vp
[s
]);
625 screens
[s
].clear_viewport();
626 /* display the screen title */
627 screens
[s
].puts_scroll(0, 0, title
);
629 /* these are not selectable, so we draw them outside the loop */
630 /* name of the week day */
631 screens
[s
].putsxy(0, cursor
[3][INDEX_Y
],
632 str(LANG_WEEKDAY_SUNDAY
+ tm
->tm_wday
));
634 /* draw the selected item with drawmode set to
635 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
636 items with drawmode DRMODE_SOLID */
639 if (cursorpos
== (int)i
)
640 vp
[s
].drawmode
= (DRMODE_SOLID
|DRMODE_INVERSEVID
);
642 screens
[s
].putsxy(cursor
[i
][INDEX_X
],
643 cursor
[i
][INDEX_Y
], ptr
[i
]);
645 vp
[s
].drawmode
= DRMODE_SOLID
;
647 screens
[s
].putsxy(cursor
[i
/4 +1][INDEX_X
] - separator_width
,
648 cursor
[0][INDEX_Y
], SEPARATOR
);
651 /* print help text */
653 screens
[s
].puts(0, 4, str(LANG_TIME_SET_BUTTON
));
655 screens
[s
].puts(0, 5, str(LANG_TIME_REVERT
));
656 screens
[s
].update_viewport();
657 screens
[s
].set_viewport(NULL
);
660 /* set the most common numbers */
663 /* calculate the minimum and maximum for the number under cursor */
667 valptr
= &tm
->tm_hour
;
670 valptr
= &tm
->tm_min
;
673 valptr
= &tm
->tm_sec
;
678 valptr
= &tm
->tm_year
;
682 valptr
= &tm
->tm_mon
;
686 max
= daysinmonth
[tm
->tm_mon
];
687 valptr
= &tm
->tm_mday
;
691 #ifdef HAVE_TOUCHSCREEN
692 enum touchscreen_mode old_mode
= touchscreen_get_mode();
694 touchscreen_set_mode(TOUCHSCREEN_BUTTON
);
696 button
= get_action(CONTEXT_SETTINGS_TIME
, TIMEOUT_BLOCK
);
697 #ifdef HAVE_TOUCHSCREEN
698 touchscreen_set_mode(old_mode
);
701 case ACTION_STD_PREV
:
702 cursorpos
= clamp_value_wrap(--cursorpos
, 5, 0);
703 say_time(cursorpos
, tm
);
705 case ACTION_STD_NEXT
:
706 cursorpos
= clamp_value_wrap(++cursorpos
, 5, 0);
707 say_time(cursorpos
, tm
);
709 case ACTION_SETTINGS_INC
:
710 case ACTION_SETTINGS_INCREPEAT
:
711 *valptr
= clamp_value_wrap(++(*valptr
), max
, min
);
712 say_time(cursorpos
, tm
);
714 case ACTION_SETTINGS_DEC
:
715 case ACTION_SETTINGS_DECREPEAT
:
716 *valptr
= clamp_value_wrap(--(*valptr
), max
, min
);
717 say_time(cursorpos
, tm
);
724 case ACTION_STD_CANCEL
:
730 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
737 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
739 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
740 bool shutdown_screen(void)
744 long time_entered
= current_tick
;
748 splash(0, str(LANG_CONFIRM_SHUTDOWN
));
750 while(!done
&& TIME_BEFORE(current_tick
,time_entered
+HZ
*2))
752 button
= get_action(CONTEXT_STD
,HZ
);
755 case ACTION_STD_CANCEL
:
759 /* do nothing here, because ACTION_NONE might be caused
760 * by timeout or button release. In case of timeout the loop
761 * is terminated by TIME_BEFORE */
766 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
776 static const int id3_headers
[]=
781 LANG_ID3_ALBUMARTIST
,
792 #if CONFIG_CODEC == SWCODEC
799 struct id3view_info
{
800 struct mp3entry
* id3
;
802 int info_id
[ARRAYLEN(id3_headers
)];
805 static const char* id3_get_info(int selected_item
, void* data
,
806 char *buffer
, size_t buffer_len
)
808 struct id3view_info
*info
= (struct id3view_info
*)data
;
809 struct mp3entry
* id3
=info
->id3
;
810 int info_no
=selected_item
/2;
811 if(!(selected_item
%2))
813 return(str(id3_headers
[info
->info_id
[info_no
]]));
819 switch(info
->info_id
[info_no
])
821 case 0:/*LANG_ID3_TITLE*/
824 case 1:/*LANG_ID3_ARTIST*/
827 case 2:/*LANG_ID3_ALBUM*/
830 case 3:/*LANG_ID3_ALBUMARTIST*/
831 val
=id3
->albumartist
;
833 case 4:/*LANG_ID3_GROUPING*/
836 case 5:/*LANG_ID3_DISCNUM*/
837 if (id3
->disc_string
)
838 val
= id3
->disc_string
;
839 else if (id3
->discnum
)
841 snprintf(buffer
, buffer_len
, "%d", id3
->discnum
);
845 case 6:/*LANG_ID3_TRACKNUM*/
846 if (id3
->track_string
)
847 val
= id3
->track_string
;
848 else if (id3
->tracknum
)
850 snprintf(buffer
, buffer_len
, "%d", id3
->tracknum
);
854 case 7:/*LANG_ID3_COMMENT*/
857 case 8:/*LANG_ID3_GENRE*/
858 val
= id3
->genre_string
;
860 case 9:/*LANG_ID3_YEAR*/
861 if (id3
->year_string
)
862 val
= id3
->year_string
;
865 snprintf(buffer
, buffer_len
, "%d", id3
->year
);
869 case 10:/*LANG_ID3_LENGTH*/
870 format_time(buffer
, buffer_len
, id3
->length
);
873 case 11:/*LANG_ID3_PLAYLIST*/
874 snprintf(buffer
, buffer_len
, "%d/%d",
875 playlist_get_display_index(), playlist_amount());
878 case 12:/*LANG_ID3_BITRATE*/
879 snprintf(buffer
, buffer_len
, "%d kbps%s", id3
->bitrate
,
880 id3
->vbr
? str(LANG_ID3_VBR
) : (const unsigned char*) "");
883 case 13:/*LANG_ID3_FREQUENCY*/
884 snprintf(buffer
, buffer_len
, "%ld Hz", id3
->frequency
);
887 #if CONFIG_CODEC == SWCODEC
888 case 14:/*LANG_ID3_TRACK_GAIN*/
889 val
=id3
->track_gain_string
;
891 case 15:/*LANG_ID3_ALBUM_GAIN*/
892 val
=id3
->album_gain_string
;
894 case 16:/*LANG_ID3_PATH*/
896 case 14:/*LANG_ID3_PATH*/
901 return val
&& *val
? val
: NULL
;
905 bool browse_id3(void)
907 struct gui_synclist id3_lists
;
908 struct mp3entry
* id3
= audio_current_track();
911 struct id3view_info info
;
914 for (i
= 0; i
< ARRAYLEN(id3_headers
); i
++)
918 if (id3_get_info((i
*2)+1, &info
, temp
, 8) != NULL
)
919 info
.info_id
[info
.count
++] = i
;
922 gui_synclist_init(&id3_lists
, &id3_get_info
, &info
, true, 2, NULL
);
923 gui_synclist_set_nb_items(&id3_lists
, info
.count
*2);
924 gui_synclist_draw(&id3_lists
);
926 key
= get_action(CONTEXT_LIST
,HZ
/2);
927 if(key
!=ACTION_NONE
&& key
!=ACTION_UNKNOWN
928 && !gui_synclist_do_button(&id3_lists
, &key
,LIST_WRAP_UNLESS_HELD
))
930 return(default_event_handler(key
) == SYS_USB_CONNECTED
);
935 static const char* runtime_get_data(int selected_item
, void* data
,
936 char* buffer
, size_t buffer_len
)
940 switch (selected_item
)
942 case 0: return str(LANG_RUNNING_TIME
);
943 case 1: t
= global_status
.runtime
; break;
944 case 2: return str(LANG_TOP_TIME
);
945 case 3: t
= global_status
.topruntime
; break;
950 snprintf(buffer
, buffer_len
, "%dh %dm %ds",
951 t
/ 3600, (t
% 3600) / 60, t
% 60);
955 static int runtime_speak_data(int selected_item
, void* data
)
959 (selected_item
< 2) ? LANG_RUNNING_TIME
: LANG_TOP_TIME
,
960 TALK_ID((selected_item
< 2) ? global_status
.runtime
961 : global_status
.topruntime
, UNIT_TIME
));
966 bool view_runtime(void)
968 static const char *lines
[]={ID2P(LANG_CLEAR_TIME
)};
969 static const struct text_message message
={lines
, 1};
971 struct gui_synclist lists
;
973 gui_synclist_init(&lists
, runtime_get_data
, NULL
, false, 2, NULL
);
974 #if !defined(HAVE_LCD_CHARCELLS)
975 gui_synclist_set_title(&lists
, str(LANG_RUNNING_TIME
), NOICON
);
977 gui_synclist_set_title(&lists
, NULL
, NOICON
);
979 if(global_settings
.talk_menu
)
980 gui_synclist_set_voice_callback(&lists
, runtime_speak_data
);
981 gui_synclist_set_icon_callback(&lists
, NULL
);
982 gui_synclist_set_nb_items(&lists
, 4);
983 gui_synclist_speak_item(&lists
);
987 if (charger_inserted())
989 global_status
.runtime
= 0;
994 global_status
.runtime
+= ((current_tick
- lasttime
) / HZ
);
996 lasttime
= current_tick
;
997 gui_synclist_draw(&lists
);
998 list_do_action(CONTEXT_STD
, HZ
,
999 &lists
, &action
, LIST_WRAP_UNLESS_HELD
);
1000 if(action
== ACTION_STD_CANCEL
)
1002 if(action
== ACTION_STD_OK
) {
1003 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
1005 if (!(gui_synclist_get_sel_pos(&lists
)/2))
1006 global_status
.runtime
= 0;
1008 global_status
.topruntime
= 0;
1009 gui_synclist_speak_item(&lists
);
1012 if(default_event_handler(action
) == SYS_USB_CONNECTED
)
1018 #ifdef HAVE_TOUCHSCREEN
1019 static int get_sample(struct touchscreen_calibration
*cal
, int x
, int y
, int i
,
1020 struct screen
* screen
)
1026 screen
->drawline(x
- 10, y
, x
- 2, y
);
1027 screen
->drawline(x
+ 2, y
, x
+ 10, y
);
1028 screen
->drawline(x
, y
- 10, x
, y
- 2);
1029 screen
->drawline(x
, y
+ 2, x
, y
+ 10);
1032 /* Wait for a touchscreen press */
1035 action
= get_action(CONTEXT_STD
, TIMEOUT_BLOCK
);
1036 if(action
== ACTION_TOUCHSCREEN
)
1038 if(action_get_touchscreen_press(&ts_x
, &ts_y
) == BUTTON_REL
)
1041 else if(action
== ACTION_STD_CANCEL
)
1045 cal
->x
[i
][0] = ts_x
;
1046 cal
->y
[i
][0] = ts_y
;
1056 short points
[3][2] = {
1057 {LCD_WIDTH
/10, LCD_HEIGHT
/10},
1058 {7*LCD_WIDTH
/8, LCD_HEIGHT
/2},
1059 {LCD_WIDTH
/2, 7*LCD_HEIGHT
/8}
1061 struct screen
* screen
= &screens
[SCREEN_MAIN
];
1062 enum touchscreen_mode old_mode
= touchscreen_get_mode();
1063 struct touchscreen_calibration cal
;
1065 int statusbar
= global_settings
.statusbar
; /* hide the statusbar */
1066 global_settings
.statusbar
= STATUSBAR_OFF
;
1068 touchscreen_disable_mapping(); /* set raw mode */
1069 touchscreen_set_mode(TOUCHSCREEN_POINT
);
1072 screen
->clear_display();
1074 if(get_sample(&cal
, points
[i
][0], points
[i
][1], i
, screen
))
1082 touchscreen_calibrate(&cal
);
1084 touchscreen_reset_mapping();
1085 memcpy(&global_settings
.ts_calibration_data
, &calibration_parameters
, sizeof(struct touchscreen_parameter
));
1086 touchscreen_set_mode(old_mode
);
1087 global_settings
.statusbar
= statusbar
;
1092 int reset_mapping(void)
1094 touchscreen_reset_mapping();
1095 memcpy(&global_settings
.ts_calibration_data
, &calibration_parameters
, sizeof(struct touchscreen_parameter
));