Commits

William Giokas  committed bd3c3b4

battery.h: change floats to doubles

Signed-off-by: William Giokas <1007380@gmail.com>

  • Participants
  • Parent commits 3b9fc08

Comments (0)

Files changed (2)

         /* Update every 10 seconds */
         if (runevery(&count10, 10)) {
             free(avgs);
-            free(batt);
             free(temp);
+            free(batt);
 
             avgs   = loadavg();
-            batt   = getbattery(BATT_PATH);
             temp   = gettemperature(TEMP_SENSOR_PATH, TEMP_SENSOR_UNIT);
+            batt   = getbattery(BATT_PATH);
             if(!temp) free(temp);
         }
         /* Update every second */

File include/battery.h

     char status;
     int descap;
     int remcap;
-    float remaining;
-    float using;
-    float voltage;
-    float current;
+    double remaining;
+    double using;
+    double voltage;
+    double current;
 
     descap = -1;
     remcap = -1;
     co = readfile(base, "power_now"); /* µWattage being used */
     if (co == NULL) {
         co = readfile(base, "voltage_now");
-        sscanf(co, "%f", &voltage);
+        sscanf(co, "%lf", &voltage);
         free(co);
         co = readfile(base, "current_now");
-        sscanf(co, "%f", &current);
+        sscanf(co, "%lf", &current);
         free(co);
-        remcap  = (voltage / 1000.0) * ((float)remcap / 1000.0);
-        descap  = (voltage / 1000.0) * ((float)descap / 1000.0);
-        using = (voltage / 1000.0) * ((float)current / 1000.0);
+        remcap  = (voltage / 1000.0) * ((double)remcap / 1000.0);
+        descap  = (voltage / 1000.0) * ((double)descap / 1000.0);
+        using = (voltage / 1000.0) * ((double)current / 1000.0);
     } else {
-        sscanf(co, "%f", &using);
+        sscanf(co, "%lf", &using);
         free(co);
     }
 
 
     /* Getting time remaining */
     if (status == 'D') {
-        remaining = (float)remcap / using;
+        remaining = (double)remcap / using;
         stat = "B";
     } else if (status == 'C') {
-        remaining = ((float)descap - (float)remcap) /using;
+        remaining = ((double)descap - (double)remcap) /using;
         stat = "C";
     } else {
         remaining = 0;
     if (seconds < 0 || minutes < 0 || hours < 0)
         ret = smprintf("%s: Calculating...", stat);
     else
-        ret = smprintf("%s: %.2f%% %02d:%02d:%02d", stat, (((float)remcap / (float)descap) * 100), hours, minutes, seconds);
+        ret = smprintf("%s: %.2lf%% %02d:%02d:%02d", stat, (((double)remcap / (double)descap) * 100), hours, minutes, seconds);
     if(!stat) { free(stat); }
     return ret;
 }