Really small performace improvement to voltage.c
Signed-off-by: Stefan `Sec` Zehl <sec@42.org>
This commit is contained in:
parent
756b7385c1
commit
56519946c0
|
@ -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 ram(void) {
|
||||
int v,mv,c;
|
||||
int v,mv,c,c_old=0,mv_old=0;
|
||||
do{
|
||||
lcdClear();
|
||||
lcdPrintln("Battery status:");
|
||||
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.
|
||||
if(!c){
|
||||
lcdNl();
|
||||
DoString(17, 26, "Charging");
|
||||
}else if (mv<3550){
|
||||
lcdPrintln(" Charge NOW!");
|
||||
}else if (mv<3650){
|
||||
lcdPrintln(" Charge soon");
|
||||
rectFill(16, 22, 12, 16, true);
|
||||
}else if (mv<4000){
|
||||
lcdPrintln(" OK");
|
||||
rectFill(16, 22, 12, 16, true);
|
||||
rectFill(30, 22, 12, 16, true);
|
||||
}else if (mv<4120){
|
||||
lcdPrintln(" Good");
|
||||
rectFill(16, 22, 12, 16, true);
|
||||
rectFill(30, 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);
|
||||
};
|
||||
// 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.
|
||||
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.
|
||||
if(!c){
|
||||
lcdNl();
|
||||
DoString(17, 26, "Charging");
|
||||
}else if (mv<3550){
|
||||
lcdPrintln(" Charge NOW!");
|
||||
}else if (mv<3650){
|
||||
lcdPrintln(" Charge soon");
|
||||
rectFill(16, 22, 12, 16, true);
|
||||
}else if (mv<4000){
|
||||
lcdPrintln(" OK");
|
||||
rectFill(16, 22, 12, 16, true);
|
||||
rectFill(30, 22, 12, 16, true);
|
||||
}else if (mv<4120){
|
||||
lcdPrintln(" Good");
|
||||
rectFill(16, 22, 12, 16, true);
|
||||
rectFill(30, 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.
|
||||
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.
|
||||
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();
|
||||
}
|
||||
} 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) {
|
||||
for (int i=y; i<=y+heigth; ++i) {
|
||||
for (int j=x; j<=x+width; ++j) {
|
||||
lcdSetPixel(j, i, pixel);
|
||||
}
|
||||
hLine(i, x, x+width, pixel);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue