This program consists of the software developed for the ELEC5870M Individual Project. It runs on the mbed LPC1768. It uses the mbed RTOS to perform the following tasks: - Implements intuitive GUI with buttons, LCD TFT Display and LEDs. - Serial Communication with the RPi - I2C communication with INA219 voltage current sensors - Power control at the USB ports
Dependencies: Adafruit_GFX Adafruit_ST7735 INA219 MODSERIAL MbedJSONValue mbed-rtos mbed
Screens/DeleteLogScreen.h@6:196a63a3378d, 2017-04-30 (annotated)
- Committer:
- OHstin
- Date:
- Sun Apr 30 17:19:22 2017 +0000
- Revision:
- 6:196a63a3378d
- Parent:
- 3:7666de697752
Final Code for mbed operation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
OHstin | 3:7666de697752 | 1 | #ifndef DELETELOGSCREEN_H |
OHstin | 3:7666de697752 | 2 | #define DELETELOGSCREEN_H |
OHstin | 3:7666de697752 | 3 | |
OHstin | 3:7666de697752 | 4 | #include "LogManager.h" |
OHstin | 3:7666de697752 | 5 | |
OHstin | 3:7666de697752 | 6 | class DeleteLogScreen: public Button <DeleteLogScreen> |
OHstin | 3:7666de697752 | 7 | { |
OHstin | 3:7666de697752 | 8 | public: |
OHstin | 3:7666de697752 | 9 | DeleteLogScreen(uint16_t backgroundColor); // constructor |
OHstin | 3:7666de697752 | 10 | int start(); |
OHstin | 3:7666de697752 | 11 | void buttonPressed(int button); |
OHstin | 3:7666de697752 | 12 | private: |
OHstin | 3:7666de697752 | 13 | void getLogRecords(); // this function fills the Log Array with records available |
OHstin | 3:7666de697752 | 14 | void displayRecords(); // displays the available records |
OHstin | 3:7666de697752 | 15 | void deleteRecord(int id); // deletes the selected record |
OHstin | 3:7666de697752 | 16 | void emptyRecords(); // empty the array that stores the records |
OHstin | 3:7666de697752 | 17 | ListController *list; // this is the list used to display the logs |
OHstin | 3:7666de697752 | 18 | LogRecord records[4]; // array that stores a maximum of 4 log records |
OHstin | 3:7666de697752 | 19 | int numberOfRecords; // stores the number of records to show |
OHstin | 3:7666de697752 | 20 | int changeScreen; |
OHstin | 3:7666de697752 | 21 | uint16_t backgroundColor; // stores the background color |
OHstin | 3:7666de697752 | 22 | // updated when a scroll event occurs |
OHstin | 3:7666de697752 | 23 | bool scroll; |
OHstin | 3:7666de697752 | 24 | // updated when an enter event occurs |
OHstin | 3:7666de697752 | 25 | bool enter; |
OHstin | 3:7666de697752 | 26 | |
OHstin | 3:7666de697752 | 27 | }; |
OHstin | 3:7666de697752 | 28 | |
OHstin | 3:7666de697752 | 29 | DeleteLogScreen::DeleteLogScreen(uint16_t bgColor) |
OHstin | 3:7666de697752 | 30 | { |
OHstin | 3:7666de697752 | 31 | backgroundColor = bgColor; |
OHstin | 3:7666de697752 | 32 | } |
OHstin | 3:7666de697752 | 33 | |
OHstin | 3:7666de697752 | 34 | int DeleteLogScreen::start() |
OHstin | 3:7666de697752 | 35 | { |
OHstin | 3:7666de697752 | 36 | // retireves the Log Records |
OHstin | 3:7666de697752 | 37 | getLogRecords(); |
OHstin | 3:7666de697752 | 38 | // display those records on a list controller |
OHstin | 3:7666de697752 | 39 | displayRecords(); |
OHstin | 3:7666de697752 | 40 | |
OHstin | 3:7666de697752 | 41 | // attach interrupts to buttons |
OHstin | 3:7666de697752 | 42 | Button<DeleteLogScreen>::activateButtons(this); |
OHstin | 3:7666de697752 | 43 | |
OHstin | 3:7666de697752 | 44 | changeScreen = 0; |
OHstin | 3:7666de697752 | 45 | scroll = false; |
OHstin | 3:7666de697752 | 46 | enter = false; |
OHstin | 3:7666de697752 | 47 | |
OHstin | 3:7666de697752 | 48 | // have the infinite while loop that waits for an event |
OHstin | 3:7666de697752 | 49 | while (changeScreen == 0) { |
OHstin | 3:7666de697752 | 50 | |
OHstin | 3:7666de697752 | 51 | // scroll event occured |
OHstin | 3:7666de697752 | 52 | if (scroll) |
OHstin | 3:7666de697752 | 53 | { |
OHstin | 3:7666de697752 | 54 | // perform scroll on the list |
OHstin | 3:7666de697752 | 55 | list->scroll(); |
OHstin | 3:7666de697752 | 56 | // reset the variable |
OHstin | 3:7666de697752 | 57 | scroll = false; |
OHstin | 3:7666de697752 | 58 | |
OHstin | 3:7666de697752 | 59 | } |
OHstin | 3:7666de697752 | 60 | |
OHstin | 3:7666de697752 | 61 | // enter event occured |
OHstin | 3:7666de697752 | 62 | if (enter) |
OHstin | 3:7666de697752 | 63 | { |
OHstin | 3:7666de697752 | 64 | // delete the appropriate record |
OHstin | 3:7666de697752 | 65 | deleteRecord(list->getCurrentOption()); |
OHstin | 3:7666de697752 | 66 | changeScreen = -1; |
OHstin | 3:7666de697752 | 67 | } |
OHstin | 3:7666de697752 | 68 | |
OHstin | 3:7666de697752 | 69 | //wait_ms(500); |
OHstin | 3:7666de697752 | 70 | Thread::wait(200); |
OHstin | 3:7666de697752 | 71 | } |
OHstin | 3:7666de697752 | 72 | |
OHstin | 3:7666de697752 | 73 | // release memory back to heap |
OHstin | 3:7666de697752 | 74 | delete list; |
OHstin | 3:7666de697752 | 75 | |
OHstin | 3:7666de697752 | 76 | // empty records |
OHstin | 3:7666de697752 | 77 | emptyRecords(); |
OHstin | 3:7666de697752 | 78 | |
OHstin | 3:7666de697752 | 79 | // dettach interrupts to buttons |
OHstin | 3:7666de697752 | 80 | Button<DeleteLogScreen>::deActivateButtons(); |
OHstin | 3:7666de697752 | 81 | |
OHstin | 3:7666de697752 | 82 | return changeScreen; |
OHstin | 3:7666de697752 | 83 | } |
OHstin | 3:7666de697752 | 84 | |
OHstin | 3:7666de697752 | 85 | void DeleteLogScreen::getLogRecords() |
OHstin | 3:7666de697752 | 86 | { |
OHstin | 3:7666de697752 | 87 | |
OHstin | 3:7666de697752 | 88 | // create a Log Manager object |
OHstin | 3:7666de697752 | 89 | // send the reference of the records array and Log Manager |
OHstin | 3:7666de697752 | 90 | // will fill it with available records |
OHstin | 3:7666de697752 | 91 | // it returns the number of records availble |
OHstin | 3:7666de697752 | 92 | LogManager manager; |
OHstin | 3:7666de697752 | 93 | numberOfRecords = manager.retrieveLog(records); |
OHstin | 3:7666de697752 | 94 | |
OHstin | 3:7666de697752 | 95 | // arrange records with according to time. The latest record first |
OHstin | 3:7666de697752 | 96 | if(numberOfRecords > 1) { |
OHstin | 3:7666de697752 | 97 | for(int i = 0; i < (numberOfRecords-1); i++) { |
OHstin | 3:7666de697752 | 98 | // compare a given record with all proceding records |
OHstin | 3:7666de697752 | 99 | for( int j = 0; j < (numberOfRecords-1); j++) { |
OHstin | 3:7666de697752 | 100 | // check if the time of recording is earlier than the record of interest |
OHstin | 3:7666de697752 | 101 | if(records[i].getTimeStamp() < records[j+1].getTimeStamp()) { |
OHstin | 3:7666de697752 | 102 | // swap records |
OHstin | 3:7666de697752 | 103 | LogRecord record = records[i]; |
OHstin | 3:7666de697752 | 104 | records[i] = records[j+1]; |
OHstin | 3:7666de697752 | 105 | records[j+1] = record; |
OHstin | 3:7666de697752 | 106 | } |
OHstin | 3:7666de697752 | 107 | } |
OHstin | 3:7666de697752 | 108 | } |
OHstin | 3:7666de697752 | 109 | |
OHstin | 3:7666de697752 | 110 | } |
OHstin | 3:7666de697752 | 111 | |
OHstin | 3:7666de697752 | 112 | // use the data to construct a list controller with the data |
OHstin | 3:7666de697752 | 113 | } |
OHstin | 3:7666de697752 | 114 | |
OHstin | 3:7666de697752 | 115 | void DeleteLogScreen::displayRecords() |
OHstin | 3:7666de697752 | 116 | { |
OHstin | 3:7666de697752 | 117 | |
OHstin | 3:7666de697752 | 118 | myled2 = 1; |
OHstin | 3:7666de697752 | 119 | list = new ListController( 0, |
OHstin | 3:7666de697752 | 120 | 0, |
OHstin | 3:7666de697752 | 121 | "Logs", |
OHstin | 3:7666de697752 | 122 | records[0].getName(), |
OHstin | 3:7666de697752 | 123 | records[1].getName(), |
OHstin | 3:7666de697752 | 124 | records[2].getName(), |
OHstin | 3:7666de697752 | 125 | records[3].getName(), |
OHstin | 3:7666de697752 | 126 | backgroundColor, |
OHstin | 3:7666de697752 | 127 | numberOfRecords); |
OHstin | 3:7666de697752 | 128 | |
OHstin | 3:7666de697752 | 129 | |
OHstin | 3:7666de697752 | 130 | list->drawList(); |
OHstin | 3:7666de697752 | 131 | |
OHstin | 3:7666de697752 | 132 | } |
OHstin | 3:7666de697752 | 133 | |
OHstin | 3:7666de697752 | 134 | void DeleteLogScreen::deleteRecord(int id) |
OHstin | 3:7666de697752 | 135 | { |
OHstin | 3:7666de697752 | 136 | // deletes the record in the id |
OHstin | 3:7666de697752 | 137 | |
OHstin | 3:7666de697752 | 138 | LogManager manager; |
OHstin | 3:7666de697752 | 139 | manager.deleteLog(records[id-1]); |
OHstin | 3:7666de697752 | 140 | } |
OHstin | 3:7666de697752 | 141 | |
OHstin | 3:7666de697752 | 142 | void DeleteLogScreen::emptyRecords() |
OHstin | 3:7666de697752 | 143 | { |
OHstin | 3:7666de697752 | 144 | |
OHstin | 3:7666de697752 | 145 | for(int i = 0; i < 4; i++) |
OHstin | 3:7666de697752 | 146 | { |
OHstin | 3:7666de697752 | 147 | LogRecord record; // empty record |
OHstin | 3:7666de697752 | 148 | records[i] = record; // store empty record |
OHstin | 3:7666de697752 | 149 | } |
OHstin | 3:7666de697752 | 150 | |
OHstin | 3:7666de697752 | 151 | numberOfRecords = 0; // there are now no records left |
OHstin | 3:7666de697752 | 152 | } |
OHstin | 3:7666de697752 | 153 | |
OHstin | 3:7666de697752 | 154 | void DeleteLogScreen::buttonPressed(int button) |
OHstin | 3:7666de697752 | 155 | { |
OHstin | 3:7666de697752 | 156 | switch(button) { |
OHstin | 3:7666de697752 | 157 | |
OHstin | 3:7666de697752 | 158 | case BACKBUTTON: |
OHstin | 3:7666de697752 | 159 | // navigate to the previous screen |
OHstin | 3:7666de697752 | 160 | changeScreen = -1; |
OHstin | 3:7666de697752 | 161 | break; |
OHstin | 3:7666de697752 | 162 | |
OHstin | 3:7666de697752 | 163 | case SCROLLBUTTON: |
OHstin | 3:7666de697752 | 164 | // scroll to the next option |
OHstin | 3:7666de697752 | 165 | scroll = true; |
OHstin | 3:7666de697752 | 166 | break; |
OHstin | 3:7666de697752 | 167 | |
OHstin | 3:7666de697752 | 168 | case ENTERBUTTON: |
OHstin | 3:7666de697752 | 169 | // navigate to the selected option |
OHstin | 3:7666de697752 | 170 | //changeScreen = ListController::getCurrentOption(); |
OHstin | 3:7666de697752 | 171 | enter = true; |
OHstin | 3:7666de697752 | 172 | break; |
OHstin | 3:7666de697752 | 173 | |
OHstin | 3:7666de697752 | 174 | default: |
OHstin | 3:7666de697752 | 175 | // do nothing |
OHstin | 3:7666de697752 | 176 | break; |
OHstin | 3:7666de697752 | 177 | } |
OHstin | 3:7666de697752 | 178 | } |
OHstin | 3:7666de697752 | 179 | #endif |