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

LogDurationScreen.h

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