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

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?

UserRevisionLine numberNew contents of line
OHstin 3:7666de697752 1 #ifndef VIEWLOGSCREEN_H
OHstin 3:7666de697752 2 #define VIEWLOGSCREEN_H
OHstin 3:7666de697752 3
OHstin 3:7666de697752 4 #include "ListController.h"
OHstin 3:7666de697752 5 #include "LogManager.h"
OHstin 3:7666de697752 6 #include "RecordScreen.h"
OHstin 3:7666de697752 7
OHstin 3:7666de697752 8 class ViewLogScreen: public Button <ViewLogScreen>
OHstin 3:7666de697752 9 {
OHstin 3:7666de697752 10 public:
OHstin 3:7666de697752 11 ViewLogScreen(uint16_t backgroundColor); // constructor
OHstin 3:7666de697752 12 int start();
OHstin 3:7666de697752 13 void buttonPressed(int button);
OHstin 3:7666de697752 14 private:
OHstin 3:7666de697752 15 void getLogRecords(); // this function fills the Log Array with records available
OHstin 3:7666de697752 16 void displayRecords(); // displays the available records
OHstin 3:7666de697752 17 void emptyRecords(); // empty the array that stores the records
OHstin 3:7666de697752 18 ListController *list; // this is the list used to display the logs
OHstin 3:7666de697752 19 LogRecord records[4]; // array that stores a maximum of 4 log records
OHstin 3:7666de697752 20 int numberOfRecords; // stores the number of records to show
OHstin 3:7666de697752 21 int changeScreen;
OHstin 3:7666de697752 22 uint16_t backgroundColor; // stores the background color
OHstin 3:7666de697752 23 bool showDetails; // knows when it is time to show a record's details
OHstin 6:196a63a3378d 24 bool scroll;
OHstin 3:7666de697752 25 };
OHstin 3:7666de697752 26
OHstin 3:7666de697752 27 ViewLogScreen::ViewLogScreen(uint16_t bgColor)
OHstin 3:7666de697752 28 {
OHstin 3:7666de697752 29 backgroundColor = bgColor;
OHstin 3:7666de697752 30 }
OHstin 3:7666de697752 31
OHstin 3:7666de697752 32 int ViewLogScreen::start()
OHstin 3:7666de697752 33 {
OHstin 3:7666de697752 34 // retireves the Log Records
OHstin 3:7666de697752 35 getLogRecords();
OHstin 3:7666de697752 36 // display those records on a list controller
OHstin 3:7666de697752 37 displayRecords();
OHstin 3:7666de697752 38
OHstin 3:7666de697752 39 // attach interrupts to buttons
OHstin 3:7666de697752 40 Button<ViewLogScreen>::activateButtons(this);
OHstin 3:7666de697752 41
OHstin 3:7666de697752 42 changeScreen = 0;
OHstin 3:7666de697752 43 showDetails = false;
OHstin 3:7666de697752 44
OHstin 3:7666de697752 45 // have the infinite while loop that waits for an event
OHstin 3:7666de697752 46 while (changeScreen == 0) {
OHstin 3:7666de697752 47 //updateTile();
OHstin 3:7666de697752 48 //wait_ms(250);
OHstin 6:196a63a3378d 49 Thread::wait(250);
OHstin 6:196a63a3378d 50
OHstin 6:196a63a3378d 51 if (scroll){
OHstin 6:196a63a3378d 52 list->scroll();
OHstin 6:196a63a3378d 53 scroll = false;
OHstin 6:196a63a3378d 54 }
OHstin 3:7666de697752 55
OHstin 3:7666de697752 56 if(showDetails && (numberOfRecords>0)) {
OHstin 3:7666de697752 57 // first deactivate the buttons
OHstin 3:7666de697752 58 Button<ViewLogScreen>::deActivateButtons();
OHstin 3:7666de697752 59
OHstin 3:7666de697752 60 // then clear the screen
OHstin 3:7666de697752 61 tft.fillScreen(backgroundColor);
OHstin 3:7666de697752 62
OHstin 3:7666de697752 63 // get the option selected
OHstin 3:7666de697752 64 int detail = (list->getCurrentOption())-1;
OHstin 3:7666de697752 65
OHstin 3:7666de697752 66 // create record screen object
OHstin 3:7666de697752 67 RecordScreen recordScreen(backgroundColor);
OHstin 3:7666de697752 68
OHstin 3:7666de697752 69 // launch record screen with appropriate object
OHstin 3:7666de697752 70 recordScreen.start(records[detail]);
OHstin 3:7666de697752 71
OHstin 3:7666de697752 72 // recativate the buttons
OHstin 3:7666de697752 73 Button<ViewLogScreen>::activateButtons(this);
OHstin 3:7666de697752 74
OHstin 3:7666de697752 75 // then clear the screen
OHstin 3:7666de697752 76 tft.fillScreen(backgroundColor);
OHstin 3:7666de697752 77
OHstin 3:7666de697752 78 // show the data again
OHstin 3:7666de697752 79 list->drawList();
OHstin 3:7666de697752 80
OHstin 3:7666de697752 81 // reset flag
OHstin 3:7666de697752 82 showDetails = false;
OHstin 3:7666de697752 83 }
OHstin 3:7666de697752 84 }
OHstin 3:7666de697752 85
OHstin 3:7666de697752 86 // release memory back to heap
OHstin 3:7666de697752 87 delete list;
OHstin 3:7666de697752 88
OHstin 3:7666de697752 89 // empty the records array
OHstin 3:7666de697752 90 emptyRecords();
OHstin 3:7666de697752 91
OHstin 3:7666de697752 92 // dettach interrupts to buttons
OHstin 3:7666de697752 93 Button<ViewLogScreen>::deActivateButtons();
OHstin 3:7666de697752 94
OHstin 3:7666de697752 95 return changeScreen;
OHstin 3:7666de697752 96 }
OHstin 3:7666de697752 97
OHstin 3:7666de697752 98 void ViewLogScreen::getLogRecords()
OHstin 3:7666de697752 99 {
OHstin 3:7666de697752 100
OHstin 3:7666de697752 101 // create a Log Manager object
OHstin 3:7666de697752 102 // send the reference of the records array and Log Manager
OHstin 3:7666de697752 103 // will fill it with available records
OHstin 3:7666de697752 104 // it returns the number of records availble
OHstin 3:7666de697752 105 LogManager manager;
OHstin 3:7666de697752 106 numberOfRecords = manager.retrieveLog(records);
OHstin 3:7666de697752 107
OHstin 3:7666de697752 108 // arrange records with according to time. The latest record first
OHstin 3:7666de697752 109 if(numberOfRecords > 1) {
OHstin 3:7666de697752 110 for(int i = 0; i < (numberOfRecords-1); i++) {
OHstin 3:7666de697752 111 // compare a given record with all proceding records
OHstin 3:7666de697752 112 for( int j = 0; j < (numberOfRecords-1); j++) {
OHstin 3:7666de697752 113 // check if the time of recording is earlier than the record of interest
OHstin 3:7666de697752 114 if(records[i].getTimeStamp() < records[j+1].getTimeStamp()) {
OHstin 3:7666de697752 115 // swap records
OHstin 3:7666de697752 116 LogRecord record = records[i];
OHstin 3:7666de697752 117 records[i] = records[j+1];
OHstin 3:7666de697752 118 records[j+1] = record;
OHstin 3:7666de697752 119 }
OHstin 3:7666de697752 120 }
OHstin 3:7666de697752 121 }
OHstin 3:7666de697752 122
OHstin 3:7666de697752 123 }
OHstin 3:7666de697752 124
OHstin 3:7666de697752 125
OHstin 3:7666de697752 126 // use the data to construct a list controller with the data
OHstin 3:7666de697752 127 }
OHstin 3:7666de697752 128
OHstin 3:7666de697752 129 void ViewLogScreen::displayRecords()
OHstin 3:7666de697752 130 {
OHstin 3:7666de697752 131
OHstin 3:7666de697752 132 myled2 = 1;
OHstin 3:7666de697752 133 list = new ListController( 0,
OHstin 3:7666de697752 134 0,
OHstin 3:7666de697752 135 "Logs",
OHstin 3:7666de697752 136 records[0].getName(),
OHstin 3:7666de697752 137 records[1].getName(),
OHstin 3:7666de697752 138 records[2].getName(),
OHstin 3:7666de697752 139 records[3].getName(),
OHstin 3:7666de697752 140 backgroundColor,
OHstin 3:7666de697752 141 numberOfRecords);
OHstin 3:7666de697752 142
OHstin 3:7666de697752 143
OHstin 3:7666de697752 144 list->drawList();
OHstin 3:7666de697752 145
OHstin 3:7666de697752 146 }
OHstin 3:7666de697752 147
OHstin 3:7666de697752 148 void ViewLogScreen::emptyRecords()
OHstin 3:7666de697752 149 {
OHstin 3:7666de697752 150
OHstin 3:7666de697752 151 for(int i = 0; i < 4; i++) {
OHstin 3:7666de697752 152 LogRecord record; // empty record
OHstin 3:7666de697752 153 records[i] = record; // store empty record
OHstin 3:7666de697752 154 }
OHstin 3:7666de697752 155
OHstin 3:7666de697752 156 numberOfRecords = 0; // there are now no records left
OHstin 3:7666de697752 157 }
OHstin 3:7666de697752 158
OHstin 3:7666de697752 159 void ViewLogScreen::buttonPressed(int button)
OHstin 3:7666de697752 160 {
OHstin 3:7666de697752 161 switch(button) {
OHstin 3:7666de697752 162
OHstin 3:7666de697752 163 case BACKBUTTON:
OHstin 3:7666de697752 164 // navigate to the previous screen
OHstin 3:7666de697752 165 changeScreen = -1;
OHstin 3:7666de697752 166 break;
OHstin 3:7666de697752 167
OHstin 3:7666de697752 168 case SCROLLBUTTON:
OHstin 3:7666de697752 169 // scroll to the next option
OHstin 6:196a63a3378d 170 //list->scroll();
OHstin 6:196a63a3378d 171 scroll = true;
OHstin 3:7666de697752 172 break;
OHstin 3:7666de697752 173
OHstin 3:7666de697752 174 case ENTERBUTTON:
OHstin 3:7666de697752 175 // navigate to the selected option
OHstin 3:7666de697752 176 //changeScreen = ListController::getCurrentOption();
OHstin 3:7666de697752 177 showDetails = true;
OHstin 6:196a63a3378d 178 break;
OHstin 3:7666de697752 179
OHstin 3:7666de697752 180 default:
OHstin 3:7666de697752 181 // do nothing
OHstin 3:7666de697752 182 break;
OHstin 3:7666de697752 183 }
OHstin 3:7666de697752 184 }
OHstin 3:7666de697752 185
OHstin 3:7666de697752 186
OHstin 3:7666de697752 187 #endif