Augustine Kizito / Mbed 2 deprecated Solar_Powered_Smart_Camera

Dependencies:   Adafruit_GFX Adafruit_ST7735 INA219 MODSERIAL MbedJSONValue mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SolarIcon.h Source File

SolarIcon.h

00001 #ifndef SOLARICON_H
00002 #define SOLARICON_H
00003 
00004 class SolarIcon
00005 {
00006 public:
00007     SolarIcon(uint8_t xCoordinate,  uint8_t yCoordinate, uint16_t backgroundColor );
00008     void drawSolarIcon();
00009     void animateSolarIcon(bool solarStatus);
00010 
00011 private:
00012     uint8_t startingWidth; // x coordinate of the centre of the sun (yello circle)
00013     uint8_t startingHeight; // y coordinate of the centre of the sun
00014     uint16_t bgColor;
00015     uint16_t linesColor; // color of the lines on the solar panel
00016     int solarRayCounter;
00017     bool solarIconAnimating;
00018 
00019     void drawRays(uint16_t color);
00020     void animateRays();
00021 };
00022 
00023 SolarIcon::SolarIcon(uint8_t xCoordinate,uint8_t yCoordinate,uint16_t backgroundColor)
00024                     : solarRayCounter(1),solarIconAnimating(false)
00025 {
00026     // set the centre of the sun (yellow circle)
00027     startingWidth = xCoordinate + 40;
00028     startingHeight = yCoordinate + 18;
00029 
00030     bgColor = backgroundColor;
00031 
00032     // determine the color of the lines on the solar panel
00033     if (bgColor == ST7735_WHITE ) {
00034         linesColor = ST7735_BLACK;
00035     } else if (bgColor == ST7735_BLACK) {
00036         linesColor = ST7735_WHITE;
00037     }
00038 
00039 }
00040 
00041 void SolarIcon::drawSolarIcon()
00042 {
00043 
00044     // draw a small yellow circle
00045     tft.fillCircle(startingWidth, startingHeight, 7, ST7735_YELLOW);
00046 
00047     // draw the solar panel
00048 
00049     // draw a triangle to the right
00050     tft.fillTriangle(startingWidth, startingHeight, startingWidth, startingHeight +30, startingWidth +10, startingHeight + 30, ST7735_BLUE);
00051 
00052     // draw rectangle
00053     tft.fillRect(startingWidth-30, startingHeight, 30, 31, ST7735_BLUE);
00054 
00055     // draw a triangle to the left
00056     //tft.fillTriangle(startingWidthTwo-30, startingHeightTwo, startingWidthTwo, startingHeightTwo +30, startingWidthTwo - 40, startingHeightTwo + 30, ST7735_BLUE);
00057     tft.fillTriangle(startingWidth-30, startingHeight, startingWidth-30, startingHeight +30, startingWidth - 40, startingHeight + 30, ST7735_BLUE);
00058 
00059     // draw horizontal lines
00060     tft.drawFastHLine(startingWidth-32, startingHeight+8,35,linesColor);
00061     tft.drawFastHLine(startingWidth-36, startingHeight+20,43,linesColor);
00062     //tft.drawFastHLine(startingWidthTwo-32, startingHeightTwo+8,35,ST7735_WHITE);
00063 
00064     // draw vertical lines
00065     tft.drawLine(startingWidth-10, startingHeight, startingWidth-2, startingHeight + 30,linesColor);
00066     tft.drawLine(startingWidth-19, startingHeight, startingWidth-27, startingHeight + 30,linesColor);
00067     //tft.drawFastVLine(startingWidthTwo-22, startingHeightTwo,31,ST7735_WHITE);
00068 
00069 
00070     // draw solar rays
00071     drawRays(ST7735_YELLOW);
00072 
00073 }
00074 
00075 void SolarIcon::animateSolarIcon(bool solarStatus)
00076 {
00077 
00078     // if panel is receiving solar radiation
00079     if (solarStatus) {
00080         // check if already animating
00081         if(!solarIconAnimating) {
00082             // first delete all solar rays
00083             drawRays(bgColor);
00084             // solarIcon is now animating
00085             solarIconAnimating = true;
00086             // set the ray counter to 1
00087             solarRayCounter = 1;
00088             // call the animateray
00089             animateRays();
00090 
00091         } else {
00092             // call animateray
00093             animateRays();
00094         }
00095 
00096     } else {
00097         // check if it was animating
00098         if(solarIconAnimating) {
00099             // show all the rays
00100             drawRays(ST7735_YELLOW);
00101             // set the ray counter to 1
00102             solarRayCounter = 1;
00103             // set solarIcon animate to false
00104             solarIconAnimating = false;
00105         } else {
00106             // do nothing
00107         }
00108 
00109     }
00110 
00111 }
00112 
00113 void SolarIcon::drawRays(uint16_t color)
00114 {
00115     // draw solar rays
00116     tft.drawLine(startingWidth-7, startingHeight-8, startingWidth-12, startingHeight-13,color);
00117     tft.drawLine(startingWidth, startingHeight-12, startingWidth, startingHeight-18,color);
00118     tft.drawLine(startingWidth+7, startingHeight-8, startingWidth+12, startingHeight-13,color);
00119     tft.drawLine(startingWidth+10, startingHeight, startingWidth+17, startingHeight,color);
00120     tft.drawLine(startingWidth+7, startingHeight+8, startingWidth+12, startingHeight+13,color);
00121 }
00122 
00123 void SolarIcon::animateRays()
00124 {
00125     if (solarRayCounter == 1) {
00126         // draw the first ray
00127         tft.drawLine(startingWidth-7, startingHeight-8, startingWidth-12, startingHeight-13,ST7735_YELLOW);
00128     } else if (solarRayCounter == 2) {
00129         // draw the second ray
00130         tft.drawLine(startingWidth, startingHeight-12, startingWidth, startingHeight-18,ST7735_YELLOW);
00131     } else if (solarRayCounter == 3) {
00132         // draw the third ray
00133         tft.drawLine(startingWidth+7, startingHeight-8, startingWidth+12, startingHeight-13,ST7735_YELLOW);
00134     } else if (solarRayCounter == 4) {
00135         // draw the fourth ray
00136         tft.drawLine(startingWidth+10, startingHeight, startingWidth+17, startingHeight,ST7735_YELLOW);
00137     } else if (solarRayCounter == 5) {
00138         // draw the fifth ray
00139         tft.drawLine(startingWidth+7, startingHeight+8, startingWidth+12, startingHeight+13,ST7735_YELLOW);
00140     } else if (solarRayCounter == 6) {
00141         // delete arrays
00142         drawRays(bgColor);
00143     }
00144 
00145     // increase the counter accordingly
00146     solarRayCounter++;
00147 
00148     // reset the counter if necessary
00149     if (solarRayCounter > 6) {
00150         solarRayCounter = 1;
00151     }
00152 }
00153 
00154 #endif