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 OutputIcon.h Source File

OutputIcon.h

00001 #ifndef OUTPUTICON_H
00002 #define OUTPUTICON_H
00003 
00004 class OutputIcon
00005 {
00006 public:
00007     OutputIcon(uint8_t xCoordiate, uint8_t yCoordinate, uint16_t backgroundColor);
00008     void drawOutputIcon();
00009     void animateOutputIcon(bool outputing);
00010 
00011 private:    
00012     uint8_t startingWidth; // x coordinate of the centre of large circle
00013     uint8_t startingHeight; // y coordinate of the centre of large circle
00014     uint16_t bgColor;
00015     uint16_t drawColor;
00016     int colorCounter;
00017     bool outputIconAnimating;
00018     
00019     void drawFilledRectangles();
00020     void animateRectangles();
00021     
00022 };
00023 
00024 OutputIcon::OutputIcon(uint8_t xCoordinate, uint8_t yCoordinate, uint16_t backgroundColor)
00025                 : colorCounter(1),outputIconAnimating(false)
00026 {
00027     // set the centre of the big circle
00028     startingWidth = xCoordinate + 31;
00029     startingHeight = yCoordinate + 17;
00030 
00031     bgColor = backgroundColor;
00032 
00033     // determine the color of the lines on the solar panel
00034     if (bgColor == ST7735_WHITE ) {
00035         drawColor = ST7735_BLACK;
00036     } else if (bgColor == ST7735_BLACK) {
00037         drawColor = ST7735_WHITE;
00038     }
00039 
00040     
00041 }
00042 
00043 void OutputIcon::drawOutputIcon()
00044 {
00045     // draw big circle
00046     tft.fillCircle(startingWidth, startingHeight, 17, drawColor);
00047 
00048     // draw deleting rectangle to cut the circle in half
00049     tft.fillRect(startingWidth, startingHeight-17,18, 35, bgColor);
00050 
00051     // draw rectangle extension of half circle
00052     tft.fillRect(startingWidth, startingHeight-17,5,35, drawColor);
00053 
00054     // draw pin one
00055     tft.fillRect(startingWidth+5, startingHeight-10,12,5, drawColor);
00056 
00057     // draw pin two
00058     tft.fillRect(startingWidth+5, startingHeight+7, 12, 5, drawColor);
00059 
00060     // draw a small rounnd rectangle at the back of the circle
00061     tft.fillRoundRect(startingWidth-19, startingHeight-5,12,10,2, drawColor);
00062 
00063     // draw empty rectangle one
00064     tft.drawRect(startingWidth-23, startingHeight-4,5,8,drawColor);
00065 
00066     // draw empty rectangle two
00067     tft.drawRect(startingWidth-27, startingHeight-4,5,8,drawColor);
00068 
00069     // draw empty rectangle three
00070     tft.drawRect(startingWidth-31, startingHeight-4,5,8,drawColor);
00071 
00072     // draw the filled rectangles
00073     drawFilledRectangles();
00074 }
00075 
00076 void OutputIcon::animateOutputIcon(bool outputing)
00077 {
00078     // check if any device is drawing power (outputing)
00079     if (outputing) {
00080         
00081         // check if the output icon is not animating
00082         if (!outputIconAnimating) {
00083 
00084             // the output icon is now animating
00085             outputIconAnimating = true;
00086 
00087             // set to the second color arrangement
00088             colorCounter = 2;
00089 
00090             // animate the filled rectangles
00091             animateRectangles();
00092         } else {
00093 
00094             // continue animation
00095             animateRectangles();
00096 
00097         }
00098     } else {
00099 
00100         //check if output icon is animating
00101         if (outputIconAnimating) {
00102             // reset all the colors
00103             drawFilledRectangles();
00104             // stop any future animation
00105             outputIconAnimating = false;
00106         } else {
00107             // do nothing
00108         }
00109 
00110     }
00111     
00112 }
00113 
00114 void OutputIcon::drawFilledRectangles()
00115 {
00116     // fill rectangle one
00117     tft.fillRect(startingWidth-22, startingHeight-3,3,6,ST7735_GREEN);
00118 
00119     // fill rectangle two
00120     tft.fillRect(startingWidth-26, startingHeight-3,3,6,ST7735_YELLOW);
00121 
00122     // fill rectangle three
00123     tft.fillRect(startingWidth-30, startingHeight-3,3,6, ST7735_RED);
00124 }
00125 
00126 void OutputIcon::animateRectangles()
00127 {
00128     if(colorCounter == 1) {
00129         // green
00130         // yellow
00131         // red
00132         drawFilledRectangles();
00133     } else if (colorCounter == 2) {
00134         // red
00135         // green
00136         // yellow
00137         
00138         // fill rectangle one
00139         tft.fillRect(startingWidth-22, startingHeight-3,3,6,ST7735_RED);
00140 
00141         // fill rectangle two
00142         tft.fillRect(startingWidth-26, startingHeight-3,3,6,ST7735_GREEN);
00143 
00144         // fill rectangle three
00145         tft.fillRect(startingWidth-30, startingHeight-3,3,6, ST7735_YELLOW);
00146     } else if (colorCounter == 3) {
00147         // yellow
00148         // red
00149         // green
00150         
00151         // fill rectangle one
00152         tft.fillRect(startingWidth-22, startingHeight-3,3,6,ST7735_YELLOW);
00153 
00154         // fill rectangle two
00155         tft.fillRect(startingWidth-26, startingHeight-3,3,6,ST7735_RED);
00156 
00157         // fill rectangle three
00158         tft.fillRect(startingWidth-30, startingHeight-3,3,6, ST7735_GREEN);
00159     } 
00160 
00161     // increase the color counter accordingly
00162     colorCounter++;
00163 
00164     // make sure color counter stays within range
00165     if (colorCounter > 3) {
00166         colorCounter = 1;
00167     }
00168 
00169 }
00170 #endif