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:
Sat Feb 04 20:17:44 2017 +0000
Revision:
3:7666de697752
Parent:
OutputIcon.h@2:104bec169fb6
This version before adding serial communication and pathways

Who changed what in which revision?

UserRevisionLine numberNew contents of line
OHstin 2:104bec169fb6 1 #ifndef OUTPUTICON_H
OHstin 2:104bec169fb6 2 #define OUTPUTICON_H
OHstin 2:104bec169fb6 3
OHstin 2:104bec169fb6 4 class OutputIcon
OHstin 2:104bec169fb6 5 {
OHstin 2:104bec169fb6 6 public:
OHstin 2:104bec169fb6 7 OutputIcon(uint8_t xCoordiate, uint8_t yCoordinate, uint16_t backgroundColor);
OHstin 2:104bec169fb6 8 void drawOutputIcon();
OHstin 2:104bec169fb6 9 void animateOutputIcon(bool outputing);
OHstin 2:104bec169fb6 10
OHstin 2:104bec169fb6 11 private:
OHstin 2:104bec169fb6 12 uint8_t startingWidth; // x coordinate of the centre of large circle
OHstin 2:104bec169fb6 13 uint8_t startingHeight; // y coordinate of the centre of large circle
OHstin 2:104bec169fb6 14 uint16_t bgColor;
OHstin 2:104bec169fb6 15 uint16_t drawColor;
OHstin 2:104bec169fb6 16 int colorCounter;
OHstin 2:104bec169fb6 17 bool outputIconAnimating;
OHstin 2:104bec169fb6 18
OHstin 2:104bec169fb6 19 void drawFilledRectangles();
OHstin 2:104bec169fb6 20 void animateRectangles();
OHstin 2:104bec169fb6 21
OHstin 2:104bec169fb6 22 };
OHstin 2:104bec169fb6 23
OHstin 2:104bec169fb6 24 OutputIcon::OutputIcon(uint8_t xCoordinate, uint8_t yCoordinate, uint16_t backgroundColor)
OHstin 2:104bec169fb6 25 : colorCounter(1),outputIconAnimating(false)
OHstin 2:104bec169fb6 26 {
OHstin 2:104bec169fb6 27 // set the centre of the big circle
OHstin 2:104bec169fb6 28 startingWidth = xCoordinate + 31;
OHstin 2:104bec169fb6 29 startingHeight = yCoordinate + 17;
OHstin 2:104bec169fb6 30
OHstin 2:104bec169fb6 31 bgColor = backgroundColor;
OHstin 2:104bec169fb6 32
OHstin 2:104bec169fb6 33 // determine the color of the lines on the solar panel
OHstin 2:104bec169fb6 34 if (bgColor == ST7735_WHITE ) {
OHstin 2:104bec169fb6 35 drawColor = ST7735_BLACK;
OHstin 2:104bec169fb6 36 } else if (bgColor == ST7735_BLACK) {
OHstin 2:104bec169fb6 37 drawColor = ST7735_WHITE;
OHstin 2:104bec169fb6 38 }
OHstin 2:104bec169fb6 39
OHstin 2:104bec169fb6 40
OHstin 2:104bec169fb6 41 }
OHstin 2:104bec169fb6 42
OHstin 2:104bec169fb6 43 void OutputIcon::drawOutputIcon()
OHstin 2:104bec169fb6 44 {
OHstin 2:104bec169fb6 45 // draw big circle
OHstin 2:104bec169fb6 46 tft.fillCircle(startingWidth, startingHeight, 17, drawColor);
OHstin 2:104bec169fb6 47
OHstin 2:104bec169fb6 48 // draw deleting rectangle to cut the circle in half
OHstin 2:104bec169fb6 49 tft.fillRect(startingWidth, startingHeight-17,18, 35, bgColor);
OHstin 2:104bec169fb6 50
OHstin 2:104bec169fb6 51 // draw rectangle extension of half circle
OHstin 2:104bec169fb6 52 tft.fillRect(startingWidth, startingHeight-17,5,35, drawColor);
OHstin 2:104bec169fb6 53
OHstin 2:104bec169fb6 54 // draw pin one
OHstin 2:104bec169fb6 55 tft.fillRect(startingWidth+5, startingHeight-10,12,5, drawColor);
OHstin 2:104bec169fb6 56
OHstin 2:104bec169fb6 57 // draw pin two
OHstin 2:104bec169fb6 58 tft.fillRect(startingWidth+5, startingHeight+7, 12, 5, drawColor);
OHstin 2:104bec169fb6 59
OHstin 2:104bec169fb6 60 // draw a small rounnd rectangle at the back of the circle
OHstin 2:104bec169fb6 61 tft.fillRoundRect(startingWidth-19, startingHeight-5,12,10,2, drawColor);
OHstin 2:104bec169fb6 62
OHstin 2:104bec169fb6 63 // draw empty rectangle one
OHstin 2:104bec169fb6 64 tft.drawRect(startingWidth-23, startingHeight-4,5,8,drawColor);
OHstin 2:104bec169fb6 65
OHstin 2:104bec169fb6 66 // draw empty rectangle two
OHstin 2:104bec169fb6 67 tft.drawRect(startingWidth-27, startingHeight-4,5,8,drawColor);
OHstin 2:104bec169fb6 68
OHstin 2:104bec169fb6 69 // draw empty rectangle three
OHstin 2:104bec169fb6 70 tft.drawRect(startingWidth-31, startingHeight-4,5,8,drawColor);
OHstin 2:104bec169fb6 71
OHstin 2:104bec169fb6 72 // draw the filled rectangles
OHstin 2:104bec169fb6 73 drawFilledRectangles();
OHstin 2:104bec169fb6 74 }
OHstin 2:104bec169fb6 75
OHstin 2:104bec169fb6 76 void OutputIcon::animateOutputIcon(bool outputing)
OHstin 2:104bec169fb6 77 {
OHstin 2:104bec169fb6 78 // check if any device is drawing power (outputing)
OHstin 2:104bec169fb6 79 if (outputing) {
OHstin 2:104bec169fb6 80
OHstin 2:104bec169fb6 81 // check if the output icon is not animating
OHstin 2:104bec169fb6 82 if (!outputIconAnimating) {
OHstin 2:104bec169fb6 83
OHstin 2:104bec169fb6 84 // the output icon is now animating
OHstin 2:104bec169fb6 85 outputIconAnimating = true;
OHstin 2:104bec169fb6 86
OHstin 2:104bec169fb6 87 // set to the second color arrangement
OHstin 2:104bec169fb6 88 colorCounter = 2;
OHstin 2:104bec169fb6 89
OHstin 2:104bec169fb6 90 // animate the filled rectangles
OHstin 2:104bec169fb6 91 animateRectangles();
OHstin 2:104bec169fb6 92 } else {
OHstin 2:104bec169fb6 93
OHstin 2:104bec169fb6 94 // continue animation
OHstin 2:104bec169fb6 95 animateRectangles();
OHstin 2:104bec169fb6 96
OHstin 2:104bec169fb6 97 }
OHstin 2:104bec169fb6 98 } else {
OHstin 2:104bec169fb6 99
OHstin 2:104bec169fb6 100 //check if output icon is animating
OHstin 2:104bec169fb6 101 if (outputIconAnimating) {
OHstin 2:104bec169fb6 102 // reset all the colors
OHstin 2:104bec169fb6 103 drawFilledRectangles();
OHstin 2:104bec169fb6 104 // stop any future animation
OHstin 2:104bec169fb6 105 outputIconAnimating = false;
OHstin 2:104bec169fb6 106 } else {
OHstin 2:104bec169fb6 107 // do nothing
OHstin 2:104bec169fb6 108 }
OHstin 2:104bec169fb6 109
OHstin 2:104bec169fb6 110 }
OHstin 2:104bec169fb6 111
OHstin 2:104bec169fb6 112 }
OHstin 2:104bec169fb6 113
OHstin 2:104bec169fb6 114 void OutputIcon::drawFilledRectangles()
OHstin 2:104bec169fb6 115 {
OHstin 2:104bec169fb6 116 // fill rectangle one
OHstin 2:104bec169fb6 117 tft.fillRect(startingWidth-22, startingHeight-3,3,6,ST7735_GREEN);
OHstin 2:104bec169fb6 118
OHstin 2:104bec169fb6 119 // fill rectangle two
OHstin 2:104bec169fb6 120 tft.fillRect(startingWidth-26, startingHeight-3,3,6,ST7735_YELLOW);
OHstin 2:104bec169fb6 121
OHstin 2:104bec169fb6 122 // fill rectangle three
OHstin 2:104bec169fb6 123 tft.fillRect(startingWidth-30, startingHeight-3,3,6, ST7735_RED);
OHstin 2:104bec169fb6 124 }
OHstin 2:104bec169fb6 125
OHstin 2:104bec169fb6 126 void OutputIcon::animateRectangles()
OHstin 2:104bec169fb6 127 {
OHstin 2:104bec169fb6 128 if(colorCounter == 1) {
OHstin 2:104bec169fb6 129 // green
OHstin 2:104bec169fb6 130 // yellow
OHstin 2:104bec169fb6 131 // red
OHstin 2:104bec169fb6 132 drawFilledRectangles();
OHstin 2:104bec169fb6 133 } else if (colorCounter == 2) {
OHstin 2:104bec169fb6 134 // red
OHstin 2:104bec169fb6 135 // green
OHstin 2:104bec169fb6 136 // yellow
OHstin 2:104bec169fb6 137
OHstin 2:104bec169fb6 138 // fill rectangle one
OHstin 2:104bec169fb6 139 tft.fillRect(startingWidth-22, startingHeight-3,3,6,ST7735_RED);
OHstin 2:104bec169fb6 140
OHstin 2:104bec169fb6 141 // fill rectangle two
OHstin 2:104bec169fb6 142 tft.fillRect(startingWidth-26, startingHeight-3,3,6,ST7735_GREEN);
OHstin 2:104bec169fb6 143
OHstin 2:104bec169fb6 144 // fill rectangle three
OHstin 2:104bec169fb6 145 tft.fillRect(startingWidth-30, startingHeight-3,3,6, ST7735_YELLOW);
OHstin 2:104bec169fb6 146 } else if (colorCounter == 3) {
OHstin 2:104bec169fb6 147 // yellow
OHstin 2:104bec169fb6 148 // red
OHstin 2:104bec169fb6 149 // green
OHstin 2:104bec169fb6 150
OHstin 2:104bec169fb6 151 // fill rectangle one
OHstin 2:104bec169fb6 152 tft.fillRect(startingWidth-22, startingHeight-3,3,6,ST7735_YELLOW);
OHstin 2:104bec169fb6 153
OHstin 2:104bec169fb6 154 // fill rectangle two
OHstin 2:104bec169fb6 155 tft.fillRect(startingWidth-26, startingHeight-3,3,6,ST7735_RED);
OHstin 2:104bec169fb6 156
OHstin 2:104bec169fb6 157 // fill rectangle three
OHstin 2:104bec169fb6 158 tft.fillRect(startingWidth-30, startingHeight-3,3,6, ST7735_GREEN);
OHstin 2:104bec169fb6 159 }
OHstin 2:104bec169fb6 160
OHstin 2:104bec169fb6 161 // increase the color counter accordingly
OHstin 2:104bec169fb6 162 colorCounter++;
OHstin 2:104bec169fb6 163
OHstin 2:104bec169fb6 164 // make sure color counter stays within range
OHstin 2:104bec169fb6 165 if (colorCounter > 3) {
OHstin 2:104bec169fb6 166 colorCounter = 1;
OHstin 2:104bec169fb6 167 }
OHstin 2:104bec169fb6 168
OHstin 2:104bec169fb6 169 }
OHstin 2:104bec169fb6 170 #endif