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:
Wed Mar 22 21:07:07 2017 +0000
Revision:
4:c7b0670f96b2
Parent:
3:7666de697752
Child:
6:196a63a3378d
Version Before Perf Board Transfer

Who changed what in which revision?

UserRevisionLine numberNew contents of line
OHstin 3:7666de697752 1 #ifndef OUTPUTSCREEN_H
OHstin 3:7666de697752 2 #define OUTPUTSCREEN_H
OHstin 3:7666de697752 3
OHstin 3:7666de697752 4 #include "ListController.h"
OHstin 3:7666de697752 5
OHstin 3:7666de697752 6 class OutputScreen:public Button <OutputScreen>
OHstin 3:7666de697752 7 {
OHstin 3:7666de697752 8 public:
OHstin 3:7666de697752 9 OutputScreen(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 drawOutputScreen();
OHstin 3:7666de697752 15 void drawTile();
OHstin 3:7666de697752 16
OHstin 3:7666de697752 17 int changeScreen;
OHstin 3:7666de697752 18 ListController *list; // manages the list
OHstin 3:7666de697752 19 bool scroll; // updated when a scroll event occurs
OHstin 3:7666de697752 20 bool enter; // updated when an enter event occurs
OHstin 3:7666de697752 21 uint16_t bgColor; // background color
OHstin 3:7666de697752 22
OHstin 3:7666de697752 23 };
OHstin 3:7666de697752 24
OHstin 3:7666de697752 25 OutputScreen::OutputScreen(uint16_t backgroundColor)
OHstin 3:7666de697752 26 {
OHstin 3:7666de697752 27
OHstin 3:7666de697752 28 bgColor = backgroundColor;
OHstin 3:7666de697752 29 }
OHstin 3:7666de697752 30
OHstin 3:7666de697752 31 int OutputScreen::start()
OHstin 3:7666de697752 32 {
OHstin 3:7666de697752 33
OHstin 3:7666de697752 34 // draw the screen
OHstin 3:7666de697752 35 drawOutputScreen();
OHstin 3:7666de697752 36
OHstin 3:7666de697752 37 // attach interrupts to buttons
OHstin 3:7666de697752 38 Button<OutputScreen>::activateButtons(this);
OHstin 3:7666de697752 39
OHstin 3:7666de697752 40 changeScreen = 0;
OHstin 3:7666de697752 41 scroll = false;
OHstin 3:7666de697752 42 enter = false;
OHstin 3:7666de697752 43
OHstin 3:7666de697752 44
OHstin 3:7666de697752 45 while (changeScreen == 0) {
OHstin 3:7666de697752 46 //updateTile();
OHstin 3:7666de697752 47
OHstin 3:7666de697752 48 // scroll event occured
OHstin 3:7666de697752 49 if (scroll) {
OHstin 3:7666de697752 50 // perform scroll on the list
OHstin 3:7666de697752 51 list->scroll();
OHstin 3:7666de697752 52 // reset variable
OHstin 3:7666de697752 53 scroll = false;
OHstin 3:7666de697752 54 }
OHstin 3:7666de697752 55
OHstin 3:7666de697752 56 // enter event occured
OHstin 3:7666de697752 57 if (enter) {
OHstin 3:7666de697752 58 // read the current option on the list
OHstin 3:7666de697752 59 changeScreen = list->getCurrentOption();
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 // release the memory held by the list
OHstin 3:7666de697752 66 delete list;
OHstin 3:7666de697752 67
OHstin 3:7666de697752 68 // dettach interrupts to buttons
OHstin 3:7666de697752 69 Button<OutputScreen>::deActivateButtons();
OHstin 3:7666de697752 70
OHstin 3:7666de697752 71 return changeScreen;
OHstin 3:7666de697752 72 }
OHstin 3:7666de697752 73
OHstin 3:7666de697752 74
OHstin 3:7666de697752 75 void OutputScreen::drawOutputScreen()
OHstin 3:7666de697752 76 {
OHstin 3:7666de697752 77
OHstin 3:7666de697752 78 // draw the tile
OHstin 3:7666de697752 79 drawTile();
OHstin 3:7666de697752 80
OHstin 3:7666de697752 81 // construct the list
OHstin 3:7666de697752 82 list = new ListController( 0,
OHstin 3:7666de697752 83 63,
OHstin 3:7666de697752 84 "Output",
OHstin 3:7666de697752 85 "Raspberry Pi",
OHstin 3:7666de697752 86 "Utility Port",
OHstin 3:7666de697752 87 "",
OHstin 3:7666de697752 88 "",
OHstin 3:7666de697752 89 backgroundColor,
OHstin 3:7666de697752 90 2);
OHstin 3:7666de697752 91
OHstin 3:7666de697752 92
OHstin 3:7666de697752 93 // draw the list
OHstin 3:7666de697752 94 list->drawList();
OHstin 3:7666de697752 95 //Button<BatteriesScreen>::activateButtons();
OHstin 3:7666de697752 96 }
OHstin 3:7666de697752 97
OHstin 3:7666de697752 98 void OutputScreen::drawTile()
OHstin 3:7666de697752 99 {
OHstin 3:7666de697752 100 // draw the tile background
OHstin 3:7666de697752 101 tft.fillRect(0,0,tft.width(),63,ST7735_YELLOW);
OHstin 3:7666de697752 102
OHstin 3:7666de697752 103 // the design of this tile is pending
OHstin 3:7666de697752 104 tft.setCursor(5,5);
OHstin 3:7666de697752 105 tft.setTextSize(1);
OHstin 3:7666de697752 106 tft.setTextColor(ST7735_RED);
OHstin 3:7666de697752 107 tft.printf("To be designed!...");
OHstin 3:7666de697752 108 }
OHstin 3:7666de697752 109
OHstin 3:7666de697752 110 void OutputScreen::buttonPressed(int button)
OHstin 3:7666de697752 111 {
OHstin 3:7666de697752 112 switch(button) {
OHstin 3:7666de697752 113
OHstin 3:7666de697752 114 case BACKBUTTON:
OHstin 3:7666de697752 115 // navigate to the previous screen
OHstin 3:7666de697752 116 changeScreen = -1;
OHstin 3:7666de697752 117 break;
OHstin 3:7666de697752 118
OHstin 3:7666de697752 119 case SCROLLBUTTON:
OHstin 3:7666de697752 120 // scroll to the next option
OHstin 3:7666de697752 121 scroll = true;
OHstin 3:7666de697752 122 break;
OHstin 3:7666de697752 123
OHstin 3:7666de697752 124 case ENTERBUTTON:
OHstin 3:7666de697752 125 // navigate to the selected option
OHstin 3:7666de697752 126 //changeScreen = ListController::getCurrentOption();
OHstin 4:c7b0670f96b2 127 enter = true;
OHstin 4:c7b0670f96b2 128 break;
OHstin 3:7666de697752 129
OHstin 3:7666de697752 130 default:
OHstin 3:7666de697752 131 // do nothing
OHstin 3:7666de697752 132 break;
OHstin 3:7666de697752 133 }
OHstin 3:7666de697752 134 }
OHstin 3:7666de697752 135
OHstin 3:7666de697752 136 #endif