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;
187 show_main_backdrop();
189 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
190 show_remote_main_backdrop();
194 screens
[i
].backlight_on();
195 screens
[i
].clear_display();
197 if (i
== SCREEN_REMOTE
)
199 screens
[i
].bitmap(remote_usblogo
,
200 (LCD_REMOTE_WIDTH
-BMPWIDTH_remote_usblogo
),
201 (LCD_REMOTE_HEIGHT
-BMPHEIGHT_remote_usblogo
)/2,
202 BMPWIDTH_remote_usblogo
, BMPHEIGHT_remote_usblogo
);
207 #ifdef HAVE_LCD_BITMAP
208 screens
[i
].transparent_bitmap(usblogo
,
209 (LCD_WIDTH
-BMPWIDTH_usblogo
),
210 (LCD_HEIGHT
-BMPHEIGHT_usblogo
)/2,
211 BMPWIDTH_usblogo
, BMPHEIGHT_usblogo
);
213 screens
[i
].double_height(false);
214 screens
[i
].puts_scroll(0, 0, "[USB Mode]");
215 status_set_param(false);
216 status_set_audio(false);
217 status_set_usb(true);
218 #endif /* HAVE_LCD_BITMAP */
226 while (button_get(true) & BUTTON_REL
);
228 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
229 while (handle_usb_events());
230 #endif /* SIMULATOR */
231 #ifdef HAVE_LCD_CHARCELLS
232 status_set_usb(false);
233 #endif /* HAVE_LCD_CHARCELLS */
235 screens
[i
].backlight_on();
236 global_settings
.statusbar
= statusbar
;
237 #endif /* USB_NONE */
240 #if (CONFIG_STORAGE & STORAGE_MMC)
241 int mmc_remove_request(void)
243 struct queue_event ev
;
246 screens
[i
].clear_display();
247 splash(0, ID2P(LANG_REMOVE_MMC
));
251 queue_wait_w_tmo(&button_queue
, &ev
, HZ
/2);
254 case SYS_HOTSWAP_EXTRACTED
:
255 return SYS_HOTSWAP_EXTRACTED
;
257 case SYS_USB_DISCONNECTED
:
258 return SYS_USB_DISCONNECTED
;
264 /* the charging screen is only used for archos targets */
265 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
267 #ifdef HAVE_LCD_BITMAP
268 static void charging_display_info(bool animate
)
270 unsigned char charging_logo
[36];
271 const int pox_x
= (LCD_WIDTH
- sizeof(charging_logo
)) / 2;
272 const int pox_y
= 32;
273 static unsigned phase
= 3;
278 #ifdef NEED_ATA_POWER_BATT_MEASURE
279 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
282 int battv
= battery_voltage();
283 snprintf(buf
, 32, " Batt: %d.%02dV %d%% ", battv
/ 1000,
284 (battv
% 1000) / 10, battery_level());
288 #ifdef ARCHOS_RECORER
289 snprintf(buf
, 32, "Charge mode:");
292 if (charge_state
== CHARGING
)
293 snprintf(buf
, 32, str(LANG_BATTERY_CHARGE
));
294 else if (charge_state
== TOPOFF
)
295 snprintf(buf
, 32, str(LANG_BATTERY_TOPOFF_CHARGE
));
296 else if (charge_state
== TRICKLE
)
297 snprintf(buf
, 32, str(LANG_BATTERY_TRICKLE_CHARGE
));
299 snprintf(buf
, 32, "not charging");
302 if (!charger_enabled())
304 #endif /* ARCHOS_RECORER */
307 memset(charging_logo
+3, 0x00, 32);
308 charging_logo
[0] = 0x3C;
309 charging_logo
[1] = 0x24;
310 charging_logo
[2] = charging_logo
[35] = 0xFF;
313 { /* draw the outline */
315 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8,
316 sizeof(charging_logo
), 8);
317 lcd_set_drawmode(DRMODE_FG
);
319 charging_logo
[0] = charging_logo
[1] = 0x00;
320 memset(charging_logo
+2, 0x80, 34);
321 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
, sizeof(charging_logo
), 8);
323 memset(charging_logo
+2, 0x01, 34);
324 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 16,
325 sizeof(charging_logo
), 8);
326 lcd_set_drawmode(DRMODE_SOLID
);
329 { /* animate the middle part */
330 for (i
= 3; i
<MIN(sizeof(charging_logo
)-1, phase
); i
++)
332 if ((i
-phase
) % 8 == 0)
333 { /* draw a "bubble" here */
335 bitpos
= (phase
+ i
/8) % 15; /* "bounce" effect */
337 bitpos
= 14 - bitpos
;
338 charging_logo
[i
] = BIT_N(bitpos
);
341 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8,
342 sizeof(charging_logo
), 8);
347 #else /* not HAVE_LCD_BITMAP */
349 static unsigned long logo_chars
[4];
350 static const unsigned char logo_pattern
[] = {
351 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
352 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
353 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
354 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
357 static void logo_lock_patterns(bool on
)
363 for (i
= 0; i
< 4; i
++)
364 logo_chars
[i
] = lcd_get_locked_pattern();
368 for (i
= 0; i
< 4; i
++)
369 lcd_unlock_pattern(logo_chars
[i
]);
373 static void charging_display_info(bool animate
)
377 static unsigned phase
= 3;
380 battv
= battery_voltage();
381 snprintf(buf
, sizeof(buf
), " %d.%02dV", battv
/ 1000, (battv
% 1000) / 10);
384 memcpy(buf
, logo_pattern
, 32); /* copy logo patterns */
386 if (!animate
) /* build the screen */
388 lcd_double_height(false);
389 lcd_puts(0, 0, "[Charging]");
390 for (i
= 0; i
< 4; i
++)
391 lcd_putc(i
, 1, logo_chars
[i
]);
393 else /* animate the logo */
395 for (i
= 3; i
< MIN(19, phase
); i
++)
397 if ((i
- phase
) % 5 == 0)
398 { /* draw a "bubble" here */
399 ypos
= (phase
+ i
/5) % 9; /* "bounce" effect */
402 buf
[5 - ypos
+ 8 * (i
/5)] |= 0x10u
>> (i
%5);
408 for (i
= 0; i
< 4; i
++)
409 lcd_define_pattern(logo_chars
[i
], buf
+ 8 * i
);
413 #endif /* (not) HAVE_LCD_BITMAP */
415 /* blocks while charging, returns on event:
416 1 if charger cable was removed
417 2 if Off/Stop key was pressed
418 3 if On key was pressed
419 4 if USB was connected */
421 int charging_screen(void)
426 ide_power_enable(false); /* power down the disk, else would be spinning */
429 backlight_set_timeout(global_settings
.backlight_timeout
);
430 #ifdef HAVE_REMOTE_LCD
431 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
433 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
435 #ifdef HAVE_LCD_CHARCELLS
436 logo_lock_patterns(true);
438 charging_display_info(false);
442 gui_syncstatusbar_draw(&statusbars
, false);
443 charging_display_info(true);
444 button
= get_action(CONTEXT_STD
,HZ
/3);
445 if (button
== ACTION_STD_OK
)
447 else if (usb_detect() == USB_INSERTED
)
449 else if (!charger_inserted())
453 #ifdef HAVE_LCD_CHARCELLS
454 logo_lock_patterns(false);
458 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
461 void charging_splash(void)
463 splash(2*HZ
, str(LANG_BATTERY_CHARGE
));
464 button_clear_queue();
469 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
471 /* little helper function for voice output */
472 static void say_time(int cursorpos
, const struct tm
*tm
)
477 if (!global_settings
.talk_menu
)
495 value
= tm
->tm_year
+ 1900;
502 if (cursorpos
== 4) /* month */
503 talk_id(LANG_MONTH_JANUARY
+ tm
->tm_mon
, false);
505 talk_value(value
, unit
, false);
512 #define SEPARATOR ":"
513 bool set_time_screen(const char* title
, struct tm
*tm
)
517 unsigned int i
, j
, s
;
519 unsigned int julianday
;
520 unsigned int realyear
;
522 unsigned int min
, max
;
523 unsigned int statusbar_height
= 0;
524 unsigned int separator_width
, weekday_width
;
525 unsigned int prev_line_height
;
526 int daysinmonth
[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
527 unsigned char buffer
[20];
528 struct viewport vp
[NB_SCREENS
];
531 /* 6 possible cursor possitions, 2 values stored for each: x, y */
532 unsigned int cursor
[6][2];
535 unsigned char *ptr
[6];
537 if(global_settings
.statusbar
)
538 statusbar_height
= STATUSBAR_HEIGHT
;
540 /* speak selection when screen is entered */
541 say_time(cursorpos
, tm
);
544 /* for easy acess in the drawing loop */
545 ptr
[0] = buffer
; /* hours */
546 ptr
[1] = buffer
+ 3; /* minutes */
547 ptr
[2] = buffer
+ 6; /* seconds */
548 ptr
[3] = buffer
+ 9; /* year */
549 ptr
[4] = str(LANG_MONTH_JANUARY
+ tm
->tm_mon
); /* monthname */
550 ptr
[5] = buffer
+ 14; /* day of month */
552 /* calculate the number of days in febuary */
553 realyear
= tm
->tm_year
+ 1900;
554 if((realyear
% 4 == 0 && !(realyear
% 100 == 0)) || realyear
% 400 == 0)
559 /* fix day if month or year changed */
560 if (tm
->tm_mday
> daysinmonth
[tm
->tm_mon
])
561 tm
->tm_mday
= daysinmonth
[tm
->tm_mon
];
563 /* calculate day of week */
564 julianday
= tm
->tm_mday
;
565 for(i
= 0; (int)i
< tm
->tm_mon
; i
++) {
566 julianday
+= daysinmonth
[i
];
569 tm
->tm_wday
= (realyear
+ julianday
+ (realyear
- 1) / 4 -
570 (realyear
- 1) / 100 + (realyear
- 1) / 400 + 7 - 1) % 7;
572 /* put all the numbers we want from the tm struct into
573 an easily printable buffer */
574 snprintf(buffer
, sizeof(buffer
),
575 "%02d " "%02d " "%02d " "%04d " "%02d",
576 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
,
577 tm
->tm_year
+1900, tm
->tm_mday
);
579 /* convert spaces in the buffer to '\0' to make it possible to work
580 directly on the buffer */
581 for(i
=0; i
< sizeof(buffer
); i
++)
589 viewport_set_defaults(&vp
[s
], s
);
590 screens
[s
].set_viewport(&vp
[s
]);
591 nb_lines
= viewport_get_nb_lines(&vp
[s
]);
593 /* minimum lines needed is 2 + title line */
596 vp
[s
].font
= FONT_SYSFIXED
;
597 nb_lines
= viewport_get_nb_lines(&vp
[s
]);
600 /* recalculate the positions and offsets */
602 screens
[s
].getstringsize(title
, NULL
, &prev_line_height
);
604 prev_line_height
= 0;
606 screens
[s
].getstringsize(SEPARATOR
, &separator_width
, NULL
);
609 screens
[s
].getstringsize(str(LANG_WEEKDAY_SUNDAY
+ tm
->tm_wday
),
610 &weekday_width
, NULL
);
611 screens
[s
].getstringsize(" ", &separator_width
, NULL
);
613 for(i
=0, j
=0; i
< 6; i
++)
615 if(i
==3) /* second row */
617 j
= weekday_width
+ separator_width
;
618 prev_line_height
*= 2;
620 screens
[s
].getstringsize(ptr
[i
], &width
, NULL
);
621 cursor
[i
][INDEX_Y
] = prev_line_height
+ statusbar_height
;
622 cursor
[i
][INDEX_X
] = j
;
623 j
+= width
+ separator_width
;
626 /* draw the screen */
627 screens
[s
].set_viewport(&vp
[s
]);
628 screens
[s
].clear_viewport();
629 /* display the screen title */
630 screens
[s
].puts_scroll(0, 0, title
);
632 /* these are not selectable, so we draw them outside the loop */
633 /* name of the week day */
634 screens
[s
].putsxy(0, cursor
[3][INDEX_Y
],
635 str(LANG_WEEKDAY_SUNDAY
+ tm
->tm_wday
));
637 /* draw the selected item with drawmode set to
638 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
639 items with drawmode DRMODE_SOLID */
642 if (cursorpos
== (int)i
)
643 vp
[s
].drawmode
= (DRMODE_SOLID
|DRMODE_INVERSEVID
);
645 screens
[s
].putsxy(cursor
[i
][INDEX_X
],
646 cursor
[i
][INDEX_Y
], ptr
[i
]);
648 vp
[s
].drawmode
= DRMODE_SOLID
;
650 screens
[s
].putsxy(cursor
[i
/4 +1][INDEX_X
] - separator_width
,
651 cursor
[0][INDEX_Y
], SEPARATOR
);
654 /* print help text */
656 screens
[s
].puts(0, 4, str(LANG_TIME_SET_BUTTON
));
658 screens
[s
].puts(0, 5, str(LANG_TIME_REVERT
));
659 screens
[s
].update_viewport();
660 screens
[s
].set_viewport(NULL
);
663 /* set the most common numbers */
666 /* calculate the minimum and maximum for the number under cursor */
670 valptr
= &tm
->tm_hour
;
673 valptr
= &tm
->tm_min
;
676 valptr
= &tm
->tm_sec
;
681 valptr
= &tm
->tm_year
;
685 valptr
= &tm
->tm_mon
;
689 max
= daysinmonth
[tm
->tm_mon
];
690 valptr
= &tm
->tm_mday
;
694 #ifdef HAVE_TOUCHSCREEN
695 enum touchscreen_mode old_mode
= touchscreen_get_mode();
697 touchscreen_set_mode(TOUCHSCREEN_BUTTON
);
699 button
= get_action(CONTEXT_SETTINGS_TIME
, TIMEOUT_BLOCK
);
700 #ifdef HAVE_TOUCHSCREEN
701 touchscreen_set_mode(old_mode
);
704 case ACTION_STD_PREV
:
705 cursorpos
= clamp_value_wrap(--cursorpos
, 5, 0);
706 say_time(cursorpos
, tm
);
708 case ACTION_STD_NEXT
:
709 cursorpos
= clamp_value_wrap(++cursorpos
, 5, 0);
710 say_time(cursorpos
, tm
);
712 case ACTION_SETTINGS_INC
:
713 case ACTION_SETTINGS_INCREPEAT
:
714 *valptr
= clamp_value_wrap(++(*valptr
), max
, min
);
715 say_time(cursorpos
, tm
);
717 case ACTION_SETTINGS_DEC
:
718 case ACTION_SETTINGS_DECREPEAT
:
719 *valptr
= clamp_value_wrap(--(*valptr
), max
, min
);
720 say_time(cursorpos
, tm
);
727 case ACTION_STD_CANCEL
:
733 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
740 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
742 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
743 bool shutdown_screen(void)
747 long time_entered
= current_tick
;
751 splash(0, str(LANG_CONFIRM_SHUTDOWN
));
753 while(!done
&& TIME_BEFORE(current_tick
,time_entered
+HZ
*2))
755 button
= get_action(CONTEXT_STD
,HZ
);
758 case ACTION_STD_CANCEL
:
762 /* do nothing here, because ACTION_NONE might be caused
763 * by timeout or button release. In case of timeout the loop
764 * is terminated by TIME_BEFORE */
769 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
779 static const int id3_headers
[]=
784 LANG_ID3_ALBUMARTIST
,
795 #if CONFIG_CODEC == SWCODEC
801 struct id3view_info
{
802 struct mp3entry
* id3
;
804 int info_id
[sizeof(id3_headers
)/sizeof(id3_headers
[0])];
806 static char * id3_get_info(int selected_item
, void* data
,
807 char *buffer
, size_t buffer_len
)
809 struct id3view_info
*info
= (struct id3view_info
*)data
;
810 struct mp3entry
* id3
=info
->id3
;
811 int info_no
=selected_item
/2;
812 if(!(selected_item
%2))
814 return( str(id3_headers
[info
->info_id
[info_no
]]));
820 switch(info
->info_id
[info_no
])
822 case 0:/*LANG_ID3_TITLE*/
825 case 1:/*LANG_ID3_ARTIST*/
828 case 2:/*LANG_ID3_ALBUM*/
831 case 3:/*LANG_ID3_ALBUMARTIST*/
832 val
=id3
->albumartist
;
834 case 4:/*LANG_ID3_GROUPING*/
837 case 5:/*LANG_ID3_DISCNUM*/
838 if (id3
->disc_string
)
839 val
= id3
->disc_string
;
840 else if (id3
->discnum
)
842 snprintf(buffer
, buffer_len
, "%d", id3
->discnum
);
846 case 6:/*LANG_ID3_TRACKNUM*/
847 if (id3
->track_string
)
848 val
= id3
->track_string
;
849 else if (id3
->tracknum
)
851 snprintf(buffer
, buffer_len
, "%d", id3
->tracknum
);
855 case 7:/*LANG_ID3_COMMENT*/
858 case 8:/*LANG_ID3_GENRE*/
859 val
= id3
->genre_string
;
861 case 9:/*LANG_ID3_YEAR*/
862 if (id3
->year_string
)
863 val
= id3
->year_string
;
866 snprintf(buffer
, buffer_len
, "%d", id3
->year
);
870 case 10:/*LANG_ID3_LENGTH*/
871 format_time(buffer
, buffer_len
, id3
->length
);
874 case 11:/*LANG_ID3_PLAYLIST*/
875 snprintf(buffer
, buffer_len
, "%d/%d",
876 playlist_get_display_index(), playlist_amount());
879 case 12:/*LANG_ID3_BITRATE*/
880 snprintf(buffer
, buffer_len
, "%d kbps%s", id3
->bitrate
,
881 id3
->vbr
? str(LANG_ID3_VBR
) : (const unsigned char*) "");
884 case 13:/*LANG_ID3_FREQUENCY*/
885 snprintf(buffer
, buffer_len
, "%ld Hz", id3
->frequency
);
888 #if CONFIG_CODEC == SWCODEC
889 case 14:/*LANG_ID3_TRACK_GAIN*/
890 val
=id3
->track_gain_string
;
892 case 15:/*LANG_ID3_ALBUM_GAIN*/
893 val
=id3
->album_gain_string
;
895 case 16:/*LANG_ID3_PATH*/
897 case 14:/*LANG_ID3_PATH*/
902 return val
&& *val
? val
: NULL
;
906 bool browse_id3(void)
908 struct gui_synclist id3_lists
;
909 struct mp3entry
* id3
= audio_current_track();
912 struct id3view_info info
;
915 for (i
=0; i
<sizeof(id3_headers
)/sizeof(id3_headers
[0]); i
++)
919 if (id3_get_info((i
*2)+1, &info
, temp
, 8) != NULL
)
920 info
.info_id
[info
.count
++] = i
;
923 gui_synclist_init(&id3_lists
, &id3_get_info
, &info
, true, 2, NULL
);
924 gui_synclist_set_nb_items(&id3_lists
, info
.count
*2);
925 gui_synclist_draw(&id3_lists
);
927 key
= get_action(CONTEXT_LIST
,HZ
/2);
928 if(key
!=ACTION_NONE
&& key
!=ACTION_UNKNOWN
929 && !gui_synclist_do_button(&id3_lists
, &key
,LIST_WRAP_UNLESS_HELD
))
931 return(default_event_handler(key
) == SYS_USB_CONNECTED
);
936 static char* runtime_get_data(int selected_item
, void* data
,
937 char* buffer
, size_t buffer_len
)
941 switch (selected_item
)
943 case 0: return str(LANG_RUNNING_TIME
);
944 case 1: t
= global_status
.runtime
; break;
945 case 2: return str(LANG_TOP_TIME
);
946 case 3: t
= global_status
.topruntime
; break;
951 snprintf(buffer
, buffer_len
, "%dh %dm %ds",
952 t
/ 3600, (t
% 3600) / 60, t
% 60);
956 static int runtime_speak_data(int selected_item
, void* data
)
960 (selected_item
< 2) ? LANG_RUNNING_TIME
: LANG_TOP_TIME
,
961 TALK_ID((selected_item
< 2) ? global_status
.runtime
962 : global_status
.topruntime
, UNIT_TIME
));
967 bool view_runtime(void)
969 static const char *lines
[]={ID2P(LANG_CLEAR_TIME
)};
970 static const struct text_message message
={lines
, 1};
972 struct gui_synclist lists
;
974 gui_synclist_init(&lists
, runtime_get_data
, NULL
, false, 2, NULL
);
975 #if !defined(HAVE_LCD_CHARCELLS)
976 gui_synclist_set_title(&lists
, str(LANG_RUNNING_TIME
), NOICON
);
978 gui_synclist_set_title(&lists
, NULL
, NOICON
);
980 if(global_settings
.talk_menu
)
981 gui_synclist_set_voice_callback(&lists
, runtime_speak_data
);
982 gui_synclist_set_icon_callback(&lists
, NULL
);
983 gui_synclist_set_nb_items(&lists
, 4);
984 gui_synclist_speak_item(&lists
);
988 if (charger_inserted())
990 global_status
.runtime
= 0;
995 global_status
.runtime
+= ((current_tick
- lasttime
) / HZ
);
997 lasttime
= current_tick
;
998 gui_synclist_draw(&lists
);
999 list_do_action(CONTEXT_STD
, HZ
,
1000 &lists
, &action
, LIST_WRAP_UNLESS_HELD
);
1001 if(action
== ACTION_STD_CANCEL
)
1003 if(action
== ACTION_STD_OK
) {
1004 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
1006 if (!(gui_synclist_get_sel_pos(&lists
)/2))
1007 global_status
.runtime
= 0;
1009 global_status
.topruntime
= 0;
1010 gui_synclist_speak_item(&lists
);
1013 if(default_event_handler(action
) == SYS_USB_CONNECTED
)
1019 #ifdef HAVE_TOUCHSCREEN
1020 static int get_sample(struct touchscreen_calibration
*cal
, int x
, int y
, int i
,
1021 struct screen
* screen
)
1027 screen
->drawline(x
- 10, y
, x
- 2, y
);
1028 screen
->drawline(x
+ 2, y
, x
+ 10, y
);
1029 screen
->drawline(x
, y
- 10, x
, y
- 2);
1030 screen
->drawline(x
, y
+ 2, x
, y
+ 10);
1033 /* Wait for a touchscreen press */
1036 action
= get_action(CONTEXT_STD
, TIMEOUT_BLOCK
);
1037 if(action
== ACTION_TOUCHSCREEN
)
1039 if(action_get_touchscreen_press(&ts_x
, &ts_y
) == BUTTON_REL
)
1042 else if(action
== ACTION_STD_CANCEL
)
1046 cal
->x
[i
][0] = ts_x
;
1047 cal
->y
[i
][0] = ts_y
;
1057 short points
[3][2] = {
1058 {LCD_WIDTH
/10, LCD_HEIGHT
/10},
1059 {7*LCD_WIDTH
/8, LCD_HEIGHT
/2},
1060 {LCD_WIDTH
/2, 7*LCD_HEIGHT
/8}
1062 struct screen
* screen
= &screens
[SCREEN_MAIN
];
1063 enum touchscreen_mode old_mode
= touchscreen_get_mode();
1064 struct touchscreen_calibration cal
;
1066 bool statusbar
= global_settings
.statusbar
; /* hide the statusbar */
1068 global_settings
.statusbar
= false;
1069 touchscreen_disable_mapping(); /* set raw mode */
1070 touchscreen_set_mode(TOUCHSCREEN_POINT
);
1073 screen
->clear_display();
1075 if(get_sample(&cal
, points
[i
][0], points
[i
][1], i
, screen
))
1083 touchscreen_calibrate(&cal
);
1085 touchscreen_reset_mapping();
1086 memcpy(&global_settings
.ts_calibration_data
, &calibration_parameters
, sizeof(struct touchscreen_parameter
));
1087 touchscreen_set_mode(old_mode
);
1088 global_settings
.statusbar
= statusbar
;
1093 int reset_mapping(void)
1095 touchscreen_reset_mapping();
1096 memcpy(&global_settings
.ts_calibration_data
, &calibration_parameters
, sizeof(struct touchscreen_parameter
));