Augustine Kizito / Mbed 2 deprecated Solar_Powered_Smart_Camera

Dependencies:   Adafruit_GFX Adafruit_ST7735 INA219 MODSERIAL MbedJSONValue mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SolarValueScreen.h Source File

SolarValueScreen.h

00001 #ifndef SOLARVALUESCREEN_H
00002 #define SOLARVALUESCREEN_H
00003 
00004 class SolarValueScreen: Button <SolarValueScreen>
00005 {
00006 public:
00007     SolarValueScreen(uint16_t);
00008     int start();
00009     void buttonPressed( int button );
00010 private:
00011     float voltage;
00012     float current;
00013     float power;
00014     int changeScreen;
00015     uint16_t backgroundColor;   // stores the background color
00016     uint16_t textColor;         // stores the text color
00017     void displayStaticData();   // displays data that does not change
00018     void displayDynamicData();  // displays data that changes
00019 };
00020 
00021 SolarValueScreen::SolarValueScreen(uint16_t bgColor)
00022 {
00023 
00024     backgroundColor = bgColor;
00025     // determine the color of text
00026     if (bgColor == ST7735_WHITE ) {
00027         textColor = ST7735_BLACK;
00028     } else if (bgColor == ST7735_BLACK) {
00029         textColor = ST7735_WHITE;
00030     } else if (bgColor == ST7735_BLUE) {
00031         textColor = ST7735_WHITE;
00032     }
00033 }
00034 
00035 int SolarValueScreen::start()
00036 {
00037     // initial values
00038     current = -1.0;
00039     voltage =  -1.0;
00040     power = -1.0;
00041     
00042     // Populate the Screen
00043     displayStaticData();
00044     displayDynamicData();
00045 
00046     changeScreen = 0;
00047     // attach interrupts to buttons
00048     Button<SolarValueScreen>::activateButtons(this);
00049 
00050     while(changeScreen == 0) {
00051         displayDynamicData();
00052         //wait_ms(500);
00053         Thread::wait(200);   
00054     }
00055 
00056     // dettach interrupts to buttons
00057     Button<SolarValueScreen>::deActivateButtons();
00058 
00059     return changeScreen;
00060 }
00061 
00062 void SolarValueScreen::displayStaticData()
00063 {
00064     // the static data is displayed here e.g headings
00065     tft.setTextWrap(true);
00066     tft.setTextColor(textColor);
00067 
00068     // display title
00069     tft.setCursor((tft.width()/2)-50,4);
00070     tft.printf("SOLAR PANEL");
00071 
00072     // display voltage
00073     tft.setCursor(0, 20);
00074     tft.printf("VOLTAGE(V)");
00075 
00076     // display current
00077     tft.setCursor(0, 50);
00078     tft.printf("CURRENT(mA)");
00079 
00080     // display capacity remaining
00081     tft.setCursor(0, 80);
00082     tft.printf("POWER(W)");
00083 }
00084 
00085 void SolarValueScreen::displayDynamicData()
00086 {
00087     // first retrieve data from the sensor suite
00088     SensorSuite suite;
00089     SolarModel model = suite.getSolarData();
00090     
00091     float newCurrent;
00092     float newVoltage;
00093     float newPower;
00094     
00095     // the dynamic data is displayed here e.g values
00096     int added = 10;
00097     tft.setTextWrap(true);
00098     tft.setTextColor(textColor);
00099     
00100     newCurrent = model.solarCurrent;
00101     newVoltage = model.solarVoltage;
00102     newPower = newCurrent*newVoltage*0.001;
00103 
00104     // display the voltage
00105     if (newVoltage == voltage)
00106     {
00107         // do nothing    
00108     }  else {
00109         
00110         tft.setCursor(0, 20+added);
00111         // first delete the previous value
00112         tft.setTextColor(backgroundColor);
00113         tft.printf("%+6.3f",voltage);
00114         
00115         tft.setCursor(0, 20+added);
00116         // then write the new voltage values
00117         tft.setTextColor(textColor);
00118         tft.printf("%+6.3f",newVoltage);
00119     }
00120     
00121     // display the current
00122     if (newCurrent == current){
00123         // do nothing    
00124     } else {
00125         
00126         // first delete the previous value
00127         tft.setCursor(0, 50+added);
00128         tft.setTextColor(backgroundColor);
00129         tft.printf("%+6.3f",current);
00130         
00131         // then write the new current values
00132         tft.setCursor(0, 50+added);
00133         tft.setTextColor(textColor);
00134         tft.printf("%+6.3f",newCurrent);
00135     }
00136 
00137     // display capacity remaining
00138     if(newPower == power){
00139         // do nothing
00140     } else {
00141         // first delete the previous value
00142         tft.setCursor(0, 80+added);
00143         tft.setTextColor(backgroundColor);
00144         tft.printf("%+6.3f",power);
00145         
00146         // then write the new current values
00147         tft.setCursor(0, 80+added);
00148         tft.setTextColor(textColor);
00149         tft.printf("%+6.3f",newPower);
00150         
00151     }
00152     
00153     voltage = newVoltage;
00154     current = newCurrent;
00155     power = newPower;
00156 
00157 }
00158 
00159 void SolarValueScreen::buttonPressed( int button )
00160 {
00161     switch(button) {
00162 
00163         case BACKBUTTON:
00164             // navigate to the previous screen
00165             changeScreen = -1;
00166             break;
00167 
00168         case SCROLLBUTTON:
00169             // scroll to the next option
00170             //list->scroll();
00171             break;
00172 
00173         case ENTERBUTTON:
00174             // navigate to the selected option
00175             //changeScreen = ListController::getCurrentOption();
00176             //showDetails = true;
00177             break;
00178 
00179         default:
00180             // do nothing
00181             break;
00182     }
00183 }
00184 #endif