summaryrefslogtreecommitdiff
path: root/apps/gui/statusbar.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/gui/statusbar.c')
-rw-r--r--apps/gui/statusbar.c228
1 files changed, 108 insertions, 120 deletions
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;
107 107
108void gui_statusbar_init(struct gui_statusbar * bar) 108void gui_statusbar_init(struct gui_statusbar * bar)
109{ 109{
110 bar->last_volume = -1000; /* -1000 means "first update ever" */ 110 bar->redraw_volume = true;
111 bar->battery_icon_switch_tick = 0; 111 bar->volume_icon_switch_tick = bar->battery_icon_switch_tick = current_tick;
112 bar->animated_level = 0;
113} 112}
114 113
115void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw) 114void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
116{ 115{
117 struct screen * display = bar->display; 116 struct screen * display = bar->display;
118#ifdef CONFIG_RTC
119 struct tm* tm; /* For Time */
120#endif /* CONFIG_RTC */
121 117
122#ifdef HAVE_LCD_CHARCELLS 118#ifdef HAVE_LCD_CHARCELLS
123 int vol; 119 int val;
124 (void)force_redraw; /* players always "redraw" */ 120 (void)force_redraw; /* players always "redraw" */
125#endif /* HAVE_LCD_CHARCELLS */ 121#endif /* HAVE_LCD_CHARCELLS */
126 122
127 bar->info.volume = sound_val2phys(SOUND_VOLUME, global_settings.volume); 123 bar->info.battlevel = battery_level();
128#ifdef HAVE_CHARGING 124#ifdef HAVE_USB_POWER
125 bar->info.usb_power = usb_powered();
126#endif
127#ifdef CONFIG_CHARGING
129 bar->info.inserted = (charger_input_state == CHARGER); 128 bar->info.inserted = (charger_input_state == CHARGER);
129 if (bar->info.inserted)
130 {
131 bar->info.battery_state = true;
132
133#if CONFIG_CHARGING >= CHARGING_MONITOR
134
135 /* zero battery run time if charging */
136 if (charge_state > DISCHARGING)
137 lasttime = current_tick;
138
139 /* animate battery if charging */
140 if ((charge_state == DISCHARGING) || (charge_state == TRICKLE))
141 {
142 bar->info.batt_charge_step = -1;
143 }
144 else
145 {
146#else
147 lasttime = current_tick;
148 {
130#endif 149#endif
131 bar->info.battlevel = battery_level(); 150 /* animate in (max.) 4 steps, starting near the current charge level */
132 bar->info.battery_safe = battery_level_safe(); 151 if (TIME_AFTER(current_tick, bar->battery_icon_switch_tick))
152 {
153 if (++bar->info.batt_charge_step > 3)
154 bar->info.batt_charge_step = bar->info.battlevel / 34;
155 bar->battery_icon_switch_tick = current_tick + HZ;
156 }
157 }
158 }
159 else
160#endif
161 {
162 bar->info.batt_charge_step = -1;
163 if (battery_level_safe())
164 bar->info.battery_state = true;
165 else
166 /* blink battery if level is low */
167 if (TIME_AFTER(current_tick, bar->battery_icon_switch_tick) &&
168 (bar->info.battlevel > -1))
169 {
170 bar->info.battery_state = !bar->info.battery_state;
171 bar->battery_icon_switch_tick = current_tick + HZ;
172 }
173 }
133 174
175 bar->info.volume = sound_val2phys(SOUND_VOLUME, global_settings.volume);
134#ifdef HAVE_LCD_BITMAP 176#ifdef HAVE_LCD_BITMAP
135#ifdef CONFIG_RTC
136 tm = get_time();
137 bar->info.hour = tm->tm_hour;
138 bar->info.minute = tm->tm_min;
139#endif /* CONFIG_RTC */
140
141 bar->info.shuffle = global_settings.playlist_shuffle; 177 bar->info.shuffle = global_settings.playlist_shuffle;
142#ifdef HAS_BUTTON_HOLD 178#ifdef HAS_BUTTON_HOLD
143 bar->info.keylock = button_hold(); 179 bar->info.keylock = button_hold();
@@ -149,24 +185,25 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
149#endif 185#endif
150 bar->info.repeat = global_settings.repeat_mode; 186 bar->info.repeat = global_settings.repeat_mode;
151 bar->info.playmode = current_playmode(); 187 bar->info.playmode = current_playmode();
188
152#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD) 189#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
153 if(!display->has_disk_led) 190 if(!display->has_disk_led)
154 bar->info.led = led_read(HZ/2); /* delay should match polling interval */ 191 bar->info.led = led_read(HZ/2); /* delay should match polling interval */
155#endif 192#endif
156 193#ifdef CONFIG_RTC
157#ifdef HAVE_USB_POWER 194 {
158 bar->info.usb_power = usb_powered(); 195 struct tm* tm = get_time();
159#endif /* HAVE_USB_POWER */ 196 bar->info.hour = tm->tm_hour;
197 bar->info.minute = tm->tm_min;
198 }
199#endif /* CONFIG_RTC */
160 200
161 /* only redraw if forced to, or info has changed */ 201 /* only redraw if forced to, or info has changed */
162 if (force_redraw || 202 if (force_redraw || bar->redraw_volume ||
163 bar->info.inserted ||
164 !bar->info.battery_safe ||
165 bar->info.redraw_volume ||
166 memcmp(&(bar->info), &(bar->lastinfo), sizeof(struct status_info))) 203 memcmp(&(bar->info), &(bar->lastinfo), sizeof(struct status_info)))
167 { 204 {
168 display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); 205 display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
169 display->fillrect(0,0,display->width,8); 206 display->fillrect(0, 0, display->width, STATUSBAR_HEIGHT);
170 display->set_drawmode(DRMODE_SOLID); 207 display->set_drawmode(DRMODE_SOLID);
171 208
172#else 209#else
@@ -175,65 +212,10 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
175 { 212 {
176#endif /* HAVE_LCD_BITMAP */ 213#endif /* HAVE_LCD_BITMAP */
177 214
178#ifdef HAVE_CHARGING
179 if (bar->info.inserted) {
180 battery_state = true;
181#if defined(HAVE_CHARGE_CTRL) || \
182 defined(HAVE_CHARGE_STATE) || \
183 CONFIG_BATTERY == BATT_LIION2200
184 /* zero battery run time if charging */
185 if (charge_state > DISCHARGING) {
186 lasttime = current_tick;
187 }
188
189 /* animate battery if charging */
190 if ((charge_state == CHARGING)
191#ifdef HAVE_CHARGE_CTRL
192 || (charge_state == TOPOFF)
193#endif
194 ) {
195#else
196 lasttime = current_tick;
197 {
198#endif
199 /* animate in three steps (34% per step for a better look) */
200#ifndef HAVE_CHARGE_STATE
201 bar->info.battlevel = 0;
202#endif
203 if(TIME_AFTER(current_tick, bar->battery_icon_switch_tick)) {
204 if (bar->animated_level == 100)
205 {
206 bar->animated_level = bar->info.battlevel;
207 }
208 else
209 {
210 bar->animated_level += 34;
211 if (bar->animated_level > 100)
212 bar->animated_level = 100;
213 }
214 bar->battery_icon_switch_tick = current_tick + HZ;
215 }
216 }
217 }
218 else
219#endif /* HAVE_CHARGING */
220 {
221 bar->animated_level = 0;
222 if (bar->info.battery_safe)
223 battery_state = true;
224 else {
225 /* blink battery if level is low */
226 if(TIME_AFTER(current_tick, bar->battery_icon_switch_tick) &&
227 (bar->info.battlevel > -1)) {
228 bar->battery_icon_switch_tick = current_tick+HZ;
229 battery_state = !battery_state;
230 }
231 }
232 }
233#ifdef HAVE_LCD_BITMAP 215#ifdef HAVE_LCD_BITMAP
234 if (battery_state) 216 if (bar->info.battery_state)
235 gui_statusbar_icon_battery(display, bar->info.battlevel, 217 gui_statusbar_icon_battery(display, bar->info.battlevel,
236 bar->animated_level); 218 bar->info.batt_charge_step);
237#ifdef HAVE_USB_POWER 219#ifdef HAVE_USB_POWER
238 if (bar->info.usb_power) 220 if (bar->info.usb_power)
239 display->mono_bitmap(bitmap_icons_7x8[Icon_USBPlug], 221 display->mono_bitmap(bitmap_icons_7x8[Icon_USBPlug],
@@ -243,14 +225,15 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
243 else 225 else
244#endif /* HAVE_USB_POWER */ 226#endif /* HAVE_USB_POWER */
245 /* draw power plug if charging */ 227 /* draw power plug if charging */
228#ifdef CONFIG_CHARGING
246 if (bar->info.inserted) 229 if (bar->info.inserted)
247 display->mono_bitmap(bitmap_icons_7x8[Icon_Plug], 230 display->mono_bitmap(bitmap_icons_7x8[Icon_Plug],
248 STATUSBAR_PLUG_X_POS, 231 STATUSBAR_PLUG_X_POS,
249 STATUSBAR_Y_POS, STATUSBAR_PLUG_WIDTH, 232 STATUSBAR_Y_POS, STATUSBAR_PLUG_WIDTH,
250 STATUSBAR_HEIGHT); 233 STATUSBAR_HEIGHT);
234#endif
251 235
252 bar->info.redraw_volume = gui_statusbar_icon_volume(bar, 236 bar->redraw_volume = gui_statusbar_icon_volume(bar, bar->info.volume);
253 bar->info.volume);
254 gui_statusbar_icon_play_state(display, current_playmode() + 237 gui_statusbar_icon_play_state(display, current_playmode() +
255 Icon_Play); 238 Icon_Play);
256 239
@@ -292,20 +275,24 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
292 275
293 276
294#ifdef HAVE_LCD_CHARCELLS 277#ifdef HAVE_LCD_CHARCELLS
295 if (bar->info.battlevel > -1) 278 display->icon(ICON_BATTERY, bar->info.battery_state);
296 display->icon(ICON_BATTERY, battery_state); 279
297 display->icon(ICON_BATTERY_1, bar->info.battlevel > 25); 280 if (bar->info.batt_charge_step > -1)
298 display->icon(ICON_BATTERY_2, bar->info.battlevel > 50); 281 val = bar->info.batt_charge_step;
299 display->icon(ICON_BATTERY_3, bar->info.battlevel > 75); 282 else
300 283 val = (bar->info.battlevel * 3 + 50) / 100;
301 vol = 100 * (bar->info.volume - sound_min(SOUND_VOLUME)) 284 display->icon(ICON_BATTERY_1, val >= 1);
285 display->icon(ICON_BATTERY_2, val >= 2);
286 display->icon(ICON_BATTERY_3, val >= 3);
287
288 val = 10 * (bar->info.volume - sound_min(SOUND_VOLUME))
302 / (sound_max(SOUND_VOLUME) - sound_min(SOUND_VOLUME)); 289 / (sound_max(SOUND_VOLUME) - sound_min(SOUND_VOLUME));
303 display->icon(ICON_VOLUME, true); 290 display->icon(ICON_VOLUME, true);
304 display->icon(ICON_VOLUME_1, vol > 10); 291 display->icon(ICON_VOLUME_1, val >= 1);
305 display->icon(ICON_VOLUME_2, vol > 30); 292 display->icon(ICON_VOLUME_2, val >= 3);
306 display->icon(ICON_VOLUME_3, vol > 50); 293 display->icon(ICON_VOLUME_3, val >= 5);
307 display->icon(ICON_VOLUME_4, vol > 70); 294 display->icon(ICON_VOLUME_4, val >= 7);
308 display->icon(ICON_VOLUME_5, vol > 90); 295 display->icon(ICON_VOLUME_5, val >= 9);
309 296
310 display->icon(ICON_PLAY, current_playmode() == STATUS_PLAY); 297 display->icon(ICON_PLAY, current_playmode() == STATUS_PLAY);
311 display->icon(ICON_PAUSE, current_playmode() == STATUS_PAUSE); 298 display->icon(ICON_PAUSE, current_playmode() == STATUS_PAUSE);
@@ -326,40 +313,41 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
326 * Print battery icon to status bar 313 * Print battery icon to status bar
327 */ 314 */
328void gui_statusbar_icon_battery(struct screen * display, int percent, 315void gui_statusbar_icon_battery(struct screen * display, int percent,
329 int animated_percent) 316 int batt_charge_step)
330{ 317{
331 int fill, endfill; 318 int fill, endfill;
332 char buffer[5]; 319 char buffer[5];
333 unsigned int width, height; 320 unsigned int width, height;
334#if LCD_DEPTH > 1 321#if LCD_DEPTH > 1
335 unsigned int prevfg = LCD_DEFAULT_FG; 322 unsigned int prevfg = 0;
336#endif 323#endif
337 324
338 /* fill battery */ 325#ifdef CONFIG_CHARGING
339 fill = percent; 326 if (batt_charge_step >= 0)
340 if (fill < 0) 327 {
341 fill = 0; 328 fill = percent * (STATUSBAR_BATTERY_WIDTH-3) / 100;
342 if (fill > 100) 329 endfill = 34 * batt_charge_step * (STATUSBAR_BATTERY_WIDTH-3) / 100;
343 fill = 100; 330 }
344 331 else
345 endfill = animated_percent; 332#else
346 if (endfill < 0) 333 (void)batt_charge_step;
347 endfill = 0; 334#endif
348 if (endfill > 100) 335 {
349 endfill = 100; 336 fill = endfill = (percent * (STATUSBAR_BATTERY_WIDTH-3) + 50) / 100;
350 337 }
351#if (defined(HAVE_CHARGE_CTRL) || defined(HAVE_CHARGE_STATE)) && \ 338
352 !defined(SIMULATOR) /* Certain charge controlled targets */ 339#if CONFIG_CHARGING == CHARGING_MONITOR && !defined(SIMULATOR)
340 /* Certain charge controlled targets */
353 /* show graphical animation when charging instead of numbers */ 341 /* show graphical animation when charging instead of numbers */
354 if ((global_settings.battery_display) && 342 if ((global_settings.battery_display) &&
355 (charge_state != 1) && 343 (charge_state != CHARGING) &&
356 (percent > -1)) { 344 (percent > -1)) {
357#else /* all others */ 345#else /* all others */
358 if (global_settings.battery_display && (percent > -1)) { 346 if (global_settings.battery_display && (percent > -1)) {
359#endif 347#endif
360 /* Numeric display */ 348 /* Numeric display */
361 display->setfont(FONT_SYSFIXED); 349 display->setfont(FONT_SYSFIXED);
362 snprintf(buffer, sizeof(buffer), "%3d", fill); 350 snprintf(buffer, sizeof(buffer), "%3d", percent);
363 display->getstringsize(buffer, &width, &height); 351 display->getstringsize(buffer, &width, &height);
364 if (height <= STATUSBAR_HEIGHT) 352 if (height <= STATUSBAR_HEIGHT)
365 display->putsxy(STATUSBAR_BATTERY_X_POS 353 display->putsxy(STATUSBAR_BATTERY_X_POS
@@ -374,7 +362,6 @@ void gui_statusbar_icon_battery(struct screen * display, int percent,
374 display->vline(STATUSBAR_BATTERY_X_POS + 17, STATUSBAR_Y_POS + 2, 362 display->vline(STATUSBAR_BATTERY_X_POS + 17, STATUSBAR_Y_POS + 2,
375 STATUSBAR_Y_POS + 4); 363 STATUSBAR_Y_POS + 4);
376 364
377 fill = fill * 15 / 100;
378 display->fillrect(STATUSBAR_BATTERY_X_POS + 1, STATUSBAR_Y_POS + 1, 365 display->fillrect(STATUSBAR_BATTERY_X_POS + 1, STATUSBAR_Y_POS + 1,
379 fill, 5); 366 fill, 5);
380#if LCD_DEPTH > 1 367#if LCD_DEPTH > 1
@@ -384,9 +371,8 @@ void gui_statusbar_icon_battery(struct screen * display, int percent,
384 display->set_foreground(LCD_DARKGRAY); 371 display->set_foreground(LCD_DARKGRAY);
385 } 372 }
386#endif 373#endif
387 endfill = endfill * 15 / 100 - fill; 374 display->fillrect(STATUSBAR_BATTERY_X_POS + 1 + fill,
388 display->fillrect(STATUSBAR_BATTERY_X_POS + 1 + fill, 375 STATUSBAR_Y_POS + 1, endfill - fill, 5);
389 STATUSBAR_Y_POS + 1, endfill, 5);
390#if LCD_DEPTH > 1 376#if LCD_DEPTH > 1
391 if (display->depth > 1) 377 if (display->depth > 1)
392 display->set_foreground(prevfg); 378 display->set_foreground(prevfg);
@@ -507,6 +493,7 @@ void gui_statusbar_icon_lock(struct screen * display)
507 STATUSBAR_LOCKM_WIDTH, STATUSBAR_HEIGHT); 493 STATUSBAR_LOCKM_WIDTH, STATUSBAR_HEIGHT);
508} 494}
509 495
496#ifdef HAS_REMOTE_BUTTON_HOLD
510/* 497/*
511 * Print remote lock when remote hold is enabled 498 * Print remote lock when remote hold is enabled
512 */ 499 */
@@ -516,6 +503,7 @@ void gui_statusbar_icon_lock_remote(struct screen * display)
516 STATUSBAR_LOCKR_X_POS, STATUSBAR_Y_POS, 503 STATUSBAR_LOCKR_X_POS, STATUSBAR_Y_POS,
517 STATUSBAR_LOCKR_WIDTH, STATUSBAR_HEIGHT); 504 STATUSBAR_LOCKR_WIDTH, STATUSBAR_HEIGHT);
518} 505}
506#endif
519 507
520#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD) 508#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
521/* 509/*