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 SETTINGSSCREEN_H
OHstin 3:7666de697752 2 #define SETTINGSSCREEN_H
OHstin 3:7666de697752 3
OHstin 3:7666de697752 4 #include "ListController.h"
OHstin 3:7666de697752 5
OHstin 3:7666de697752 6 class SettingsScreen: public Button <SettingsScreen>
OHstin 3:7666de697752 7 {
OHstin 3:7666de697752 8 public:
OHstin 3:7666de697752 9 SettingsScreen(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 drawSettingsScreen();
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 SettingsScreen::SettingsScreen(uint16_t backgroundColor)
OHstin 3:7666de697752 24 {
OHstin 3:7666de697752 25
OHstin 3:7666de697752 26 bgColor = backgroundColor;
OHstin 3:7666de697752 27 }
OHstin 3:7666de697752 28
OHstin 3:7666de697752 29 int SettingsScreen::start()
OHstin 3:7666de697752 30 {
OHstin 3:7666de697752 31
OHstin 3:7666de697752 32 // draw the screen
OHstin 3:7666de697752 33 drawSettingsScreen();
OHstin 3:7666de697752 34
OHstin 3:7666de697752 35 // attach interrupts to buttons
OHstin 3:7666de697752 36 Button<SettingsScreen>::activateButtons(this);
OHstin 3:7666de697752 37
OHstin 3:7666de697752 38 changeScreen = 0;
OHstin 3:7666de697752 39 scroll = false;
OHstin 3:7666de697752 40 enter = false;
OHstin 3:7666de697752 41
OHstin 3:7666de697752 42
OHstin 3:7666de697752 43 while (changeScreen == 0) {
OHstin 3:7666de697752 44 //updateTile();
OHstin 3:7666de697752 45 // scroll event occured
OHstin 3:7666de697752 46 if (scroll) {
OHstin 3:7666de697752 47 // perform scroll on the list
OHstin 3:7666de697752 48 list->scroll();
OHstin 3:7666de697752 49 // reset variable
OHstin 3:7666de697752 50 scroll = false;
OHstin 3:7666de697752 51 }
OHstin 3:7666de697752 52
OHstin 3:7666de697752 53 // enter event occured
OHstin 3:7666de697752 54 if (enter) {
OHstin 3:7666de697752 55 // read the current option on the list
OHstin 3:7666de697752 56 changeScreen = list->getCurrentOption();
OHstin 3:7666de697752 57 }
OHstin 3:7666de697752 58 //wait_ms(500);
OHstin 3:7666de697752 59 Thread::wait(200);
OHstin 3:7666de697752 60 }
OHstin 3:7666de697752 61
OHstin 3:7666de697752 62 // release memory occupied by list controller
OHstin 3:7666de697752 63 delete list;
OHstin 3:7666de697752 64
OHstin 3:7666de697752 65 // dettach interrupts to buttons
OHstin 3:7666de697752 66 Button<SettingsScreen>::deActivateButtons();
OHstin 3:7666de697752 67
OHstin 3:7666de697752 68 return changeScreen;
OHstin 3:7666de697752 69 }
OHstin 3:7666de697752 70
OHstin 3:7666de697752 71 void SettingsScreen::drawSettingsScreen()
OHstin 3:7666de697752 72 {
OHstin 3:7666de697752 73
OHstin 3:7666de697752 74 // construct the list
OHstin 6:196a63a3378d 75
OHstin 6:196a63a3378d 76 /**
OHstin 3:7666de697752 77 list = new ListController( 0,
OHstin 3:7666de697752 78 0,
OHstin 3:7666de697752 79 "Settings",
OHstin 3:7666de697752 80 "LCD Screen",
OHstin 3:7666de697752 81 "Data Logs",
OHstin 3:7666de697752 82 "",
OHstin 3:7666de697752 83 "",
OHstin 3:7666de697752 84 backgroundColor,
OHstin 3:7666de697752 85 2);
OHstin 6:196a63a3378d 86
OHstin 6:196a63a3378d 87 **/
OHstin 6:196a63a3378d 88
OHstin 6:196a63a3378d 89 list = new ListController( 0,
OHstin 6:196a63a3378d 90 0,
OHstin 6:196a63a3378d 91 "Settings",
OHstin 6:196a63a3378d 92 "LCD Screen",
OHstin 6:196a63a3378d 93 "",
OHstin 6:196a63a3378d 94 "",
OHstin 6:196a63a3378d 95 "",
OHstin 6:196a63a3378d 96 backgroundColor,
OHstin 6:196a63a3378d 97 1);
OHstin 3:7666de697752 98
OHstin 3:7666de697752 99 // draw the list
OHstin 3:7666de697752 100 list->drawList();
OHstin 3:7666de697752 101 }
OHstin 3:7666de697752 102
OHstin 3:7666de697752 103 void SettingsScreen::buttonPressed(int button)
OHstin 3:7666de697752 104 {
OHstin 3:7666de697752 105 switch(button) {
OHstin 3:7666de697752 106
OHstin 3:7666de697752 107 case BACKBUTTON:
OHstin 3:7666de697752 108 // navigate to the previous screen
OHstin 3:7666de697752 109 changeScreen = -1;
OHstin 3:7666de697752 110 break;
OHstin 3:7666de697752 111
OHstin 3:7666de697752 112 case SCROLLBUTTON:
OHstin 3:7666de697752 113 // scroll to the next option
OHstin 3:7666de697752 114 scroll = true;
OHstin 3:7666de697752 115 break;
OHstin 3:7666de697752 116
OHstin 3:7666de697752 117 case ENTERBUTTON:
OHstin 3:7666de697752 118 // navigate to the selected option
OHstin 3:7666de697752 119 enter = true;
OHstin 3:7666de697752 120
OHstin 3:7666de697752 121 default:
OHstin 3:7666de697752 122 // do nothing
OHstin 3:7666de697752 123 break;
OHstin 3:7666de697752 124 }
OHstin 3:7666de697752 125 }
OHstin 3:7666de697752 126
OHstin 3:7666de697752 127 #endif