Custom project for driving a STC3100 sensor

Dependencies:   mbed

Fork of STC3100 by Levi Mariën

Revision:
1:dbc1e56be2cc
Parent:
0:014d4be7a437
--- a/STC3100Sensor.cpp	Sun Oct 29 00:11:17 2017 +0000
+++ b/STC3100Sensor.cpp	Sat Nov 04 13:07:17 2017 +0000
@@ -4,6 +4,8 @@
 #include "mbed.h"
 #include "STC3100Sensor.h"
 
+I2C i2c(D14, D15);
+
 /**
  * Configuring the STC3100
  * ------------------------
@@ -31,7 +33,7 @@
  */
 void stc3100ReadChip(void) {
 
-    i2c.read(STC3100_ADDRESS_READ, &(stc3100Data.byteArray[0]), 10);
+    i2c.read(STC3100_ADDRESS_READ, &(byteArray[0]), 10);
 }
 
 /**
@@ -45,27 +47,27 @@
     stc3100ReadChip();
 
     // Converting to voltage
-    high_byte = (unsigned int) stc3100Data.VoltageHigh;
+    high_byte = (unsigned int) VoltageHigh;
     high_byte <<= 8;
-    value = (high_byte & 0xFF00) | stc3100Data.VoltageLow;
-    stc3100ActualData.voltage = (float) value * 2.44;
+    value = (high_byte & 0xFF00) | VoltageLow;
+    voltage = (float) value * 2.44;
 
     // Converting to current
-    high_byte = (unsigned int) stc3100Data.CurrentHigh;
+    high_byte = (unsigned int) CurrentHigh;
     high_byte <<= 8;
-    value = (high_byte & 0xFF00) | stc3100Data.CurrentLow;
+    value = (high_byte & 0xFF00) | CurrentLow;
     value <<= 2;
-    stc3100ActualData.current =
+    current =
             ((((float) value * 11.77) / 10.0) / 4.0) > 0.0 ?
                     ((((float) value * 11.77) / 10.0) / 4.0) :
                     -((((float) value * 11.77) / 10.0) / 4.0);
-    stc3100ActualData.current -= 54.0;
+    current -= 54.0;
 
     // Converting to charge
-    high_byte = (unsigned int) stc3100Data.ChargeHigh;
+    high_byte = (unsigned int) ChargeHigh;
     high_byte <<= 8;
-    value = (high_byte & 0xFF00) | stc3100Data.ChargeLow;
-    stc3100ActualData.charge = ((float) value * 6.70) / 10.0;
+    value = (high_byte & 0xFF00) | ChargeLow;
+    charge = ((float) value * 6.70) / 10.0;
 
     //  // Converting to temperature
     //  high_byte = (unsigned int) stc3100Data.TemperatureHigh;
@@ -80,19 +82,19 @@
  * Method for returning the voltage
  */
 float getVoltage(void) {
-    return stc3100ActualData.voltage;
+    return voltage;
 }
 
 /**
  * Method for returning the current
  */
 float getCurrent(void) {
-    return stc3100ActualData.current;
+    return current;
 }
 
 /**
  * Method for returning the charge
  */
 float getCharge(void) {
-    return stc3100ActualData.charge;
+    return charge;
 }