2011-08-08 22:11:16 +00:00
|
|
|
#include <sysinit.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "basic/basic.h"
|
|
|
|
#include "basic/config.h"
|
|
|
|
|
|
|
|
#include "lcd/render.h"
|
|
|
|
#include "lcd/print.h"
|
|
|
|
|
|
|
|
#include "usetable.h"
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2012-01-29 18:57:40 +00:00
|
|
|
// Improved version by Ikarus:
|
|
|
|
// Fixed 4.xxV --> 4.0xxV output problem
|
|
|
|
// & added graphical battery.
|
|
|
|
|
|
|
|
// hLine and vLine code from Juna, nougad and fu86
|
|
|
|
// (camp 2011, CTHN Village)
|
|
|
|
void hLine(int y, int x1, int x2, bool pixel);
|
|
|
|
void vLine(int x, int y1, int y2, bool pixel);
|
|
|
|
|
|
|
|
void rectFill(int x, int y, int width, int heigth, bool pixel);
|
|
|
|
|
2011-08-08 22:11:16 +00:00
|
|
|
void ram(void) {
|
2011-08-21 23:40:25 +00:00
|
|
|
int v,mv,c;
|
2011-08-08 22:11:16 +00:00
|
|
|
do{
|
|
|
|
lcdClear();
|
|
|
|
lcdPrintln("Battery status:");
|
2012-01-29 18:57:40 +00:00
|
|
|
c = gpioGetValue(RB_PWR_CHRG);
|
|
|
|
mv = GetVoltage();
|
|
|
|
v = mv/1000;
|
|
|
|
|
|
|
|
// Draw battery frame.
|
|
|
|
hLine(20, 14, 72, true);
|
|
|
|
hLine(40, 14, 72, true);
|
|
|
|
vLine(14, 20, 40, true);
|
|
|
|
vLine(72, 20, 25, true);
|
|
|
|
vLine(72, 35, 40, true);
|
|
|
|
hLine(25, 72, 78, true);
|
|
|
|
hLine(35, 72, 78, true);
|
|
|
|
vLine(78, 25, 35, true);
|
|
|
|
|
|
|
|
// Print and draw status.
|
2011-08-21 23:40:25 +00:00
|
|
|
if(!c){
|
2012-01-29 18:57:40 +00:00
|
|
|
lcdNl();
|
|
|
|
DoString(17, 26, "Charging");
|
2011-08-21 23:40:25 +00:00
|
|
|
}else if (mv<3550){
|
2011-08-08 22:11:16 +00:00
|
|
|
lcdPrintln(" Charge NOW!");
|
|
|
|
}else if (mv<3650){
|
|
|
|
lcdPrintln(" Charge soon");
|
2012-01-29 18:57:40 +00:00
|
|
|
rectFill(16, 22, 12, 16, true);
|
2011-08-08 22:11:16 +00:00
|
|
|
}else if (mv<4000){
|
|
|
|
lcdPrintln(" OK");
|
2012-01-29 18:57:40 +00:00
|
|
|
rectFill(16, 22, 12, 16, true);
|
|
|
|
rectFill(30, 22, 12, 16, true);
|
|
|
|
}else if (mv<4120){
|
2011-08-08 22:11:16 +00:00
|
|
|
lcdPrintln(" Good");
|
2012-01-29 18:57:40 +00:00
|
|
|
rectFill(16, 22, 12, 16, true);
|
|
|
|
rectFill(30, 22, 12, 16, true);
|
|
|
|
rectFill(44, 22, 12, 16, true);
|
2011-08-08 22:11:16 +00:00
|
|
|
}else{
|
|
|
|
lcdPrintln(" Full");
|
2012-01-29 18:57:40 +00:00
|
|
|
rectFill(16, 22, 12, 16, true);
|
|
|
|
rectFill(30, 22, 12, 16, true);
|
|
|
|
rectFill(44, 22, 12, 16, true);
|
|
|
|
rectFill(58, 22, 12, 16, true);
|
2011-08-08 22:11:16 +00:00
|
|
|
};
|
|
|
|
|
2012-01-29 18:57:40 +00:00
|
|
|
// Print voltage.
|
|
|
|
lcdNl();
|
|
|
|
lcdNl();
|
|
|
|
lcdNl();
|
2011-08-08 22:11:16 +00:00
|
|
|
lcdNl();
|
2012-01-29 18:57:40 +00:00
|
|
|
lcdPrint(" ");
|
2011-08-08 22:11:16 +00:00
|
|
|
lcdPrint(IntToStr(v,2,0));
|
|
|
|
lcdPrint(".");
|
2012-01-29 18:57:40 +00:00
|
|
|
lcdPrint(IntToStr(mv%1000, 3, F_ZEROS | F_LONG));
|
2011-08-08 22:11:16 +00:00
|
|
|
lcdPrintln("V");
|
2012-01-29 18:57:40 +00:00
|
|
|
// Print if not charging.
|
2011-08-21 23:40:25 +00:00
|
|
|
if(c){
|
2011-08-08 22:11:16 +00:00
|
|
|
lcdPrintln("(not charging)");
|
|
|
|
};
|
|
|
|
lcdRefresh();
|
|
|
|
} while ((getInputWaitTimeout(242))==BTN_NONE);
|
|
|
|
}
|
2012-01-29 18:57:40 +00:00
|
|
|
|
|
|
|
void hLine(int y, int x1, int x2, bool pixel) {
|
|
|
|
for (int i=x1; i<=x2; ++i) {
|
|
|
|
lcdSetPixel(i, y, pixel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void vLine(int x, int y1, int y2, bool pixel) {
|
|
|
|
for (int i=y1; i<=y2; ++i) {
|
|
|
|
lcdSetPixel(x, i, pixel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void rectFill(int x, int y, int width, int heigth, bool pixel) {
|
|
|
|
for (int i=y; i<=y+heigth; ++i) {
|
|
|
|
for (int j=x; j<=x+width; ++j) {
|
|
|
|
lcdSetPixel(j, i, pixel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|