summaryrefslogtreecommitdiffstats
path: root/apps/status.c
blob: 0270d75a13fab43cd5a27b2102c300774ae8de64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/***************************************************************************
 *             __________               __   ___.
 *   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.
 *
 ****************************************************************************/
#include "lcd.h"
#include "debug.h"
#include "kernel.h"
#include "power.h"
#include "thread.h"
#include "settings.h"
#include "status.h"
#include "mpeg.h"
#include "wps.h"
#ifdef HAVE_RTC
#include "rtc.h"
#endif
#ifdef HAVE_LCD_BITMAP
#include "icons.h"
#endif
#include "powermgmt.h"

static enum playmode current_mode = STATUS_STOP;

long switch_tick;
int  battery_charge_step = 0;
#ifdef HAVE_LCD_BITMAP
bool plug_state;
bool battery_state;
#endif

void status_init(void)
{
    status_set_playmode(STATUS_STOP);
}

void status_set_playmode(enum playmode mode)
{
    current_mode = mode;
    status_draw();
}

void status_draw(void)
{
    int battlevel = battery_level();
    int volume = mpeg_val2phys(SOUND_VOLUME, global_settings.volume);
#if defined(HAVE_LCD_BITMAP) && defined(HAVE_RTC)
    int hour, minute;
#endif

    if ( !global_settings.statusbar )
        return;

#if defined(HAVE_LCD_CHARCELLS)
    lcd_icon(ICON_VOLUME, true);
    if(volume > 10)
        lcd_icon(ICON_VOLUME_1, true);
    else
        lcd_icon(ICON_VOLUME_1, false);
    if(volume > 30)
        lcd_icon(ICON_VOLUME_2, true);
    else
        lcd_icon(ICON_VOLUME_2, false);
    if(volume > 50)
        lcd_icon(ICON_VOLUME_3, true);
    else
        lcd_icon(ICON_VOLUME_3, false);
    if(volume > 70)
        lcd_icon(ICON_VOLUME_4, true);
    else
        lcd_icon(ICON_VOLUME_4, false);
    if(volume > 90)
        lcd_icon(ICON_VOLUME_5, true);
    else
        lcd_icon(ICON_VOLUME_5, false);

    switch(current_mode)
    {
        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;

        default:
            break;
    }
    if(charger_inserted())
    {
        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;
            }
           switch_tick = current_tick + (HZ/2);
       }
    } else {
        lcd_icon(ICON_BATTERY, true);
        if(battlevel > 25)
            lcd_icon(ICON_BATTERY_1, true);
        else
            lcd_icon(ICON_BATTERY_1, false);
        if(battlevel > 50)
            lcd_icon(ICON_BATTERY_2, true);
        else
            lcd_icon(ICON_BATTERY_2, false);
        if(battlevel > 75)
            lcd_icon(ICON_BATTERY_3, true);
        else
            lcd_icon(ICON_BATTERY_3, false);
    }

    lcd_icon(ICON_REPEAT, global_settings.repeat_mode != REPEAT_OFF);
    lcd_icon(ICON_1, global_settings.repeat_mode == REPEAT_ONE);
    
#endif
#ifdef HAVE_LCD_BITMAP
    if (global_settings.statusbar) {
        statusbar_wipe();
#ifdef HAVE_CHARGE_CTRL
        if(charger_inserted()) {
            battery_state = true;
            plug_state = true;
            if(charger_enabled) { /* animate battery if charging */
                battlevel = battery_charge_step * 34; /* 34 for a better look */
                battlevel = battlevel > 100 ? 100 : battlevel;
                if(TIME_AFTER(current_tick, switch_tick)) {
                    battery_charge_step=(battery_charge_step+1)%4;
                    switch_tick = current_tick + HZ;
                }
            }
        }
        else {
            plug_state=false;
            if(battery_level_safe())
                battery_state = true;
            else /* blink battery if level is low */
                if(TIME_AFTER(current_tick, switch_tick)) {
                    switch_tick = current_tick+HZ;
                    battery_state =! battery_state;
                }
        }
                
        if (battery_state)
            statusbar_icon_battery(battlevel, plug_state);
#else
        statusbar_icon_battery(battlevel, false);
#endif
        statusbar_icon_volume(volume);
        statusbar_icon_play_state(current_mode + Icon_Play);
        switch (global_settings.repeat_mode) {
            case REPEAT_ONE:
                statusbar_icon_play_mode(Icon_RepeatOne);
                break;

            case REPEAT_ALL:
                statusbar_icon_play_mode(Icon_Repeat);
                break;
        }
        if(global_settings.playlist_shuffle)
            statusbar_icon_shuffle();
        if (keys_locked)
            statusbar_icon_lock();
#ifdef HAVE_RTC
        hour = rtc_read(3);
        hour = ((hour & 0x30) >> 4) * 10 + (hour & 0x0f);
        minute = rtc_read(2);
        minute = ((minute & 0x70) >> 4) * 10 + (minute & 0x0f);
        statusbar_time(hour, minute);
#endif

        lcd_update_rect(0, 0, LCD_WIDTH, STATUSBAR_HEIGHT);
    }
#endif
}