Merge pull request #7 from blind/double-save

Avoid converting value to a double
This commit is contained in:
John Stäck 2019-06-08 10:11:24 +02:00 committed by GitHub
commit 91aecdb82d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -487,18 +487,18 @@ void drawMenuScreen(){
//Construct the title including voltage reading.
//Involves intricate splicing of the title string with battery voltage
char menuTitle[] = "MENU XXX Y.Y "; //Allocate string buffer of appropriate size with some placeholders
char menuTitle[] = "MENU XXX Y.YV"; //Allocate string buffer of appropriate size with some placeholders
char* splice1 = menuTitle + 13;
char* splice2 = menuTitle + 17;
int vMeterReading = analogRead(vMeterPin);
memcpy(splice1, (vMeterReading > 3000) ? "USB" : "BAT", 3);
if (vMeterReading < 2294) {
memcpy(splice2, "LOW ", 3);
memcpy(splice2, "LOW ", 4);
} else {
double voltage = map(vMeterReading,0,3030,0,50)*0.1;
dtostrf(voltage, 3, 1, splice2);
splice2[3]='V'; //Put the V at the end (last char of buffer before \0)
int voltage = map(vMeterReading,0,3030,0,50);
splice2[0] = (voltage/10)+'0';
splice2[2] = (voltage%10)+'0';
}
drawMenu(menuTitle, mainMenuCursor, 6,