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/RaspiSerial.h	Thu Mar 23 10:59:50 2017 +0000
+++ b/RaspiSerial.h	Sun Apr 30 17:19:22 2017 +0000
@@ -1,10 +1,10 @@
 #ifndef RASPISERIAL_H
 #define RASPISERIAL_H
-
 #include "MbedJSONValue.h"
 #include "MODSERIAL.h"
 #include <string>
 MODSERIAL raspi(p28, p27); // tx, rx
+DigitalOut piPin(p7);
 
 // this function determines wherther serial is active or inactive
 
@@ -29,6 +29,8 @@
     float b2Current = 0.0;
     float sVoltage = 0.0;
     float sCurrent = 0.0;
+    float oVoltage = 0.0;
+    float oCurrent = 0.0;
 
     // define string to store rounded off sensor data
     char b1VoltageString[5];
@@ -37,17 +39,21 @@
     char b2CurrentString[5];
     char sVoltageString[5];
     char sCurrentString[5];
+    char oVoltageString[5];
+    char oCurrentString[5];
 
     // get access to the sensor suite
     SensorSuite suite;
  
 
     // power up the raspberry pi
+    piPin = 1;
 
     // give the pi some time to boot
-
+    //Thread::wait(1000*10);
+    
     // wait for character x
-    int counter = 120;  // count down to 2 minutes
+    int counter = 180;  // count down to 3 minutes
     char x = NULL;
     while(counter > 0 && x != 'x') {
         x = raspi.getc();
@@ -106,6 +112,16 @@
         // read solar panel data
         sVoltage = sModel.solarVoltage;
         sCurrent = sModel.solarCurrent;
+        
+        
+        
+        // create model to get consumption data
+        ConsumptionModel oModel = suite.getConsumptionData();
+        // read the consumption data
+        oVoltage = oModel.consumptionVoltage;
+        oCurrent = oModel.consumptionCurrent;
+        
+        
 
         ////////////////////////////////////////////////////////////////////////
 
@@ -123,6 +139,8 @@
         sprintf(b2CurrentString,"%0.2f",b2Current);
         sprintf(sVoltageString,"%0.2f",sVoltage);
         sprintf(sCurrentString,"%0.2f",sCurrent);
+        sprintf(oVoltageString,"%0.2f",oVoltage);
+        sprintf(oCurrentString,"%0.2f",oCurrent);
 
         // construct json data
         holder["b1V"] = b1VoltageString;
@@ -131,6 +149,8 @@
         holder["b2C"] = b2CurrentString;
         holder["sV"]  = sVoltageString;
         holder["sC"]  = sCurrentString;
+        holder["oV"]  = oVoltageString;
+        holder["oC"]  = oCurrentString;
 
         // convert json data to string
         jsonString = holder.serialize();
@@ -226,6 +246,9 @@
     }
     
     if (p == 'x') {
+        Thread::wait(1000*12);// wait 12 seconds
+        piPin = 0;
+        myled = 0;
         piStatus = false;
         // send message that connection was made
         serial_ui_letter *letter2 = serial_ui_mail.alloc();