2002-07-22 22:41:32 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by Linus Nielsen Feltzing
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2003-04-23 11:26:25 +00:00
|
|
|
#include "string.h"
|
2002-07-22 22:41:32 +00:00
|
|
|
#include "lcd.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "power.h"
|
|
|
|
#include "thread.h"
|
|
|
|
#include "settings.h"
|
|
|
|
#include "status.h"
|
2002-07-23 08:35:35 +00:00
|
|
|
#include "mpeg.h"
|
2002-08-07 10:35:26 +00:00
|
|
|
#include "wps.h"
|
2002-08-30 00:58:55 +00:00
|
|
|
#ifdef HAVE_RTC
|
2003-01-27 14:24:40 +00:00
|
|
|
#include "timefuncs.h"
|
2002-08-30 00:58:55 +00:00
|
|
|
#endif
|
2002-08-07 10:35:26 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
#include "icons.h"
|
2003-11-04 13:17:29 +00:00
|
|
|
#include "font.h"
|
2002-08-07 10:35:26 +00:00
|
|
|
#endif
|
2002-08-07 11:41:31 +00:00
|
|
|
#include "powermgmt.h"
|
2002-08-07 10:35:26 +00:00
|
|
|
|
2002-08-07 12:45:02 +00:00
|
|
|
static enum playmode current_mode = STATUS_STOP;
|
2002-07-22 22:41:32 +00:00
|
|
|
|
2002-12-18 14:57:45 +00:00
|
|
|
static long switch_tick;
|
|
|
|
static int battery_charge_step = 0;
|
|
|
|
static bool plug_state;
|
|
|
|
static bool battery_state;
|
2002-08-07 10:35:26 +00:00
|
|
|
|
2003-04-23 11:26:25 +00:00
|
|
|
struct status_info {
|
|
|
|
int battlevel;
|
|
|
|
int volume;
|
|
|
|
int hour;
|
|
|
|
int minute;
|
|
|
|
int playmode;
|
|
|
|
int repeat;
|
|
|
|
bool inserted;
|
|
|
|
bool shuffle;
|
|
|
|
bool keylock;
|
|
|
|
bool battery_safe;
|
|
|
|
};
|
|
|
|
|
2002-07-22 22:41:32 +00:00
|
|
|
void status_init(void)
|
|
|
|
{
|
|
|
|
status_set_playmode(STATUS_STOP);
|
|
|
|
}
|
|
|
|
|
|
|
|
void status_set_playmode(enum playmode mode)
|
|
|
|
{
|
|
|
|
current_mode = mode;
|
2003-04-23 11:26:25 +00:00
|
|
|
status_draw(false);
|
2002-07-22 22:41:32 +00:00
|
|
|
}
|
|
|
|
|
2002-10-15 12:53:33 +00:00
|
|
|
#if defined(HAVE_LCD_CHARCELLS)
|
|
|
|
static bool record = false;
|
|
|
|
static bool audio = false;
|
|
|
|
static bool param = false;
|
|
|
|
static bool usb = false;
|
|
|
|
|
|
|
|
void status_set_record(bool b)
|
|
|
|
{
|
|
|
|
record = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
void status_set_audio(bool b)
|
|
|
|
{
|
|
|
|
audio = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
void status_set_param(bool b)
|
|
|
|
{
|
|
|
|
param = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
void status_set_usb(bool b)
|
|
|
|
{
|
|
|
|
usb = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_LCD_CHARCELLS */
|
|
|
|
|
2003-04-23 11:26:25 +00:00
|
|
|
void status_draw(bool force_redraw)
|
2002-07-22 22:41:32 +00:00
|
|
|
{
|
2003-04-23 11:26:25 +00:00
|
|
|
struct status_info info;
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
static struct status_info lastinfo;
|
2003-01-27 14:24:40 +00:00
|
|
|
struct tm* tm;
|
2002-09-30 21:27:53 +00:00
|
|
|
|
|
|
|
if ( !global_settings.statusbar )
|
|
|
|
return;
|
2003-04-23 11:26:25 +00:00
|
|
|
#else
|
|
|
|
(void)force_redraw; /* players always "redraw" */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
info.volume = mpeg_val2phys(SOUND_VOLUME, global_settings.volume);
|
|
|
|
info.inserted = charger_inserted();
|
2003-06-04 12:03:23 +00:00
|
|
|
info.battlevel = battery_level();
|
|
|
|
info.battery_safe = battery_level_safe();
|
2002-09-30 21:27:53 +00:00
|
|
|
|
2002-08-07 10:35:26 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2003-04-23 11:26:25 +00:00
|
|
|
tm = get_time();
|
|
|
|
info.hour = tm->tm_hour;
|
|
|
|
info.minute = tm->tm_min;
|
|
|
|
info.shuffle = global_settings.playlist_shuffle;
|
|
|
|
info.keylock = keys_locked;
|
|
|
|
info.repeat = global_settings.repeat_mode;
|
2003-10-17 14:49:00 +00:00
|
|
|
info.playmode = current_mode;
|
2003-04-23 11:26:25 +00:00
|
|
|
|
2003-06-04 12:03:23 +00:00
|
|
|
/* only redraw if forced to, or info has changed */
|
2003-04-23 11:26:25 +00:00
|
|
|
if (force_redraw ||
|
|
|
|
info.inserted ||
|
|
|
|
!info.battery_safe ||
|
2003-06-04 12:03:23 +00:00
|
|
|
memcmp(&info, &lastinfo, sizeof(struct status_info)))
|
|
|
|
{
|
2003-04-23 11:26:25 +00:00
|
|
|
lcd_clearrect(0,0,LCD_WIDTH,8);
|
2003-06-04 12:03:23 +00:00
|
|
|
#else
|
|
|
|
/* players always "redraw" */
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (info.inserted) {
|
2002-08-12 12:31:36 +00:00
|
|
|
battery_state = true;
|
2002-08-13 14:58:09 +00:00
|
|
|
plug_state = true;
|
2003-06-04 12:03:23 +00:00
|
|
|
#ifdef HAVE_CHARGE_CTRL
|
|
|
|
/* zero battery run time if charging */
|
2003-10-17 13:54:48 +00:00
|
|
|
if (charge_state > 0) {
|
2002-12-04 11:25:56 +00:00
|
|
|
global_settings.runtime = 0;
|
2003-10-17 13:54:48 +00:00
|
|
|
lasttime = current_tick;
|
|
|
|
}
|
2003-06-04 12:03:23 +00:00
|
|
|
|
|
|
|
/* animate battery if charging */
|
|
|
|
if (charge_state == 1) {
|
|
|
|
#else
|
2003-10-17 13:54:48 +00:00
|
|
|
global_settings.runtime = 0;
|
|
|
|
lasttime = current_tick;
|
2003-06-04 12:03:23 +00:00
|
|
|
{
|
|
|
|
#endif
|
|
|
|
/* animate in three steps (34% per step for a better look) */
|
|
|
|
info.battlevel = battery_charge_step * 34;
|
2003-04-23 11:26:25 +00:00
|
|
|
if (info.battlevel > 100)
|
|
|
|
info.battlevel = 100;
|
2002-08-13 14:58:09 +00:00
|
|
|
if(TIME_AFTER(current_tick, switch_tick)) {
|
|
|
|
battery_charge_step=(battery_charge_step+1)%4;
|
|
|
|
switch_tick = current_tick + HZ;
|
|
|
|
}
|
2002-08-07 13:05:13 +00:00
|
|
|
}
|
|
|
|
}
|
2002-08-09 11:56:54 +00:00
|
|
|
else {
|
2002-08-07 13:05:13 +00:00
|
|
|
plug_state=false;
|
2003-06-04 12:03:23 +00:00
|
|
|
if (info.battery_safe)
|
2002-08-12 12:31:36 +00:00
|
|
|
battery_state = true;
|
2003-06-04 12:03:23 +00:00
|
|
|
else {
|
|
|
|
/* blink battery if level is low */
|
2002-08-09 11:56:54 +00:00
|
|
|
if(TIME_AFTER(current_tick, switch_tick)) {
|
2002-08-12 12:31:36 +00:00
|
|
|
switch_tick = current_tick+HZ;
|
|
|
|
battery_state =! battery_state;
|
2002-08-09 11:56:54 +00:00
|
|
|
}
|
2003-06-04 12:03:23 +00:00
|
|
|
}
|
2002-08-09 11:56:54 +00:00
|
|
|
}
|
2003-06-04 12:03:23 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2003-11-19 14:14:41 +00:00
|
|
|
if (battery_state && (info.battlevel > -1))
|
2003-06-04 12:03:23 +00:00
|
|
|
statusbar_icon_battery(info.battlevel, plug_state);
|
2003-11-19 14:14:41 +00:00
|
|
|
|
2003-04-23 11:26:25 +00:00
|
|
|
statusbar_icon_volume(info.volume);
|
2002-08-12 12:31:36 +00:00
|
|
|
statusbar_icon_play_state(current_mode + Icon_Play);
|
2003-04-23 11:26:25 +00:00
|
|
|
switch (info.repeat) {
|
2002-10-08 10:24:29 +00:00
|
|
|
case REPEAT_ONE:
|
|
|
|
statusbar_icon_play_mode(Icon_RepeatOne);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case REPEAT_ALL:
|
|
|
|
statusbar_icon_play_mode(Icon_Repeat);
|
|
|
|
break;
|
|
|
|
}
|
2003-06-04 12:03:23 +00:00
|
|
|
if (info.shuffle)
|
2002-08-12 12:31:36 +00:00
|
|
|
statusbar_icon_shuffle();
|
2003-04-23 11:26:25 +00:00
|
|
|
if (info.keylock)
|
2002-08-12 12:31:36 +00:00
|
|
|
statusbar_icon_lock();
|
2002-08-07 10:35:26 +00:00
|
|
|
#ifdef HAVE_RTC
|
2003-04-23 11:26:25 +00:00
|
|
|
statusbar_time(info.hour, info.minute);
|
2002-08-20 14:33:02 +00:00
|
|
|
#endif
|
2002-08-20 19:40:35 +00:00
|
|
|
lcd_update_rect(0, 0, LCD_WIDTH, STATUSBAR_HEIGHT);
|
2003-06-04 12:03:23 +00:00
|
|
|
lastinfo = info;
|
|
|
|
#endif
|
2002-08-07 10:35:26 +00:00
|
|
|
}
|
2003-04-23 11:26:25 +00:00
|
|
|
|
2003-06-04 12:03:23 +00:00
|
|
|
|
|
|
|
#if defined(HAVE_LCD_CHARCELLS)
|
2003-11-19 14:14:41 +00:00
|
|
|
if (info.battlevel > -1)
|
2003-06-04 12:03:23 +00:00
|
|
|
lcd_icon(ICON_BATTERY, battery_state);
|
|
|
|
lcd_icon(ICON_BATTERY_1, info.battlevel > 25);
|
|
|
|
lcd_icon(ICON_BATTERY_2, info.battlevel > 50);
|
|
|
|
lcd_icon(ICON_BATTERY_3, info.battlevel > 75);
|
|
|
|
|
|
|
|
lcd_icon(ICON_VOLUME, true);
|
|
|
|
lcd_icon(ICON_VOLUME_1, info.volume > 10);
|
|
|
|
lcd_icon(ICON_VOLUME_2, info.volume > 30);
|
|
|
|
lcd_icon(ICON_VOLUME_3, info.volume > 50);
|
|
|
|
lcd_icon(ICON_VOLUME_4, info.volume > 70);
|
|
|
|
lcd_icon(ICON_VOLUME_5, info.volume > 90);
|
|
|
|
|
|
|
|
lcd_icon(ICON_PLAY, current_mode == STATUS_PLAY);
|
|
|
|
lcd_icon(ICON_PAUSE, current_mode == STATUS_PAUSE);
|
|
|
|
|
|
|
|
lcd_icon(ICON_REPEAT, global_settings.repeat_mode != REPEAT_OFF);
|
|
|
|
lcd_icon(ICON_1, global_settings.repeat_mode == REPEAT_ONE);
|
|
|
|
|
|
|
|
lcd_icon(ICON_RECORD, record);
|
|
|
|
lcd_icon(ICON_AUDIO, audio);
|
|
|
|
lcd_icon(ICON_PARAM, param);
|
|
|
|
lcd_icon(ICON_USB, usb);
|
2002-08-07 10:35:26 +00:00
|
|
|
#endif
|
2003-06-04 12:03:23 +00:00
|
|
|
|
2002-07-22 22:41:32 +00:00
|
|
|
}
|
2003-06-04 12:03:23 +00:00
|
|
|
|
2003-11-04 13:17:29 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
static void draw_buttonbar_btn(int num, char* caption)
|
|
|
|
{
|
|
|
|
int xpos, ypos, button_width, text_width;
|
|
|
|
int fw, fh;
|
|
|
|
|
|
|
|
lcd_setfont(FONT_SYSFIXED);
|
|
|
|
lcd_getstringsize("M", &fw, &fh);
|
|
|
|
|
|
|
|
button_width = LCD_WIDTH/3;
|
|
|
|
xpos = num * button_width;
|
|
|
|
ypos = LCD_HEIGHT - fh;
|
|
|
|
|
|
|
|
if(caption)
|
|
|
|
{
|
|
|
|
/* center the text */
|
|
|
|
text_width = fw * strlen(caption);
|
|
|
|
lcd_putsxy(xpos + (button_width - text_width)/2, ypos, caption);
|
|
|
|
}
|
|
|
|
|
|
|
|
lcd_invertrect(xpos, ypos, button_width - 1, fh);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char stored_caption1[8];
|
|
|
|
static char stored_caption2[8];
|
|
|
|
static char stored_caption3[8];
|
|
|
|
|
2003-11-05 08:59:55 +00:00
|
|
|
void buttonbar_set(char* caption1, char *caption2, char *caption3)
|
2003-11-04 13:17:29 +00:00
|
|
|
{
|
|
|
|
strncpy(stored_caption1, caption1, 7);
|
|
|
|
stored_caption1[7] = 0;
|
|
|
|
strncpy(stored_caption2, caption2, 7);
|
|
|
|
stored_caption2[7] = 0;
|
|
|
|
strncpy(stored_caption3, caption3, 7);
|
|
|
|
stored_caption3[7] = 0;
|
|
|
|
}
|
|
|
|
|
2003-11-05 08:59:55 +00:00
|
|
|
void buttonbar_draw(void)
|
2003-11-04 13:17:29 +00:00
|
|
|
{
|
2003-11-05 09:42:29 +00:00
|
|
|
lcd_clearrect(0, LCD_HEIGHT-8, LCD_WIDTH, 8);
|
2003-11-04 13:17:29 +00:00
|
|
|
draw_buttonbar_btn(0, stored_caption1);
|
|
|
|
draw_buttonbar_btn(1, stored_caption2);
|
|
|
|
draw_buttonbar_btn(2, stored_caption3);
|
|
|
|
}
|
|
|
|
#endif
|