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 SettingsTest.h Source File

SettingsTest.h

00001 #ifndef TESTSCREEN_H
00002 #define TESTSCREEN_H
00003 
00004 #include "ListController.h"
00005 #include "Settings.h"
00006 
00007 // On board LEDS
00008 DigitalOut led1(LED1);
00009 DigitalOut led2(LED2);
00010 DigitalOut led3(LED3);
00011 
00012 
00013 
00014 class TestScreen: public Button <TestScreen>
00015 {
00016 
00017 public:
00018     TestScreen(uint16_t backgroundColor);
00019     int start();
00020     void createController(uint16_t backgroundColor);
00021     void buttonPressed(int button);
00022     void changeColor( int level);
00023 
00024 private:
00025 
00026     void drawTestScreen();
00027     //void deAllocateMemory();
00028     void intialiseSettings();
00029     
00030     int bgC;
00031     int colorInt;
00032     MbedJSONValue holder;
00033     uint16_t bgColor;
00034 
00035     int changeScreen;
00036     float previousWattage;
00037     ListController *controller;
00038     bool writeFlag;
00039     bool scroll;
00040     bool enter;
00041 
00042 };
00043 
00044 
00045 TestScreen::TestScreen(uint16_t backgroundColor)
00046 {
00047 
00048 }
00049 
00050 void TestScreen::intialiseSettings()
00051 {
00052     // create the settings object
00053     Settings settings;
00054     bgColor = settings.getBackgroundColor();
00055 }
00056 
00057 
00058 int TestScreen::start()
00059 {
00060     // initialise settings
00061     intialiseSettings();
00062 
00063     switch (bgC) {
00064         case 1:
00065             bgColor = ST7735_BLACK;
00066             break;
00067         case 2:
00068             bgColor = ST7735_WHITE;
00069     }
00070 
00071     createController(bgColor);
00072 
00073     writeFlag = false;
00074     drawTestScreen();
00075     // attach interrupts to buttons
00076     Button<TestScreen>::activateButtons(this);
00077 
00078     changeScreen = 0;
00079 
00080     while (changeScreen != -1) {
00081 
00082         if (writeFlag) {
00083             
00084             // create settings object
00085             Settings settings;
00086             // set the new backgroundColor
00087             // it is saved in memory
00088             settings.setBackgroundColor(colorInt);
00089 
00090             writeFlag = false;
00091         }
00092         
00093         if (scroll) {
00094             
00095             controller->scroll();
00096             scroll = false;
00097         }
00098         
00099         if (enter) {
00100             changeScreen = controller->getCurrentOption();
00101             changeColor(changeScreen);
00102             enter = false;
00103         }
00104         //wait_ms(500);
00105         Thread::wait(200);   
00106     }
00107 
00108     // dettach interrupts to buttons
00109     Button<TestScreen>::deActivateButtons();
00110 
00111     // release memory
00112     delete controller;
00113 
00114     return changeScreen;
00115 }
00116 
00117 
00118 void TestScreen::drawTestScreen()
00119 {
00120     // draw the list
00121     controller->drawList();
00122 }
00123 
00124 void TestScreen::changeColor(int level)
00125 {   
00126     // first release the memory occupied by the current controller
00127     delete controller;
00128     
00129     // will store the new color
00130     uint16_t bg;
00131     
00132     // determine the new background color
00133     switch(level) {
00134         // integer 1 is for black background
00135         case 1:
00136             bg = ST7735_BLACK;
00137             break;
00138         // integer 2 is for white background
00139         case 2:
00140             bg = ST7735_WHITE;
00141             break;
00142         default:
00143             break;
00144 
00145     }
00146     
00147     // create a new controller with new background color
00148     createController(bg);
00149     
00150     // draw the controller
00151     controller->drawList();
00152     
00153     // set the color variable
00154     colorInt = level;
00155     
00156     // raise flag so that settings are saved in persistent memory
00157     writeFlag = true;
00158 }
00159 
00160 void TestScreen::createController(uint16_t bg)
00161 {
00162     controller = new ListController( 0,
00163                                      0,
00164                                      "Background",
00165                                      "Black",
00166                                      "White",
00167                                      "",
00168                                      "",
00169                                      bg,
00170                                      2);
00171 }
00172 
00173 void TestScreen::buttonPressed(int button)
00174 {
00175     switch(button) {
00176 
00177         case BACKBUTTON:
00178             // navigate to the previous screen
00179             changeScreen = -1;
00180             break;
00181 
00182         case SCROLLBUTTON:
00183             // scroll to the next option
00184             scroll = true;
00185             break;
00186 
00187         case ENTERBUTTON:
00188             // navigate to the selected option
00189             enter = true;
00190 
00191         default:
00192             // do nothing
00193             break;
00194     }
00195 }
00196 
00197 #endif
00198 
00199