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
);
204 #ifdef USB_ENABLE_HID
205 char mode_name
[MODE_NAME_LEN
];
208 screens
[i
].getstringsize(str(LANG_USB_KEYPAD_MODE
), &w
, &h
);
210 y
= (LCD_HEIGHT
- BMPHEIGHT_usblogo
) / 2 + BMPHEIGHT_usblogo
+ h
;
211 screens
[i
].putsxy((LCD_WIDTH
- w
) / 2, y
,
212 str(LANG_USB_KEYPAD_MODE
));
215 snprintf(mode_name
, MODE_NAME_LEN
, "%s",
216 str(keypad_mode_name_get()));
217 screens
[i
].getstringsize(mode_name
, &w
, &h
);
218 screens
[i
].putsxy((LCD_WIDTH
- w
) / 2, y
, mode_name
);
220 #else /* HAVE_LCD_BITMAP */
221 screens
[i
].double_height(false);
222 #ifdef USB_ENABLE_HID
223 snprintf(mode_name
, MODE_NAME_LEN
, "[USB Mode; %s]",
224 str(keypad_mode_name_get()));
225 screens
[i
].puts_scroll(0, 0, mode_name
);
227 screens
[i
].puts_scroll(0, 0, "[USB Mode]");
229 status_set_param(false);
230 status_set_audio(false);
231 status_set_usb(true);
232 #endif /* HAVE_LCD_BITMAP */
236 /* force statusbar by ignoring the setting */
237 usb_bars
|= VP_SB_IGNORE_SETTING(i
);
240 viewportmanager_set_statusbar(usb_bars
);
243 if (button_get_w_tmo(HZ
/2))
245 send_event(GUI_EVENT_ACTIONUPDATE
, NULL
);
247 if (handle_usb_events())
249 #endif /* SIMULATOR */
252 #ifdef USB_ENABLE_HID
253 if (global_settings
.usb_keypad_mode
!= usb_keypad_mode
)
255 global_settings
.usb_keypad_mode
= usb_keypad_mode
;
260 #ifdef HAVE_TOUCHSCREEN
261 touchscreen_set_mode(old_mode
);
264 #ifdef HAVE_LCD_CHARCELLS
265 status_set_usb(false);
266 #endif /* HAVE_LCD_CHARCELLS */
269 screens
[i
].backlight_on();
271 viewportmanager_set_statusbar(old_bars
);
272 send_event(GUI_EVENT_REFRESH
, NULL
);
274 #endif /* USB_NONE */
277 #if (CONFIG_STORAGE & STORAGE_MMC)
278 int mmc_remove_request(void)
280 struct queue_event ev
;
283 screens
[i
].clear_display();
284 splash(0, ID2P(LANG_REMOVE_MMC
));
288 queue_wait_w_tmo(&button_queue
, &ev
, HZ
/2);
291 case SYS_HOTSWAP_EXTRACTED
:
292 return SYS_HOTSWAP_EXTRACTED
;
294 case SYS_USB_DISCONNECTED
:
295 return SYS_USB_DISCONNECTED
;
301 /* the charging screen is only used for archos targets */
302 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
304 #ifdef HAVE_LCD_BITMAP
305 static void charging_display_info(bool animate
)
307 unsigned char charging_logo
[36];
308 const int pox_x
= (LCD_WIDTH
- sizeof(charging_logo
)) / 2;
309 const int pox_y
= 32;
310 static unsigned phase
= 3;
315 #ifdef NEED_ATA_POWER_BATT_MEASURE
316 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
319 int battv
= battery_voltage();
320 snprintf(buf
, 32, " Batt: %d.%02dV %d%% ", battv
/ 1000,
321 (battv
% 1000) / 10, battery_level());
325 #ifdef ARCHOS_RECORER
326 snprintf(buf
, 32, "Charge mode:");
329 if (charge_state
== CHARGING
)
330 snprintf(buf
, 32, str(LANG_BATTERY_CHARGE
));
331 else if (charge_state
== TOPOFF
)
332 snprintf(buf
, 32, str(LANG_BATTERY_TOPOFF_CHARGE
));
333 else if (charge_state
== TRICKLE
)
334 snprintf(buf
, 32, str(LANG_BATTERY_TRICKLE_CHARGE
));
336 snprintf(buf
, 32, "not charging");
339 if (!charger_enabled())
341 #endif /* ARCHOS_RECORER */
344 memset(charging_logo
+3, 0x00, 32);
345 charging_logo
[0] = 0x3C;
346 charging_logo
[1] = 0x24;
347 charging_logo
[2] = charging_logo
[35] = 0xFF;
350 { /* draw the outline */
352 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8,
353 sizeof(charging_logo
), 8);
354 lcd_set_drawmode(DRMODE_FG
);
356 charging_logo
[0] = charging_logo
[1] = 0x00;
357 memset(charging_logo
+2, 0x80, 34);
358 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
, sizeof(charging_logo
), 8);
360 memset(charging_logo
+2, 0x01, 34);
361 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 16,
362 sizeof(charging_logo
), 8);
363 lcd_set_drawmode(DRMODE_SOLID
);
366 { /* animate the middle part */
367 for (i
= 3; i
<MIN(sizeof(charging_logo
)-1, phase
); i
++)
369 if ((i
-phase
) % 8 == 0)
370 { /* draw a "bubble" here */
372 bitpos
= (phase
+ i
/8) % 15; /* "bounce" effect */
374 bitpos
= 14 - bitpos
;
375 charging_logo
[i
] = BIT_N(bitpos
);
378 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8,
379 sizeof(charging_logo
), 8);
384 #else /* not HAVE_LCD_BITMAP */
386 static unsigned long logo_chars
[4];
387 static const unsigned char logo_pattern
[] = {
388 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
389 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
390 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
391 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
394 static void logo_lock_patterns(bool on
)
400 for (i
= 0; i
< 4; i
++)
401 logo_chars
[i
] = lcd_get_locked_pattern();
405 for (i
= 0; i
< 4; i
++)
406 lcd_unlock_pattern(logo_chars
[i
]);
410 static void charging_display_info(bool animate
)
414 static unsigned phase
= 3;
417 battv
= battery_voltage();
418 snprintf(buf
, sizeof(buf
), " %d.%02dV", battv
/ 1000, (battv
% 1000) / 10);
421 memcpy(buf
, logo_pattern
, 32); /* copy logo patterns */
423 if (!animate
) /* build the screen */
425 lcd_double_height(false);
426 lcd_puts(0, 0, "[Charging]");
427 for (i
= 0; i
< 4; i
++)
428 lcd_putc(i
, 1, logo_chars
[i
]);
430 else /* animate the logo */
432 for (i
= 3; i
< MIN(19, phase
); i
++)
434 if ((i
- phase
) % 5 == 0)
435 { /* draw a "bubble" here */
436 ypos
= (phase
+ i
/5) % 9; /* "bounce" effect */
439 buf
[5 - ypos
+ 8 * (i
/5)] |= 0x10u
>> (i
%5);
445 for (i
= 0; i
< 4; i
++)
446 lcd_define_pattern(logo_chars
[i
], buf
+ 8 * i
);
450 #endif /* (not) HAVE_LCD_BITMAP */
452 /* blocks while charging, returns on event:
453 1 if charger cable was removed
454 2 if Off/Stop key was pressed
455 3 if On key was pressed
456 4 if USB was connected */
458 int charging_screen(void)
463 ide_power_enable(false); /* power down the disk, else would be spinning */
466 backlight_set_timeout(global_settings
.backlight_timeout
);
467 #ifdef HAVE_REMOTE_LCD
468 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
470 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
472 #ifdef HAVE_LCD_CHARCELLS
473 logo_lock_patterns(true);
475 charging_display_info(false);
479 gui_syncstatusbar_draw(&statusbars
, false);
480 charging_display_info(true);
481 button
= get_action(CONTEXT_STD
,HZ
/3);
482 if (button
== ACTION_STD_OK
)
484 else if (usb_detect() == USB_INSERTED
)
486 else if (!charger_inserted())
490 #ifdef HAVE_LCD_CHARCELLS
491 logo_lock_patterns(false);
495 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
498 void charging_splash(void)
500 splash(2*HZ
, str(LANG_BATTERY_CHARGE
));
501 button_clear_queue();
506 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
508 /* little helper function for voice output */
509 static void say_time(int cursorpos
, const struct tm
*tm
)
514 if (!global_settings
.talk_menu
)
532 value
= tm
->tm_year
+ 1900;
539 if (cursorpos
== 4) /* month */
540 talk_id(LANG_MONTH_JANUARY
+ tm
->tm_mon
, false);
542 talk_value(value
, unit
, false);
549 #define SEPARATOR ":"
550 bool set_time_screen(const char* title
, struct tm
*tm
)
554 unsigned int i
, j
, s
;
556 unsigned int realyear
;
558 unsigned int min
, max
;
559 unsigned int statusbar_height
= 0;
560 unsigned int separator_width
, weekday_width
;
561 unsigned int prev_line_height
;
562 static unsigned char daysinmonth
[] =
563 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
564 unsigned char buffer
[20];
565 struct viewport vp
[NB_SCREENS
];
568 /* 6 possible cursor possitions, 2 values stored for each: x, y */
569 unsigned int cursor
[6][2];
572 unsigned char *ptr
[6];
574 if(global_settings
.statusbar
)
575 statusbar_height
= STATUSBAR_HEIGHT
;
577 /* speak selection when screen is entered */
578 say_time(cursorpos
, tm
);
581 /* for easy acess in the drawing loop */
582 ptr
[0] = buffer
; /* hours */
583 ptr
[1] = buffer
+ 3; /* minutes */
584 ptr
[2] = buffer
+ 6; /* seconds */
585 ptr
[3] = buffer
+ 9; /* year */
586 ptr
[4] = str(LANG_MONTH_JANUARY
+ tm
->tm_mon
); /* monthname */
587 ptr
[5] = buffer
+ 14; /* day of month */
589 /* calculate the number of days in febuary */
590 realyear
= tm
->tm_year
+ 1900;
591 if((realyear
% 4 == 0 && !(realyear
% 100 == 0)) || realyear
% 400 == 0)
596 /* fix day if month or year changed */
597 if (tm
->tm_mday
> daysinmonth
[tm
->tm_mon
])
598 tm
->tm_mday
= daysinmonth
[tm
->tm_mon
];
600 /* calculate day of week */
603 /* put all the numbers we want from the tm struct into
604 an easily printable buffer */
605 snprintf(buffer
, sizeof(buffer
),
606 "%02d " "%02d " "%02d " "%04d " "%02d",
607 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
,
608 tm
->tm_year
+1900, tm
->tm_mday
);
610 /* convert spaces in the buffer to '\0' to make it possible to work
611 directly on the buffer */
612 for(i
=0; i
< sizeof(buffer
); i
++)
620 viewport_set_defaults(&vp
[s
], s
);
621 screens
[s
].set_viewport(&vp
[s
]);
622 nb_lines
= viewport_get_nb_lines(&vp
[s
]);
624 /* minimum lines needed is 2 + title line */
627 vp
[s
].font
= FONT_SYSFIXED
;
628 nb_lines
= viewport_get_nb_lines(&vp
[s
]);
631 /* recalculate the positions and offsets */
633 screens
[s
].getstringsize(title
, NULL
, &prev_line_height
);
635 prev_line_height
= 0;
637 screens
[s
].getstringsize(SEPARATOR
, &separator_width
, NULL
);
640 screens
[s
].getstringsize(str(LANG_WEEKDAY_SUNDAY
+ tm
->tm_wday
),
641 &weekday_width
, NULL
);
642 screens
[s
].getstringsize(" ", &separator_width
, NULL
);
644 for(i
=0, j
=0; i
< 6; i
++)
646 if(i
==3) /* second row */
648 j
= weekday_width
+ separator_width
;
649 prev_line_height
*= 2;
651 screens
[s
].getstringsize(ptr
[i
], &width
, NULL
);
652 cursor
[i
][INDEX_Y
] = prev_line_height
+ statusbar_height
;
653 cursor
[i
][INDEX_X
] = j
;
654 j
+= width
+ separator_width
;
657 /* draw the screen */
658 screens
[s
].set_viewport(&vp
[s
]);
659 screens
[s
].clear_viewport();
660 /* display the screen title */
661 screens
[s
].puts_scroll(0, 0, title
);
663 /* these are not selectable, so we draw them outside the loop */
664 /* name of the week day */
665 screens
[s
].putsxy(0, cursor
[3][INDEX_Y
],
666 str(LANG_WEEKDAY_SUNDAY
+ tm
->tm_wday
));
668 /* draw the selected item with drawmode set to
669 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
670 items with drawmode DRMODE_SOLID */
673 if (cursorpos
== (int)i
)
674 vp
[s
].drawmode
= (DRMODE_SOLID
|DRMODE_INVERSEVID
);
676 screens
[s
].putsxy(cursor
[i
][INDEX_X
],
677 cursor
[i
][INDEX_Y
], ptr
[i
]);
679 vp
[s
].drawmode
= DRMODE_SOLID
;
681 screens
[s
].putsxy(cursor
[i
/4 +1][INDEX_X
] - separator_width
,
682 cursor
[0][INDEX_Y
], SEPARATOR
);
685 /* print help text */
687 screens
[s
].puts(0, 4, str(LANG_TIME_SET_BUTTON
));
689 screens
[s
].puts(0, 5, str(LANG_TIME_REVERT
));
690 screens
[s
].update_viewport();
691 screens
[s
].set_viewport(NULL
);
694 /* set the most common numbers */
697 /* calculate the minimum and maximum for the number under cursor */
701 valptr
= &tm
->tm_hour
;
704 valptr
= &tm
->tm_min
;
707 valptr
= &tm
->tm_sec
;
712 valptr
= &tm
->tm_year
;
716 valptr
= &tm
->tm_mon
;
720 max
= daysinmonth
[tm
->tm_mon
];
721 valptr
= &tm
->tm_mday
;
725 #ifdef HAVE_TOUCHSCREEN
726 enum touchscreen_mode old_mode
= touchscreen_get_mode();
728 touchscreen_set_mode(TOUCHSCREEN_BUTTON
);
730 button
= get_action(CONTEXT_SETTINGS_TIME
, TIMEOUT_BLOCK
);
731 #ifdef HAVE_TOUCHSCREEN
732 touchscreen_set_mode(old_mode
);
735 case ACTION_STD_PREV
:
736 cursorpos
= clamp_value_wrap(--cursorpos
, 5, 0);
737 say_time(cursorpos
, tm
);
739 case ACTION_STD_NEXT
:
740 cursorpos
= clamp_value_wrap(++cursorpos
, 5, 0);
741 say_time(cursorpos
, tm
);
743 case ACTION_SETTINGS_INC
:
744 case ACTION_SETTINGS_INCREPEAT
:
745 *valptr
= clamp_value_wrap(++(*valptr
), max
, min
);
746 say_time(cursorpos
, tm
);
748 case ACTION_SETTINGS_DEC
:
749 case ACTION_SETTINGS_DECREPEAT
:
750 *valptr
= clamp_value_wrap(--(*valptr
), max
, min
);
751 say_time(cursorpos
, tm
);
758 case ACTION_STD_CANCEL
:
764 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
771 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
773 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
774 bool shutdown_screen(void)
778 long time_entered
= current_tick
;
782 splash(0, str(LANG_CONFIRM_SHUTDOWN
));
784 while(!done
&& TIME_BEFORE(current_tick
,time_entered
+HZ
*2))
786 button
= get_action(CONTEXT_STD
,HZ
);
789 case ACTION_STD_CANCEL
:
793 /* do nothing here, because ACTION_NONE might be caused
794 * by timeout or button release. In case of timeout the loop
795 * is terminated by TIME_BEFORE */
800 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
810 static const int id3_headers
[]=
815 LANG_ID3_ALBUMARTIST
,
826 #if CONFIG_CODEC == SWCODEC
833 struct id3view_info
{
834 struct mp3entry
* id3
;
836 int info_id
[ARRAYLEN(id3_headers
)];
839 static const char* id3_get_info(int selected_item
, void* data
,
840 char *buffer
, size_t buffer_len
)
842 struct id3view_info
*info
= (struct id3view_info
*)data
;
843 struct mp3entry
* id3
=info
->id3
;
844 int info_no
=selected_item
/2;
845 if(!(selected_item
%2))
847 return(str(id3_headers
[info
->info_id
[info_no
]]));
853 switch(info
->info_id
[info_no
])
855 case 0:/*LANG_ID3_TITLE*/
858 case 1:/*LANG_ID3_ARTIST*/
861 case 2:/*LANG_ID3_ALBUM*/
864 case 3:/*LANG_ID3_ALBUMARTIST*/
865 val
=id3
->albumartist
;
867 case 4:/*LANG_ID3_GROUPING*/
870 case 5:/*LANG_ID3_DISCNUM*/
871 if (id3
->disc_string
)
872 val
= id3
->disc_string
;
873 else if (id3
->discnum
)
875 snprintf(buffer
, buffer_len
, "%d", id3
->discnum
);
879 case 6:/*LANG_ID3_TRACKNUM*/
880 if (id3
->track_string
)
881 val
= id3
->track_string
;
882 else if (id3
->tracknum
)
884 snprintf(buffer
, buffer_len
, "%d", id3
->tracknum
);
888 case 7:/*LANG_ID3_COMMENT*/
891 case 8:/*LANG_ID3_GENRE*/
892 val
= id3
->genre_string
;
894 case 9:/*LANG_ID3_YEAR*/
895 if (id3
->year_string
)
896 val
= id3
->year_string
;
899 snprintf(buffer
, buffer_len
, "%d", id3
->year
);
903 case 10:/*LANG_ID3_LENGTH*/
904 format_time(buffer
, buffer_len
, id3
->length
);
907 case 11:/*LANG_ID3_PLAYLIST*/
908 snprintf(buffer
, buffer_len
, "%d/%d",
909 playlist_get_display_index(), playlist_amount());
912 case 12:/*LANG_ID3_BITRATE*/
913 snprintf(buffer
, buffer_len
, "%d kbps%s", id3
->bitrate
,
914 id3
->vbr
? str(LANG_ID3_VBR
) : (const unsigned char*) "");
917 case 13:/*LANG_ID3_FREQUENCY*/
918 snprintf(buffer
, buffer_len
, "%ld Hz", id3
->frequency
);
921 #if CONFIG_CODEC == SWCODEC
922 case 14:/*LANG_ID3_TRACK_GAIN*/
923 val
=id3
->track_gain_string
;
925 case 15:/*LANG_ID3_ALBUM_GAIN*/
926 val
=id3
->album_gain_string
;
928 case 16:/*LANG_ID3_PATH*/
930 case 14:/*LANG_ID3_PATH*/
935 return val
&& *val
? val
: NULL
;
939 bool browse_id3(void)
941 struct gui_synclist id3_lists
;
942 struct mp3entry
* id3
= audio_current_track();
945 struct id3view_info info
;
948 for (i
= 0; i
< ARRAYLEN(id3_headers
); i
++)
952 if (id3_get_info((i
*2)+1, &info
, temp
, 8) != NULL
)
953 info
.info_id
[info
.count
++] = i
;
956 gui_synclist_init(&id3_lists
, &id3_get_info
, &info
, true, 2, NULL
);
957 gui_synclist_set_nb_items(&id3_lists
, info
.count
*2);
958 gui_synclist_draw(&id3_lists
);
960 key
= get_action(CONTEXT_LIST
,HZ
/2);
961 if(key
!=ACTION_NONE
&& key
!=ACTION_UNKNOWN
962 && !gui_synclist_do_button(&id3_lists
, &key
,LIST_WRAP_UNLESS_HELD
))
964 return(default_event_handler(key
) == SYS_USB_CONNECTED
);
969 static const char* runtime_get_data(int selected_item
, void* data
,
970 char* buffer
, size_t buffer_len
)
974 switch (selected_item
)
976 case 0: return str(LANG_RUNNING_TIME
);
977 case 1: t
= global_status
.runtime
; break;
978 case 2: return str(LANG_TOP_TIME
);
979 case 3: t
= global_status
.topruntime
; break;
984 snprintf(buffer
, buffer_len
, "%dh %dm %ds",
985 t
/ 3600, (t
% 3600) / 60, t
% 60);
989 static int runtime_speak_data(int selected_item
, void* data
)
993 (selected_item
< 2) ? LANG_RUNNING_TIME
: LANG_TOP_TIME
,
994 TALK_ID((selected_item
< 2) ? global_status
.runtime
995 : global_status
.topruntime
, UNIT_TIME
));
1000 bool view_runtime(void)
1002 static const char *lines
[]={ID2P(LANG_CLEAR_TIME
)};
1003 static const struct text_message message
={lines
, 1};
1005 struct gui_synclist lists
;
1007 gui_synclist_init(&lists
, runtime_get_data
, NULL
, false, 2, NULL
);
1008 #if !defined(HAVE_LCD_CHARCELLS)
1009 gui_synclist_set_title(&lists
, str(LANG_RUNNING_TIME
), NOICON
);
1011 gui_synclist_set_title(&lists
, NULL
, NOICON
);
1013 if(global_settings
.talk_menu
)
1014 gui_synclist_set_voice_callback(&lists
, runtime_speak_data
);
1015 gui_synclist_set_icon_callback(&lists
, NULL
);
1016 gui_synclist_set_nb_items(&lists
, 4);
1017 gui_synclist_speak_item(&lists
);
1021 if (charger_inserted())
1023 global_status
.runtime
= 0;
1028 global_status
.runtime
+= ((current_tick
- lasttime
) / HZ
);
1030 lasttime
= current_tick
;
1031 gui_synclist_draw(&lists
);
1032 list_do_action(CONTEXT_STD
, HZ
,
1033 &lists
, &action
, LIST_WRAP_UNLESS_HELD
);
1034 if(action
== ACTION_STD_CANCEL
)
1036 if(action
== ACTION_STD_OK
) {
1037 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
1039 if (!(gui_synclist_get_sel_pos(&lists
)/2))
1040 global_status
.runtime
= 0;
1042 global_status
.topruntime
= 0;
1043 gui_synclist_speak_item(&lists
);
1046 if(default_event_handler(action
) == SYS_USB_CONNECTED
)
1052 #ifdef HAVE_TOUCHSCREEN
1053 static int get_sample(struct touchscreen_calibration
*cal
, int x
, int y
, int i
,
1054 struct screen
* screen
)
1060 screen
->drawline(x
- 10, y
, x
- 2, y
);
1061 screen
->drawline(x
+ 2, y
, x
+ 10, y
);
1062 screen
->drawline(x
, y
- 10, x
, y
- 2);
1063 screen
->drawline(x
, y
+ 2, x
, y
+ 10);
1066 /* Wait for a touchscreen press */
1069 action
= get_action(CONTEXT_STD
, TIMEOUT_BLOCK
);
1070 if(action
== ACTION_TOUCHSCREEN
)
1072 if(action_get_touchscreen_press(&ts_x
, &ts_y
) == BUTTON_REL
)
1075 else if(action
== ACTION_STD_CANCEL
)
1079 cal
->x
[i
][0] = ts_x
;
1080 cal
->y
[i
][0] = ts_y
;
1090 short points
[3][2] = {
1091 {LCD_WIDTH
/10, LCD_HEIGHT
/10},
1092 {7*LCD_WIDTH
/8, LCD_HEIGHT
/2},
1093 {LCD_WIDTH
/2, 7*LCD_HEIGHT
/8}
1095 struct screen
* screen
= &screens
[SCREEN_MAIN
];
1096 enum touchscreen_mode old_mode
= touchscreen_get_mode();
1097 struct touchscreen_calibration cal
;
1099 int statusbar
= global_settings
.statusbar
; /* hide the statusbar */
1100 global_settings
.statusbar
= STATUSBAR_OFF
;
1102 touchscreen_disable_mapping(); /* set raw mode */
1103 touchscreen_set_mode(TOUCHSCREEN_POINT
);
1106 screen
->clear_display();
1108 if(get_sample(&cal
, points
[i
][0], points
[i
][1], i
, screen
))
1116 touchscreen_calibrate(&cal
);
1118 touchscreen_reset_mapping();
1119 memcpy(&global_settings
.ts_calibration_data
, &calibration_parameters
, sizeof(struct touchscreen_parameter
));
1120 touchscreen_set_mode(old_mode
);
1121 global_settings
.statusbar
= statusbar
;
1126 int reset_mapping(void)
1128 touchscreen_reset_mapping();
1129 memcpy(&global_settings
.ts_calibration_data
, &calibration_parameters
, sizeof(struct touchscreen_parameter
));