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

DeleteLogScreen.h

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