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

ViewLogScreen.h

00001 #ifndef VIEWLOGSCREEN_H
00002 #define VIEWLOGSCREEN_H
00003 
00004 #include "ListController.h"
00005 #include "LogManager.h"
00006 #include "RecordScreen.h"
00007 
00008 class ViewLogScreen: public Button <ViewLogScreen>
00009 {
00010 public:
00011     ViewLogScreen(uint16_t backgroundColor); // constructor
00012     int start();
00013     void buttonPressed(int button);
00014 private:
00015     void getLogRecords();    // this function fills the Log Array with records available
00016     void displayRecords();  // displays the available records
00017     void emptyRecords();    // empty the array that stores the records
00018     ListController *list;   // this is the list used to display the logs
00019     LogRecord records[4];      // array that stores a maximum of 4 log records
00020     int numberOfRecords;    // stores the number of records to show
00021     int changeScreen;
00022     uint16_t backgroundColor;   // stores the background color
00023     bool showDetails;   // knows when it is time to show a record's details
00024     bool scroll;
00025 };
00026 
00027 ViewLogScreen::ViewLogScreen(uint16_t bgColor)
00028 {
00029     backgroundColor = bgColor;
00030 }
00031 
00032 int ViewLogScreen::start()
00033 {
00034     // retireves the Log Records
00035     getLogRecords();
00036     // display those records on a list controller
00037     displayRecords();
00038 
00039     // attach interrupts to buttons
00040     Button<ViewLogScreen>::activateButtons(this);
00041 
00042     changeScreen = 0;
00043     showDetails = false;
00044 
00045     // have the infinite while loop that waits for an event
00046     while (changeScreen == 0) {
00047         //updateTile();
00048         //wait_ms(250);
00049        Thread::wait(250);  
00050        
00051        if (scroll){
00052             list->scroll();
00053             scroll = false;   
00054         } 
00055 
00056         if(showDetails && (numberOfRecords>0)) {
00057             // first deactivate the buttons
00058             Button<ViewLogScreen>::deActivateButtons();
00059 
00060             // then clear the screen
00061             tft.fillScreen(backgroundColor);
00062 
00063             // get the option selected
00064             int detail = (list->getCurrentOption())-1;
00065 
00066             // create record screen object
00067             RecordScreen recordScreen(backgroundColor);
00068 
00069             // launch record screen with appropriate object
00070             recordScreen.start(records[detail]);
00071 
00072             // recativate the buttons
00073             Button<ViewLogScreen>::activateButtons(this);
00074             
00075             // then clear the screen
00076             tft.fillScreen(backgroundColor);
00077             
00078             // show the data again
00079             list->drawList();
00080 
00081             // reset flag
00082             showDetails = false;
00083         }
00084     }
00085 
00086     // release memory back to heap
00087     delete list;
00088 
00089     // empty the records array
00090     emptyRecords();
00091 
00092     // dettach interrupts to buttons
00093     Button<ViewLogScreen>::deActivateButtons();
00094 
00095     return changeScreen;
00096 }
00097 
00098 void ViewLogScreen::getLogRecords()
00099 {
00100 
00101     // create a Log Manager object
00102     // send the reference of the records array and Log Manager
00103     // will fill it with available records
00104     // it returns the number of records availble
00105     LogManager manager;
00106     numberOfRecords = manager.retrieveLog(records);
00107 
00108     // arrange records with according to time. The latest record first
00109     if(numberOfRecords > 1) {       
00110         for(int i = 0; i < (numberOfRecords-1); i++) {
00111             // compare a given record with all proceding records
00112             for( int j = 0; j < (numberOfRecords-1); j++) {     
00113                 // check if the time of recording is earlier than the record of interest
00114                 if(records[i].getTimeStamp() < records[j+1].getTimeStamp()) {
00115                     // swap records
00116                     LogRecord record = records[i];
00117                     records[i] = records[j+1];
00118                     records[j+1] = record;
00119                 }
00120             }
00121         }
00122 
00123     }
00124 
00125 
00126     // use the data to construct a list controller with the data
00127 }
00128 
00129 void ViewLogScreen::displayRecords()
00130 {
00131 
00132     myled2 = 1;
00133     list = new ListController( 0,
00134                                0,
00135                                "Logs",
00136                                records[0].getName(),
00137                                records[1].getName(),
00138                                records[2].getName(),
00139                                records[3].getName(),
00140                                backgroundColor,
00141                                numberOfRecords);
00142 
00143 
00144     list->drawList();
00145 
00146 }
00147 
00148 void ViewLogScreen::emptyRecords()
00149 {
00150 
00151     for(int i = 0; i < 4; i++) {
00152         LogRecord record;   // empty record
00153         records[i] = record;    // store empty record
00154     }
00155 
00156     numberOfRecords = 0;    // there are now no records left
00157 }
00158 
00159 void ViewLogScreen::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             scroll = true;
00172             break;
00173 
00174         case ENTERBUTTON:
00175             // navigate to the selected option
00176             //changeScreen = ListController::getCurrentOption();
00177             showDetails = true;
00178             break;
00179 
00180         default:
00181             // do nothing
00182             break;
00183     }
00184 }
00185 
00186 
00187 #endif