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
Diff: Inputs.h
- Revision:
- 6:196a63a3378d
- Parent:
- 5:366f17f1ea9b
--- a/Inputs.h Thu Mar 23 10:59:50 2017 +0000 +++ b/Inputs.h Sun Apr 30 17:19:22 2017 +0000 @@ -14,19 +14,54 @@ Timer debounce; Ticker timerRefresh; -//AnalogIn ain(p20); -float ain = 0.5; -float ain1 = 0.5; -float ain2 = 0.5; -//AnalogIn ain1(p19); -//AnalogIn ain2(p18); +AnalogIn ain(p20); +//float ain = 0.5; +//float ain1 = 0.5; +//float ain2 = 0.5; +AnalogIn ain1(p19); +AnalogIn ain2(p18); int getBatteryPercentage() { - // read from the potentiometer - int percentage = ain2*100; + // Define SensorSuite class to access the data + SensorSuite suite; + // create sensor model to get battery data + BatteryModel model; + model = suite.getBatteryData(); + + float percentage1 = ((model.batteryOneVoltage-3.0)/1.2)*100; + + float percentage2 = ((model.batteryTwoVoltage-3.0)/1.2)*100; + + // because battery one has 6600mAH and battery two has 4400mAH + int percentage = percentage1*0.6+percentage2*0.4; + + return percentage; +} +int getBatteryOnePercentage() +{ + // Define SensorSuite class to access the data + SensorSuite suite; + // create sensor model to get battery data + BatteryModel model; + model = suite.getBatteryData(); + + int percentage = ((model.batteryOneVoltage-3.0)/1.2)*100; + return percentage; +} + +int getBatteryTwoPercentage() +{ + // Define SensorSuite class to access the data + SensorSuite suite; + // create sensor model to get battery data + BatteryModel model; + model = suite.getBatteryData(); + + int percentage = ((model.batteryTwoVoltage-3.0)/1.2)*100; + return percentage; } @@ -73,9 +108,14 @@ { bool outputStatus; + + // Define SensorSuite class to access the data + SensorSuite suite; + // create sensor model to get consumption data + ConsumptionModel model = suite.getConsumptionData(); - // read the potentiometer - if (ain > 0.5) { + // read the current + if (model.consumptionCurrent > 20) { outputStatus = true; } else { outputStatus = false; @@ -121,6 +161,21 @@ } } +float getConsumptionPower() +{ + // Define SensorSuite class to access the data + SensorSuite suite; + // create sensor model to get battery data + ConsumptionModel model = suite.getConsumptionData(); + + // return the power + if (model.consumptionCurrent > 0.5) { + return model.consumptionCurrent*model.consumptionVoltage*0.001; + } else { + return 0.0; + } +} + template < class T > class Button {