summaryrefslogtreecommitdiffstats
path: root/uisimulator/battery.c
blob: d8580b42d10031f98e26c229f1e7edd41187fc3c (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
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 1999 Robert Hak (rhak@ramapo.edu)
 *
 * Heavily modified for embedded use by Björn Stenberg (bjorn@haxx.se)
 *
 * 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 "types.h"
#include "lcd.h"
#include "debug.h"
#define CONFIG_KEYPAD RECORDER_PAD
#include "button.h"

#ifdef SIMULATOR
#include <stdio.h>
#include <unistd.h>
#endif

/* I hacked this function to be placed inside because I figure we will need
   something like it eventually.

   Args are fairly straight forward. 
   int xbase: location of "bottom" of battery on screen 
   int ybase: location of "left" edge of battery on screen 
   int len: how long is the battery to be (in pixels) 
   int wid: how tall is the battery to be (in pixels) 
   int percent: what percentage of the charge has been used 

   Note: I am making use of the Logf() function until logging is 
         straightened out. 
*/ 

void draw_battery(int xbase, int ybase, int len, int wid, int percent) 
{ 
    float capacity = 0; 
    int bar_xoffset = 2; 
    int bar_yoffset = 2; 
    int bar_len = 0; 
    int bar_wid = wid - (bar_xoffset*2); 
    int i = 0; 

    /* We only worry about length and width because if you place 
       the battery off the screen, its your own damn fault. We log 
       and then just draw an empty battery */ 
    if((percent > 100) || (percent < 0) || (len < 0) || (wid < 0)) { 
/*       debug("Error: Battery data invalid");  */
        percent = 0; 
    }

    /* top batt. edge */ 
    lcd_drawline(xbase, ybase, xbase+len-2, ybase); 

    /* bot batt. edge */ 
    lcd_drawline(xbase, ybase+wid, 
                 xbase+len-2, ybase+wid); 

    /* left batt. edge */ 
    lcd_drawline(xbase, ybase, xbase, ybase+wid); 

    /* right batt. edge */ 
    lcd_drawline(xbase+len, ybase+1, 
                 xbase+len, ybase+wid-1); 

    /* 2 dots that account for the nub on the right side of the battery */ 
    lcd_drawpixel(xbase+len-1, ybase+1); 
    lcd_drawpixel(xbase+len-1, ybase+wid-1); 

    if(percent > 0) { 
        /* % battery is full, 100% is length-bar_xoffset-1 pixels */ 
        capacity = ((float)percent / 100.0) * (len-(bar_xoffset*2)-1); 
        bar_len = capacity; 

        for(i = 0; i < bar_wid+1; i++) { 
            lcd_drawline(xbase+bar_xoffset, ybase+bar_yoffset+i, 
                         xbase+bar_xoffset+bar_len, ybase+bar_yoffset+i); 
        } 
    } 
	lcd_update();
}