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

LogSelectScreen.h

00001 #ifndef LOGSELECTSCREEN_H
00002 #define LOGSELECTSCREEN_H
00003 
00004 #include "ListController.h"
00005 
00006 class LogSelectScreen: public Button <LogSelectScreen>
00007 {
00008 public:
00009     LogSelectScreen(uint16_t backgroundColor);
00010     int start();
00011     void buttonPressed(int button);
00012 
00013 private:
00014     void drawLogSelectScreen();
00015     int changeScreen;  
00016     ListController *list;  // manages the list
00017     bool scroll;    // updated when a scroll event occurs
00018     bool enter;     // updated when an enter event occurs
00019     uint16_t bgColor;    // background color
00020     
00021 };
00022 
00023 LogSelectScreen::LogSelectScreen(uint16_t backgroundColor)
00024 {
00025      bgColor = backgroundColor;
00026     
00027 }
00028 
00029 int LogSelectScreen::start(){
00030     
00031     // draw the screen
00032     drawLogSelectScreen();
00033     
00034     // attach interrupts to buttons
00035     Button<LogSelectScreen>::activateButtons(this);
00036     
00037     changeScreen = 0;
00038     scroll = false;
00039     enter = false;
00040     
00041     
00042     while (changeScreen == 0){
00043         //updateTile();
00044         
00045         // scroll event occured
00046         if (scroll)
00047         {
00048             // perfrom scroll on the list
00049             list->scroll();
00050             // reset variable
00051             scroll = false;    
00052         }
00053         
00054         // enter event occured
00055         if (enter)
00056         {
00057             // read the current option on the list
00058             changeScreen = list->getCurrentOption();    
00059         }
00060         
00061         //wait_ms(500);
00062         Thread::wait(200);    
00063     }
00064     
00065     // relese memory occupied by list
00066     delete list;
00067     
00068     // dettach interrupts to buttons
00069     Button<LogSelectScreen>::deActivateButtons();
00070     
00071     return changeScreen;
00072 }
00073 
00074 void LogSelectScreen::drawLogSelectScreen(){
00075        
00076     // construct the list
00077     list = new ListController( 0,
00078                      0,
00079                    "Parameter",
00080                 "Solar",
00081                 "Power Usage",
00082                 "",
00083                 "",
00084                 bgColor,
00085                 2);
00086     
00087     // draw the list 
00088     list->drawList();   
00089 }
00090 
00091 void LogSelectScreen::buttonPressed(int button)
00092 {
00093     switch(button){
00094         
00095         case BACKBUTTON:
00096             // navigate to the previous screen
00097             changeScreen = -1;
00098             break;
00099         
00100         case SCROLLBUTTON:
00101             // scroll to the next option
00102             scroll = true;
00103             break;
00104         
00105         case ENTERBUTTON:
00106             // navigate to the selected option
00107             enter = true;
00108             break;
00109             
00110         default:
00111             // do nothing
00112             break;    
00113     }
00114 }
00115 
00116 #endif