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"
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
)
102 static int handle_usb_events(void)
104 #if (CONFIG_STORAGE & STORAGE_MMC)
106 #endif /* STORAGE_MMC */
108 /* Don't return until we get SYS_USB_DISCONNECTED or SYS_TIMEOUT */
112 #ifdef USB_ENABLE_HID
113 if (usb_core_driver_enabled(USB_DRIVER_HID
))
115 button
= get_hid_usb_action();
117 /* On mode change, we need to refresh the screen */
118 if (button
== ACTION_USB_HID_MODE_SWITCH_NEXT
||
119 button
== ACTION_USB_HID_MODE_SWITCH_PREV
)
127 button
= button_get_w_tmo(HZ
/2);
128 /* hid emits the event in get_action */
129 send_event(GUI_EVENT_ACTIONUPDATE
, NULL
);
134 case SYS_USB_DISCONNECTED
:
135 usb_acknowledge(SYS_USB_DISCONNECTED_ACK
);
141 #if (CONFIG_STORAGE & STORAGE_MMC) /* USB-MMC bridge can report activity */
142 if(TIME_AFTER(current_tick
,next_update
))
145 led(mmc_usb_active(HZ
));
147 next_update
=current_tick
+HZ
/2;
149 #endif /* STORAGE_MMC */
156 #define MODE_NAME_LEN 32
157 void usb_screen(void)
163 int usb_bars
= VP_SB_ALLSCREENS
; /* force statusbars */
164 int old_bars
= viewportmanager_get_statusbar();
165 #if defined HAVE_TOUCHSCREEN
166 enum touchscreen_mode old_mode
= touchscreen_get_mode();
168 /* TODO: Paint buttons on screens OR switch to point mode and use
169 * touchscreen as a touchpad to move the host's mouse cursor */
170 touchscreen_set_mode(TOUCHSCREEN_BUTTON
);
174 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
177 #ifdef USB_ENABLE_HID
178 usb_keypad_mode
= global_settings
.usb_keypad_mode
;
185 screens
[i
].backdrop_show(BACKDROP_MAIN
);
186 screens
[i
].backlight_on();
187 screens
[i
].clear_display();
188 #ifdef HAVE_REMOTE_LCD
189 if (i
== SCREEN_REMOTE
)
191 screens
[i
].bitmap(remote_usblogo
,
192 (LCD_REMOTE_WIDTH
-BMPWIDTH_remote_usblogo
),
193 (LCD_REMOTE_HEIGHT
-BMPHEIGHT_remote_usblogo
)/2,
194 BMPWIDTH_remote_usblogo
, BMPHEIGHT_remote_usblogo
);
199 #ifdef HAVE_LCD_BITMAP
200 screens
[i
].transparent_bitmap(usblogo
,
201 (LCD_WIDTH
-BMPWIDTH_usblogo
),
202 (LCD_HEIGHT
-BMPHEIGHT_usblogo
)/2,
203 BMPWIDTH_usblogo
, BMPHEIGHT_usblogo
);
204 #ifdef USB_ENABLE_HID
207 screens
[i
].getstringsize(str(keypad_mode_name_get()), &w
, &h
);
208 screens
[i
].putsxy((LCD_WIDTH
- w
) / 2, BMPHEIGHT_usblogo
+
209 (LCD_HEIGHT
- BMPHEIGHT_usblogo
+ h
) / 2,
210 str(keypad_mode_name_get()));
211 #endif /* USB_ENABLE_HID */
212 #else /* HAVE_LCD_BITMAP */
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 */
222 /* force statusbar by ignoring the setting */
223 usb_bars
|= VP_SB_IGNORE_SETTING(i
);
226 viewportmanager_set_statusbar(usb_bars
);
229 if (button_get_w_tmo(HZ
/2))
231 send_event(GUI_EVENT_ACTIONUPDATE
, NULL
);
233 if (handle_usb_events())
235 #endif /* SIMULATOR */
238 #ifdef USB_ENABLE_HID
239 if (global_settings
.usb_keypad_mode
!= usb_keypad_mode
)
241 global_settings
.usb_keypad_mode
= usb_keypad_mode
;
246 #ifdef HAVE_TOUCHSCREEN
247 touchscreen_set_mode(old_mode
);
250 #ifdef HAVE_LCD_CHARCELLS
251 status_set_usb(false);
252 #endif /* HAVE_LCD_CHARCELLS */
255 screens
[i
].backlight_on();
257 viewportmanager_set_statusbar(old_bars
);
258 send_event(GUI_EVENT_REFRESH
, NULL
);
260 #endif /* USB_NONE */
263 #if (CONFIG_STORAGE & STORAGE_MMC)
264 int mmc_remove_request(void)
266 struct queue_event ev
;
269 screens
[i
].clear_display();
270 splash(0, ID2P(LANG_REMOVE_MMC
));
274 queue_wait_w_tmo(&button_queue
, &ev
, HZ
/2);
277 case SYS_HOTSWAP_EXTRACTED
:
278 return SYS_HOTSWAP_EXTRACTED
;
280 case SYS_USB_DISCONNECTED
:
281 return SYS_USB_DISCONNECTED
;
287 /* the charging screen is only used for archos targets */
288 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
290 #ifdef HAVE_LCD_BITMAP
291 static void charging_display_info(bool animate
)
293 unsigned char charging_logo
[36];
294 const int pox_x
= (LCD_WIDTH
- sizeof(charging_logo
)) / 2;
295 const int pox_y
= 32;
296 static unsigned phase
= 3;
299 #ifdef NEED_ATA_POWER_BATT_MEASURE
300 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
303 int battv
= battery_voltage();
304 lcd_putsf(0, 7, " Batt: %d.%02dV %d%% ", battv
/ 1000,
305 (battv
% 1000) / 10, battery_level());
308 #ifdef ARCHOS_RECORDER
309 lcd_puts(0, 2, "Charge mode:");
312 if (charge_state
== CHARGING
)
313 s
= str(LANG_BATTERY_CHARGE
);
314 else if (charge_state
== TOPOFF
)
315 s
= str(LANG_BATTERY_TOPOFF_CHARGE
);
316 else if (charge_state
== TRICKLE
)
317 s
= str(LANG_BATTERY_TRICKLE_CHARGE
);
322 if (!charger_enabled())
324 #endif /* ARCHOS_RECORDER */
327 memset(charging_logo
+3, 0x00, 32);
328 charging_logo
[0] = 0x3C;
329 charging_logo
[1] = 0x24;
330 charging_logo
[2] = charging_logo
[35] = 0xFF;
333 { /* draw the outline */
335 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8,
336 sizeof(charging_logo
), 8);
337 lcd_set_drawmode(DRMODE_FG
);
339 charging_logo
[0] = charging_logo
[1] = 0x00;
340 memset(charging_logo
+2, 0x80, 34);
341 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
, sizeof(charging_logo
), 8);
343 memset(charging_logo
+2, 0x01, 34);
344 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 16,
345 sizeof(charging_logo
), 8);
346 lcd_set_drawmode(DRMODE_SOLID
);
349 { /* animate the middle part */
350 for (i
= 3; i
<MIN(sizeof(charging_logo
)-1, phase
); i
++)
352 if ((i
-phase
) % 8 == 0)
353 { /* draw a "bubble" here */
355 bitpos
= (phase
+ i
/8) % 15; /* "bounce" effect */
357 bitpos
= 14 - bitpos
;
358 charging_logo
[i
] = BIT_N(bitpos
);
361 lcd_mono_bitmap(charging_logo
, pox_x
, pox_y
+ 8,
362 sizeof(charging_logo
), 8);
367 #else /* not HAVE_LCD_BITMAP */
369 static unsigned long logo_chars
[4];
370 static const unsigned char logo_pattern
[] = {
371 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
372 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
373 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
374 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
377 static void logo_lock_patterns(bool on
)
383 for (i
= 0; i
< 4; i
++)
384 logo_chars
[i
] = lcd_get_locked_pattern();
388 for (i
= 0; i
< 4; i
++)
389 lcd_unlock_pattern(logo_chars
[i
]);
393 static void charging_display_info(bool animate
)
397 static unsigned phase
= 3;
400 battv
= battery_voltage();
401 lcd_putsf(4, 1, " %d.%02dV", battv
/ 1000, (battv
% 1000) / 10);
403 memcpy(buf
, logo_pattern
, 32); /* copy logo patterns */
405 if (!animate
) /* build the screen */
407 lcd_double_height(false);
408 lcd_puts(0, 0, "[Charging]");
409 for (i
= 0; i
< 4; i
++)
410 lcd_putc(i
, 1, logo_chars
[i
]);
412 else /* animate the logo */
414 for (i
= 3; i
< MIN(19, phase
); i
++)
416 if ((i
- phase
) % 5 == 0)
417 { /* draw a "bubble" here */
418 ypos
= (phase
+ i
/5) % 9; /* "bounce" effect */
421 buf
[5 - ypos
+ 8 * (i
/5)] |= 0x10u
>> (i
%5);
427 for (i
= 0; i
< 4; i
++)
428 lcd_define_pattern(logo_chars
[i
], buf
+ 8 * i
);
432 #endif /* (not) HAVE_LCD_BITMAP */
434 /* blocks while charging, returns on event:
435 1 if charger cable was removed
436 2 if Off/Stop key was pressed
437 3 if On key was pressed
438 4 if USB was connected */
440 int charging_screen(void)
445 ide_power_enable(false); /* power down the disk, else would be spinning */
448 backlight_set_timeout(global_settings
.backlight_timeout
);
449 #ifdef HAVE_REMOTE_LCD
450 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
452 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
454 #ifdef HAVE_LCD_CHARCELLS
455 logo_lock_patterns(true);
457 charging_display_info(false);
461 gui_syncstatusbar_draw(&statusbars
, false);
462 charging_display_info(true);
463 button
= get_action(CONTEXT_STD
,HZ
/3);
464 if (button
== ACTION_STD_OK
)
466 else if (usb_detect() == USB_INSERTED
)
468 else if (!charger_inserted())
472 #ifdef HAVE_LCD_CHARCELLS
473 logo_lock_patterns(false);
477 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
480 void charging_splash(void)
482 splash(2*HZ
, str(LANG_BATTERY_CHARGE
));
483 button_clear_queue();
488 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
490 /* little helper function for voice output */
491 static void say_time(int cursorpos
, const struct tm
*tm
)
496 if (!global_settings
.talk_menu
)
514 value
= tm
->tm_year
+ 1900;
521 if (cursorpos
== 4) /* month */
522 talk_id(LANG_MONTH_JANUARY
+ tm
->tm_mon
, false);
524 talk_value(value
, unit
, false);
531 #define SEPARATOR ":"
534 #define IDX_MINUTES 1
535 #define IDX_SECONDS 2
541 #define OFF_MINUTES 3
542 #define OFF_SECONDS 6
546 bool set_time_screen(const char* title
, struct tm
*tm
)
550 unsigned int statusbar_height
= 0;
551 unsigned char offsets_ptr
[] =
552 { OFF_HOURS
, OFF_MINUTES
, OFF_SECONDS
, OFF_YEAR
, 0, OFF_DAY
};
556 offsets_ptr
[IDX_HOURS
] = OFF_SECONDS
;
557 offsets_ptr
[IDX_SECONDS
] = OFF_HOURS
;
558 offsets_ptr
[IDX_YEAR
] = OFF_DAY
;
559 offsets_ptr
[IDX_DAY
] = OFF_YEAR
;
562 if(global_settings
.statusbar
)
563 statusbar_height
= STATUSBAR_HEIGHT
;
565 /* speak selection when screen is entered */
566 say_time(cursorpos
, tm
);
570 unsigned int i
, s
, realyear
, min
, max
;
571 unsigned char *ptr
[6];
572 unsigned char buffer
[20];
574 static unsigned char daysinmonth
[] =
575 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
577 /* for easy acess in the drawing loop */
578 for (i
= 0; i
< 6; i
++)
579 ptr
[i
] = buffer
+ offsets_ptr
[i
];
580 ptr
[IDX_MONTH
] = str(LANG_MONTH_JANUARY
+ tm
->tm_mon
); /* month name */
582 /* calculate the number of days in febuary */
583 realyear
= tm
->tm_year
+ 1900;
584 if((realyear
% 4 == 0 && !(realyear
% 100 == 0)) || realyear
% 400 == 0)
589 /* fix day if month or year changed */
590 if (tm
->tm_mday
> daysinmonth
[tm
->tm_mon
])
591 tm
->tm_mday
= daysinmonth
[tm
->tm_mon
];
593 /* calculate day of week */
596 /* put all the numbers we want from the tm struct into
597 an easily printable buffer */
598 snprintf(buffer
, sizeof(buffer
),
599 "%02d " "%02d " "%02d " "%04d " "%02d",
600 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
,
601 tm
->tm_year
+1900, tm
->tm_mday
);
603 /* convert spaces in the buffer to '\0' to make it possible to work
604 directly on the buffer */
605 for(i
=0; i
< sizeof(buffer
); i
++)
614 unsigned int separator_width
, weekday_width
;
615 unsigned int j
, width
, prev_line_height
;
616 struct viewport viewports
[NB_SCREENS
];
617 /* 6 possible cursor possitions, 2 values stored for each: x, y */
618 unsigned int cursor
[6][2];
619 struct viewport
*vp
= &viewports
[s
];
620 struct screen
*screen
= &screens
[s
];
621 static unsigned char rtl_idx
[] =
622 { IDX_SECONDS
, IDX_MINUTES
, IDX_HOURS
, IDX_DAY
, IDX_MONTH
, IDX_YEAR
};
624 viewport_set_defaults(vp
, s
);
625 screen
->set_viewport(vp
);
626 nb_lines
= viewport_get_nb_lines(vp
);
628 /* minimum lines needed is 2 + title line */
631 vp
->font
= FONT_SYSFIXED
;
632 nb_lines
= viewport_get_nb_lines(vp
);
635 /* recalculate the positions and offsets */
637 screen
->getstringsize(title
, NULL
, &prev_line_height
);
639 prev_line_height
= 0;
641 screen
->getstringsize(SEPARATOR
, &separator_width
, NULL
);
644 screen
->getstringsize(str(LANG_WEEKDAY_SUNDAY
+ tm
->tm_wday
),
645 &weekday_width
, NULL
);
646 screen
->getstringsize(" ", &separator_width
, NULL
);
648 for(i
=0, j
=0; i
< 6; i
++)
650 if(i
==3) /* second row */
652 j
= weekday_width
+ separator_width
;
653 prev_line_height
*= 2;
655 screen
->getstringsize(ptr
[i
], &width
, NULL
);
656 cursor
[i
][INDEX_Y
] = prev_line_height
+ statusbar_height
;
657 cursor
[i
][INDEX_X
] = j
;
658 j
+= width
+ separator_width
;
661 /* draw the screen */
662 screen
->set_viewport(vp
);
663 screen
->clear_viewport();
664 /* display the screen title */
665 screen
->puts_scroll(0, 0, title
);
667 /* these are not selectable, so we draw them outside the loop */
668 /* name of the week day */
669 screen
->putsxy(0, cursor
[3][INDEX_Y
],
670 str(LANG_WEEKDAY_SUNDAY
+ tm
->tm_wday
));
672 pos
= lang_is_rtl() ? rtl_idx
[cursorpos
] : cursorpos
;
673 /* draw the selected item with drawmode set to
674 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
675 items with drawmode DRMODE_SOLID */
679 vp
->drawmode
= (DRMODE_SOLID
|DRMODE_INVERSEVID
);
681 screen
->putsxy(cursor
[i
][INDEX_X
],
682 cursor
[i
][INDEX_Y
], ptr
[i
]);
684 vp
->drawmode
= DRMODE_SOLID
;
686 screen
->putsxy(cursor
[i
/4 +1][INDEX_X
] - separator_width
,
687 cursor
[0][INDEX_Y
], SEPARATOR
);
690 /* print help text */
692 screen
->puts(0, 4, str(LANG_TIME_SET_BUTTON
));
694 screen
->puts(0, 5, str(LANG_TIME_REVERT
));
695 screen
->update_viewport();
696 screen
->set_viewport(NULL
);
699 /* set the most common numbers */
702 /* calculate the minimum and maximum for the number under cursor */
706 valptr
= &tm
->tm_hour
;
709 valptr
= &tm
->tm_min
;
712 valptr
= &tm
->tm_sec
;
717 valptr
= &tm
->tm_year
;
721 valptr
= &tm
->tm_mon
;
725 max
= daysinmonth
[tm
->tm_mon
];
726 valptr
= &tm
->tm_mday
;
730 #ifdef HAVE_TOUCHSCREEN
731 enum touchscreen_mode old_mode
= touchscreen_get_mode();
733 touchscreen_set_mode(TOUCHSCREEN_BUTTON
);
735 button
= get_action(CONTEXT_SETTINGS_TIME
, TIMEOUT_BLOCK
);
736 #ifdef HAVE_TOUCHSCREEN
737 touchscreen_set_mode(old_mode
);
740 case ACTION_STD_PREV
:
741 cursorpos
= clamp_value_wrap(--cursorpos
, 5, 0);
742 say_time(cursorpos
, tm
);
744 case ACTION_STD_NEXT
:
745 cursorpos
= clamp_value_wrap(++cursorpos
, 5, 0);
746 say_time(cursorpos
, tm
);
748 case ACTION_SETTINGS_INC
:
749 case ACTION_SETTINGS_INCREPEAT
:
750 *valptr
= clamp_value_wrap(++(*valptr
), max
, min
);
751 say_time(cursorpos
, tm
);
753 case ACTION_SETTINGS_DEC
:
754 case ACTION_SETTINGS_DECREPEAT
:
755 *valptr
= clamp_value_wrap(--(*valptr
), max
, min
);
756 say_time(cursorpos
, tm
);
763 case ACTION_STD_CANCEL
:
769 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
776 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
778 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
779 bool shutdown_screen(void)
783 long time_entered
= current_tick
;
787 splash(0, str(LANG_CONFIRM_SHUTDOWN
));
789 while(!done
&& TIME_BEFORE(current_tick
,time_entered
+HZ
*2))
791 button
= get_action(CONTEXT_STD
,HZ
);
794 case ACTION_STD_CANCEL
:
798 /* do nothing here, because ACTION_NONE might be caused
799 * by timeout or button release. In case of timeout the loop
800 * is terminated by TIME_BEFORE */
805 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
815 static const int id3_headers
[]=
820 LANG_ID3_ALBUMARTIST
,
831 #if CONFIG_CODEC == SWCODEC
838 struct id3view_info
{
839 struct mp3entry
* id3
;
841 int info_id
[ARRAYLEN(id3_headers
)];
844 static const char* id3_get_info(int selected_item
, void* data
,
845 char *buffer
, size_t buffer_len
)
847 struct id3view_info
*info
= (struct id3view_info
*)data
;
848 struct mp3entry
* id3
=info
->id3
;
849 int info_no
=selected_item
/2;
850 if(!(selected_item
%2))
852 return(str(id3_headers
[info
->info_id
[info_no
]]));
858 switch(info
->info_id
[info_no
])
860 case 0:/*LANG_ID3_TITLE*/
863 case 1:/*LANG_ID3_ARTIST*/
866 case 2:/*LANG_ID3_ALBUM*/
869 case 3:/*LANG_ID3_ALBUMARTIST*/
870 val
=id3
->albumartist
;
872 case 4:/*LANG_ID3_GROUPING*/
875 case 5:/*LANG_ID3_DISCNUM*/
876 if (id3
->disc_string
)
877 val
= id3
->disc_string
;
878 else if (id3
->discnum
)
880 snprintf(buffer
, buffer_len
, "%d", id3
->discnum
);
884 case 6:/*LANG_ID3_TRACKNUM*/
885 if (id3
->track_string
)
886 val
= id3
->track_string
;
887 else if (id3
->tracknum
)
889 snprintf(buffer
, buffer_len
, "%d", id3
->tracknum
);
893 case 7:/*LANG_ID3_COMMENT*/
896 case 8:/*LANG_ID3_GENRE*/
897 val
= id3
->genre_string
;
899 case 9:/*LANG_ID3_YEAR*/
900 if (id3
->year_string
)
901 val
= id3
->year_string
;
904 snprintf(buffer
, buffer_len
, "%d", id3
->year
);
908 case 10:/*LANG_ID3_LENGTH*/
909 format_time(buffer
, buffer_len
, id3
->length
);
912 case 11:/*LANG_ID3_PLAYLIST*/
913 snprintf(buffer
, buffer_len
, "%d/%d",
914 playlist_get_display_index(), playlist_amount());
917 case 12:/*LANG_ID3_BITRATE*/
918 snprintf(buffer
, buffer_len
, "%d kbps%s", id3
->bitrate
,
919 id3
->vbr
? str(LANG_ID3_VBR
) : (const unsigned char*) "");
922 case 13:/*LANG_ID3_FREQUENCY*/
923 snprintf(buffer
, buffer_len
, "%ld Hz", id3
->frequency
);
926 #if CONFIG_CODEC == SWCODEC
927 case 14:/*LANG_ID3_TRACK_GAIN*/
928 val
=id3
->track_gain_string
;
930 case 15:/*LANG_ID3_ALBUM_GAIN*/
931 val
=id3
->album_gain_string
;
933 case 16:/*LANG_ID3_PATH*/
935 case 14:/*LANG_ID3_PATH*/
940 return val
&& *val
? val
: NULL
;
944 bool browse_id3(void)
946 struct gui_synclist id3_lists
;
947 struct mp3entry
* id3
= audio_current_track();
950 struct id3view_info info
;
953 for (i
= 0; i
< ARRAYLEN(id3_headers
); i
++)
957 if (id3_get_info((i
*2)+1, &info
, temp
, 8) != NULL
)
958 info
.info_id
[info
.count
++] = i
;
961 gui_synclist_init(&id3_lists
, &id3_get_info
, &info
, true, 2, NULL
);
962 gui_synclist_set_nb_items(&id3_lists
, info
.count
*2);
963 gui_synclist_draw(&id3_lists
);
965 key
= get_action(CONTEXT_LIST
,HZ
/2);
966 if(key
!=ACTION_NONE
&& key
!=ACTION_UNKNOWN
967 && !gui_synclist_do_button(&id3_lists
, &key
,LIST_WRAP_UNLESS_HELD
))
969 return(default_event_handler(key
) == SYS_USB_CONNECTED
);
974 static const char* runtime_get_data(int selected_item
, void* data
,
975 char* buffer
, size_t buffer_len
)
979 switch (selected_item
)
981 case 0: return str(LANG_RUNNING_TIME
);
982 case 1: t
= global_status
.runtime
; break;
983 case 2: return str(LANG_TOP_TIME
);
984 case 3: t
= global_status
.topruntime
; break;
989 snprintf(buffer
, buffer_len
, "%dh %dm %ds",
990 t
/ 3600, (t
% 3600) / 60, t
% 60);
994 static int runtime_speak_data(int selected_item
, void* data
)
998 (selected_item
< 2) ? LANG_RUNNING_TIME
: LANG_TOP_TIME
,
999 TALK_ID((selected_item
< 2) ? global_status
.runtime
1000 : global_status
.topruntime
, UNIT_TIME
));
1005 bool view_runtime(void)
1007 static const char *lines
[]={ID2P(LANG_CLEAR_TIME
)};
1008 static const struct text_message message
={lines
, 1};
1010 struct gui_synclist lists
;
1012 gui_synclist_init(&lists
, runtime_get_data
, NULL
, false, 2, NULL
);
1013 #if !defined(HAVE_LCD_CHARCELLS)
1014 gui_synclist_set_title(&lists
, str(LANG_RUNNING_TIME
), NOICON
);
1016 gui_synclist_set_title(&lists
, NULL
, NOICON
);
1018 if(global_settings
.talk_menu
)
1019 gui_synclist_set_voice_callback(&lists
, runtime_speak_data
);
1020 gui_synclist_set_icon_callback(&lists
, NULL
);
1021 gui_synclist_set_nb_items(&lists
, 4);
1022 gui_synclist_speak_item(&lists
);
1026 if (charger_inserted())
1028 global_status
.runtime
= 0;
1033 global_status
.runtime
+= ((current_tick
- lasttime
) / HZ
);
1035 lasttime
= current_tick
;
1036 gui_synclist_draw(&lists
);
1037 list_do_action(CONTEXT_STD
, HZ
,
1038 &lists
, &action
, LIST_WRAP_UNLESS_HELD
);
1039 if(action
== ACTION_STD_CANCEL
)
1041 if(action
== ACTION_STD_OK
) {
1042 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
1044 if (!(gui_synclist_get_sel_pos(&lists
)/2))
1045 global_status
.runtime
= 0;
1047 global_status
.topruntime
= 0;
1048 gui_synclist_speak_item(&lists
);
1051 if(default_event_handler(action
) == SYS_USB_CONNECTED
)
1057 #ifdef HAVE_TOUCHSCREEN
1058 static int get_sample(struct touchscreen_calibration
*cal
, int x
, int y
, int i
,
1059 struct screen
* screen
)
1065 screen
->drawline(x
- 10, y
, x
- 2, y
);
1066 screen
->drawline(x
+ 2, y
, x
+ 10, y
);
1067 screen
->drawline(x
, y
- 10, x
, y
- 2);
1068 screen
->drawline(x
, y
+ 2, x
, y
+ 10);
1071 /* Wait for a touchscreen press */
1074 action
= get_action(CONTEXT_STD
, TIMEOUT_BLOCK
);
1075 if(action
== ACTION_TOUCHSCREEN
)
1077 if(action_get_touchscreen_press(&ts_x
, &ts_y
) == BUTTON_REL
)
1080 else if(action
== ACTION_STD_CANCEL
)
1084 cal
->x
[i
][0] = ts_x
;
1085 cal
->y
[i
][0] = ts_y
;
1095 short points
[3][2] = {
1096 {LCD_WIDTH
/10, LCD_HEIGHT
/10},
1097 {7*LCD_WIDTH
/8, LCD_HEIGHT
/2},
1098 {LCD_WIDTH
/2, 7*LCD_HEIGHT
/8}
1100 struct screen
* screen
= &screens
[SCREEN_MAIN
];
1101 enum touchscreen_mode old_mode
= touchscreen_get_mode();
1102 struct touchscreen_calibration cal
;
1104 int statusbar
= global_settings
.statusbar
; /* hide the statusbar */
1105 global_settings
.statusbar
= STATUSBAR_OFF
;
1107 touchscreen_disable_mapping(); /* set raw mode */
1108 touchscreen_set_mode(TOUCHSCREEN_POINT
);
1111 screen
->clear_display();
1113 if(get_sample(&cal
, points
[i
][0], points
[i
][1], i
, screen
))
1121 touchscreen_calibrate(&cal
);
1123 touchscreen_reset_mapping();
1124 memcpy(&global_settings
.ts_calibration_data
, &calibration_parameters
, sizeof(struct touchscreen_parameter
));
1125 touchscreen_set_mode(old_mode
);
1126 global_settings
.statusbar
= statusbar
;
1131 int reset_mapping(void)
1133 touchscreen_reset_mapping();
1134 memcpy(&global_settings
.ts_calibration_data
, &calibration_parameters
, sizeof(struct touchscreen_parameter
));