
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
Icons/SolarIcon.h@6:196a63a3378d, 2017-04-30 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
OHstin | 2:104bec169fb6 | 1 | #ifndef SOLARICON_H |
OHstin | 2:104bec169fb6 | 2 | #define SOLARICON_H |
OHstin | 2:104bec169fb6 | 3 | |
OHstin | 2:104bec169fb6 | 4 | class SolarIcon |
OHstin | 2:104bec169fb6 | 5 | { |
OHstin | 2:104bec169fb6 | 6 | public: |
OHstin | 2:104bec169fb6 | 7 | SolarIcon(uint8_t xCoordinate, uint8_t yCoordinate, uint16_t backgroundColor ); |
OHstin | 2:104bec169fb6 | 8 | void drawSolarIcon(); |
OHstin | 2:104bec169fb6 | 9 | void animateSolarIcon(bool solarStatus); |
OHstin | 2:104bec169fb6 | 10 | |
OHstin | 2:104bec169fb6 | 11 | private: |
OHstin | 2:104bec169fb6 | 12 | uint8_t startingWidth; // x coordinate of the centre of the sun (yello circle) |
OHstin | 2:104bec169fb6 | 13 | uint8_t startingHeight; // y coordinate of the centre of the sun |
OHstin | 2:104bec169fb6 | 14 | uint16_t bgColor; |
OHstin | 2:104bec169fb6 | 15 | uint16_t linesColor; // color of the lines on the solar panel |
OHstin | 2:104bec169fb6 | 16 | int solarRayCounter; |
OHstin | 2:104bec169fb6 | 17 | bool solarIconAnimating; |
OHstin | 2:104bec169fb6 | 18 | |
OHstin | 2:104bec169fb6 | 19 | void drawRays(uint16_t color); |
OHstin | 2:104bec169fb6 | 20 | void animateRays(); |
OHstin | 2:104bec169fb6 | 21 | }; |
OHstin | 2:104bec169fb6 | 22 | |
OHstin | 2:104bec169fb6 | 23 | SolarIcon::SolarIcon(uint8_t xCoordinate,uint8_t yCoordinate,uint16_t backgroundColor) |
OHstin | 2:104bec169fb6 | 24 | : solarRayCounter(1),solarIconAnimating(false) |
OHstin | 2:104bec169fb6 | 25 | { |
OHstin | 2:104bec169fb6 | 26 | // set the centre of the sun (yellow circle) |
OHstin | 2:104bec169fb6 | 27 | startingWidth = xCoordinate + 40; |
OHstin | 2:104bec169fb6 | 28 | startingHeight = yCoordinate + 18; |
OHstin | 2:104bec169fb6 | 29 | |
OHstin | 2:104bec169fb6 | 30 | bgColor = backgroundColor; |
OHstin | 2:104bec169fb6 | 31 | |
OHstin | 2:104bec169fb6 | 32 | // determine the color of the lines on the solar panel |
OHstin | 2:104bec169fb6 | 33 | if (bgColor == ST7735_WHITE ) { |
OHstin | 2:104bec169fb6 | 34 | linesColor = ST7735_BLACK; |
OHstin | 2:104bec169fb6 | 35 | } else if (bgColor == ST7735_BLACK) { |
OHstin | 2:104bec169fb6 | 36 | linesColor = ST7735_WHITE; |
OHstin | 2:104bec169fb6 | 37 | } |
OHstin | 2:104bec169fb6 | 38 | |
OHstin | 2:104bec169fb6 | 39 | } |
OHstin | 2:104bec169fb6 | 40 | |
OHstin | 2:104bec169fb6 | 41 | void SolarIcon::drawSolarIcon() |
OHstin | 2:104bec169fb6 | 42 | { |
OHstin | 2:104bec169fb6 | 43 | |
OHstin | 2:104bec169fb6 | 44 | // draw a small yellow circle |
OHstin | 2:104bec169fb6 | 45 | tft.fillCircle(startingWidth, startingHeight, 7, ST7735_YELLOW); |
OHstin | 2:104bec169fb6 | 46 | |
OHstin | 2:104bec169fb6 | 47 | // draw the solar panel |
OHstin | 2:104bec169fb6 | 48 | |
OHstin | 2:104bec169fb6 | 49 | // draw a triangle to the right |
OHstin | 2:104bec169fb6 | 50 | tft.fillTriangle(startingWidth, startingHeight, startingWidth, startingHeight +30, startingWidth +10, startingHeight + 30, ST7735_BLUE); |
OHstin | 2:104bec169fb6 | 51 | |
OHstin | 2:104bec169fb6 | 52 | // draw rectangle |
OHstin | 2:104bec169fb6 | 53 | tft.fillRect(startingWidth-30, startingHeight, 30, 31, ST7735_BLUE); |
OHstin | 2:104bec169fb6 | 54 | |
OHstin | 2:104bec169fb6 | 55 | // draw a triangle to the left |
OHstin | 2:104bec169fb6 | 56 | //tft.fillTriangle(startingWidthTwo-30, startingHeightTwo, startingWidthTwo, startingHeightTwo +30, startingWidthTwo - 40, startingHeightTwo + 30, ST7735_BLUE); |
OHstin | 2:104bec169fb6 | 57 | tft.fillTriangle(startingWidth-30, startingHeight, startingWidth-30, startingHeight +30, startingWidth - 40, startingHeight + 30, ST7735_BLUE); |
OHstin | 2:104bec169fb6 | 58 | |
OHstin | 2:104bec169fb6 | 59 | // draw horizontal lines |
OHstin | 2:104bec169fb6 | 60 | tft.drawFastHLine(startingWidth-32, startingHeight+8,35,linesColor); |
OHstin | 2:104bec169fb6 | 61 | tft.drawFastHLine(startingWidth-36, startingHeight+20,43,linesColor); |
OHstin | 2:104bec169fb6 | 62 | //tft.drawFastHLine(startingWidthTwo-32, startingHeightTwo+8,35,ST7735_WHITE); |
OHstin | 2:104bec169fb6 | 63 | |
OHstin | 2:104bec169fb6 | 64 | // draw vertical lines |
OHstin | 2:104bec169fb6 | 65 | tft.drawLine(startingWidth-10, startingHeight, startingWidth-2, startingHeight + 30,linesColor); |
OHstin | 2:104bec169fb6 | 66 | tft.drawLine(startingWidth-19, startingHeight, startingWidth-27, startingHeight + 30,linesColor); |
OHstin | 2:104bec169fb6 | 67 | //tft.drawFastVLine(startingWidthTwo-22, startingHeightTwo,31,ST7735_WHITE); |
OHstin | 2:104bec169fb6 | 68 | |
OHstin | 2:104bec169fb6 | 69 | |
OHstin | 2:104bec169fb6 | 70 | // draw solar rays |
OHstin | 2:104bec169fb6 | 71 | drawRays(ST7735_YELLOW); |
OHstin | 2:104bec169fb6 | 72 | |
OHstin | 2:104bec169fb6 | 73 | } |
OHstin | 2:104bec169fb6 | 74 | |
OHstin | 2:104bec169fb6 | 75 | void SolarIcon::animateSolarIcon(bool solarStatus) |
OHstin | 2:104bec169fb6 | 76 | { |
OHstin | 2:104bec169fb6 | 77 | |
OHstin | 2:104bec169fb6 | 78 | // if panel is receiving solar radiation |
OHstin | 2:104bec169fb6 | 79 | if (solarStatus) { |
OHstin | 2:104bec169fb6 | 80 | // check if already animating |
OHstin | 2:104bec169fb6 | 81 | if(!solarIconAnimating) { |
OHstin | 2:104bec169fb6 | 82 | // first delete all solar rays |
OHstin | 2:104bec169fb6 | 83 | drawRays(bgColor); |
OHstin | 2:104bec169fb6 | 84 | // solarIcon is now animating |
OHstin | 2:104bec169fb6 | 85 | solarIconAnimating = true; |
OHstin | 2:104bec169fb6 | 86 | // set the ray counter to 1 |
OHstin | 2:104bec169fb6 | 87 | solarRayCounter = 1; |
OHstin | 2:104bec169fb6 | 88 | // call the animateray |
OHstin | 2:104bec169fb6 | 89 | animateRays(); |
OHstin | 2:104bec169fb6 | 90 | |
OHstin | 2:104bec169fb6 | 91 | } else { |
OHstin | 2:104bec169fb6 | 92 | // call animateray |
OHstin | 2:104bec169fb6 | 93 | animateRays(); |
OHstin | 2:104bec169fb6 | 94 | } |
OHstin | 2:104bec169fb6 | 95 | |
OHstin | 2:104bec169fb6 | 96 | } else { |
OHstin | 2:104bec169fb6 | 97 | // check if it was animating |
OHstin | 2:104bec169fb6 | 98 | if(solarIconAnimating) { |
OHstin | 2:104bec169fb6 | 99 | // show all the rays |
OHstin | 2:104bec169fb6 | 100 | drawRays(ST7735_YELLOW); |
OHstin | 2:104bec169fb6 | 101 | // set the ray counter to 1 |
OHstin | 2:104bec169fb6 | 102 | solarRayCounter = 1; |
OHstin | 2:104bec169fb6 | 103 | // set solarIcon animate to false |
OHstin | 2:104bec169fb6 | 104 | solarIconAnimating = false; |
OHstin | 2:104bec169fb6 | 105 | } else { |
OHstin | 2:104bec169fb6 | 106 | // do nothing |
OHstin | 2:104bec169fb6 | 107 | } |
OHstin | 2:104bec169fb6 | 108 | |
OHstin | 2:104bec169fb6 | 109 | } |
OHstin | 2:104bec169fb6 | 110 | |
OHstin | 2:104bec169fb6 | 111 | } |
OHstin | 2:104bec169fb6 | 112 | |
OHstin | 2:104bec169fb6 | 113 | void SolarIcon::drawRays(uint16_t color) |
OHstin | 2:104bec169fb6 | 114 | { |
OHstin | 2:104bec169fb6 | 115 | // draw solar rays |
OHstin | 2:104bec169fb6 | 116 | tft.drawLine(startingWidth-7, startingHeight-8, startingWidth-12, startingHeight-13,color); |
OHstin | 2:104bec169fb6 | 117 | tft.drawLine(startingWidth, startingHeight-12, startingWidth, startingHeight-18,color); |
OHstin | 2:104bec169fb6 | 118 | tft.drawLine(startingWidth+7, startingHeight-8, startingWidth+12, startingHeight-13,color); |
OHstin | 2:104bec169fb6 | 119 | tft.drawLine(startingWidth+10, startingHeight, startingWidth+17, startingHeight,color); |
OHstin | 2:104bec169fb6 | 120 | tft.drawLine(startingWidth+7, startingHeight+8, startingWidth+12, startingHeight+13,color); |
OHstin | 2:104bec169fb6 | 121 | } |
OHstin | 2:104bec169fb6 | 122 | |
OHstin | 2:104bec169fb6 | 123 | void SolarIcon::animateRays() |
OHstin | 2:104bec169fb6 | 124 | { |
OHstin | 2:104bec169fb6 | 125 | if (solarRayCounter == 1) { |
OHstin | 2:104bec169fb6 | 126 | // draw the first ray |
OHstin | 2:104bec169fb6 | 127 | tft.drawLine(startingWidth-7, startingHeight-8, startingWidth-12, startingHeight-13,ST7735_YELLOW); |
OHstin | 2:104bec169fb6 | 128 | } else if (solarRayCounter == 2) { |
OHstin | 2:104bec169fb6 | 129 | // draw the second ray |
OHstin | 2:104bec169fb6 | 130 | tft.drawLine(startingWidth, startingHeight-12, startingWidth, startingHeight-18,ST7735_YELLOW); |
OHstin | 2:104bec169fb6 | 131 | } else if (solarRayCounter == 3) { |
OHstin | 2:104bec169fb6 | 132 | // draw the third ray |
OHstin | 2:104bec169fb6 | 133 | tft.drawLine(startingWidth+7, startingHeight-8, startingWidth+12, startingHeight-13,ST7735_YELLOW); |
OHstin | 2:104bec169fb6 | 134 | } else if (solarRayCounter == 4) { |
OHstin | 2:104bec169fb6 | 135 | // draw the fourth ray |
OHstin | 2:104bec169fb6 | 136 | tft.drawLine(startingWidth+10, startingHeight, startingWidth+17, startingHeight,ST7735_YELLOW); |
OHstin | 2:104bec169fb6 | 137 | } else if (solarRayCounter == 5) { |
OHstin | 2:104bec169fb6 | 138 | // draw the fifth ray |
OHstin | 2:104bec169fb6 | 139 | tft.drawLine(startingWidth+7, startingHeight+8, startingWidth+12, startingHeight+13,ST7735_YELLOW); |
OHstin | 2:104bec169fb6 | 140 | } else if (solarRayCounter == 6) { |
OHstin | 2:104bec169fb6 | 141 | // delete arrays |
OHstin | 2:104bec169fb6 | 142 | drawRays(bgColor); |
OHstin | 2:104bec169fb6 | 143 | } |
OHstin | 2:104bec169fb6 | 144 | |
OHstin | 2:104bec169fb6 | 145 | // increase the counter accordingly |
OHstin | 2:104bec169fb6 | 146 | solarRayCounter++; |
OHstin | 2:104bec169fb6 | 147 | |
OHstin | 2:104bec169fb6 | 148 | // reset the counter if necessary |
OHstin | 2:104bec169fb6 | 149 | if (solarRayCounter > 6) { |
OHstin | 2:104bec169fb6 | 150 | solarRayCounter = 1; |
OHstin | 2:104bec169fb6 | 151 | } |
OHstin | 2:104bec169fb6 | 152 | } |
OHstin | 2:104bec169fb6 | 153 | |
OHstin | 2:104bec169fb6 | 154 | #endif |