voltage.c: Draw battery and state info only if they change. Draw voltage every frame.

Signed-off-by: Stefan `Sec` Zehl <sec@42.org>
This commit is contained in:
IKARUS 2012-02-02 17:03:40 +01:00 committed by Stefan `Sec` Zehl
parent 56519946c0
commit 60390f1f28
1 changed files with 73 additions and 61 deletions

View File

@ -12,84 +12,96 @@
/**************************************************************************/ /**************************************************************************/
// Improved version by Ikarus: // Improved version by Ikarus:
// Fixed 4.xxV --> 4.0xxV output problem // Added graphical battery.
// & added graphical battery.
// hLine and vLine code from Juna, nougad and fu86 // hLine and vLine code from Juna, nougad and fu86
// (camp 2011, CTHN Village) // (camp 2011, CTHN Village)
void hLine(int y, int x1, int x2, bool pixel); void hLine(int y, int x1, int x2, bool pixel);
void vLine(int x, int y1, int y2, bool pixel); void vLine(int x, int y1, int y2, bool pixel);
void drawCommonThings(int c);
void rectFill(int x, int y, int width, int heigth, bool pixel); void rectFill(int x, int y, int width, int heigth, bool pixel);
void ram(void) { void ram(void) {
int v,mv,c,c_old=0,mv_old=0; int v,mv,c;
char old_state=-1;
do{ do{
c = gpioGetValue(RB_PWR_CHRG); c = gpioGetValue(RB_PWR_CHRG);
mv = GetVoltage(); mv = GetVoltage();
// Need repaint?
if (c != c_old || mv != mv_old) {
c_old = c;
mv_old = mv;
lcdClear();
lcdPrintln("Battery status:");
v = mv/1000;
// Draw battery frame. // Print state and draw battery (only if state changed).
hLine(20, 14, 72, true); if(!c && old_state != 0){
hLine(40, 14, 72, true); drawCommonThings(c);
vLine(14, 20, 40, true); DoString(17, 29, "Charging");
vLine(72, 20, 25, true); old_state = 0;
vLine(72, 35, 40, true); }else if (c && mv<3550 && old_state != 1){
hLine(25, 72, 78, true); drawCommonThings(c);
hLine(35, 72, 78, true); lcdPrintln(" Charge NOW!");
vLine(78, 25, 35, true); old_state = 1;
}else if (c && mv<3650 && mv>=3550 && old_state != 2){
// Print and draw status. drawCommonThings(c);
if(!c){ lcdPrintln(" Charge soon");
lcdNl(); rectFill(16, 25, 12, 16, true);
DoString(17, 26, "Charging"); old_state = 2;
}else if (mv<3550){ }else if (c && mv<4000 && mv>=3650 && old_state != 3){
lcdPrintln(" Charge NOW!"); drawCommonThings(c);
}else if (mv<3650){ lcdPrintln(" OK");
lcdPrintln(" Charge soon"); rectFill(16, 25, 12, 16, true);
rectFill(16, 22, 12, 16, true); rectFill(30, 25, 12, 16, true);
}else if (mv<4000){ old_state = 3;
lcdPrintln(" OK"); }else if (c && mv<4120 && mv>=4000 && old_state != 4){
rectFill(16, 22, 12, 16, true); drawCommonThings(c);
rectFill(30, 22, 12, 16, true); lcdPrintln(" Good");
}else if (mv<4120){ rectFill(16, 25, 12, 16, true);
lcdPrintln(" Good"); rectFill(30, 25, 12, 16, true);
rectFill(16, 22, 12, 16, true); rectFill(44, 25, 12, 16, true);
rectFill(30, 22, 12, 16, true); old_state = 4;
rectFill(44, 22, 12, 16, true); }else if (c && mv>=4120 && old_state != 5){
}else{ drawCommonThings(c);
lcdPrintln(" Full"); lcdPrintln(" Full");
rectFill(16, 22, 12, 16, true); rectFill(16, 25, 12, 16, true);
rectFill(30, 22, 12, 16, true); rectFill(30, 25, 12, 16, true);
rectFill(44, 22, 12, 16, true); rectFill(44, 25, 12, 16, true);
rectFill(58, 22, 12, 16, true); rectFill(58, 25, 12, 16, true);
}; old_state = 5;
// Print voltage.
lcdNl();
lcdNl();
lcdNl();
lcdNl();
lcdPrint(" ");
lcdPrint(IntToStr(v,2,0));
lcdPrint(".");
lcdPrint(IntToStr(mv%1000, 3, F_ZEROS | F_LONG));
lcdPrintln("V");
// Print if not charging.
if(c){
lcdPrintln("(not charging)");
};
lcdRefresh();
} }
// Print voltage. (Every frame).
lcdSetCrsr(0, 50);
v = mv/1000;
lcdPrint(" ");
lcdPrint(IntToStr(v,2,0));
lcdPrint(".");
lcdPrint(IntToStr(mv%1000, 3, F_ZEROS | F_LONG));
lcdPrintln("V");
lcdSetCrsr(0, 0);
lcdRefresh();
} while ((getInputWaitTimeout(242))==BTN_NONE); } while ((getInputWaitTimeout(242))==BTN_NONE);
} }
void drawCommonThings(int c) {
lcdClear();
// Print header.
lcdPrintln("Battery status:");
// Draw battery frame.
hLine(23, 14, 72, true);
hLine(43, 14, 72, true);
vLine(14, 23, 43, true);
vLine(72, 23, 28, true);
vLine(72, 38, 43, true);
hLine(28, 72, 78, true);
hLine(38, 72, 78, true);
vLine(78, 28, 38, true);
// Print if not charging.
lcdSetCrsr(0, 60);
if(c){
lcdPrintln("(not charging)");
};
lcdSetCrsr(0, 10);
}
void hLine(int y, int x1, int x2, bool pixel) { void hLine(int y, int x1, int x2, bool pixel) {
for (int i=x1; i<=x2; ++i) { for (int i=x1; i<=x2; ++i) {
lcdSetPixel(i, y, pixel); lcdSetPixel(i, y, pixel);