cell detection (voltage based), remaining % cell based, moved cells to temperature for CT
cell detection (voltage based), remaining % cell based, moved cells to temperature for CT

--- a/MAVLink.ino
+++ b/MAVLink.ino
@@ -72,6 +72,7 @@
 //unsigned int   osd_rssi;
 float          _cellVoltage;
 static float   osd_analog_batt = 0;                 // Battery A voltage in milivolt
+float          pack_max_voltage;
 
 #endif
 
@@ -232,11 +233,18 @@
                   //Serial.println (float(osd_vbat_A/100));
                   osd_vbat_A = float(osd_vbat_A/100);
                   
+                  if(osd_vbat_A > 21) cell_count = 6;
+                  else if (osd_vbat_A > 16.8 && cell_count != 6) cell_count = 5;
+                  else if(osd_vbat_A > 12.6 && cell_count != 5) cell_count = 4;
+                  else if(osd_vbat_A > 8.4 && cell_count != 4) cell_count = 3;
+                  else if(osd_vbat_A > 4.2 && cell_count != 3) cell_count = 2;
+                  else cell_count = 0;
+                  
                 } else if (appId >= CURR_FIRST_ID && appId <= CURR_LAST_ID) {
                   osd_curr_A = SPORT_DATA_U32(buffer);
                   osd_curr_A = float(osd_curr_A/100);
                   unsigned long now = micros();
-                  //osd_battery_remaining_A += (long)osd_curr_A * 1000 / (3600000000 / (now - _uptime));
+                  //osd_battery_remaining_A = (long)osd_curr_A * 1000 / (3600000000 / (now - _uptime));
                   //Serial.println ("osd_curr_A");
                   //Serial.println (osd_curr_A);
                   
@@ -249,7 +257,11 @@
                   _cellVoltage = ((((cells & 0x000FFF00) >> 8) / 10)*2);
                   //Serial.println ("cellVoltage");
                   //Serial.println ( cellVoltage/100, 2 );
-                   osd_battery_remaining_A = float(_cellVoltage/100);
+                  // use cells as temperature to use CT
+                  _cellVoltage = float(_cellVoltage/100);
+                  osd_battery_remaining_A = ((_cellVoltage-3.72)*100) / (4.2-3.72);
+                  
+                  temperature = _cellVoltage;
                   
                 } else if (appId >= GPS_SPEED_FIRST_ID && appId <= GPS_SPEED_LAST_ID) {
                    osd_groundspeed = SPORT_DATA_U32(buffer);

--- a/OSD_Panels.ino
+++ b/OSD_Panels.ino
@@ -198,7 +198,12 @@
     osd.setPanel(first_col, first_line);
     osd.openPanel();
 //    osd.printf("%c%5.1f%c", 0x0a, (float(temperature * tempconv + tempconvAdd) / 100), temps);
+#ifdef FRSKY
+    //osd.printf("%c%5.2f%c", 0x17, (double)temperature, 0x0d);
+    osd.printf("%c%4.2f%c", 0x17, (double)temperature, 0x0d);
+#else
     osd.printf("%5.1f%c", (float(temperature * tempconv + tempconvAdd) / 1000), temps);
+#endif    
     osd.closePanel();
 }
 
@@ -716,7 +721,7 @@
           }
  if (rotation > 5) rotation = 0;
 #ifdef FRSKY
-  if (warning[4] == 1 && rotation == 5) {
+  if (warning[4] == 1 && rotation == 5 || rotation == 1) {
         osd.printf("%s",warning_string);  
   }
 #else
@@ -753,11 +758,11 @@
     osd.openPanel();
     
     if (EEPROM.read(OSD_BATT_SHOW_PERCENT_ADDR) == 1){
-#ifdef FRSKY
-        osd.printf("%c%5.2f%c", 0x17, (double)osd_battery_remaining_A, 0x25);
-#else
+//#ifdef FRSKY
+//        osd.printf("%c%5.2f%c", 0x17, (double)osd_battery_remaining_A, 0x25);
+//#else
         osd.printf("%c%3.0i%c", 0x17, osd_battery_remaining_A, 0x25);
-#endif        
+
     }else{
         osd.printf("%c%4.0f%c", 0x17, mah_used, 0x01);
     }

file:a/OSD_Vars.h -> file:b/OSD_Vars.h
--- a/OSD_Vars.h
+++ b/OSD_Vars.h
@@ -68,17 +68,15 @@
 static int16_t      temps = 0;
 static float        osd_vbat_A = 0;                 // Battery A voltage in milivolt
 #ifdef FRSKY
+uint8_t             cell_count = 0;
 static float        osd_curr_A = 0;                 // Battery A current
 #else
 static int16_t      osd_curr_A = 0;                 // Battery A current
 #endif
 static float        mah_used = 0;
-#ifdef FRSKY
-static float        osd_battery_remaining_A = 0;    // 0 to 100 <=> 0 to 1000
-#else
 static int8_t       osd_battery_remaining_A = 0;    // 0 to 100 <=> 0 to 1000
-#endif
 static uint8_t      batt_warn_level = 0;
+
 
 //static uint8_t    osd_battery_pic_A = 0xb4;       // picture to show battery remaining
 //static float      osd_vbat_B = 0;               // voltage in milivolt
@@ -144,7 +142,11 @@
 
 static float        osd_groundspeed = 0;            // ground speed
 static uint8_t     osd_throttle = 0;               // throtle
+#ifdef FRSKY
+static float        temperature = 0;
+#else
 static uint16_t     temperature = 0;
+#endif
 static uint8_t      tempconv = 1;
 static uint16_t     tempconvAdd = 0;
 static byte     distchar = 0;

comments