aconno acnsensa project for iOS devices with iBeacon packets support.

Dependencies:   LSM9DS1 Si7006A20 aconno_SEGGER_RTT aconno_bsp adc52832_common

Revision:
7:7fa0da697c8d
Parent:
6:51745805d8b0
Child:
9:0453d592221b
Child:
10:a2364dee495f
diff -r 51745805d8b0 -r 7fa0da697c8d main.cpp
--- a/main.cpp	Tue Mar 20 08:40:21 2018 +0000
+++ b/main.cpp	Wed Mar 21 10:07:24 2018 +0000
@@ -148,6 +148,7 @@
 
 uint8_t getBattery(){
     uint16_t batteryVoltage = analogIn.getData()[0];
+    /* // Old code.
     if(batteryVoltage >= 810) return 100;
     if(batteryVoltage >= 796) return 85;
     if(batteryVoltage >= 782) return 75;
@@ -155,6 +156,29 @@
     if(batteryVoltage >= 754) return 25;
     if(batteryVoltage >= 740) return 10;
     return 0;
+    */
+    // New version.
+    const uint16_t zero_percent_limit = 739;
+    const uint16_t onehundred_percent_limit = 810;
+    const uint16_t percentage_increments = 5;
+    uint8_t percentage;
+    
+    if (batteryVoltage < zero_percent_limit)
+    {
+        percentage = 0;
+    }
+    else if(batteryVoltage > onehundred_percent_limit)
+    {
+        percentage = 100;
+    }
+    else
+    {
+        batteryVoltage -= zero_percent_limit;
+        percentage = (batteryVoltage*100)/(onehundred_percent_limit - zero_percent_limit);
+        percentage = percentage/percentage_increments*percentage_increments;
+    }
+    
+    return percentage;
 }
 
 float getHumidity(){