Really small performace improvement to voltage.c

Signed-off-by: Stefan `Sec` Zehl <sec@42.org>
This commit is contained in:
IKARUS 2012-01-31 19:42:10 +01:00 committed by Stefan `Sec` Zehl
parent 756b7385c1
commit 56519946c0
1 changed files with 61 additions and 58 deletions

View File

@ -23,65 +23,70 @@ void vLine(int x, int y1, int y2, bool pixel);
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; int v,mv,c,c_old=0,mv_old=0;
do{ do{
lcdClear();
lcdPrintln("Battery status:");
c = gpioGetValue(RB_PWR_CHRG); c = gpioGetValue(RB_PWR_CHRG);
mv = GetVoltage(); mv = GetVoltage();
v = mv/1000; // Need repaint?
if (c != c_old || mv != mv_old) {
// Draw battery frame. c_old = c;
hLine(20, 14, 72, true); mv_old = mv;
hLine(40, 14, 72, true); lcdClear();
vLine(14, 20, 40, true); lcdPrintln("Battery status:");
vLine(72, 20, 25, true); v = mv/1000;
vLine(72, 35, 40, true);
hLine(25, 72, 78, true); // Draw battery frame.
hLine(35, 72, 78, true); hLine(20, 14, 72, true);
vLine(78, 25, 35, true); hLine(40, 14, 72, true);
vLine(14, 20, 40, true);
// Print and draw status. vLine(72, 20, 25, true);
if(!c){ vLine(72, 35, 40, true);
lcdNl(); hLine(25, 72, 78, true);
DoString(17, 26, "Charging"); hLine(35, 72, 78, true);
}else if (mv<3550){ vLine(78, 25, 35, true);
lcdPrintln(" Charge NOW!");
}else if (mv<3650){ // Print and draw status.
lcdPrintln(" Charge soon"); if(!c){
rectFill(16, 22, 12, 16, true); lcdNl();
}else if (mv<4000){ DoString(17, 26, "Charging");
lcdPrintln(" OK"); }else if (mv<3550){
rectFill(16, 22, 12, 16, true); lcdPrintln(" Charge NOW!");
rectFill(30, 22, 12, 16, true); }else if (mv<3650){
}else if (mv<4120){ lcdPrintln(" Charge soon");
lcdPrintln(" Good"); rectFill(16, 22, 12, 16, true);
rectFill(16, 22, 12, 16, true); }else if (mv<4000){
rectFill(30, 22, 12, 16, true); lcdPrintln(" OK");
rectFill(44, 22, 12, 16, true); rectFill(16, 22, 12, 16, true);
}else{ rectFill(30, 22, 12, 16, true);
lcdPrintln(" Full"); }else if (mv<4120){
rectFill(16, 22, 12, 16, true); lcdPrintln(" Good");
rectFill(30, 22, 12, 16, true); rectFill(16, 22, 12, 16, true);
rectFill(44, 22, 12, 16, true); rectFill(30, 22, 12, 16, true);
rectFill(58, 22, 12, 16, true); rectFill(44, 22, 12, 16, true);
}; }else{
lcdPrintln(" Full");
rectFill(16, 22, 12, 16, true);
rectFill(30, 22, 12, 16, true);
rectFill(44, 22, 12, 16, true);
rectFill(58, 22, 12, 16, true);
};
// Print voltage. // Print voltage.
lcdNl(); lcdNl();
lcdNl(); lcdNl();
lcdNl(); lcdNl();
lcdNl(); lcdNl();
lcdPrint(" "); lcdPrint(" ");
lcdPrint(IntToStr(v,2,0)); lcdPrint(IntToStr(v,2,0));
lcdPrint("."); lcdPrint(".");
lcdPrint(IntToStr(mv%1000, 3, F_ZEROS | F_LONG)); lcdPrint(IntToStr(mv%1000, 3, F_ZEROS | F_LONG));
lcdPrintln("V"); lcdPrintln("V");
// Print if not charging. // Print if not charging.
if(c){ if(c){
lcdPrintln("(not charging)"); lcdPrintln("(not charging)");
}; };
lcdRefresh(); lcdRefresh();
}
} while ((getInputWaitTimeout(242))==BTN_NONE); } while ((getInputWaitTimeout(242))==BTN_NONE);
} }
@ -99,8 +104,6 @@ void vLine(int x, int y1, int y2, bool pixel) {
void rectFill(int x, int y, int width, int heigth, bool pixel) { void rectFill(int x, int y, int width, int heigth, bool pixel) {
for (int i=y; i<=y+heigth; ++i) { for (int i=y; i<=y+heigth; ++i) {
for (int j=x; j<=x+width; ++j) { hLine(i, x, x+width, pixel);
lcdSetPixel(j, i, pixel);
}
} }
} }