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: Screens/SolarScreen.h
- Revision:
- 3:7666de697752
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Screens/SolarScreen.h Sat Feb 04 20:17:44 2017 +0000 @@ -0,0 +1,229 @@ +#ifndef SOLARSCREEN_H +#define SOLARSCREEN_H + +#include "ListController.h" + +class SolarScreen: public Button <SolarScreen> +{ + +public: + SolarScreen(uint16_t backgroundColor); + int start(); + void buttonPressed(int button); + +private: + + void drawSolarScreen(); + void drawTile(); + void updateTile(); + //void deAllocateMemory(); + void drawWattage(float wattage, uint16_t color); + + int changeScreen; + float previousWattage; + + ListController *list; // manages the list + bool scroll; // updated when a scroll event occurs + bool enter; // updated when an enter event occurs + uint16_t bgColor; // background color + + + +}; + + +SolarScreen::SolarScreen(uint16_t backgroundColor) +{ + + bgColor = backgroundColor; +} + +int SolarScreen::start(){ + + previousWattage = -1; + + // attach interrupts to buttons + Button<SolarScreen>::activateButtons(this); + + // draw the screen + drawSolarScreen(); + + + changeScreen = 0; + scroll = false; + enter = false; + + + + while (changeScreen == 0){ + updateTile(); + + // scroll event occured + if (scroll) { + // perform scroll on the list + list->scroll(); + // reset variable + scroll = false; + } + + // enter event occured + if (enter) { + // read the current option on the list + changeScreen = list->getCurrentOption(); + } + //wait_ms(500); + Thread::wait(200); + } + + // relese memory occupied by list controller + delete list; + + // dettach interrupts to buttons + Button<SolarScreen>::deActivateButtons(); + + return changeScreen; +} + + +void SolarScreen::drawSolarScreen(){ + + // draw the tile + drawTile(); + + // construct the list + list = new ListController( 0, + 63, + "Solar", + "Values", + "Graph", + "", + "", + backgroundColor, + 2); + + // draw the list + list->drawList(); +} + +void SolarScreen::drawTile() +{ + // draw the green background + tft.fillRect(0,0,tft.width(),63,ST7735_GREEN); + + // draw the text + tft.setTextSize(1); + tft.setCursor(5,5); + tft.setTextColor(ST7735_RED); + tft.printf("Power:"); + + // update the power values + updateTile(); +} + +void SolarScreen::updateTile() +{ + // read the current power + float wattage = getSolarPower(); + + // temporary storage + char wattageString[5]; + + // tracks previously measured power + // ensure first value is ridiculous + // to enable print on startup + //static float previousWattage = -1; + + // convert float to char* + // to round off to 1 decimal place + sprintf(wattageString,"%.1f",wattage); + + // convert back to float + wattage = atof(wattageString); + + // multiply by 10 + wattage = wattage*10; + + // convert float to integer + float currentWattage = wattage; + + if(currentWattage != previousWattage){ + + // first delete the previous wattage + drawWattage(previousWattage,ST7735_GREEN); + // then write the new wattage + drawWattage(currentWattage,ST7735_BLUE); + + + }else{ + // do nothing + } + + // update the previous wattage + previousWattage = currentWattage; +} + +void SolarScreen::drawWattage(float wattage, uint16_t color) +{ + // convert float to integer + int wattageInt = wattage; + + // divide by 10 + int firstInt = wattageInt/10; + + // print the quotient as the first value + int secondInt = wattageInt%10; + + // the coordinates of the first large digit + int startWidth = 40; + int startHeight = 15; + + // The first Large Digit + tft.setTextSize(6); + tft.setCursor(startWidth, startHeight); + tft.setTextColor(color); + tft.printf("%d",firstInt); + + // the decimal point + tft.setCursor(startWidth+ 28, startHeight + 21); + tft.setTextSize(3); + tft.printf("."); + + // The second Large Digit + tft.setCursor(startWidth + 45, startHeight); + tft.setTextSize(6); + tft.printf("%d", secondInt); + + // The power units + tft.setCursor(startWidth + 80, startHeight + 15); + tft.setTextSize(3); + tft.printf("W"); + + // reset the text size to smallest + tft.setTextSize(1); +} + +void SolarScreen::buttonPressed(int button) +{ + switch(button){ + + case BACKBUTTON: + // navigate to the previous screen + changeScreen = -1; + break; + + case SCROLLBUTTON: + // scroll to the next option + scroll = true; + break; + + case ENTERBUTTON: + // navigate to the selected option + enter = true; + + default: + // do nothing + break; + } +} + +#endif \ No newline at end of file