From b98e547ee27eefa41e0e98272aa6005b53d77124 Mon Sep 17 00:00:00 2001 From: Mitchell Pomery Date: Wed, 29 Jan 2014 22:10:19 +0800 Subject: [PATCH] Comments and Colour instead of color --- BlinkenLights.ino | 128 +++++++++++++++++++++++++++++++--------------- 1 file changed, 88 insertions(+), 40 deletions(-) diff --git a/BlinkenLights.ino b/BlinkenLights.ino index 3241bd8..4ae5577 100644 --- a/BlinkenLights.ino +++ b/BlinkenLights.ino @@ -1,4 +1,4 @@ -/* +/** BlinkenLights Code by Mitchell Pomery [BG3] with help from Andrew Adamson [BOB] @@ -65,20 +65,23 @@ WebServer webserver(PREFIX, 80); void showArray() { ///TODO: Rename this to something better? for (int i = 0; i < STRIPLENGTH; i ++) { - strip.setPixelColor(i, (int) ledArray[i].red, (int) ledArray[i].green, (int) ledArray[i].blue); + strip.setPixelColour(i, (int) ledArray[i].red, (int) ledArray[i].green, (int) ledArray[i].blue); } strip.show(); } /** - * Set the LED at pos in the strip to the defined color + * go from (x,y) to position in the array * @param xpos x coordinate * @param ypos y cordinate - * @return position in the array + * @return position in the array, -1 if out of array */ int coordToPos(int xpos, int ypos) { ///TODO: Test this function int pos = 0; + if ((xpos < 0 || xpos >= WIDTH) || (ypos < 0 || ypos >= HEIGHT)) { + return -1; + } if (ypos % 2 == 0) { // if we are on an even line, add y pos = ypos * WIDTH + xpos; } @@ -94,11 +97,11 @@ int coordToPos(int xpos, int ypos) { } /** - * Set the LED at pos in the strip to the defined color + * Set the LED at pos in the strip to the defined colour * @param pos position in the array - * @param red red portion of color - * @param green green portion of color - * @param blue blue portion of color + * @param red red portion of colour + * @param green green portion of colour + * @param blue blue portion of colour */ void setLED(int pos, int red, int green, int blue) { ledArray[pos].red = red; @@ -107,12 +110,12 @@ void setLED(int pos, int red, int green, int blue) { } /** - * Set the LED at (xpos, ypos) in the strip to the defined color + * Set the LED at (xpos, ypos) in the strip to the defined colour * @param xpos x coordinate * @param ypos y coordinate - * @param red red portion of color - * @param green green portion of color - * @param blue blue portion of color + * @param red red portion of colour + * @param green green portion of colour + * @param blue blue portion of colour */ void setLED(int xpos, int ypos, int red, int green, int blue) { int pos = coordToPos(xpos, ypos); @@ -122,7 +125,7 @@ void setLED(int xpos, int ypos, int red, int green, int blue) { /** * Get the colour of the LED in pos position in the strip * @param pos position in the strip - * @return color of LED at pos + * @return colour of LED at pos */ struct led getLED(int pos) { return ledArray[pos]; @@ -132,7 +135,7 @@ struct led getLED(int pos) { * Get the colour of the LED at (xpos, ypos) * @param xpos x coordinate * @param ypos y coordinate - * @return color of LED at (xpos, ypos) + * @return colour of LED at (xpos, ypos) */ struct led getLED(int xpos, int ypos) { int pos = coordToPos(xpos, ypos); @@ -143,10 +146,16 @@ struct led getLED(int xpos, int ypos) { ///TODO: Comment this stuff ///TODO: Reduce code reuse in the web page functions -///TODO: Start using post requests ///TODO: Make a function to set all the lights at once -// Sets the light sequence to one that is predefined +/** + * Sets the light sequence to one that is predefined. + * Set it to 0 to disable the cycling of lights. + * @param server + * @param type + * @param url_tail + * @param tail_complete + */ void webSetSequence(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete) { URLPARAM_RESULT rc; char name[NAMELEN]; @@ -175,6 +184,13 @@ void webSetSequence(WebServer &server, WebServer::ConnectionType type, char *url } } +/** + * Set a specific LED to a specific colour + * @param server + * @param type + * @param url_tail + * @param tail_complete + */ void webSetLED(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete) { URLPARAM_RESULT rc; char name[NAMELEN]; @@ -222,6 +238,13 @@ void webSetLED(WebServer &server, WebServer::ConnectionType type, char *url_tail } } +/** + * Set the brightness to a specific magnitude + * @param server + * @param type + * @param url_tail + * @param tail_complete + */ void webSetBrightness(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete) { URLPARAM_RESULT rc; char name[NAMELEN]; @@ -253,95 +276,120 @@ void webSetBrightness(WebServer &server, WebServer::ConnectionType type, char *u // ============================== LIGHT DISPLAYS ============================== -///TODO: Comment this stuff -///TODO: Make sure these functions don't block. Otherwise web requests are slow - -// Fill the dots one after the other with a color -void colorWipe(uint32_t c, uint8_t wait) { +/** + * Fill the dots one after the other with a colour + * @param colour colour to fill the array with + * @param wait delay between colour changes + */ +void colourWipe(uint32_t c, uint8_t wait) { + ///TODO: stop this blocking for(uint16_t i=0; i