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 LOGSELECTSCREEN_H
OHstin 3:7666de697752 2 #define LOGSELECTSCREEN_H
OHstin 3:7666de697752 3
OHstin 3:7666de697752 4 #include "ListController.h"
OHstin 3:7666de697752 5
OHstin 3:7666de697752 6 class LogSelectScreen: public Button <LogSelectScreen>
OHstin 3:7666de697752 7 {
OHstin 3:7666de697752 8 public:
OHstin 3:7666de697752 9 LogSelectScreen(uint16_t backgroundColor);
OHstin 3:7666de697752 10 int start();
OHstin 3:7666de697752 11 void buttonPressed(int button);
OHstin 3:7666de697752 12
OHstin 3:7666de697752 13 private:
OHstin 3:7666de697752 14 void drawLogSelectScreen();
OHstin 3:7666de697752 15 int changeScreen;
OHstin 3:7666de697752 16 ListController *list; // manages the list
OHstin 3:7666de697752 17 bool scroll; // updated when a scroll event occurs
OHstin 3:7666de697752 18 bool enter; // updated when an enter event occurs
OHstin 3:7666de697752 19 uint16_t bgColor; // background color
OHstin 3:7666de697752 20
OHstin 3:7666de697752 21 };
OHstin 3:7666de697752 22
OHstin 3:7666de697752 23 LogSelectScreen::LogSelectScreen(uint16_t backgroundColor)
OHstin 3:7666de697752 24 {
OHstin 3:7666de697752 25 bgColor = backgroundColor;
OHstin 3:7666de697752 26
OHstin 3:7666de697752 27 }
OHstin 3:7666de697752 28
OHstin 3:7666de697752 29 int LogSelectScreen::start(){
OHstin 3:7666de697752 30
OHstin 3:7666de697752 31 // draw the screen
OHstin 3:7666de697752 32 drawLogSelectScreen();
OHstin 3:7666de697752 33
OHstin 3:7666de697752 34 // attach interrupts to buttons
OHstin 3:7666de697752 35 Button<LogSelectScreen>::activateButtons(this);
OHstin 3:7666de697752 36
OHstin 3:7666de697752 37 changeScreen = 0;
OHstin 3:7666de697752 38 scroll = false;
OHstin 3:7666de697752 39 enter = false;
OHstin 3:7666de697752 40
OHstin 3:7666de697752 41
OHstin 3:7666de697752 42 while (changeScreen == 0){
OHstin 3:7666de697752 43 //updateTile();
OHstin 3:7666de697752 44
OHstin 3:7666de697752 45 // scroll event occured
OHstin 3:7666de697752 46 if (scroll)
OHstin 3:7666de697752 47 {
OHstin 3:7666de697752 48 // perfrom scroll on the list
OHstin 3:7666de697752 49 list->scroll();
OHstin 3:7666de697752 50 // reset variable
OHstin 3:7666de697752 51 scroll = false;
OHstin 3:7666de697752 52 }
OHstin 3:7666de697752 53
OHstin 3:7666de697752 54 // enter event occured
OHstin 3:7666de697752 55 if (enter)
OHstin 3:7666de697752 56 {
OHstin 3:7666de697752 57 // read the current option on the list
OHstin 3:7666de697752 58 changeScreen = list->getCurrentOption();
OHstin 3:7666de697752 59 }
OHstin 3:7666de697752 60
OHstin 3:7666de697752 61 //wait_ms(500);
OHstin 3:7666de697752 62 Thread::wait(200);
OHstin 3:7666de697752 63 }
OHstin 3:7666de697752 64
OHstin 3:7666de697752 65 // relese memory occupied by list
OHstin 3:7666de697752 66 delete list;
OHstin 3:7666de697752 67
OHstin 3:7666de697752 68 // dettach interrupts to buttons
OHstin 3:7666de697752 69 Button<LogSelectScreen>::deActivateButtons();
OHstin 3:7666de697752 70
OHstin 3:7666de697752 71 return changeScreen;
OHstin 3:7666de697752 72 }
OHstin 3:7666de697752 73
OHstin 3:7666de697752 74 void LogSelectScreen::drawLogSelectScreen(){
OHstin 3:7666de697752 75
OHstin 3:7666de697752 76 // construct the list
OHstin 3:7666de697752 77 list = new ListController( 0,
OHstin 3:7666de697752 78 0,
OHstin 3:7666de697752 79 "Parameter",
OHstin 3:7666de697752 80 "Solar",
OHstin 3:7666de697752 81 "Power Usage",
OHstin 3:7666de697752 82 "",
OHstin 3:7666de697752 83 "",
OHstin 3:7666de697752 84 bgColor,
OHstin 3:7666de697752 85 2);
OHstin 3:7666de697752 86
OHstin 3:7666de697752 87 // draw the list
OHstin 3:7666de697752 88 list->drawList();
OHstin 3:7666de697752 89 }
OHstin 3:7666de697752 90
OHstin 3:7666de697752 91 void LogSelectScreen::buttonPressed(int button)
OHstin 3:7666de697752 92 {
OHstin 3:7666de697752 93 switch(button){
OHstin 3:7666de697752 94
OHstin 3:7666de697752 95 case BACKBUTTON:
OHstin 3:7666de697752 96 // navigate to the previous screen
OHstin 3:7666de697752 97 changeScreen = -1;
OHstin 3:7666de697752 98 break;
OHstin 3:7666de697752 99
OHstin 3:7666de697752 100 case SCROLLBUTTON:
OHstin 3:7666de697752 101 // scroll to the next option
OHstin 3:7666de697752 102 scroll = true;
OHstin 3:7666de697752 103 break;
OHstin 3:7666de697752 104
OHstin 3:7666de697752 105 case ENTERBUTTON:
OHstin 3:7666de697752 106 // navigate to the selected option
OHstin 3:7666de697752 107 enter = true;
OHstin 6:196a63a3378d 108 break;
OHstin 3:7666de697752 109
OHstin 3:7666de697752 110 default:
OHstin 3:7666de697752 111 // do nothing
OHstin 3:7666de697752 112 break;
OHstin 3:7666de697752 113 }
OHstin 3:7666de697752 114 }
OHstin 3:7666de697752 115
OHstin 3:7666de697752 116 #endif