Plugin/file type association system. Patch #879411 by Henrik Backe
[kugel-rb.git] / apps / status.c
blob5ff7a92e75b0a2c93db462cb00bd84eaaa46cda3
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include "string.h"
20 #include "lcd.h"
21 #include "debug.h"
22 #include "kernel.h"
23 #include "power.h"
24 #include "thread.h"
25 #include "settings.h"
26 #include "status.h"
27 #include "mp3_playback.h"
28 #include "wps.h"
29 #ifdef HAVE_RTC
30 #include "timefuncs.h"
31 #endif
32 #ifdef HAVE_LCD_BITMAP
33 #include "icons.h"
34 #include "font.h"
35 #endif
36 #include "powermgmt.h"
38 static enum playmode current_mode = STATUS_STOP;
40 static long switch_tick;
41 static int battery_charge_step = 0;
42 static bool plug_state;
43 static bool battery_state = true;
45 struct status_info {
46 int battlevel;
47 int volume;
48 int hour;
49 int minute;
50 int playmode;
51 int repeat;
52 bool inserted;
53 bool shuffle;
54 bool keylock;
55 bool battery_safe;
58 void status_init(void)
60 status_set_playmode(STATUS_STOP);
63 void status_set_playmode(enum playmode mode)
65 current_mode = mode;
66 status_draw(false);
69 #if defined(HAVE_LCD_CHARCELLS)
70 static bool record = false;
71 static bool audio = false;
72 static bool param = false;
73 static bool usb = false;
75 void status_set_record(bool b)
77 record = b;
80 void status_set_audio(bool b)
82 audio = b;
85 void status_set_param(bool b)
87 param = b;
90 void status_set_usb(bool b)
92 usb = b;
95 #endif /* HAVE_LCD_CHARCELLS */
97 void status_draw(bool force_redraw)
99 struct status_info info;
101 #ifdef HAVE_LCD_BITMAP
102 static struct status_info lastinfo;
103 struct tm* tm;
105 if ( !global_settings.statusbar )
106 return;
107 #else
108 (void)force_redraw; /* players always "redraw" */
109 #endif
111 info.volume = mpeg_val2phys(SOUND_VOLUME, global_settings.volume);
112 info.inserted = charger_inserted();
113 info.battlevel = battery_level();
114 info.battery_safe = battery_level_safe();
116 #ifdef HAVE_LCD_BITMAP
117 tm = get_time();
118 info.hour = tm->tm_hour;
119 info.minute = tm->tm_min;
120 info.shuffle = global_settings.playlist_shuffle;
121 info.keylock = keys_locked;
122 info.repeat = global_settings.repeat_mode;
123 info.playmode = current_mode;
125 /* only redraw if forced to, or info has changed */
126 if (force_redraw ||
127 info.inserted ||
128 !info.battery_safe ||
129 memcmp(&info, &lastinfo, sizeof(struct status_info)))
131 lcd_clearrect(0,0,LCD_WIDTH,8);
132 #else
133 /* players always "redraw" */
135 #endif
137 if (info.inserted) {
138 battery_state = true;
139 plug_state = true;
140 #if defined(HAVE_CHARGE_CTRL) || defined(HAVE_LIION)
141 /* zero battery run time if charging */
142 if (charge_state > 0) {
143 global_settings.runtime = 0;
144 lasttime = current_tick;
147 /* animate battery if charging */
148 if ((charge_state == 1) ||
149 (charge_state == 2)) {
150 #else
151 global_settings.runtime = 0;
152 lasttime = current_tick;
154 #endif
155 /* animate in three steps (34% per step for a better look) */
156 info.battlevel = battery_charge_step * 34;
157 if (info.battlevel > 100)
158 info.battlevel = 100;
159 if(TIME_AFTER(current_tick, switch_tick)) {
160 battery_charge_step=(battery_charge_step+1)%4;
161 switch_tick = current_tick + HZ;
165 else {
166 plug_state=false;
167 if (info.battery_safe)
168 battery_state = true;
169 else {
170 /* blink battery if level is low */
171 if(TIME_AFTER(current_tick, switch_tick) &&
172 (info.battlevel > -1)) {
173 switch_tick = current_tick+HZ;
174 battery_state =! battery_state;
179 #ifdef HAVE_LCD_BITMAP
180 if (battery_state)
181 statusbar_icon_battery(info.battlevel, plug_state);
183 statusbar_icon_volume(info.volume);
184 statusbar_icon_play_state(current_mode + Icon_Play);
185 switch (info.repeat) {
186 case REPEAT_ONE:
187 statusbar_icon_play_mode(Icon_RepeatOne);
188 break;
190 case REPEAT_ALL:
191 statusbar_icon_play_mode(Icon_Repeat);
192 break;
194 if (info.shuffle)
195 statusbar_icon_shuffle();
196 if (info.keylock)
197 statusbar_icon_lock();
198 #ifdef HAVE_RTC
199 statusbar_time(info.hour, info.minute);
200 #endif
201 lcd_update_rect(0, 0, LCD_WIDTH, STATUSBAR_HEIGHT);
202 lastinfo = info;
203 #endif
207 #if defined(HAVE_LCD_CHARCELLS)
208 if (info.battlevel > -1)
209 lcd_icon(ICON_BATTERY, battery_state);
210 lcd_icon(ICON_BATTERY_1, info.battlevel > 25);
211 lcd_icon(ICON_BATTERY_2, info.battlevel > 50);
212 lcd_icon(ICON_BATTERY_3, info.battlevel > 75);
214 lcd_icon(ICON_VOLUME, true);
215 lcd_icon(ICON_VOLUME_1, info.volume > 10);
216 lcd_icon(ICON_VOLUME_2, info.volume > 30);
217 lcd_icon(ICON_VOLUME_3, info.volume > 50);
218 lcd_icon(ICON_VOLUME_4, info.volume > 70);
219 lcd_icon(ICON_VOLUME_5, info.volume > 90);
221 lcd_icon(ICON_PLAY, current_mode == STATUS_PLAY);
222 lcd_icon(ICON_PAUSE, current_mode == STATUS_PAUSE);
224 lcd_icon(ICON_REPEAT, global_settings.repeat_mode != REPEAT_OFF);
225 lcd_icon(ICON_1, global_settings.repeat_mode == REPEAT_ONE);
227 lcd_icon(ICON_RECORD, record);
228 lcd_icon(ICON_AUDIO, audio);
229 lcd_icon(ICON_PARAM, param);
230 lcd_icon(ICON_USB, usb);
231 #endif
235 #ifdef HAVE_LCD_BITMAP
236 static void draw_buttonbar_btn(int num, char* caption)
238 int xpos, ypos, button_width, text_width;
239 int fw, fh;
241 lcd_setfont(FONT_SYSFIXED);
242 lcd_getstringsize("M", &fw, &fh);
244 button_width = LCD_WIDTH/3;
245 xpos = num * button_width;
246 ypos = LCD_HEIGHT - fh;
248 if(caption)
250 /* center the text */
251 text_width = fw * strlen(caption);
252 lcd_putsxy(xpos + (button_width - text_width)/2, ypos, caption);
255 lcd_invertrect(xpos, ypos, button_width - 1, fh);
258 static char stored_caption1[8];
259 static char stored_caption2[8];
260 static char stored_caption3[8];
262 void buttonbar_set(char* caption1, char *caption2, char *caption3)
264 buttonbar_unset();
265 if(caption1)
267 strncpy(stored_caption1, caption1, 7);
268 stored_caption1[7] = 0;
270 if(caption2)
272 strncpy(stored_caption2, caption2, 7);
273 stored_caption2[7] = 0;
275 if(caption3)
277 strncpy(stored_caption3, caption3, 7);
278 stored_caption3[7] = 0;
282 void buttonbar_unset(void)
284 stored_caption1[0] = 0;
285 stored_caption2[0] = 0;
286 stored_caption3[0] = 0;
289 void buttonbar_draw(void)
291 lcd_clearrect(0, LCD_HEIGHT-8, LCD_WIDTH, 8);
292 draw_buttonbar_btn(0, stored_caption1);
293 draw_buttonbar_btn(1, stored_caption2);
294 draw_buttonbar_btn(2, stored_caption3);
297 bool buttonbar_isset(void)
299 /* If all buttons are unset, the button bar is considered disabled */
300 return (global_settings.buttonbar &&
301 ((stored_caption1[0] != 0) ||
302 (stored_caption2[0] != 0) ||
303 (stored_caption3[0] != 0)));
306 #endif