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 "usb_keymaps.h"
50 #include "powermgmt.h"
59 #include "statusbar.h"
60 #include "screen_access.h"
66 #include "appevents.h"
68 #ifdef HAVE_LCD_BITMAP
69 #include "bitmaps/usblogo.h"
72 #ifdef HAVE_REMOTE_LCD
73 #include "bitmaps/remote_usblogo.h"
76 #if (CONFIG_STORAGE & STORAGE_MMC)
79 #if CONFIG_CODEC == SWCODEC
83 /* only used in set_time screen */
84 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
85 static int clamp_value_wrap(int value
, int max
, int min
)
101 static int handle_usb_events(void)
103 #if (CONFIG_STORAGE & STORAGE_MMC)
105 #endif /* STORAGE_MMC */
107 /* Don't return until we get SYS_USB_DISCONNECTED or SYS_TIMEOUT */
111 #ifdef USB_ENABLE_HID
112 if (usb_core_driver_enabled(USB_DRIVER_HID
))
114 button
= get_hid_usb_action();
116 /* On mode change, we need to refresh the screen */
117 if (button
== ACTION_USB_HID_MODE
||
118 button
== ACTION_USB_HID_MODE_LONG
)
126 button
= button_get_w_tmo(HZ
/2);
127 /* hid emits the event in get_action */
128 send_event(GUI_EVENT_ACTIONUPDATE
, NULL
);
133 case SYS_USB_DISCONNECTED
:
134 usb_acknowledge(SYS_USB_DISCONNECTED_ACK
);
140 #if (CONFIG_STORAGE & STORAGE_MMC) /* USB-MMC bridge can report activity */
141 if(TIME_AFTER(current_tick
,next_update
))
144 led(mmc_usb_active(HZ
));
146 next_update
=current_tick
+HZ
/2;
148 #endif /* STORAGE_MMC */
155 #define MODE_NAME_LEN 32
156 void usb_screen(void)
162 int usb_bars
= VP_SB_ALLSCREENS
; /* force statusbars */
163 int old_bars
= viewportmanager_get_statusbar();
164 #if defined HAVE_TOUCHSCREEN
165 enum touchscreen_mode old_mode
= touchscreen_get_mode();
167 /* TODO: Paint buttons on screens OR switch to point mode and use
168 * touchscreen as a touchpad to move the host's mouse cursor */
169 touchscreen_set_mode(TOUCHSCREEN_BUTTON
);
173 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
176 #ifdef USB_ENABLE_HID
177 usb_keypad_mode
= global_settings
.usb_keypad_mode
;
184 screens
[i
].backdrop_show(BACKDROP_MAIN
);
185 screens
[i
].backlight_on();
186 screens
[i
].clear_display();
187 #ifdef HAVE_REMOTE_LCD
188 if (i
== SCREEN_REMOTE
)
190 screens
[i
].bitmap(remote_usblogo
,
191 (LCD_REMOTE_WIDTH
-BMPWIDTH_remote_usblogo
),
192 (LCD_REMOTE_HEIGHT
-BMPHEIGHT_remote_usblogo
)/2,
193 BMPWIDTH_remote_usblogo
, BMPHEIGHT_remote_usblogo
);
198 #ifdef HAVE_LCD_BITMAP
199 screens
[i
].transparent_bitmap(usblogo
,
200 (LCD_WIDTH
-BMPWIDTH_usblogo
),
201 (LCD_HEIGHT
-BMPHEIGHT_usblogo
)/2,
202 BMPWIDTH_usblogo
, BMPHEIGHT_usblogo
);
203 #ifdef USB_ENABLE_HID
206 screens
[i
].getstringsize(str(keypad_mode_name_get()), &w
, &h
);
207 screens
[i
].putsxy((LCD_WIDTH
- w
) / 2, BMPHEIGHT_usblogo
+
208 (LCD_HEIGHT
- BMPHEIGHT_usblogo
+ h
) / 2,
209 str(keypad_mode_name_get()));
210 #endif /* USB_ENABLE_HID */
211 #else /* HAVE_LCD_BITMAP */
212 screens
[i
].double_height(false);
213 screens
[i
].puts_scroll(0, 0, "[USB Mode]");
214 status_set_param(false);
215 status_set_audio(false);
216 status_set_usb(true);
217 #endif /* HAVE_LCD_BITMAP */
221 /* force statusbar by ignoring the setting */
222 usb_bars
|= VP_SB_IGNORE_SETTING(i
);
225 viewportmanager_set_statusbar(usb_bars
);
228 if (button_get_w_tmo(HZ
/2))
230 send_event(GUI_EVENT_ACTIONUPDATE
, NULL
);
232 if (handle_usb_events())
234 #endif /* SIMULATOR */
237 #ifdef USB_ENABLE_HID
238 if (global_settings
.usb_keypad_mode
!= usb_keypad_mode
)
240 global_settings
.usb_keypad_mode
= usb_keypad_mode
;
245 #ifdef HAVE_TOUCHSCREEN
246 touchscreen_set_mode(old_mode
);
249 #ifdef HAVE_LCD_CHARCELLS
250 status_set_usb(false);
251 #endif /* HAVE_LCD_CHARCELLS */
254 screens
[i
].backlight_on();
256 viewportmanager_set_statusbar(old_bars
);
257 send_event(GUI_EVENT_REFRESH
, NULL
);
259 #endif /* USB_NONE */
262 #if (CONFIG_STORAGE & STORAGE_MMC)
263 int mmc_remove_request(void)
265 struct queue_event ev
;
268 screens
[i
].clear_display();
269 splash(0, ID2P(LANG_REMOVE_MMC
));
273 queue_wait_w_tmo(&button_queue
, &ev
, HZ
/2);
276 case SYS_HOTSWAP_EXTRACTED
:
277 return SYS_HOTSWAP_EXTRACTED
;
279 case SYS_USB_DISCONNECTED
:
280 return SYS_USB_DISCONNECTED
;
286 /* the charging screen is only used for archos targets */
287 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
289 #ifdef HAVE_LCD_BITMAP
290 static void charging_display_info(bool animate
)
292 unsigned char charging_logo
[36];
293 const int pox_x
= (LCD_WIDTH
- sizeof(charging_logo
)) / 2;
294 const int pox_y
= 32;
295 static unsigned phase
= 3;
300 #ifdef NEED_ATA_POWER_BATT_MEASURE
301 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
304 int battv
= battery_voltage();
305 snprintf(buf
, 32, " Batt: %d.%02dV %d%% ", battv
/ 1000,
306 (battv
% 1000) / 10, battery_level());
310 #ifdef ARCHOS_RECORER
311 snprintf(buf
, 32, "Charge mode:");
314 if (charge_state
== CHARGING
)
315 snprintf(buf
, 32, str(LANG_BATTERY_CHARGE
));
316 else if (charge_state
== TOPOFF
)
317 snprintf(buf
, 32, str(LANG_BATTERY_TOPOFF_CHARGE
));
318 else if (charge_state
== TRICKLE
)
319 snprintf(buf
, 32, str(LANG_BATTERY_TRICKLE_CHARGE
));
321 snprintf(buf
, 32, "not charging");
324 if (!charger_enabled())
326 #endif /* ARCHOS_RECORER */
329 memset(charging_logo
+3, 0x00, 32);
330 charging_logo
[0] = 0x3C;
331 charging_logo
[1] = 0x24;
332 charging_logo
[2] = charging_logo
[35] = 0xFF;
335 { /* draw the outline */
337 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8,
338 sizeof(charging_logo
), 8);
339 lcd_set_drawmode(DRMODE_FG
);
341 charging_logo
[0] = charging_logo
[1] = 0x00;
342 memset(charging_logo
+2, 0x80, 34);
343 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
, sizeof(charging_logo
), 8);
345 memset(charging_logo
+2, 0x01, 34);
346 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 16,
347 sizeof(charging_logo
), 8);
348 lcd_set_drawmode(DRMODE_SOLID
);
351 { /* animate the middle part */
352 for (i
= 3; i
<MIN(sizeof(charging_logo
)-1, phase
); i
++)
354 if ((i
-phase
) % 8 == 0)
355 { /* draw a "bubble" here */
357 bitpos
= (phase
+ i
/8) % 15; /* "bounce" effect */
359 bitpos
= 14 - bitpos
;
360 charging_logo
[i
] = BIT_N(bitpos
);
363 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8,
364 sizeof(charging_logo
), 8);
369 #else /* not HAVE_LCD_BITMAP */
371 static unsigned long logo_chars
[4];
372 static const unsigned char logo_pattern
[] = {
373 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
374 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
375 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
376 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
379 static void logo_lock_patterns(bool on
)
385 for (i
= 0; i
< 4; i
++)
386 logo_chars
[i
] = lcd_get_locked_pattern();
390 for (i
= 0; i
< 4; i
++)
391 lcd_unlock_pattern(logo_chars
[i
]);
395 static void charging_display_info(bool animate
)
399 static unsigned phase
= 3;
402 battv
= battery_voltage();
403 snprintf(buf
, sizeof(buf
), " %d.%02dV", battv
/ 1000, (battv
% 1000) / 10);
406 memcpy(buf
, logo_pattern
, 32); /* copy logo patterns */
408 if (!animate
) /* build the screen */
410 lcd_double_height(false);
411 lcd_puts(0, 0, "[Charging]");
412 for (i
= 0; i
< 4; i
++)
413 lcd_putc(i
, 1, logo_chars
[i
]);
415 else /* animate the logo */
417 for (i
= 3; i
< MIN(19, phase
); i
++)
419 if ((i
- phase
) % 5 == 0)
420 { /* draw a "bubble" here */
421 ypos
= (phase
+ i
/5) % 9; /* "bounce" effect */
424 buf
[5 - ypos
+ 8 * (i
/5)] |= 0x10u
>> (i
%5);
430 for (i
= 0; i
< 4; i
++)
431 lcd_define_pattern(logo_chars
[i
], buf
+ 8 * i
);
435 #endif /* (not) HAVE_LCD_BITMAP */
437 /* blocks while charging, returns on event:
438 1 if charger cable was removed
439 2 if Off/Stop key was pressed
440 3 if On key was pressed
441 4 if USB was connected */
443 int charging_screen(void)
448 ide_power_enable(false); /* power down the disk, else would be spinning */
451 backlight_set_timeout(global_settings
.backlight_timeout
);
452 #ifdef HAVE_REMOTE_LCD
453 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
455 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
457 #ifdef HAVE_LCD_CHARCELLS
458 logo_lock_patterns(true);
460 charging_display_info(false);
464 gui_syncstatusbar_draw(&statusbars
, false);
465 charging_display_info(true);
466 button
= get_action(CONTEXT_STD
,HZ
/3);
467 if (button
== ACTION_STD_OK
)
469 else if (usb_detect() == USB_INSERTED
)
471 else if (!charger_inserted())
475 #ifdef HAVE_LCD_CHARCELLS
476 logo_lock_patterns(false);
480 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
483 void charging_splash(void)
485 splash(2*HZ
, str(LANG_BATTERY_CHARGE
));
486 button_clear_queue();
491 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
493 /* little helper function for voice output */
494 static void say_time(int cursorpos
, const struct tm
*tm
)
499 if (!global_settings
.talk_menu
)
517 value
= tm
->tm_year
+ 1900;
524 if (cursorpos
== 4) /* month */
525 talk_id(LANG_MONTH_JANUARY
+ tm
->tm_mon
, false);
527 talk_value(value
, unit
, false);
534 #define SEPARATOR ":"
535 bool set_time_screen(const char* title
, struct tm
*tm
)
539 unsigned int i
, j
, s
;
541 unsigned int realyear
;
543 unsigned int min
, max
;
544 unsigned int statusbar_height
= 0;
545 unsigned int separator_width
, weekday_width
;
546 unsigned int prev_line_height
;
547 static unsigned char daysinmonth
[] =
548 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
549 unsigned char buffer
[20];
550 struct viewport vp
[NB_SCREENS
];
553 /* 6 possible cursor possitions, 2 values stored for each: x, y */
554 unsigned int cursor
[6][2];
557 unsigned char *ptr
[6];
559 if(global_settings
.statusbar
)
560 statusbar_height
= STATUSBAR_HEIGHT
;
562 /* speak selection when screen is entered */
563 say_time(cursorpos
, tm
);
566 /* for easy acess in the drawing loop */
567 ptr
[0] = buffer
; /* hours */
568 ptr
[1] = buffer
+ 3; /* minutes */
569 ptr
[2] = buffer
+ 6; /* seconds */
570 ptr
[3] = buffer
+ 9; /* year */
571 ptr
[4] = str(LANG_MONTH_JANUARY
+ tm
->tm_mon
); /* monthname */
572 ptr
[5] = buffer
+ 14; /* day of month */
574 /* calculate the number of days in febuary */
575 realyear
= tm
->tm_year
+ 1900;
576 if((realyear
% 4 == 0 && !(realyear
% 100 == 0)) || realyear
% 400 == 0)
581 /* fix day if month or year changed */
582 if (tm
->tm_mday
> daysinmonth
[tm
->tm_mon
])
583 tm
->tm_mday
= daysinmonth
[tm
->tm_mon
];
585 /* calculate day of week */
588 /* put all the numbers we want from the tm struct into
589 an easily printable buffer */
590 snprintf(buffer
, sizeof(buffer
),
591 "%02d " "%02d " "%02d " "%04d " "%02d",
592 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
,
593 tm
->tm_year
+1900, tm
->tm_mday
);
595 /* convert spaces in the buffer to '\0' to make it possible to work
596 directly on the buffer */
597 for(i
=0; i
< sizeof(buffer
); i
++)
605 viewport_set_defaults(&vp
[s
], s
);
606 screens
[s
].set_viewport(&vp
[s
]);
607 nb_lines
= viewport_get_nb_lines(&vp
[s
]);
609 /* minimum lines needed is 2 + title line */
612 vp
[s
].font
= FONT_SYSFIXED
;
613 nb_lines
= viewport_get_nb_lines(&vp
[s
]);
616 /* recalculate the positions and offsets */
618 screens
[s
].getstringsize(title
, NULL
, &prev_line_height
);
620 prev_line_height
= 0;
622 screens
[s
].getstringsize(SEPARATOR
, &separator_width
, NULL
);
625 screens
[s
].getstringsize(str(LANG_WEEKDAY_SUNDAY
+ tm
->tm_wday
),
626 &weekday_width
, NULL
);
627 screens
[s
].getstringsize(" ", &separator_width
, NULL
);
629 for(i
=0, j
=0; i
< 6; i
++)
631 if(i
==3) /* second row */
633 j
= weekday_width
+ separator_width
;
634 prev_line_height
*= 2;
636 screens
[s
].getstringsize(ptr
[i
], &width
, NULL
);
637 cursor
[i
][INDEX_Y
] = prev_line_height
+ statusbar_height
;
638 cursor
[i
][INDEX_X
] = j
;
639 j
+= width
+ separator_width
;
642 /* draw the screen */
643 screens
[s
].set_viewport(&vp
[s
]);
644 screens
[s
].clear_viewport();
645 /* display the screen title */
646 screens
[s
].puts_scroll(0, 0, title
);
648 /* these are not selectable, so we draw them outside the loop */
649 /* name of the week day */
650 screens
[s
].putsxy(0, cursor
[3][INDEX_Y
],
651 str(LANG_WEEKDAY_SUNDAY
+ tm
->tm_wday
));
653 /* draw the selected item with drawmode set to
654 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
655 items with drawmode DRMODE_SOLID */
658 if (cursorpos
== (int)i
)
659 vp
[s
].drawmode
= (DRMODE_SOLID
|DRMODE_INVERSEVID
);
661 screens
[s
].putsxy(cursor
[i
][INDEX_X
],
662 cursor
[i
][INDEX_Y
], ptr
[i
]);
664 vp
[s
].drawmode
= DRMODE_SOLID
;
666 screens
[s
].putsxy(cursor
[i
/4 +1][INDEX_X
] - separator_width
,
667 cursor
[0][INDEX_Y
], SEPARATOR
);
670 /* print help text */
672 screens
[s
].puts(0, 4, str(LANG_TIME_SET_BUTTON
));
674 screens
[s
].puts(0, 5, str(LANG_TIME_REVERT
));
675 screens
[s
].update_viewport();
676 screens
[s
].set_viewport(NULL
);
679 /* set the most common numbers */
682 /* calculate the minimum and maximum for the number under cursor */
686 valptr
= &tm
->tm_hour
;
689 valptr
= &tm
->tm_min
;
692 valptr
= &tm
->tm_sec
;
697 valptr
= &tm
->tm_year
;
701 valptr
= &tm
->tm_mon
;
705 max
= daysinmonth
[tm
->tm_mon
];
706 valptr
= &tm
->tm_mday
;
710 #ifdef HAVE_TOUCHSCREEN
711 enum touchscreen_mode old_mode
= touchscreen_get_mode();
713 touchscreen_set_mode(TOUCHSCREEN_BUTTON
);
715 button
= get_action(CONTEXT_SETTINGS_TIME
, TIMEOUT_BLOCK
);
716 #ifdef HAVE_TOUCHSCREEN
717 touchscreen_set_mode(old_mode
);
720 case ACTION_STD_PREV
:
721 cursorpos
= clamp_value_wrap(--cursorpos
, 5, 0);
722 say_time(cursorpos
, tm
);
724 case ACTION_STD_NEXT
:
725 cursorpos
= clamp_value_wrap(++cursorpos
, 5, 0);
726 say_time(cursorpos
, tm
);
728 case ACTION_SETTINGS_INC
:
729 case ACTION_SETTINGS_INCREPEAT
:
730 *valptr
= clamp_value_wrap(++(*valptr
), max
, min
);
731 say_time(cursorpos
, tm
);
733 case ACTION_SETTINGS_DEC
:
734 case ACTION_SETTINGS_DECREPEAT
:
735 *valptr
= clamp_value_wrap(--(*valptr
), max
, min
);
736 say_time(cursorpos
, tm
);
743 case ACTION_STD_CANCEL
:
749 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
756 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
758 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
759 bool shutdown_screen(void)
763 long time_entered
= current_tick
;
767 splash(0, str(LANG_CONFIRM_SHUTDOWN
));
769 while(!done
&& TIME_BEFORE(current_tick
,time_entered
+HZ
*2))
771 button
= get_action(CONTEXT_STD
,HZ
);
774 case ACTION_STD_CANCEL
:
778 /* do nothing here, because ACTION_NONE might be caused
779 * by timeout or button release. In case of timeout the loop
780 * is terminated by TIME_BEFORE */
785 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
795 static const int id3_headers
[]=
800 LANG_ID3_ALBUMARTIST
,
811 #if CONFIG_CODEC == SWCODEC
818 struct id3view_info
{
819 struct mp3entry
* id3
;
821 int info_id
[ARRAYLEN(id3_headers
)];
824 static const char* id3_get_info(int selected_item
, void* data
,
825 char *buffer
, size_t buffer_len
)
827 struct id3view_info
*info
= (struct id3view_info
*)data
;
828 struct mp3entry
* id3
=info
->id3
;
829 int info_no
=selected_item
/2;
830 if(!(selected_item
%2))
832 return(str(id3_headers
[info
->info_id
[info_no
]]));
838 switch(info
->info_id
[info_no
])
840 case 0:/*LANG_ID3_TITLE*/
843 case 1:/*LANG_ID3_ARTIST*/
846 case 2:/*LANG_ID3_ALBUM*/
849 case 3:/*LANG_ID3_ALBUMARTIST*/
850 val
=id3
->albumartist
;
852 case 4:/*LANG_ID3_GROUPING*/
855 case 5:/*LANG_ID3_DISCNUM*/
856 if (id3
->disc_string
)
857 val
= id3
->disc_string
;
858 else if (id3
->discnum
)
860 snprintf(buffer
, buffer_len
, "%d", id3
->discnum
);
864 case 6:/*LANG_ID3_TRACKNUM*/
865 if (id3
->track_string
)
866 val
= id3
->track_string
;
867 else if (id3
->tracknum
)
869 snprintf(buffer
, buffer_len
, "%d", id3
->tracknum
);
873 case 7:/*LANG_ID3_COMMENT*/
876 case 8:/*LANG_ID3_GENRE*/
877 val
= id3
->genre_string
;
879 case 9:/*LANG_ID3_YEAR*/
880 if (id3
->year_string
)
881 val
= id3
->year_string
;
884 snprintf(buffer
, buffer_len
, "%d", id3
->year
);
888 case 10:/*LANG_ID3_LENGTH*/
889 format_time(buffer
, buffer_len
, id3
->length
);
892 case 11:/*LANG_ID3_PLAYLIST*/
893 snprintf(buffer
, buffer_len
, "%d/%d",
894 playlist_get_display_index(), playlist_amount());
897 case 12:/*LANG_ID3_BITRATE*/
898 snprintf(buffer
, buffer_len
, "%d kbps%s", id3
->bitrate
,
899 id3
->vbr
? str(LANG_ID3_VBR
) : (const unsigned char*) "");
902 case 13:/*LANG_ID3_FREQUENCY*/
903 snprintf(buffer
, buffer_len
, "%ld Hz", id3
->frequency
);
906 #if CONFIG_CODEC == SWCODEC
907 case 14:/*LANG_ID3_TRACK_GAIN*/
908 val
=id3
->track_gain_string
;
910 case 15:/*LANG_ID3_ALBUM_GAIN*/
911 val
=id3
->album_gain_string
;
913 case 16:/*LANG_ID3_PATH*/
915 case 14:/*LANG_ID3_PATH*/
920 return val
&& *val
? val
: NULL
;
924 bool browse_id3(void)
926 struct gui_synclist id3_lists
;
927 struct mp3entry
* id3
= audio_current_track();
930 struct id3view_info info
;
933 for (i
= 0; i
< ARRAYLEN(id3_headers
); i
++)
937 if (id3_get_info((i
*2)+1, &info
, temp
, 8) != NULL
)
938 info
.info_id
[info
.count
++] = i
;
941 gui_synclist_init(&id3_lists
, &id3_get_info
, &info
, true, 2, NULL
);
942 gui_synclist_set_nb_items(&id3_lists
, info
.count
*2);
943 gui_synclist_draw(&id3_lists
);
945 key
= get_action(CONTEXT_LIST
,HZ
/2);
946 if(key
!=ACTION_NONE
&& key
!=ACTION_UNKNOWN
947 && !gui_synclist_do_button(&id3_lists
, &key
,LIST_WRAP_UNLESS_HELD
))
949 return(default_event_handler(key
) == SYS_USB_CONNECTED
);
954 static const char* runtime_get_data(int selected_item
, void* data
,
955 char* buffer
, size_t buffer_len
)
959 switch (selected_item
)
961 case 0: return str(LANG_RUNNING_TIME
);
962 case 1: t
= global_status
.runtime
; break;
963 case 2: return str(LANG_TOP_TIME
);
964 case 3: t
= global_status
.topruntime
; break;
969 snprintf(buffer
, buffer_len
, "%dh %dm %ds",
970 t
/ 3600, (t
% 3600) / 60, t
% 60);
974 static int runtime_speak_data(int selected_item
, void* data
)
978 (selected_item
< 2) ? LANG_RUNNING_TIME
: LANG_TOP_TIME
,
979 TALK_ID((selected_item
< 2) ? global_status
.runtime
980 : global_status
.topruntime
, UNIT_TIME
));
985 bool view_runtime(void)
987 static const char *lines
[]={ID2P(LANG_CLEAR_TIME
)};
988 static const struct text_message message
={lines
, 1};
990 struct gui_synclist lists
;
992 gui_synclist_init(&lists
, runtime_get_data
, NULL
, false, 2, NULL
);
993 #if !defined(HAVE_LCD_CHARCELLS)
994 gui_synclist_set_title(&lists
, str(LANG_RUNNING_TIME
), NOICON
);
996 gui_synclist_set_title(&lists
, NULL
, NOICON
);
998 if(global_settings
.talk_menu
)
999 gui_synclist_set_voice_callback(&lists
, runtime_speak_data
);
1000 gui_synclist_set_icon_callback(&lists
, NULL
);
1001 gui_synclist_set_nb_items(&lists
, 4);
1002 gui_synclist_speak_item(&lists
);
1006 if (charger_inserted())
1008 global_status
.runtime
= 0;
1013 global_status
.runtime
+= ((current_tick
- lasttime
) / HZ
);
1015 lasttime
= current_tick
;
1016 gui_synclist_draw(&lists
);
1017 list_do_action(CONTEXT_STD
, HZ
,
1018 &lists
, &action
, LIST_WRAP_UNLESS_HELD
);
1019 if(action
== ACTION_STD_CANCEL
)
1021 if(action
== ACTION_STD_OK
) {
1022 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
1024 if (!(gui_synclist_get_sel_pos(&lists
)/2))
1025 global_status
.runtime
= 0;
1027 global_status
.topruntime
= 0;
1028 gui_synclist_speak_item(&lists
);
1031 if(default_event_handler(action
) == SYS_USB_CONNECTED
)
1037 #ifdef HAVE_TOUCHSCREEN
1038 static int get_sample(struct touchscreen_calibration
*cal
, int x
, int y
, int i
,
1039 struct screen
* screen
)
1045 screen
->drawline(x
- 10, y
, x
- 2, y
);
1046 screen
->drawline(x
+ 2, y
, x
+ 10, y
);
1047 screen
->drawline(x
, y
- 10, x
, y
- 2);
1048 screen
->drawline(x
, y
+ 2, x
, y
+ 10);
1051 /* Wait for a touchscreen press */
1054 action
= get_action(CONTEXT_STD
, TIMEOUT_BLOCK
);
1055 if(action
== ACTION_TOUCHSCREEN
)
1057 if(action_get_touchscreen_press(&ts_x
, &ts_y
) == BUTTON_REL
)
1060 else if(action
== ACTION_STD_CANCEL
)
1064 cal
->x
[i
][0] = ts_x
;
1065 cal
->y
[i
][0] = ts_y
;
1075 short points
[3][2] = {
1076 {LCD_WIDTH
/10, LCD_HEIGHT
/10},
1077 {7*LCD_WIDTH
/8, LCD_HEIGHT
/2},
1078 {LCD_WIDTH
/2, 7*LCD_HEIGHT
/8}
1080 struct screen
* screen
= &screens
[SCREEN_MAIN
];
1081 enum touchscreen_mode old_mode
= touchscreen_get_mode();
1082 struct touchscreen_calibration cal
;
1084 int statusbar
= global_settings
.statusbar
; /* hide the statusbar */
1085 global_settings
.statusbar
= STATUSBAR_OFF
;
1087 touchscreen_disable_mapping(); /* set raw mode */
1088 touchscreen_set_mode(TOUCHSCREEN_POINT
);
1091 screen
->clear_display();
1093 if(get_sample(&cal
, points
[i
][0], points
[i
][1], i
, screen
))
1101 touchscreen_calibrate(&cal
);
1103 touchscreen_reset_mapping();
1104 memcpy(&global_settings
.ts_calibration_data
, &calibration_parameters
, sizeof(struct touchscreen_parameter
));
1105 touchscreen_set_mode(old_mode
);
1106 global_settings
.statusbar
= statusbar
;
1111 int reset_mapping(void)
1113 touchscreen_reset_mapping();
1114 memcpy(&global_settings
.ts_calibration_data
, &calibration_parameters
, sizeof(struct touchscreen_parameter
));