Spidey Wall is the name for a physical wall lit up by multiple addressable LED strips. This program is an LPC1768 web server to control the wall from a browser.
Dependencies: EthernetInterfacePlusHostname RdWebServer mbed-rtos mbed
This project is part of a Light-Wall using addressable LED strips (WS2801). I have published a few posts on my blog about the construction of the wall and building a game to play on it (PacMan). I have also had a guest post from a friend who has set his children the task of producing some interesting animations. The original post is http://robdobson.com/2015/07/spidey-wall/
So far, however, I hadn't fully connected the physical (and electronic) wall with the web-browser creations to drive it. This project is hopefully the final link. A fast and reliable web server using REST commands to drive the 1686 LEDs in the Spidey Wall from code running in a browser (say on an iPad while you are playing a game).
The approach taken here results in the ability to control the RGB values of all 1686 LEDs at a rate of 20 frames per second.
A blog post describing the whole thing is here:
http://robdobson.com/2015/08/a-reliable-mbed-webserver/
DrawingManager.cpp@6:8df79fe1afcd, 2015-09-03 (annotated)
- Committer:
- Bobty
- Date:
- Thu Sep 03 20:17:23 2015 +0000
- Revision:
- 6:8df79fe1afcd
- Parent:
- 5:910909f34907
Fixed an unforeseen problem with messages not aligned on RGB boundaries; Fixed potential hanging pointer problem in colourconverters; Changed Idle screen to a set of colourful snakes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Bobty | 1:362331cec9b7 | 1 | // |
Bobty | 4:b521815f2657 | 2 | // Drawing Manager for LightWall |
Bobty | 1:362331cec9b7 | 3 | // Rob Dobson 2015 |
Bobty | 1:362331cec9b7 | 4 | // |
Bobty | 1:362331cec9b7 | 5 | |
Bobty | 1:362331cec9b7 | 6 | #include "DrawingManager.h" |
Bobty | 1:362331cec9b7 | 7 | #include "rtos.h" |
Bobty | 5:910909f34907 | 8 | #include "colourconverters.h" |
Bobty | 1:362331cec9b7 | 9 | |
Bobty | 2:99eb4c6e9ea4 | 10 | DrawingManager::DrawingManager() |
Bobty | 1:362331cec9b7 | 11 | { |
Bobty | 2:99eb4c6e9ea4 | 12 | pLedStrip = NULL; |
Bobty | 1:362331cec9b7 | 13 | isBusy = false; |
Bobty | 6:8df79fe1afcd | 14 | rawFillPayloadOverhangBytes = 0; |
Bobty | 1:362331cec9b7 | 15 | } |
Bobty | 1:362331cec9b7 | 16 | |
Bobty | 4:b521815f2657 | 17 | void DrawingManager::Init(int numLeds, int splitPoint) |
Bobty | 1:362331cec9b7 | 18 | { |
Bobty | 2:99eb4c6e9ea4 | 19 | pLedStrip = new ledstrip(numLeds, splitPoint); |
Bobty | 2:99eb4c6e9ea4 | 20 | Thread::wait(100); |
Bobty | 2:99eb4c6e9ea4 | 21 | pLedStrip->Clear(); |
Bobty | 2:99eb4c6e9ea4 | 22 | pLedStrip->ShowLeds(); |
Bobty | 2:99eb4c6e9ea4 | 23 | |
Bobty | 1:362331cec9b7 | 24 | } |
Bobty | 1:362331cec9b7 | 25 | |
Bobty | 4:b521815f2657 | 26 | void DrawingManager::Clear() |
Bobty | 4:b521815f2657 | 27 | { |
Bobty | 4:b521815f2657 | 28 | // printf("CLEAR\r\n"); |
Bobty | 4:b521815f2657 | 29 | if (pLedStrip) |
Bobty | 4:b521815f2657 | 30 | pLedStrip->Clear(); |
Bobty | 4:b521815f2657 | 31 | } |
Bobty | 4:b521815f2657 | 32 | |
Bobty | 4:b521815f2657 | 33 | void DrawingManager::RawFill(char* args, unsigned char* payload, int payloadLen, int payloadOffset) |
Bobty | 1:362331cec9b7 | 34 | { |
Bobty | 4:b521815f2657 | 35 | // printf("RAWFILL %s payloadLen %d, payloadOffset %d\r\n", args, payloadLen, payloadOffset); |
Bobty | 4:b521815f2657 | 36 | int startLed = GetIntFromNameValPair(args, "start=", -1); |
Bobty | 4:b521815f2657 | 37 | if (startLed != -1 && payloadLen > 0) |
Bobty | 4:b521815f2657 | 38 | { |
Bobty | 6:8df79fe1afcd | 39 | // Include any overhang bytes from the last payload |
Bobty | 6:8df79fe1afcd | 40 | int numLeds = (rawFillPayloadOverhangBytes + payloadLen) / 3; |
Bobty | 4:b521815f2657 | 41 | int fromLed = startLed + (payloadOffset / 3); |
Bobty | 6:8df79fe1afcd | 42 | unsigned char newPayload[numLeds*3]; |
Bobty | 6:8df79fe1afcd | 43 | memcpy(newPayload, pRawFillPayloadOverhang, rawFillPayloadOverhangBytes); |
Bobty | 6:8df79fe1afcd | 44 | memcpy(newPayload+rawFillPayloadOverhangBytes, payload, numLeds*3-rawFillPayloadOverhangBytes); |
Bobty | 6:8df79fe1afcd | 45 | |
Bobty | 6:8df79fe1afcd | 46 | // Send the data |
Bobty | 4:b521815f2657 | 47 | // printf("RAWFILL fromLed %d numLeds %d\r\n", fromLed, numLeds); |
Bobty | 6:8df79fe1afcd | 48 | // for (int i = 0; i < numLeds*3; i+=3) |
Bobty | 6:8df79fe1afcd | 49 | // { |
Bobty | 6:8df79fe1afcd | 50 | // printf("%02x %02x %02x\r\n", newPayload[i], newPayload[i+1], newPayload[i+2]); |
Bobty | 6:8df79fe1afcd | 51 | // } |
Bobty | 6:8df79fe1afcd | 52 | pLedStrip->RawFill(fromLed, numLeds, newPayload); |
Bobty | 6:8df79fe1afcd | 53 | |
Bobty | 6:8df79fe1afcd | 54 | // Save any overhanging bytes for the next fill |
Bobty | 6:8df79fe1afcd | 55 | int overhangStart = (numLeds * 3) - rawFillPayloadOverhangBytes; |
Bobty | 6:8df79fe1afcd | 56 | rawFillPayloadOverhangBytes = rawFillPayloadOverhangBytes + payloadLen - (numLeds * 3); |
Bobty | 6:8df79fe1afcd | 57 | for (int i = 0; i < rawFillPayloadOverhangBytes; i++) |
Bobty | 6:8df79fe1afcd | 58 | { |
Bobty | 6:8df79fe1afcd | 59 | pRawFillPayloadOverhang[i] = payload[overhangStart + i]; |
Bobty | 6:8df79fe1afcd | 60 | } |
Bobty | 4:b521815f2657 | 61 | } |
Bobty | 1:362331cec9b7 | 62 | } |
Bobty | 1:362331cec9b7 | 63 | |
Bobty | 4:b521815f2657 | 64 | void DrawingManager::Fill(char* args) |
Bobty | 1:362331cec9b7 | 65 | { |
Bobty | 4:b521815f2657 | 66 | // printf("FILL %s\r\n", args); |
Bobty | 4:b521815f2657 | 67 | int startLed = GetIntFromNameValPair(args, "start=", -1); |
Bobty | 4:b521815f2657 | 68 | int numLeds = GetIntFromNameValPair(args, "len=", -1); |
Bobty | 4:b521815f2657 | 69 | int r1 = GetIntFromNameValPair(args, "r1=", -1); |
Bobty | 4:b521815f2657 | 70 | int g1 = GetIntFromNameValPair(args, "g1=", -1); |
Bobty | 4:b521815f2657 | 71 | int b1 = GetIntFromNameValPair(args, "b1=", -1); |
Bobty | 4:b521815f2657 | 72 | int r2 = GetIntFromNameValPair(args, "r2=", -1); |
Bobty | 4:b521815f2657 | 73 | int g2 = GetIntFromNameValPair(args, "g2=", -1); |
Bobty | 4:b521815f2657 | 74 | int b2 = GetIntFromNameValPair(args, "b2=", -1); |
Bobty | 4:b521815f2657 | 75 | if (startLed != -1 && numLeds != -1 && r1 != -1 && g1 != -1 && b1 != -1) |
Bobty | 4:b521815f2657 | 76 | { |
Bobty | 4:b521815f2657 | 77 | if (r2 == -1 || g2 == -1 || b2 == -1) |
Bobty | 4:b521815f2657 | 78 | pLedStrip->Fill(startLed, numLeds, r1, g1, b1); |
Bobty | 4:b521815f2657 | 79 | else |
Bobty | 4:b521815f2657 | 80 | pLedStrip->Fill(startLed, numLeds, r1, g1, b1, r2, g2, b2); |
Bobty | 4:b521815f2657 | 81 | } |
Bobty | 1:362331cec9b7 | 82 | } |
Bobty | 4:b521815f2657 | 83 | |
Bobty | 4:b521815f2657 | 84 | void DrawingManager::ShowLeds() |
Bobty | 4:b521815f2657 | 85 | { |
Bobty | 4:b521815f2657 | 86 | // printf("SHOWLEDS\r\n"); |
Bobty | 6:8df79fe1afcd | 87 | rawFillPayloadOverhangBytes = 0; |
Bobty | 4:b521815f2657 | 88 | if (pLedStrip) |
Bobty | 4:b521815f2657 | 89 | pLedStrip->ShowLeds(); |
Bobty | 4:b521815f2657 | 90 | } |
Bobty | 4:b521815f2657 | 91 | |
Bobty | 5:910909f34907 | 92 | void DrawingManager::DisplayIdle(unsigned int stepCount) |
Bobty | 5:910909f34907 | 93 | { |
Bobty | 5:910909f34907 | 94 | // Display a step in an auto sequence |
Bobty | 5:910909f34907 | 95 | if (!pLedStrip) |
Bobty | 5:910909f34907 | 96 | return; |
Bobty | 5:910909f34907 | 97 | if (pLedStrip->IsBusy()) |
Bobty | 5:910909f34907 | 98 | return; |
Bobty | 5:910909f34907 | 99 | pLedStrip->Clear(); |
Bobty | 6:8df79fe1afcd | 100 | int numSnakes = 15; |
Bobty | 6:8df79fe1afcd | 101 | int ledsPerGroup = pLedStrip->GetNumLeds() / numSnakes; |
Bobty | 6:8df79fe1afcd | 102 | int snakeLen = 10; |
Bobty | 6:8df79fe1afcd | 103 | int snakeStep = stepCount % ledsPerGroup; |
Bobty | 6:8df79fe1afcd | 104 | int colrBase = (stepCount / ledsPerGroup); |
Bobty | 6:8df79fe1afcd | 105 | // Create a set of colourful snakes that roam around the wall |
Bobty | 6:8df79fe1afcd | 106 | for (int i = 0; i < numSnakes; i ++) |
Bobty | 5:910909f34907 | 107 | { |
Bobty | 6:8df79fe1afcd | 108 | HsvColor hsv1(((colrBase + i) * 237) % 255, 128, 10); |
Bobty | 6:8df79fe1afcd | 109 | RgbColor rgb1(0,0,0); |
Bobty | 6:8df79fe1afcd | 110 | HsvToRgb(hsv1, rgb1); |
Bobty | 6:8df79fe1afcd | 111 | HsvColor hsv2(((colrBase + i + 27) * 13) % 255, 255, 255); |
Bobty | 6:8df79fe1afcd | 112 | RgbColor rgb2(0,0,0); |
Bobty | 6:8df79fe1afcd | 113 | HsvToRgb(hsv2, rgb2); |
Bobty | 6:8df79fe1afcd | 114 | pLedStrip->Fill((i*ledsPerGroup)+snakeStep,snakeLen/2, rgb1.r, rgb1.g, rgb1.b, rgb2.r, rgb2.g, rgb2.b); |
Bobty | 6:8df79fe1afcd | 115 | pLedStrip->Fill((i*ledsPerGroup)+snakeStep+snakeLen/2, snakeLen/2, rgb2.r, rgb2.g, rgb2.b, rgb1.r, rgb1.g, rgb1.b); |
Bobty | 5:910909f34907 | 116 | } |
Bobty | 5:910909f34907 | 117 | pLedStrip->ShowLeds(); |
Bobty | 5:910909f34907 | 118 | } |
Bobty | 5:910909f34907 | 119 | |
Bobty | 4:b521815f2657 | 120 | int DrawingManager::GetIntFromNameValPair(char* buf, char* name, int invalidVal) |
Bobty | 4:b521815f2657 | 121 | { |
Bobty | 4:b521815f2657 | 122 | int val = invalidVal; |
Bobty | 4:b521815f2657 | 123 | char* pFnd = strstr(buf, name); |
Bobty | 4:b521815f2657 | 124 | if (pFnd) |
Bobty | 4:b521815f2657 | 125 | val = atoi(pFnd + strlen(name)); |
Bobty | 4:b521815f2657 | 126 | return val; |
Bobty | 4:b521815f2657 | 127 | } |
Bobty | 5:910909f34907 | 128 |