summaryrefslogtreecommitdiff
path: root/apps/gui
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2006-06-06 22:23:52 +0000
committerJens Arnold <amiconn@rockbox.org>2006-06-06 22:23:52 +0000
commit0dd1f8ec11f28fe34c93ba97af95eb2be2fef44f (patch)
treee3e77d4e6b25b82c82b3570cd8c4a988c7788e66 /apps/gui
parent8c9e22580e220b793130ed3ac67b9c54e85b3d0f (diff)
Work-in-progress rework of charging status reading & display: * Changed several charging related HAVE_* macros into one multi-value CONFIG_CHARGING. * Always use proper macros for charging states. * Battery symbol charging animation now starts from current level on all targets with charging. Two-colour animation kept for non-b&w targets. Round down fill level while charging as before, but round to nearest pixel value for discharging on all targets. * Charging anim fixed on player. * Some code cleanup.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10080 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/gui')
-rw-r--r--apps/gui/gwps-common.c6
-rw-r--r--apps/gui/statusbar.c228
-rw-r--r--apps/gui/statusbar.h26
3 files changed, 124 insertions, 136 deletions
diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c
index 5ab6ce8c82..171784c0ad 100644
--- a/apps/gui/gwps-common.c
+++ b/apps/gui/gwps-common.c
@@ -823,7 +823,7 @@ static char* get_tag(struct wps_data* wps_data,
}
}
-#ifdef HAVE_CHARGING
+#ifdef CONFIG_CHARGING
case 'p': /* External power plugged in? */
{
if(charger_input_state==CHARGER)
@@ -832,9 +832,7 @@ static char* get_tag(struct wps_data* wps_data,
return NULL;
}
#endif
-#if defined(HAVE_CHARGE_CTRL) || \
- defined (HAVE_CHARGE_STATE) || \
- CONFIG_BATTERY == BATT_LIION2200
+#if CONFIG_CHARGING >= CHARGING_MONITOR
case 'c': /* Charging */
{
if (charge_state == CHARGING || charge_state == TOPOFF) {
diff --git a/apps/gui/statusbar.c b/apps/gui/statusbar.c
index c9b27aea7c..b5d8b7c9ed 100644
--- a/apps/gui/statusbar.c
+++ b/apps/gui/statusbar.c
@@ -107,37 +107,73 @@ struct gui_syncstatusbar statusbars;
void gui_statusbar_init(struct gui_statusbar * bar)
{
- bar->last_volume = -1000; /* -1000 means "first update ever" */
- bar->battery_icon_switch_tick = 0;
- bar->animated_level = 0;
+ bar->redraw_volume = true;
+ bar->volume_icon_switch_tick = bar->battery_icon_switch_tick = current_tick;
}
void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
{
struct screen * display = bar->display;
-#ifdef CONFIG_RTC
- struct tm* tm; /* For Time */
-#endif /* CONFIG_RTC */
#ifdef HAVE_LCD_CHARCELLS
- int vol;
+ int val;
(void)force_redraw; /* players always "redraw" */
#endif /* HAVE_LCD_CHARCELLS */
- bar->info.volume = sound_val2phys(SOUND_VOLUME, global_settings.volume);
-#ifdef HAVE_CHARGING
+ bar->info.battlevel = battery_level();
+#ifdef HAVE_USB_POWER
+ bar->info.usb_power = usb_powered();
+#endif
+#ifdef CONFIG_CHARGING
bar->info.inserted = (charger_input_state == CHARGER);
+ if (bar->info.inserted)
+ {
+ bar->info.battery_state = true;
+
+#if CONFIG_CHARGING >= CHARGING_MONITOR
+
+ /* zero battery run time if charging */
+ if (charge_state > DISCHARGING)
+ lasttime = current_tick;
+
+ /* animate battery if charging */
+ if ((charge_state == DISCHARGING) || (charge_state == TRICKLE))
+ {
+ bar->info.batt_charge_step = -1;
+ }
+ else
+ {
+#else
+ lasttime = current_tick;
+ {
#endif
- bar->info.battlevel = battery_level();
- bar->info.battery_safe = battery_level_safe();
+ /* animate in (max.) 4 steps, starting near the current charge level */
+ if (TIME_AFTER(current_tick, bar->battery_icon_switch_tick))
+ {
+ if (++bar->info.batt_charge_step > 3)
+ bar->info.batt_charge_step = bar->info.battlevel / 34;
+ bar->battery_icon_switch_tick = current_tick + HZ;
+ }
+ }
+ }
+ else
+#endif
+ {
+ bar->info.batt_charge_step = -1;
+ if (battery_level_safe())
+ bar->info.battery_state = true;
+ else
+ /* blink battery if level is low */
+ if (TIME_AFTER(current_tick, bar->battery_icon_switch_tick) &&
+ (bar->info.battlevel > -1))
+ {
+ bar->info.battery_state = !bar->info.battery_state;
+ bar->battery_icon_switch_tick = current_tick + HZ;
+ }
+ }
+ bar->info.volume = sound_val2phys(SOUND_VOLUME, global_settings.volume);
#ifdef HAVE_LCD_BITMAP
-#ifdef CONFIG_RTC
- tm = get_time();
- bar->info.hour = tm->tm_hour;
- bar->info.minute = tm->tm_min;
-#endif /* CONFIG_RTC */
-
bar->info.shuffle = global_settings.playlist_shuffle;
#ifdef HAS_BUTTON_HOLD
bar->info.keylock = button_hold();
@@ -149,24 +185,25 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
#endif
bar->info.repeat = global_settings.repeat_mode;
bar->info.playmode = current_playmode();
+
#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
if(!display->has_disk_led)
bar->info.led = led_read(HZ/2); /* delay should match polling interval */
#endif
-
-#ifdef HAVE_USB_POWER
- bar->info.usb_power = usb_powered();
-#endif /* HAVE_USB_POWER */
+#ifdef CONFIG_RTC
+ {
+ struct tm* tm = get_time();
+ bar->info.hour = tm->tm_hour;
+ bar->info.minute = tm->tm_min;
+ }
+#endif /* CONFIG_RTC */
/* only redraw if forced to, or info has changed */
- if (force_redraw ||
- bar->info.inserted ||
- !bar->info.battery_safe ||
- bar->info.redraw_volume ||
+ if (force_redraw || bar->redraw_volume ||
memcmp(&(bar->info), &(bar->lastinfo), sizeof(struct status_info)))
{
display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
- display->fillrect(0,0,display->width,8);
+ display->fillrect(0, 0, display->width, STATUSBAR_HEIGHT);
display->set_drawmode(DRMODE_SOLID);
#else
@@ -175,65 +212,10 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
{
#endif /* HAVE_LCD_BITMAP */
-#ifdef HAVE_CHARGING
- if (bar->info.inserted) {
- battery_state = true;
-#if defined(HAVE_CHARGE_CTRL) || \
- defined(HAVE_CHARGE_STATE) || \
- CONFIG_BATTERY == BATT_LIION2200
- /* zero battery run time if charging */
- if (charge_state > DISCHARGING) {
- lasttime = current_tick;
- }
-
- /* animate battery if charging */
- if ((charge_state == CHARGING)
-#ifdef HAVE_CHARGE_CTRL
- || (charge_state == TOPOFF)
-#endif
- ) {
-#else
- lasttime = current_tick;
- {
-#endif
- /* animate in three steps (34% per step for a better look) */
-#ifndef HAVE_CHARGE_STATE
- bar->info.battlevel = 0;
-#endif
- if(TIME_AFTER(current_tick, bar->battery_icon_switch_tick)) {
- if (bar->animated_level == 100)
- {
- bar->animated_level = bar->info.battlevel;
- }
- else
- {
- bar->animated_level += 34;
- if (bar->animated_level > 100)
- bar->animated_level = 100;
- }
- bar->battery_icon_switch_tick = current_tick + HZ;
- }
- }
- }
- else
-#endif /* HAVE_CHARGING */
- {
- bar->animated_level = 0;
- if (bar->info.battery_safe)
- battery_state = true;
- else {
- /* blink battery if level is low */
- if(TIME_AFTER(current_tick, bar->battery_icon_switch_tick) &&
- (bar->info.battlevel > -1)) {
- bar->battery_icon_switch_tick = current_tick+HZ;
- battery_state = !battery_state;
- }
- }
- }
#ifdef HAVE_LCD_BITMAP
- if (battery_state)
+ if (bar->info.battery_state)
gui_statusbar_icon_battery(display, bar->info.battlevel,
- bar->animated_level);
+ bar->info.batt_charge_step);
#ifdef HAVE_USB_POWER
if (bar->info.usb_power)
display->mono_bitmap(bitmap_icons_7x8[Icon_USBPlug],
@@ -243,14 +225,15 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
else
#endif /* HAVE_USB_POWER */
/* draw power plug if charging */
+#ifdef CONFIG_CHARGING
if (bar->info.inserted)
display->mono_bitmap(bitmap_icons_7x8[Icon_Plug],
STATUSBAR_PLUG_X_POS,
STATUSBAR_Y_POS, STATUSBAR_PLUG_WIDTH,
STATUSBAR_HEIGHT);
+#endif
- bar->info.redraw_volume = gui_statusbar_icon_volume(bar,
- bar->info.volume);
+ bar->redraw_volume = gui_statusbar_icon_volume(bar, bar->info.volume);
gui_statusbar_icon_play_state(display, current_playmode() +
Icon_Play);
@@ -292,20 +275,24 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
#ifdef HAVE_LCD_CHARCELLS
- if (bar->info.battlevel > -1)
- display->icon(ICON_BATTERY, battery_state);
- display->icon(ICON_BATTERY_1, bar->info.battlevel > 25);
- display->icon(ICON_BATTERY_2, bar->info.battlevel > 50);
- display->icon(ICON_BATTERY_3, bar->info.battlevel > 75);
-
- vol = 100 * (bar->info.volume - sound_min(SOUND_VOLUME))
+ display->icon(ICON_BATTERY, bar->info.battery_state);
+
+ if (bar->info.batt_charge_step > -1)
+ val = bar->info.batt_charge_step;
+ else
+ val = (bar->info.battlevel * 3 + 50) / 100;
+ display->icon(ICON_BATTERY_1, val >= 1);
+ display->icon(ICON_BATTERY_2, val >= 2);
+ display->icon(ICON_BATTERY_3, val >= 3);
+
+ val = 10 * (bar->info.volume - sound_min(SOUND_VOLUME))
/ (sound_max(SOUND_VOLUME) - sound_min(SOUND_VOLUME));
display->icon(ICON_VOLUME, true);
- display->icon(ICON_VOLUME_1, vol > 10);
- display->icon(ICON_VOLUME_2, vol > 30);
- display->icon(ICON_VOLUME_3, vol > 50);
- display->icon(ICON_VOLUME_4, vol > 70);
- display->icon(ICON_VOLUME_5, vol > 90);
+ display->icon(ICON_VOLUME_1, val >= 1);
+ display->icon(ICON_VOLUME_2, val >= 3);
+ display->icon(ICON_VOLUME_3, val >= 5);
+ display->icon(ICON_VOLUME_4, val >= 7);
+ display->icon(ICON_VOLUME_5, val >= 9);
display->icon(ICON_PLAY, current_playmode() == STATUS_PLAY);
display->icon(ICON_PAUSE, current_playmode() == STATUS_PAUSE);
@@ -326,40 +313,41 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
* Print battery icon to status bar
*/
void gui_statusbar_icon_battery(struct screen * display, int percent,
- int animated_percent)
+ int batt_charge_step)
{
int fill, endfill;
char buffer[5];
unsigned int width, height;
#if LCD_DEPTH > 1
- unsigned int prevfg = LCD_DEFAULT_FG;
+ unsigned int prevfg = 0;
#endif
- /* fill battery */
- fill = percent;
- if (fill < 0)
- fill = 0;
- if (fill > 100)
- fill = 100;
-
- endfill = animated_percent;
- if (endfill < 0)
- endfill = 0;
- if (endfill > 100)
- endfill = 100;
-
-#if (defined(HAVE_CHARGE_CTRL) || defined(HAVE_CHARGE_STATE)) && \
- !defined(SIMULATOR) /* Certain charge controlled targets */
+#ifdef CONFIG_CHARGING
+ if (batt_charge_step >= 0)
+ {
+ fill = percent * (STATUSBAR_BATTERY_WIDTH-3) / 100;
+ endfill = 34 * batt_charge_step * (STATUSBAR_BATTERY_WIDTH-3) / 100;
+ }
+ else
+#else
+ (void)batt_charge_step;
+#endif
+ {
+ fill = endfill = (percent * (STATUSBAR_BATTERY_WIDTH-3) + 50) / 100;
+ }
+
+#if CONFIG_CHARGING == CHARGING_MONITOR && !defined(SIMULATOR)
+ /* Certain charge controlled targets */
/* show graphical animation when charging instead of numbers */
if ((global_settings.battery_display) &&
- (charge_state != 1) &&
+ (charge_state != CHARGING) &&
(percent > -1)) {
#else /* all others */
if (global_settings.battery_display && (percent > -1)) {
#endif
/* Numeric display */
display->setfont(FONT_SYSFIXED);
- snprintf(buffer, sizeof(buffer), "%3d", fill);
+ snprintf(buffer, sizeof(buffer), "%3d", percent);
display->getstringsize(buffer, &width, &height);
if (height <= STATUSBAR_HEIGHT)
display->putsxy(STATUSBAR_BATTERY_X_POS
@@ -374,7 +362,6 @@ void gui_statusbar_icon_battery(struct screen * display, int percent,
display->vline(STATUSBAR_BATTERY_X_POS + 17, STATUSBAR_Y_POS + 2,
STATUSBAR_Y_POS + 4);
- fill = fill * 15 / 100;
display->fillrect(STATUSBAR_BATTERY_X_POS + 1, STATUSBAR_Y_POS + 1,
fill, 5);
#if LCD_DEPTH > 1
@@ -384,9 +371,8 @@ void gui_statusbar_icon_battery(struct screen * display, int percent,
display->set_foreground(LCD_DARKGRAY);
}
#endif
- endfill = endfill * 15 / 100 - fill;
- display->fillrect(STATUSBAR_BATTERY_X_POS + 1 + fill,
- STATUSBAR_Y_POS + 1, endfill, 5);
+ display->fillrect(STATUSBAR_BATTERY_X_POS + 1 + fill,
+ STATUSBAR_Y_POS + 1, endfill - fill, 5);
#if LCD_DEPTH > 1
if (display->depth > 1)
display->set_foreground(prevfg);
@@ -507,6 +493,7 @@ void gui_statusbar_icon_lock(struct screen * display)
STATUSBAR_LOCKM_WIDTH, STATUSBAR_HEIGHT);
}
+#ifdef HAS_REMOTE_BUTTON_HOLD
/*
* Print remote lock when remote hold is enabled
*/
@@ -516,6 +503,7 @@ void gui_statusbar_icon_lock_remote(struct screen * display)
STATUSBAR_LOCKR_X_POS, STATUSBAR_Y_POS,
STATUSBAR_LOCKR_WIDTH, STATUSBAR_HEIGHT);
}
+#endif
#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
/*
diff --git a/apps/gui/statusbar.h b/apps/gui/statusbar.h
index 03add6a6d9..a03c294523 100644
--- a/apps/gui/statusbar.h
+++ b/apps/gui/statusbar.h
@@ -31,38 +31,40 @@
struct status_info {
int battlevel;
+ int batt_charge_step;
int volume;
+ int playmode;
+ int repeat;
#ifdef CONFIG_RTC
int hour;
int minute;
#endif
- int playmode;
- int repeat;
+
+#ifdef CONFIG_CHARGING
bool inserted;
+#endif
+#ifdef HAVE_USB_POWER
+ bool usb_power;
+#endif
+ bool battery_state;
bool shuffle;
bool keylock;
#ifdef HAS_REMOTE_BUTTON_HOLD
bool keylockremote;
#endif
- bool battery_safe;
- bool redraw_volume; /* true if the volume gauge needs updating */
#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
bool led; /* disk LED simulation in the status bar */
#endif
-#ifdef HAVE_USB_POWER
- bool usb_power;
-#endif
};
struct gui_statusbar
{
- /* Volume icon stuffs */
+ long battery_icon_switch_tick;
+
long volume_icon_switch_tick;
int last_volume;
-
- long battery_icon_switch_tick;
- int animated_level;
+ bool redraw_volume; /* true if the volume gauge needs updating */
struct status_info info;
struct status_info lastinfo;
@@ -95,7 +97,7 @@ extern void gui_statusbar_init(struct gui_statusbar * bar);
*/
extern void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw);
-void gui_statusbar_icon_battery(struct screen * display, int percent, int animated_percent);
+void gui_statusbar_icon_battery(struct screen * display, int percent, int batt_charge_step);
bool gui_statusbar_icon_volume(struct gui_statusbar * bar, int volume);
void gui_statusbar_icon_play_state(struct screen * display, int state);
void gui_statusbar_icon_play_mode(struct screen * display, int mode);