summaryrefslogtreecommitdiffstats
path: root/uisimulator/battery.c
diff options
context:
space:
mode:
authorRobert Hak <adiamas@rockbox.org>2002-04-23 08:50:38 +0000
committerRobert Hak <adiamas@rockbox.org>2002-04-23 08:50:38 +0000
commitc92bead2cfefaff61008f358ab223cf7b77bdc29 (patch)
tree2c77af0a207a66051c7003dd40a351a049b7e21d /uisimulator/battery.c
parent6755f82a7002b98fc522dab216ab32bb62c289c2 (diff)
downloadrockbox-c92bead2cfefaff61008f358ab223cf7b77bdc29.tar.gz
rockbox-c92bead2cfefaff61008f358ab223cf7b77bdc29.tar.bz2
rockbox-c92bead2cfefaff61008f358ab223cf7b77bdc29.zip
a simple battery function to display a battery of passed width, length,
and location on the player. As similar to the player display as I could get. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@186 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator/battery.c')
-rw-r--r--uisimulator/battery.c102
1 files changed, 102 insertions, 0 deletions
diff --git a/uisimulator/battery.c b/uisimulator/battery.c
new file mode 100644
index 0000000000..1af8e71787
--- /dev/null
+++ b/uisimulator/battery.c
@@ -0,0 +1,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 HAVE_RECORDER_KEYPAD
+#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();
+}
+
+
+
+
+
+
+
+
+