summaryrefslogtreecommitdiffstats
path: root/data.cpp
diff options
context:
space:
mode:
authorDees_Troy <dees_troy@teamw.in>2012-09-14 19:33:53 +0200
committerDees_Troy <dees_troy@teamw.in>2012-09-14 19:36:32 +0200
commit38bd760b589d405db9a2e6bf304f07d1b0bae342 (patch)
tree8f7dd4ccdcf52ea8b85007bdbeb7d682c1119815 /data.cpp
parentMake text appear in GUI console, Zip install works. (diff)
downloadandroid_bootable_recovery-38bd760b589d405db9a2e6bf304f07d1b0bae342.tar
android_bootable_recovery-38bd760b589d405db9a2e6bf304f07d1b0bae342.tar.gz
android_bootable_recovery-38bd760b589d405db9a2e6bf304f07d1b0bae342.tar.bz2
android_bootable_recovery-38bd760b589d405db9a2e6bf304f07d1b0bae342.tar.lz
android_bootable_recovery-38bd760b589d405db9a2e6bf304f07d1b0bae342.tar.xz
android_bootable_recovery-38bd760b589d405db9a2e6bf304f07d1b0bae342.tar.zst
android_bootable_recovery-38bd760b589d405db9a2e6bf304f07d1b0bae342.zip
Diffstat (limited to '')
-rw-r--r--data.cpp32
1 files changed, 29 insertions, 3 deletions
diff --git a/data.cpp b/data.cpp
index 8b717f517..896bb1bc6 100644
--- a/data.cpp
+++ b/data.cpp
@@ -50,8 +50,6 @@ extern "C"
void gui_notifyVarChange(const char *name, const char* value);
- int get_battery_level(void);
-
int __system(const char *command);
}
@@ -761,8 +759,36 @@ int DataManager::GetMagicValue(const string varName, string& value)
if (varName == "tw_battery")
{
char tmp[16];
+ static char charging = ' ';
+ static int lastVal = -1;
+ static time_t nextSecCheck = 0;
+
+ struct timeval curTime;
+ gettimeofday(&curTime, NULL);
+ if (curTime.tv_sec > nextSecCheck)
+ {
+ char cap_s[4];
+ FILE * cap = fopen("/sys/class/power_supply/battery/capacity","rt");
+ if (cap){
+ fgets(cap_s, 4, cap);
+ fclose(cap);
+ lastVal = atoi(cap_s);
+ if (lastVal > 100) lastVal = 101;
+ if (lastVal < 0) lastVal = 0;
+ }
+ cap = fopen("/sys/class/power_supply/battery/status","rt");
+ if (cap) {
+ fgets(cap_s, 2, cap);
+ fclose(cap);
+ if (cap_s[0] == 'C')
+ charging = '+';
+ else
+ charging = ' ';
+ }
+ nextSecCheck = curTime.tv_sec + 60;
+ }
- sprintf(tmp, "%i%%", get_battery_level());
+ sprintf(tmp, "%i%%%c", lastVal, charging);
value = tmp;
return 0;
}