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"
|
|
|
|
#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
|
|
|
#if defined(HAVE_LCD_CHARCELLS) || defined(HAVE_CHARGE_CTRL)
|
|
|
|
static long switch_tick;
|
|
|
|
static int battery_charge_step = 0;
|
|
|
|
#ifdef HAVE_CHARGE_CTRL
|
|
|
|
static bool plug_state;
|
|
|
|
static bool battery_state;
|
|
|
|
#endif
|
2002-08-07 10:35:26 +00:00
|
|
|
#endif
|
|
|
|
|
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.battlevel = battery_level();
|
|
|
|
info.volume = mpeg_val2phys(SOUND_VOLUME, global_settings.volume);
|
|
|
|
info.inserted = charger_inserted();
|
2002-09-30 21:27:53 +00:00
|
|
|
|
2002-08-30 00:39:31 +00:00
|
|
|
#if defined(HAVE_LCD_CHARCELLS)
|
2002-07-22 22:41:32 +00:00
|
|
|
lcd_icon(ICON_VOLUME, true);
|
2003-04-23 11:26:25 +00:00
|
|
|
if(info.volume > 10)
|
2002-07-23 08:35:35 +00:00
|
|
|
lcd_icon(ICON_VOLUME_1, true);
|
2002-07-22 22:41:32 +00:00
|
|
|
else
|
2002-07-23 08:35:35 +00:00
|
|
|
lcd_icon(ICON_VOLUME_1, false);
|
2003-04-23 11:26:25 +00:00
|
|
|
if(info.volume > 30)
|
2002-07-23 08:35:35 +00:00
|
|
|
lcd_icon(ICON_VOLUME_2, true);
|
2002-07-22 22:41:32 +00:00
|
|
|
else
|
2002-07-23 08:35:35 +00:00
|
|
|
lcd_icon(ICON_VOLUME_2, false);
|
2003-04-23 11:26:25 +00:00
|
|
|
if(info.volume > 50)
|
2002-07-23 08:35:35 +00:00
|
|
|
lcd_icon(ICON_VOLUME_3, true);
|
2002-07-22 22:41:32 +00:00
|
|
|
else
|
2002-07-23 08:35:35 +00:00
|
|
|
lcd_icon(ICON_VOLUME_3, false);
|
2003-04-23 11:26:25 +00:00
|
|
|
if(info.volume > 70)
|
2002-07-23 08:35:35 +00:00
|
|
|
lcd_icon(ICON_VOLUME_4, true);
|
2002-07-22 22:41:32 +00:00
|
|
|
else
|
2002-07-23 08:35:35 +00:00
|
|
|
lcd_icon(ICON_VOLUME_4, false);
|
2003-04-23 11:26:25 +00:00
|
|
|
if(info.volume > 90)
|
2002-07-23 08:35:35 +00:00
|
|
|
lcd_icon(ICON_VOLUME_5, true);
|
2002-07-22 22:41:32 +00:00
|
|
|
else
|
2002-07-23 08:35:35 +00:00
|
|
|
lcd_icon(ICON_VOLUME_5, false);
|
2002-07-22 22:41:32 +00:00
|
|
|
|
|
|
|
switch(current_mode)
|
|
|
|
{
|
2002-07-23 08:35:35 +00:00
|
|
|
case STATUS_PLAY:
|
|
|
|
lcd_icon(ICON_PLAY, true);
|
|
|
|
lcd_icon(ICON_PAUSE, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATUS_STOP:
|
|
|
|
lcd_icon(ICON_PLAY, false);
|
|
|
|
lcd_icon(ICON_PAUSE, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATUS_PAUSE:
|
|
|
|
lcd_icon(ICON_PLAY, false);
|
|
|
|
lcd_icon(ICON_PAUSE, true);
|
|
|
|
break;
|
2002-08-21 11:51:24 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2002-07-22 22:41:32 +00:00
|
|
|
}
|
2003-04-23 11:26:25 +00:00
|
|
|
if(info.inserted)
|
2002-09-04 22:29:04 +00:00
|
|
|
{
|
2002-12-04 11:25:56 +00:00
|
|
|
global_settings.runtime = 0;
|
2002-09-04 22:29:04 +00:00
|
|
|
if(TIME_AFTER(current_tick, switch_tick))
|
|
|
|
{
|
|
|
|
lcd_icon(ICON_BATTERY, true);
|
|
|
|
lcd_icon(ICON_BATTERY_1, false);
|
|
|
|
lcd_icon(ICON_BATTERY_2, false);
|
|
|
|
lcd_icon(ICON_BATTERY_3, false);
|
|
|
|
switch(battery_charge_step)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
battery_charge_step++;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
lcd_icon(ICON_BATTERY_1, true);
|
|
|
|
battery_charge_step++;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
lcd_icon(ICON_BATTERY_1, true);
|
|
|
|
lcd_icon(ICON_BATTERY_2, true);
|
|
|
|
battery_charge_step++;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
lcd_icon(ICON_BATTERY_1, true);
|
|
|
|
lcd_icon(ICON_BATTERY_2, true);
|
|
|
|
lcd_icon(ICON_BATTERY_3, true);
|
|
|
|
battery_charge_step = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
battery_charge_step = 0;
|
|
|
|
break;
|
|
|
|
}
|
2002-09-04 22:32:19 +00:00
|
|
|
switch_tick = current_tick + (HZ/2);
|
2002-09-04 22:29:04 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
lcd_icon(ICON_BATTERY, true);
|
2003-04-23 11:26:25 +00:00
|
|
|
if(info.battlevel > 25)
|
2002-09-04 22:29:04 +00:00
|
|
|
lcd_icon(ICON_BATTERY_1, true);
|
|
|
|
else
|
|
|
|
lcd_icon(ICON_BATTERY_1, false);
|
2003-04-23 11:26:25 +00:00
|
|
|
if(info.battlevel > 50)
|
2002-09-04 22:29:04 +00:00
|
|
|
lcd_icon(ICON_BATTERY_2, true);
|
|
|
|
else
|
|
|
|
lcd_icon(ICON_BATTERY_2, false);
|
2003-04-23 11:26:25 +00:00
|
|
|
if(info.battlevel > 75)
|
2002-09-04 22:29:04 +00:00
|
|
|
lcd_icon(ICON_BATTERY_3, true);
|
|
|
|
else
|
|
|
|
lcd_icon(ICON_BATTERY_3, false);
|
|
|
|
}
|
2002-10-05 13:12:01 +00:00
|
|
|
|
|
|
|
lcd_icon(ICON_REPEAT, global_settings.repeat_mode != REPEAT_OFF);
|
|
|
|
lcd_icon(ICON_1, global_settings.repeat_mode == REPEAT_ONE);
|
|
|
|
|
2002-10-15 12:53:33 +00:00
|
|
|
lcd_icon(ICON_RECORD, record);
|
|
|
|
lcd_icon(ICON_AUDIO, audio);
|
|
|
|
lcd_icon(ICON_PARAM, param);
|
|
|
|
lcd_icon(ICON_USB, usb);
|
|
|
|
|
2002-07-22 22:41:32 +00:00
|
|
|
#endif
|
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.battery_safe = battery_level_safe();
|
|
|
|
info.repeat = global_settings.repeat_mode;
|
|
|
|
|
|
|
|
if (force_redraw ||
|
|
|
|
info.inserted ||
|
|
|
|
!info.battery_safe ||
|
|
|
|
memcmp(&info, &lastinfo, sizeof(struct status_info))) {
|
|
|
|
lcd_clearrect(0,0,LCD_WIDTH,8);
|
|
|
|
|
2003-02-13 21:45:19 +00:00
|
|
|
#ifdef HAVE_CHARGE_CTRL /* Recorder */
|
2003-04-23 11:26:25 +00:00
|
|
|
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;
|
2002-12-14 15:46:23 +00:00
|
|
|
if (charge_state > 0) /* charge || top off || trickle */
|
2002-12-04 11:25:56 +00:00
|
|
|
global_settings.runtime = 0;
|
2002-12-18 19:00:34 +00:00
|
|
|
if (charge_state == 1) { /* animate battery if charging */
|
2003-04-23 11:26:25 +00:00
|
|
|
info.battlevel = battery_charge_step * 34; /* 34 for a better look */
|
|
|
|
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-04-23 11:26:25 +00:00
|
|
|
if(!info.battery_safe)
|
2002-08-12 12:31:36 +00:00
|
|
|
battery_state = true;
|
2002-08-13 14:58:09 +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-04-23 11:26:25 +00:00
|
|
|
statusbar_icon_battery(info.battlevel, plug_state);
|
2002-08-07 10:35:26 +00:00
|
|
|
#else
|
2003-02-13 21:45:19 +00:00
|
|
|
#ifdef HAVE_FMADC /* FM */
|
2003-04-23 11:26:25 +00:00
|
|
|
statusbar_icon_battery(info.battlevel, charger_inserted());
|
2003-02-13 21:45:19 +00:00
|
|
|
#else /* Player */
|
2003-04-23 11:26:25 +00:00
|
|
|
statusbar_icon_battery(info.battlevel, false);
|
2003-02-13 21:45:19 +00:00
|
|
|
#endif /* HAVE_FMADC */
|
|
|
|
#endif /* HAVE_CHARGE_CTRL */
|
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-04-23 11:26:25 +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-30 00:39:31 +00:00
|
|
|
|
2002-08-20 19:40:35 +00:00
|
|
|
lcd_update_rect(0, 0, LCD_WIDTH, STATUSBAR_HEIGHT);
|
2002-08-07 10:35:26 +00:00
|
|
|
}
|
2003-04-23 11:26:25 +00:00
|
|
|
|
|
|
|
lastinfo = info;
|
2002-08-07 10:35:26 +00:00
|
|
|
#endif
|
2002-07-22 22:41:32 +00:00
|
|
|
}
|