battery: Add divider for voltage_now
[sysstatus.git] / src / status / battery.c
index 65fdd1bc93bb9eb53a16bfc972a3945ed2ea0a26..79d65da49e13cbd631c24679b1876d502e450068 100644 (file)
@@ -25,7 +25,8 @@ void status_battery(GlobalData *g, char *batname)
   int chargeNow = 0;
   int chargeFull = -1;
   int chargePercent = -1;
-  int battW = 1;
+  int currentNow = 1;
+  int voltageNow = 0;
   float battTime = -1;
 
 
@@ -52,22 +53,28 @@ void status_battery(GlobalData *g, char *batname)
 
 
   /* Get info */
-  strcpy(&batpath[batpathlen], "/energy_now");
+  strcpy(&batpath[batpathlen], "/charge_now");
   stlen = fileRead(stline, sizeof(stline), batpath);
   if (stlen > 0) {
     chargeNow = atoi(stline);
   }
 
-  strcpy(&batpath[batpathlen], "/energy_full");
+  strcpy(&batpath[batpathlen], "/charge_full");
   stlen = fileRead(stline, sizeof(stline), batpath);
   if (stlen > 0) {
     chargeFull = atoi(stline);
   }
 
-  strcpy(&batpath[batpathlen], "/power_now");
+  strcpy(&batpath[batpathlen], "/current_now");
   stlen = fileRead(stline, sizeof(stline), batpath);
   if (stlen > 0) {
-    battW = atoi(stline);
+    currentNow = atoi(stline);
+  }
+
+  strcpy(&batpath[batpathlen], "/voltage_now");
+  stlen = fileRead(stline, sizeof(stline), batpath);
+  if (stlen > 0) {
+    voltageNow = atoi(stline);
   }
 
 
@@ -79,33 +86,33 @@ void status_battery(GlobalData *g, char *batname)
   if (chargePercent <= 40) {
     if (chargePercent <= 25) {
       if (chargePercent <= 10) {
-        s.color = "red";
+        s.color = "#FF0000";  // red
       } else {
         // 11-25%
-        s.color = "orange";
+        s.color = "#FFA500";  // orange
       }
     } else {
       // 26-40%
-      s.color = "yellow";
+      s.color = "#FFFF00";  // yellow
     }
   } else {
     if (chargePercent > 70) {
-      s.color = "white";
+      s.color = "#FFFFFF";  // white
     } else {
       // 41-70%
-      s.color = "green";
+      s.color = "#22FF22";  // green
     }
   }
 
-  battTime = (float)chargeNow / (float)battW;
+  battTime = (float)chargeNow / (float)currentNow;
 
-  if (battW == 0) {
+  if (currentNow == 0) {
     // fully charged and not in use
     snprintf(text, sizeof(text), "%s: %d%% _ _",
               batname, chargePercent);
   } else {
     snprintf(text, sizeof(text), "%s: %d%% %.1fh %.1fW",
-              batname, chargePercent, battTime, (float)battW / 1000000.0);
+              batname, chargePercent, battTime, (float)voltageNow / 1000000.0 * (float)currentNow / 1000000.0);
   }
 
   line_append_item(g, &s);