1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-12-28 17:21:44 +02:00

Check if USB cable is plugged before returning the battery level.

This commit is contained in:
Paul Cercueil 2012-06-24 22:41:16 +02:00
parent 64db1d7912
commit 7484ad2ef0

View File

@ -1461,21 +1461,25 @@ typedef struct {
} MMSP2ADC;
unsigned short GMenu2X::getBatteryLevel() {
if (!batteryHandle) return 0;
int battval = 0;
fscanf(batteryHandle, "%d", &battval);
rewind(batteryHandle);
if (battval>90) return 5;
if (battval>70) return 4;
if (battval>50) return 3;
if (battval>30) return 2;
if (battval>10) return 1;
if (usbHandle) {
int usbval = 0;
fscanf(usbHandle, "%d", &usbval);
rewind(usbHandle);
if (usbval == 1)
return 6;
}
if (!usbHandle) return 0;
int usbval = 0;
fscanf(usbHandle, "%d", &usbval);
rewind(usbHandle);
if (usbval==1) return 6;
if (batteryHandle) {
int battval = 0;
fscanf(batteryHandle, "%d", &battval);
rewind(batteryHandle);
if (battval>90) return 5;
if (battval>70) return 4;
if (battval>50) return 3;
if (battval>30) return 2;
if (battval>10) return 1;
}
return 0;
}