This program consists of the software developed for the ELEC5870M Individual Project. It runs on the mbed LPC1768. It uses the mbed RTOS to perform the following tasks: - Implements intuitive GUI with buttons, LCD TFT Display and LEDs. - Serial Communication with the RPi - I2C communication with INA219 voltage current sensors - Power control at the USB ports

Dependencies:   Adafruit_GFX Adafruit_ST7735 INA219 MODSERIAL MbedJSONValue mbed-rtos mbed

Revision:
6:196a63a3378d
Parent:
5:366f17f1ea9b
--- a/SensorSuite.h	Thu Mar 23 10:59:50 2017 +0000
+++ b/SensorSuite.h	Sun Apr 30 17:19:22 2017 +0000
@@ -27,7 +27,7 @@
     // functions used to inteface with suite
     BatteryModel getBatteryData();   // retrieve information about batteries
     SolarModel getSolarData();       // retrieve information about solar panel
-    ConsumptionModel getConsumption();  // retrieve information about consumption
+    ConsumptionModel getConsumptionData();  // retrieve information about consumption
 
 
 private:
@@ -87,9 +87,10 @@
 void SensorSuite::setupSensors()
 {
     // dynamically configure the sensors
-    sensorOne = new INA219(i2c, INA219_ADDR_VG);    // for battery one
-    sensorTwo = new INA219(i2c, INA219_ADDR_GV);    // for battery two
+    sensorOne = new INA219(i2c, INA219_ADDR_GV);    // for battery one
+    sensorTwo = new INA219(i2c, INA219_ADDR_VG);    // for battery two
     sensorThree = new INA219(i2c, INA219_ADDR_GG);  // for solar panel
+    sensorFour = new INA219(i2c, INA219_ADDR_VV);  // for power consumption
 
     // querry the position of the batteries
 }
@@ -125,6 +126,26 @@
             b2Current = sensorOne->read_current();
             b2Current = sensorOne->read_bus_voltage();
         }
+        
+        if (b1Voltage < 3.4)
+        {
+            // turn on LED
+            batteryOneLowLED = 1;
+            
+        } else {
+            // turn off LED
+            batteryOneLowLED = 0;
+        }
+        
+        if (b2Voltage < 3.4)
+        {
+            // turn on LED    
+            batteryTwoLowLED = 1;
+        } else {
+            
+            // turn off LED    
+            batteryTwoLowLED = 0;
+        }
         // release access to battery data
         battery_mutex.unlock();
 
@@ -140,12 +161,14 @@
 
 
         // restrict access to consumption data
-        //consumption_mutex.lock();
+        consumption_mutex.lock();
 
         // read values from the output sensor
-
+        outVoltage = sensorFour->read_bus_voltage();
+        outCurrent = sensorFour->read_current();
+        
         // release access to consumption data
-        //consumption_mutex.unlock();
+        consumption_mutex.unlock();
 
         // unlock the general mutex
         //general_mutex.unlock();
@@ -190,6 +213,20 @@
 
 }
 
+ConsumptionModel SensorSuite::getConsumptionData()
+{
+    // restrict access to consumption data to a single thread
+    consumption_mutex.lock();
+    
+    // collect consumption data
+    ConsumptionModel model(outVoltage, outCurrent);
+    
+    // allow access to consumption data to different threads
+    consumption_mutex.unlock();   
+    
+    return model; 
+}
+
 // ensure that sensor data is initialised
 // voltage-current sensors
 INA219* SensorSuite::sensorOne = NULL;      // sensor 1