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:
1:1354a7ebd0c6
Parent:
0:5139f11cfc62
Child:
2:104bec169fb6
--- a/main.cpp	Fri Jul 01 13:33:14 2016 +0000
+++ b/main.cpp	Sun Jul 10 12:24:41 2016 +0000
@@ -1,8 +1,10 @@
 #include "mbed.h"
 #include "Adafruit_ST7735.h"
 
+Adafruit_ST7735 tft(p11, p12, p13, p10, p8, p9); // MOSI, MISO, SCLK, SSEL, TFT_DC, TFT_RST
+#include "BatteryIcon.h"
 
-Adafruit_ST7735 tft(p11, p12, p13, p10, p8, p9); // MOSI, MISO, SCLK, SSEL, TFT_DC, TFT_RST
+
 //LEDs used to display output
 
 DigitalIn enable1(p21);
@@ -19,9 +21,23 @@
 
 DigitalOut myled(LED1);
 
+
+
 void testdrawtext(char *text, uint16_t color);
+void testdrawrects(uint16_t color);
+void testfastlines(uint16_t color, int batteryLevel);
+void testDrawPercentage(char *percentage, uint16_t color);
+void displayBatteryPercentage(int percentage, uint16_t color);
+void testDrawThunderbolt();
+uint16_t determineColor(int batteryLevel);
 
 float currentFloat = 1.0;
+int currentBatteryLevel = 0;
+int previousBatteryLevel = 0;
+int previousBatteryColor = 0;
+
+int startingWidth = 20;
+int startingHeight = 10;
 
 
 int main()
@@ -29,52 +45,53 @@
     // Use this initializer if you're using a 1.8" TFT
     tft.initR(INITR_BLACKTAB);   // initialize a ST7735S chip, black tab
 
-    tft.fillScreen(ST7735_BLACK);
+    uint16_t backgroundColor = ST7735_WHITE;
+    tft.fillScreen(backgroundColor);
+    
+    // landscape view
     tft.setRotation(1);
     char current_text[40];
-    //sprintf(current_text, "current is : %+6.3f [mA]", current.read_current());
-    //testdrawtext(current_text, ST7735_WHITE);
-    //testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", ST7735_WHITE);
-    wait_ms(1000);
+    
+    int batteryLevel = ain2*32.5;
+    int percentage = ain2*100;
+    
+    sprintf(current_text, "W: %ldp H: %ldp ", tft.height(), tft.width());
+    testdrawtext(current_text, ST7735_WHITE);
 
-    while(1) {
-        //tft.fillScreen(ST7735_BLACK);
-        float newCurrent = ain2;
-        sprintf(current_text, "%+6.1f [mA]", newCurrent);
-        testdrawtext(current_text, ST7735_WHITE);
-        //testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", ST7735_WHITE);
-        
-        wait_ms(1000);
-        
-        if (newCurrent == currentFloat){
-            
-        }
-        else{
+    // determine if the battery is charging
+    bool batteryCharging;
+    if (ain1 > 0.5) {
+        batteryCharging = true;
+    } else {
+        batteryCharging = false;
+    }
+    
+    // create and initialise battery icon project
+    BatteryIcon batteryIcon(startingWidth, startingHeight,backgroundColor,percentage,batteryCharging);
+    // draw the battery icon
+    batteryIcon.drawBatteryIcon();
+
+    while (1) {
         
-            testdrawtext(current_text, ST7735_BLACK);
+        // determine if the battery is charging
+        percentage = ain2*100;
+        if (ain1 > 0.5) {
+            batteryCharging = true;
+        } else {
+            batteryCharging = false;
         }
-        currentFloat = newCurrent;
+        // set the battery percentage accordingly
+        batteryIcon.setBatteryPercentage(percentage,batteryCharging);
         
-        if (enable1){
-            led1 = !led1;
-            }
-            
-        if (enable2){
-            led2 = !led2;
-            }
-            
-        if (enable3){
-            led3 = !led3;
-            }
-        
-        
-        
+        // wait half a second
+        wait_ms(500);
     }
+
 }
 
 void testdrawtext(char *text, uint16_t color)
 {
-    tft.setCursor(0, 0);
+    tft.setCursor(0, 100);
     tft.setTextColor(color);
     tft.setTextWrap(true);
     tft.printf("%s",text);