diff options
author | Björn Stenberg <bjorn@haxx.se> | 2003-04-23 11:26:25 +0000 |
---|---|---|
committer | Björn Stenberg <bjorn@haxx.se> | 2003-04-23 11:26:25 +0000 |
commit | 942bc9449ea587fc3d50a468da56df32baf0748f (patch) | |
tree | ca3731dfb763dbb299fe0edb41fa019263b588a0 /apps/status.c | |
parent | 10fd7b6c3b3ed8bfd15ec1a6b67aaff3c4cf2a69 (diff) | |
download | rockbox-942bc9449ea587fc3d50a468da56df32baf0748f.tar.gz rockbox-942bc9449ea587fc3d50a468da56df32baf0748f.zip |
Only redraw the status line when info actually changed.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3588 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/status.c')
-rw-r--r-- | apps/status.c | 97 |
1 files changed, 66 insertions, 31 deletions
diff --git a/apps/status.c b/apps/status.c index 5d4bba6aac..9773bc6356 100644 --- a/apps/status.c +++ b/apps/status.c | |||
@@ -16,6 +16,7 @@ | |||
16 | * KIND, either express or implied. | 16 | * KIND, either express or implied. |
17 | * | 17 | * |
18 | ****************************************************************************/ | 18 | ****************************************************************************/ |
19 | #include "string.h" | ||
19 | #include "lcd.h" | 20 | #include "lcd.h" |
20 | #include "debug.h" | 21 | #include "debug.h" |
21 | #include "kernel.h" | 22 | #include "kernel.h" |
@@ -44,6 +45,19 @@ static bool battery_state; | |||
44 | #endif | 45 | #endif |
45 | #endif | 46 | #endif |
46 | 47 | ||
48 | struct status_info { | ||
49 | int battlevel; | ||
50 | int volume; | ||
51 | int hour; | ||
52 | int minute; | ||
53 | int playmode; | ||
54 | int repeat; | ||
55 | bool inserted; | ||
56 | bool shuffle; | ||
57 | bool keylock; | ||
58 | bool battery_safe; | ||
59 | }; | ||
60 | |||
47 | void status_init(void) | 61 | void status_init(void) |
48 | { | 62 | { |
49 | status_set_playmode(STATUS_STOP); | 63 | status_set_playmode(STATUS_STOP); |
@@ -52,7 +66,7 @@ void status_init(void) | |||
52 | void status_set_playmode(enum playmode mode) | 66 | void status_set_playmode(enum playmode mode) |
53 | { | 67 | { |
54 | current_mode = mode; | 68 | current_mode = mode; |
55 | status_draw(); | 69 | status_draw(false); |
56 | } | 70 | } |
57 | 71 | ||
58 | #if defined(HAVE_LCD_CHARCELLS) | 72 | #if defined(HAVE_LCD_CHARCELLS) |
@@ -83,36 +97,43 @@ void status_set_usb(bool b) | |||
83 | 97 | ||
84 | #endif /* HAVE_LCD_CHARCELLS */ | 98 | #endif /* HAVE_LCD_CHARCELLS */ |
85 | 99 | ||
86 | void status_draw(void) | 100 | void status_draw(bool force_redraw) |
87 | { | 101 | { |
88 | int battlevel = battery_level(); | 102 | struct status_info info; |
89 | int volume = mpeg_val2phys(SOUND_VOLUME, global_settings.volume); | 103 | |
90 | #if defined(HAVE_LCD_BITMAP) && defined(HAVE_RTC) | 104 | #ifdef HAVE_LCD_BITMAP |
105 | static struct status_info lastinfo; | ||
91 | struct tm* tm; | 106 | struct tm* tm; |
92 | #endif | ||
93 | 107 | ||
94 | if ( !global_settings.statusbar ) | 108 | if ( !global_settings.statusbar ) |
95 | return; | 109 | return; |
110 | #else | ||
111 | (void)force_redraw; /* players always "redraw" */ | ||
112 | #endif | ||
113 | |||
114 | info.battlevel = battery_level(); | ||
115 | info.volume = mpeg_val2phys(SOUND_VOLUME, global_settings.volume); | ||
116 | info.inserted = charger_inserted(); | ||
96 | 117 | ||
97 | #if defined(HAVE_LCD_CHARCELLS) | 118 | #if defined(HAVE_LCD_CHARCELLS) |
98 | lcd_icon(ICON_VOLUME, true); | 119 | lcd_icon(ICON_VOLUME, true); |
99 | if(volume > 10) | 120 | if(info.volume > 10) |
100 | lcd_icon(ICON_VOLUME_1, true); | 121 | lcd_icon(ICON_VOLUME_1, true); |
101 | else | 122 | else |
102 | lcd_icon(ICON_VOLUME_1, false); | 123 | lcd_icon(ICON_VOLUME_1, false); |
103 | if(volume > 30) | 124 | if(info.volume > 30) |
104 | lcd_icon(ICON_VOLUME_2, true); | 125 | lcd_icon(ICON_VOLUME_2, true); |
105 | else | 126 | else |
106 | lcd_icon(ICON_VOLUME_2, false); | 127 | lcd_icon(ICON_VOLUME_2, false); |
107 | if(volume > 50) | 128 | if(info.volume > 50) |
108 | lcd_icon(ICON_VOLUME_3, true); | 129 | lcd_icon(ICON_VOLUME_3, true); |
109 | else | 130 | else |
110 | lcd_icon(ICON_VOLUME_3, false); | 131 | lcd_icon(ICON_VOLUME_3, false); |
111 | if(volume > 70) | 132 | if(info.volume > 70) |
112 | lcd_icon(ICON_VOLUME_4, true); | 133 | lcd_icon(ICON_VOLUME_4, true); |
113 | else | 134 | else |
114 | lcd_icon(ICON_VOLUME_4, false); | 135 | lcd_icon(ICON_VOLUME_4, false); |
115 | if(volume > 90) | 136 | if(info.volume > 90) |
116 | lcd_icon(ICON_VOLUME_5, true); | 137 | lcd_icon(ICON_VOLUME_5, true); |
117 | else | 138 | else |
118 | lcd_icon(ICON_VOLUME_5, false); | 139 | lcd_icon(ICON_VOLUME_5, false); |
@@ -137,7 +158,7 @@ void status_draw(void) | |||
137 | default: | 158 | default: |
138 | break; | 159 | break; |
139 | } | 160 | } |
140 | if(charger_inserted()) | 161 | if(info.inserted) |
141 | { | 162 | { |
142 | global_settings.runtime = 0; | 163 | global_settings.runtime = 0; |
143 | if(TIME_AFTER(current_tick, switch_tick)) | 164 | if(TIME_AFTER(current_tick, switch_tick)) |
@@ -174,15 +195,15 @@ void status_draw(void) | |||
174 | } | 195 | } |
175 | } else { | 196 | } else { |
176 | lcd_icon(ICON_BATTERY, true); | 197 | lcd_icon(ICON_BATTERY, true); |
177 | if(battlevel > 25) | 198 | if(info.battlevel > 25) |
178 | lcd_icon(ICON_BATTERY_1, true); | 199 | lcd_icon(ICON_BATTERY_1, true); |
179 | else | 200 | else |
180 | lcd_icon(ICON_BATTERY_1, false); | 201 | lcd_icon(ICON_BATTERY_1, false); |
181 | if(battlevel > 50) | 202 | if(info.battlevel > 50) |
182 | lcd_icon(ICON_BATTERY_2, true); | 203 | lcd_icon(ICON_BATTERY_2, true); |
183 | else | 204 | else |
184 | lcd_icon(ICON_BATTERY_2, false); | 205 | lcd_icon(ICON_BATTERY_2, false); |
185 | if(battlevel > 75) | 206 | if(info.battlevel > 75) |
186 | lcd_icon(ICON_BATTERY_3, true); | 207 | lcd_icon(ICON_BATTERY_3, true); |
187 | else | 208 | else |
188 | lcd_icon(ICON_BATTERY_3, false); | 209 | lcd_icon(ICON_BATTERY_3, false); |
@@ -198,17 +219,31 @@ void status_draw(void) | |||
198 | 219 | ||
199 | #endif | 220 | #endif |
200 | #ifdef HAVE_LCD_BITMAP | 221 | #ifdef HAVE_LCD_BITMAP |
201 | if (global_settings.statusbar) { | 222 | |
202 | statusbar_wipe(); | 223 | tm = get_time(); |
224 | info.hour = tm->tm_hour; | ||
225 | info.minute = tm->tm_min; | ||
226 | info.shuffle = global_settings.playlist_shuffle; | ||
227 | info.keylock = keys_locked; | ||
228 | info.battery_safe = battery_level_safe(); | ||
229 | info.repeat = global_settings.repeat_mode; | ||
230 | |||
231 | if (force_redraw || | ||
232 | info.inserted || | ||
233 | !info.battery_safe || | ||
234 | memcmp(&info, &lastinfo, sizeof(struct status_info))) { | ||
235 | lcd_clearrect(0,0,LCD_WIDTH,8); | ||
236 | |||
203 | #ifdef HAVE_CHARGE_CTRL /* Recorder */ | 237 | #ifdef HAVE_CHARGE_CTRL /* Recorder */ |
204 | if(charger_inserted()) { | 238 | if(info.inserted) { |
205 | battery_state = true; | 239 | battery_state = true; |
206 | plug_state = true; | 240 | plug_state = true; |
207 | if (charge_state > 0) /* charge || top off || trickle */ | 241 | if (charge_state > 0) /* charge || top off || trickle */ |
208 | global_settings.runtime = 0; | 242 | global_settings.runtime = 0; |
209 | if (charge_state == 1) { /* animate battery if charging */ | 243 | if (charge_state == 1) { /* animate battery if charging */ |
210 | battlevel = battery_charge_step * 34; /* 34 for a better look */ | 244 | info.battlevel = battery_charge_step * 34; /* 34 for a better look */ |
211 | battlevel = battlevel > 100 ? 100 : battlevel; | 245 | if (info.battlevel > 100) |
246 | info.battlevel = 100; | ||
212 | if(TIME_AFTER(current_tick, switch_tick)) { | 247 | if(TIME_AFTER(current_tick, switch_tick)) { |
213 | battery_charge_step=(battery_charge_step+1)%4; | 248 | battery_charge_step=(battery_charge_step+1)%4; |
214 | switch_tick = current_tick + HZ; | 249 | switch_tick = current_tick + HZ; |
@@ -217,7 +252,7 @@ void status_draw(void) | |||
217 | } | 252 | } |
218 | else { | 253 | else { |
219 | plug_state=false; | 254 | plug_state=false; |
220 | if(battery_level_safe()) | 255 | if(!info.battery_safe) |
221 | battery_state = true; | 256 | battery_state = true; |
222 | else /* blink battery if level is low */ | 257 | else /* blink battery if level is low */ |
223 | if(TIME_AFTER(current_tick, switch_tick)) { | 258 | if(TIME_AFTER(current_tick, switch_tick)) { |
@@ -226,18 +261,17 @@ void status_draw(void) | |||
226 | } | 261 | } |
227 | } | 262 | } |
228 | 263 | ||
229 | if (battery_state) | 264 | statusbar_icon_battery(info.battlevel, plug_state); |
230 | statusbar_icon_battery(battlevel, plug_state); | ||
231 | #else | 265 | #else |
232 | #ifdef HAVE_FMADC /* FM */ | 266 | #ifdef HAVE_FMADC /* FM */ |
233 | statusbar_icon_battery(battlevel, charger_inserted()); | 267 | statusbar_icon_battery(info.battlevel, charger_inserted()); |
234 | #else /* Player */ | 268 | #else /* Player */ |
235 | statusbar_icon_battery(battlevel, false); | 269 | statusbar_icon_battery(info.battlevel, false); |
236 | #endif /* HAVE_FMADC */ | 270 | #endif /* HAVE_FMADC */ |
237 | #endif /* HAVE_CHARGE_CTRL */ | 271 | #endif /* HAVE_CHARGE_CTRL */ |
238 | statusbar_icon_volume(volume); | 272 | statusbar_icon_volume(info.volume); |
239 | statusbar_icon_play_state(current_mode + Icon_Play); | 273 | statusbar_icon_play_state(current_mode + Icon_Play); |
240 | switch (global_settings.repeat_mode) { | 274 | switch (info.repeat) { |
241 | case REPEAT_ONE: | 275 | case REPEAT_ONE: |
242 | statusbar_icon_play_mode(Icon_RepeatOne); | 276 | statusbar_icon_play_mode(Icon_RepeatOne); |
243 | break; | 277 | break; |
@@ -246,16 +280,17 @@ void status_draw(void) | |||
246 | statusbar_icon_play_mode(Icon_Repeat); | 280 | statusbar_icon_play_mode(Icon_Repeat); |
247 | break; | 281 | break; |
248 | } | 282 | } |
249 | if(global_settings.playlist_shuffle) | 283 | if(info.shuffle) |
250 | statusbar_icon_shuffle(); | 284 | statusbar_icon_shuffle(); |
251 | if (keys_locked) | 285 | if (info.keylock) |
252 | statusbar_icon_lock(); | 286 | statusbar_icon_lock(); |
253 | #ifdef HAVE_RTC | 287 | #ifdef HAVE_RTC |
254 | tm = get_time(); | 288 | statusbar_time(info.hour, info.minute); |
255 | statusbar_time(tm->tm_hour, tm->tm_min); | ||
256 | #endif | 289 | #endif |
257 | 290 | ||
258 | lcd_update_rect(0, 0, LCD_WIDTH, STATUSBAR_HEIGHT); | 291 | lcd_update_rect(0, 0, LCD_WIDTH, STATUSBAR_HEIGHT); |
259 | } | 292 | } |
293 | |||
294 | lastinfo = info; | ||
260 | #endif | 295 | #endif |
261 | } | 296 | } |