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 */
220 /* force statusbar by ignoring the setting */
221 usb_bars
|= VP_SB_IGNORE_SETTING(i
);
224 viewportmanager_set_statusbar(usb_bars
);
227 while (button_get(true) & BUTTON_REL
);
229 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
230 while (handle_usb_events());
231 #endif /* SIMULATOR */
232 #ifdef HAVE_LCD_CHARCELLS
233 status_set_usb(false);
234 #endif /* HAVE_LCD_CHARCELLS */
237 screens
[i
].backlight_on();
239 viewportmanager_set_statusbar(old_bars
);
240 send_event(GUI_EVENT_REFRESH
, NULL
);
242 #endif /* USB_NONE */
245 #if (CONFIG_STORAGE & STORAGE_MMC)
246 int mmc_remove_request(void)
248 struct queue_event ev
;
251 screens
[i
].clear_display();
252 splash(0, ID2P(LANG_REMOVE_MMC
));
256 queue_wait_w_tmo(&button_queue
, &ev
, HZ
/2);
259 case SYS_HOTSWAP_EXTRACTED
:
260 return SYS_HOTSWAP_EXTRACTED
;
262 case SYS_USB_DISCONNECTED
:
263 return SYS_USB_DISCONNECTED
;
269 /* the charging screen is only used for archos targets */
270 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
272 #ifdef HAVE_LCD_BITMAP
273 static void charging_display_info(bool animate
)
275 unsigned char charging_logo
[36];
276 const int pox_x
= (LCD_WIDTH
- sizeof(charging_logo
)) / 2;
277 const int pox_y
= 32;
278 static unsigned phase
= 3;
283 #ifdef NEED_ATA_POWER_BATT_MEASURE
284 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
287 int battv
= battery_voltage();
288 snprintf(buf
, 32, " Batt: %d.%02dV %d%% ", battv
/ 1000,
289 (battv
% 1000) / 10, battery_level());
293 #ifdef ARCHOS_RECORER
294 snprintf(buf
, 32, "Charge mode:");
297 if (charge_state
== CHARGING
)
298 snprintf(buf
, 32, str(LANG_BATTERY_CHARGE
));
299 else if (charge_state
== TOPOFF
)
300 snprintf(buf
, 32, str(LANG_BATTERY_TOPOFF_CHARGE
));
301 else if (charge_state
== TRICKLE
)
302 snprintf(buf
, 32, str(LANG_BATTERY_TRICKLE_CHARGE
));
304 snprintf(buf
, 32, "not charging");
307 if (!charger_enabled())
309 #endif /* ARCHOS_RECORER */
312 memset(charging_logo
+3, 0x00, 32);
313 charging_logo
[0] = 0x3C;
314 charging_logo
[1] = 0x24;
315 charging_logo
[2] = charging_logo
[35] = 0xFF;
318 { /* draw the outline */
320 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8,
321 sizeof(charging_logo
), 8);
322 lcd_set_drawmode(DRMODE_FG
);
324 charging_logo
[0] = charging_logo
[1] = 0x00;
325 memset(charging_logo
+2, 0x80, 34);
326 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
, sizeof(charging_logo
), 8);
328 memset(charging_logo
+2, 0x01, 34);
329 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 16,
330 sizeof(charging_logo
), 8);
331 lcd_set_drawmode(DRMODE_SOLID
);
334 { /* animate the middle part */
335 for (i
= 3; i
<MIN(sizeof(charging_logo
)-1, phase
); i
++)
337 if ((i
-phase
) % 8 == 0)
338 { /* draw a "bubble" here */
340 bitpos
= (phase
+ i
/8) % 15; /* "bounce" effect */
342 bitpos
= 14 - bitpos
;
343 charging_logo
[i
] = BIT_N(bitpos
);
346 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8,
347 sizeof(charging_logo
), 8);
352 #else /* not HAVE_LCD_BITMAP */
354 static unsigned long logo_chars
[4];
355 static const unsigned char logo_pattern
[] = {
356 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
357 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
358 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
359 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
362 static void logo_lock_patterns(bool on
)
368 for (i
= 0; i
< 4; i
++)
369 logo_chars
[i
] = lcd_get_locked_pattern();
373 for (i
= 0; i
< 4; i
++)
374 lcd_unlock_pattern(logo_chars
[i
]);
378 static void charging_display_info(bool animate
)
382 static unsigned phase
= 3;
385 battv
= battery_voltage();
386 snprintf(buf
, sizeof(buf
), " %d.%02dV", battv
/ 1000, (battv
% 1000) / 10);
389 memcpy(buf
, logo_pattern
, 32); /* copy logo patterns */
391 if (!animate
) /* build the screen */
393 lcd_double_height(false);
394 lcd_puts(0, 0, "[Charging]");
395 for (i
= 0; i
< 4; i
++)
396 lcd_putc(i
, 1, logo_chars
[i
]);
398 else /* animate the logo */
400 for (i
= 3; i
< MIN(19, phase
); i
++)
402 if ((i
- phase
) % 5 == 0)
403 { /* draw a "bubble" here */
404 ypos
= (phase
+ i
/5) % 9; /* "bounce" effect */
407 buf
[5 - ypos
+ 8 * (i
/5)] |= 0x10u
>> (i
%5);
413 for (i
= 0; i
< 4; i
++)
414 lcd_define_pattern(logo_chars
[i
], buf
+ 8 * i
);
418 #endif /* (not) HAVE_LCD_BITMAP */
420 /* blocks while charging, returns on event:
421 1 if charger cable was removed
422 2 if Off/Stop key was pressed
423 3 if On key was pressed
424 4 if USB was connected */
426 int charging_screen(void)
431 ide_power_enable(false); /* power down the disk, else would be spinning */
434 backlight_set_timeout(global_settings
.backlight_timeout
);
435 #ifdef HAVE_REMOTE_LCD
436 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
438 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
440 #ifdef HAVE_LCD_CHARCELLS
441 logo_lock_patterns(true);
443 charging_display_info(false);
447 gui_syncstatusbar_draw(&statusbars
, false);
448 charging_display_info(true);
449 button
= get_action(CONTEXT_STD
,HZ
/3);
450 if (button
== ACTION_STD_OK
)
452 else if (usb_detect() == USB_INSERTED
)
454 else if (!charger_inserted())
458 #ifdef HAVE_LCD_CHARCELLS
459 logo_lock_patterns(false);
463 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
466 void charging_splash(void)
468 splash(2*HZ
, str(LANG_BATTERY_CHARGE
));
469 button_clear_queue();
474 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
476 /* little helper function for voice output */
477 static void say_time(int cursorpos
, const struct tm
*tm
)
482 if (!global_settings
.talk_menu
)
500 value
= tm
->tm_year
+ 1900;
507 if (cursorpos
== 4) /* month */
508 talk_id(LANG_MONTH_JANUARY
+ tm
->tm_mon
, false);
510 talk_value(value
, unit
, false);
517 #define SEPARATOR ":"
518 bool set_time_screen(const char* title
, struct tm
*tm
)
522 unsigned int i
, j
, s
;
524 unsigned int realyear
;
526 unsigned int min
, max
;
527 unsigned int statusbar_height
= 0;
528 unsigned int separator_width
, weekday_width
;
529 unsigned int prev_line_height
;
530 static unsigned char daysinmonth
[] =
531 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
532 unsigned char buffer
[20];
533 struct viewport vp
[NB_SCREENS
];
536 /* 6 possible cursor possitions, 2 values stored for each: x, y */
537 unsigned int cursor
[6][2];
540 unsigned char *ptr
[6];
542 if(global_settings
.statusbar
)
543 statusbar_height
= STATUSBAR_HEIGHT
;
545 /* speak selection when screen is entered */
546 say_time(cursorpos
, tm
);
549 /* for easy acess in the drawing loop */
550 ptr
[0] = buffer
; /* hours */
551 ptr
[1] = buffer
+ 3; /* minutes */
552 ptr
[2] = buffer
+ 6; /* seconds */
553 ptr
[3] = buffer
+ 9; /* year */
554 ptr
[4] = str(LANG_MONTH_JANUARY
+ tm
->tm_mon
); /* monthname */
555 ptr
[5] = buffer
+ 14; /* day of month */
557 /* calculate the number of days in febuary */
558 realyear
= tm
->tm_year
+ 1900;
559 if((realyear
% 4 == 0 && !(realyear
% 100 == 0)) || realyear
% 400 == 0)
564 /* fix day if month or year changed */
565 if (tm
->tm_mday
> daysinmonth
[tm
->tm_mon
])
566 tm
->tm_mday
= daysinmonth
[tm
->tm_mon
];
568 /* calculate day of week */
571 /* put all the numbers we want from the tm struct into
572 an easily printable buffer */
573 snprintf(buffer
, sizeof(buffer
),
574 "%02d " "%02d " "%02d " "%04d " "%02d",
575 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
,
576 tm
->tm_year
+1900, tm
->tm_mday
);
578 /* convert spaces in the buffer to '\0' to make it possible to work
579 directly on the buffer */
580 for(i
=0; i
< sizeof(buffer
); i
++)
588 viewport_set_defaults(&vp
[s
], s
);
589 screens
[s
].set_viewport(&vp
[s
]);
590 nb_lines
= viewport_get_nb_lines(&vp
[s
]);
592 /* minimum lines needed is 2 + title line */
595 vp
[s
].font
= FONT_SYSFIXED
;
596 nb_lines
= viewport_get_nb_lines(&vp
[s
]);
599 /* recalculate the positions and offsets */
601 screens
[s
].getstringsize(title
, NULL
, &prev_line_height
);
603 prev_line_height
= 0;
605 screens
[s
].getstringsize(SEPARATOR
, &separator_width
, NULL
);
608 screens
[s
].getstringsize(str(LANG_WEEKDAY_SUNDAY
+ tm
->tm_wday
),
609 &weekday_width
, NULL
);
610 screens
[s
].getstringsize(" ", &separator_width
, NULL
);
612 for(i
=0, j
=0; i
< 6; i
++)
614 if(i
==3) /* second row */
616 j
= weekday_width
+ separator_width
;
617 prev_line_height
*= 2;
619 screens
[s
].getstringsize(ptr
[i
], &width
, NULL
);
620 cursor
[i
][INDEX_Y
] = prev_line_height
+ statusbar_height
;
621 cursor
[i
][INDEX_X
] = j
;
622 j
+= width
+ separator_width
;
625 /* draw the screen */
626 screens
[s
].set_viewport(&vp
[s
]);
627 screens
[s
].clear_viewport();
628 /* display the screen title */
629 screens
[s
].puts_scroll(0, 0, title
);
631 /* these are not selectable, so we draw them outside the loop */
632 /* name of the week day */
633 screens
[s
].putsxy(0, cursor
[3][INDEX_Y
],
634 str(LANG_WEEKDAY_SUNDAY
+ tm
->tm_wday
));
636 /* draw the selected item with drawmode set to
637 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
638 items with drawmode DRMODE_SOLID */
641 if (cursorpos
== (int)i
)
642 vp
[s
].drawmode
= (DRMODE_SOLID
|DRMODE_INVERSEVID
);
644 screens
[s
].putsxy(cursor
[i
][INDEX_X
],
645 cursor
[i
][INDEX_Y
], ptr
[i
]);
647 vp
[s
].drawmode
= DRMODE_SOLID
;
649 screens
[s
].putsxy(cursor
[i
/4 +1][INDEX_X
] - separator_width
,
650 cursor
[0][INDEX_Y
], SEPARATOR
);
653 /* print help text */
655 screens
[s
].puts(0, 4, str(LANG_TIME_SET_BUTTON
));
657 screens
[s
].puts(0, 5, str(LANG_TIME_REVERT
));
658 screens
[s
].update_viewport();
659 screens
[s
].set_viewport(NULL
);
662 /* set the most common numbers */
665 /* calculate the minimum and maximum for the number under cursor */
669 valptr
= &tm
->tm_hour
;
672 valptr
= &tm
->tm_min
;
675 valptr
= &tm
->tm_sec
;
680 valptr
= &tm
->tm_year
;
684 valptr
= &tm
->tm_mon
;
688 max
= daysinmonth
[tm
->tm_mon
];
689 valptr
= &tm
->tm_mday
;
693 #ifdef HAVE_TOUCHSCREEN
694 enum touchscreen_mode old_mode
= touchscreen_get_mode();
696 touchscreen_set_mode(TOUCHSCREEN_BUTTON
);
698 button
= get_action(CONTEXT_SETTINGS_TIME
, TIMEOUT_BLOCK
);
699 #ifdef HAVE_TOUCHSCREEN
700 touchscreen_set_mode(old_mode
);
703 case ACTION_STD_PREV
:
704 cursorpos
= clamp_value_wrap(--cursorpos
, 5, 0);
705 say_time(cursorpos
, tm
);
707 case ACTION_STD_NEXT
:
708 cursorpos
= clamp_value_wrap(++cursorpos
, 5, 0);
709 say_time(cursorpos
, tm
);
711 case ACTION_SETTINGS_INC
:
712 case ACTION_SETTINGS_INCREPEAT
:
713 *valptr
= clamp_value_wrap(++(*valptr
), max
, min
);
714 say_time(cursorpos
, tm
);
716 case ACTION_SETTINGS_DEC
:
717 case ACTION_SETTINGS_DECREPEAT
:
718 *valptr
= clamp_value_wrap(--(*valptr
), max
, min
);
719 say_time(cursorpos
, tm
);
726 case ACTION_STD_CANCEL
:
732 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
739 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
741 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
742 bool shutdown_screen(void)
746 long time_entered
= current_tick
;
750 splash(0, str(LANG_CONFIRM_SHUTDOWN
));
752 while(!done
&& TIME_BEFORE(current_tick
,time_entered
+HZ
*2))
754 button
= get_action(CONTEXT_STD
,HZ
);
757 case ACTION_STD_CANCEL
:
761 /* do nothing here, because ACTION_NONE might be caused
762 * by timeout or button release. In case of timeout the loop
763 * is terminated by TIME_BEFORE */
768 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
778 static const int id3_headers
[]=
783 LANG_ID3_ALBUMARTIST
,
794 #if CONFIG_CODEC == SWCODEC
801 struct id3view_info
{
802 struct mp3entry
* id3
;
804 int info_id
[ARRAYLEN(id3_headers
)];
807 static const char* id3_get_info(int selected_item
, void* data
,
808 char *buffer
, size_t buffer_len
)
810 struct id3view_info
*info
= (struct id3view_info
*)data
;
811 struct mp3entry
* id3
=info
->id3
;
812 int info_no
=selected_item
/2;
813 if(!(selected_item
%2))
815 return(str(id3_headers
[info
->info_id
[info_no
]]));
821 switch(info
->info_id
[info_no
])
823 case 0:/*LANG_ID3_TITLE*/
826 case 1:/*LANG_ID3_ARTIST*/
829 case 2:/*LANG_ID3_ALBUM*/
832 case 3:/*LANG_ID3_ALBUMARTIST*/
833 val
=id3
->albumartist
;
835 case 4:/*LANG_ID3_GROUPING*/
838 case 5:/*LANG_ID3_DISCNUM*/
839 if (id3
->disc_string
)
840 val
= id3
->disc_string
;
841 else if (id3
->discnum
)
843 snprintf(buffer
, buffer_len
, "%d", id3
->discnum
);
847 case 6:/*LANG_ID3_TRACKNUM*/
848 if (id3
->track_string
)
849 val
= id3
->track_string
;
850 else if (id3
->tracknum
)
852 snprintf(buffer
, buffer_len
, "%d", id3
->tracknum
);
856 case 7:/*LANG_ID3_COMMENT*/
859 case 8:/*LANG_ID3_GENRE*/
860 val
= id3
->genre_string
;
862 case 9:/*LANG_ID3_YEAR*/
863 if (id3
->year_string
)
864 val
= id3
->year_string
;
867 snprintf(buffer
, buffer_len
, "%d", id3
->year
);
871 case 10:/*LANG_ID3_LENGTH*/
872 format_time(buffer
, buffer_len
, id3
->length
);
875 case 11:/*LANG_ID3_PLAYLIST*/
876 snprintf(buffer
, buffer_len
, "%d/%d",
877 playlist_get_display_index(), playlist_amount());
880 case 12:/*LANG_ID3_BITRATE*/
881 snprintf(buffer
, buffer_len
, "%d kbps%s", id3
->bitrate
,
882 id3
->vbr
? str(LANG_ID3_VBR
) : (const unsigned char*) "");
885 case 13:/*LANG_ID3_FREQUENCY*/
886 snprintf(buffer
, buffer_len
, "%ld Hz", id3
->frequency
);
889 #if CONFIG_CODEC == SWCODEC
890 case 14:/*LANG_ID3_TRACK_GAIN*/
891 val
=id3
->track_gain_string
;
893 case 15:/*LANG_ID3_ALBUM_GAIN*/
894 val
=id3
->album_gain_string
;
896 case 16:/*LANG_ID3_PATH*/
898 case 14:/*LANG_ID3_PATH*/
903 return val
&& *val
? val
: NULL
;
907 bool browse_id3(void)
909 struct gui_synclist id3_lists
;
910 struct mp3entry
* id3
= audio_current_track();
913 struct id3view_info info
;
916 for (i
= 0; i
< ARRAYLEN(id3_headers
); i
++)
920 if (id3_get_info((i
*2)+1, &info
, temp
, 8) != NULL
)
921 info
.info_id
[info
.count
++] = i
;
924 gui_synclist_init(&id3_lists
, &id3_get_info
, &info
, true, 2, NULL
);
925 gui_synclist_set_nb_items(&id3_lists
, info
.count
*2);
926 gui_synclist_draw(&id3_lists
);
928 key
= get_action(CONTEXT_LIST
,HZ
/2);
929 if(key
!=ACTION_NONE
&& key
!=ACTION_UNKNOWN
930 && !gui_synclist_do_button(&id3_lists
, &key
,LIST_WRAP_UNLESS_HELD
))
932 return(default_event_handler(key
) == SYS_USB_CONNECTED
);
937 static const char* runtime_get_data(int selected_item
, void* data
,
938 char* buffer
, size_t buffer_len
)
942 switch (selected_item
)
944 case 0: return str(LANG_RUNNING_TIME
);
945 case 1: t
= global_status
.runtime
; break;
946 case 2: return str(LANG_TOP_TIME
);
947 case 3: t
= global_status
.topruntime
; break;
952 snprintf(buffer
, buffer_len
, "%dh %dm %ds",
953 t
/ 3600, (t
% 3600) / 60, t
% 60);
957 static int runtime_speak_data(int selected_item
, void* data
)
961 (selected_item
< 2) ? LANG_RUNNING_TIME
: LANG_TOP_TIME
,
962 TALK_ID((selected_item
< 2) ? global_status
.runtime
963 : global_status
.topruntime
, UNIT_TIME
));
968 bool view_runtime(void)
970 static const char *lines
[]={ID2P(LANG_CLEAR_TIME
)};
971 static const struct text_message message
={lines
, 1};
973 struct gui_synclist lists
;
975 gui_synclist_init(&lists
, runtime_get_data
, NULL
, false, 2, NULL
);
976 #if !defined(HAVE_LCD_CHARCELLS)
977 gui_synclist_set_title(&lists
, str(LANG_RUNNING_TIME
), NOICON
);
979 gui_synclist_set_title(&lists
, NULL
, NOICON
);
981 if(global_settings
.talk_menu
)
982 gui_synclist_set_voice_callback(&lists
, runtime_speak_data
);
983 gui_synclist_set_icon_callback(&lists
, NULL
);
984 gui_synclist_set_nb_items(&lists
, 4);
985 gui_synclist_speak_item(&lists
);
989 if (charger_inserted())
991 global_status
.runtime
= 0;
996 global_status
.runtime
+= ((current_tick
- lasttime
) / HZ
);
998 lasttime
= current_tick
;
999 gui_synclist_draw(&lists
);
1000 list_do_action(CONTEXT_STD
, HZ
,
1001 &lists
, &action
, LIST_WRAP_UNLESS_HELD
);
1002 if(action
== ACTION_STD_CANCEL
)
1004 if(action
== ACTION_STD_OK
) {
1005 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
1007 if (!(gui_synclist_get_sel_pos(&lists
)/2))
1008 global_status
.runtime
= 0;
1010 global_status
.topruntime
= 0;
1011 gui_synclist_speak_item(&lists
);
1014 if(default_event_handler(action
) == SYS_USB_CONNECTED
)
1020 #ifdef HAVE_TOUCHSCREEN
1021 static int get_sample(struct touchscreen_calibration
*cal
, int x
, int y
, int i
,
1022 struct screen
* screen
)
1028 screen
->drawline(x
- 10, y
, x
- 2, y
);
1029 screen
->drawline(x
+ 2, y
, x
+ 10, y
);
1030 screen
->drawline(x
, y
- 10, x
, y
- 2);
1031 screen
->drawline(x
, y
+ 2, x
, y
+ 10);
1034 /* Wait for a touchscreen press */
1037 action
= get_action(CONTEXT_STD
, TIMEOUT_BLOCK
);
1038 if(action
== ACTION_TOUCHSCREEN
)
1040 if(action_get_touchscreen_press(&ts_x
, &ts_y
) == BUTTON_REL
)
1043 else if(action
== ACTION_STD_CANCEL
)
1047 cal
->x
[i
][0] = ts_x
;
1048 cal
->y
[i
][0] = ts_y
;
1058 short points
[3][2] = {
1059 {LCD_WIDTH
/10, LCD_HEIGHT
/10},
1060 {7*LCD_WIDTH
/8, LCD_HEIGHT
/2},
1061 {LCD_WIDTH
/2, 7*LCD_HEIGHT
/8}
1063 struct screen
* screen
= &screens
[SCREEN_MAIN
];
1064 enum touchscreen_mode old_mode
= touchscreen_get_mode();
1065 struct touchscreen_calibration cal
;
1067 int statusbar
= global_settings
.statusbar
; /* hide the statusbar */
1068 global_settings
.statusbar
= STATUSBAR_OFF
;
1070 touchscreen_disable_mapping(); /* set raw mode */
1071 touchscreen_set_mode(TOUCHSCREEN_POINT
);
1074 screen
->clear_display();
1076 if(get_sample(&cal
, points
[i
][0], points
[i
][1], i
, screen
))
1084 touchscreen_calibrate(&cal
);
1086 touchscreen_reset_mapping();
1087 memcpy(&global_settings
.ts_calibration_data
, &calibration_parameters
, sizeof(struct touchscreen_parameter
));
1088 touchscreen_set_mode(old_mode
);
1089 global_settings
.statusbar
= statusbar
;
1094 int reset_mapping(void)
1096 touchscreen_reset_mapping();
1097 memcpy(&global_settings
.ts_calibration_data
, &calibration_parameters
, sizeof(struct touchscreen_parameter
));