Robert Hak | c92bead | 2002-04-23 08:50:38 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 1999 Robert Hak (rhak@ramapo.edu) |
| 11 | * |
| 12 | * Heavily modified for embedded use by Björn Stenberg (bjorn@haxx.se) |
| 13 | * |
| 14 | * All files in this archive are subject to the GNU General Public License. |
| 15 | * See the file COPYING in the source tree root for full license agreement. |
| 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | |
| 22 | #include "types.h" |
| 23 | #include "lcd.h" |
| 24 | #include "debug.h" |
Jörg Hohensohn | 593cc00 | 2004-09-28 22:13:26 +0000 | [diff] [blame] | 25 | #define CONFIG_KEYPAD RECORDER_PAD |
Robert Hak | c92bead | 2002-04-23 08:50:38 +0000 | [diff] [blame] | 26 | #include "button.h" |
| 27 | |
| 28 | #ifdef SIMULATOR |
| 29 | #include <stdio.h> |
| 30 | #include <unistd.h> |
| 31 | #endif |
| 32 | |
| 33 | /* I hacked this function to be placed inside because I figure we will need |
| 34 | something like it eventually. |
| 35 | |
| 36 | Args are fairly straight forward. |
| 37 | int xbase: location of "bottom" of battery on screen |
| 38 | int ybase: location of "left" edge of battery on screen |
| 39 | int len: how long is the battery to be (in pixels) |
| 40 | int wid: how tall is the battery to be (in pixels) |
| 41 | int percent: what percentage of the charge has been used |
| 42 | |
| 43 | Note: I am making use of the Logf() function until logging is |
| 44 | straightened out. |
| 45 | */ |
| 46 | |
| 47 | void draw_battery(int xbase, int ybase, int len, int wid, int percent) |
| 48 | { |
| 49 | float capacity = 0; |
| 50 | int bar_xoffset = 2; |
| 51 | int bar_yoffset = 2; |
| 52 | int bar_len = 0; |
| 53 | int bar_wid = wid - (bar_xoffset*2); |
| 54 | int i = 0; |
| 55 | |
| 56 | /* We only worry about length and width because if you place |
| 57 | the battery off the screen, its your own damn fault. We log |
| 58 | and then just draw an empty battery */ |
| 59 | if((percent > 100) || (percent < 0) || (len < 0) || (wid < 0)) { |
| 60 | /* debug("Error: Battery data invalid"); */ |
| 61 | percent = 0; |
| 62 | } |
| 63 | |
| 64 | /* top batt. edge */ |
Jens Arnold | 9349412 | 2005-06-25 00:28:09 +0000 | [diff] [blame] | 65 | lcd_hline(xbase, xbase+len-2, ybase); |
Robert Hak | c92bead | 2002-04-23 08:50:38 +0000 | [diff] [blame] | 66 | |
| 67 | /* bot batt. edge */ |
Jens Arnold | 9349412 | 2005-06-25 00:28:09 +0000 | [diff] [blame] | 68 | lcd_hine(xbase, xbase+len-2, ybase+wid); |
Robert Hak | c92bead | 2002-04-23 08:50:38 +0000 | [diff] [blame] | 69 | |
| 70 | /* left batt. edge */ |
Jens Arnold | 9349412 | 2005-06-25 00:28:09 +0000 | [diff] [blame] | 71 | lcd_vline(xbase, ybase, ybase+wid); |
Robert Hak | c92bead | 2002-04-23 08:50:38 +0000 | [diff] [blame] | 72 | |
| 73 | /* right batt. edge */ |
Jens Arnold | 9349412 | 2005-06-25 00:28:09 +0000 | [diff] [blame] | 74 | lcd_vline(xbase+len, ybase+1, ybase+wid-1); |
Robert Hak | c92bead | 2002-04-23 08:50:38 +0000 | [diff] [blame] | 75 | |
| 76 | /* 2 dots that account for the nub on the right side of the battery */ |
| 77 | lcd_drawpixel(xbase+len-1, ybase+1); |
| 78 | lcd_drawpixel(xbase+len-1, ybase+wid-1); |
| 79 | |
| 80 | if(percent > 0) { |
| 81 | /* % battery is full, 100% is length-bar_xoffset-1 pixels */ |
| 82 | capacity = ((float)percent / 100.0) * (len-(bar_xoffset*2)-1); |
| 83 | bar_len = capacity; |
| 84 | |
| 85 | for(i = 0; i < bar_wid+1; i++) { |
Jens Arnold | 9349412 | 2005-06-25 00:28:09 +0000 | [diff] [blame] | 86 | lcd_hline(xbase+bar_xoffset, |
| 87 | xbase+bar_xoffset+bar_len, ybase+bar_yoffset+i); |
Robert Hak | c92bead | 2002-04-23 08:50:38 +0000 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | lcd_update(); |
| 91 | } |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |