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
DrawingManager.cpp
00001 // 00002 // Drawing Manager for LightWall 00003 // Rob Dobson 2015 00004 // 00005 00006 #include "DrawingManager.h" 00007 #include "rtos.h" 00008 #include "colourconverters.h" 00009 00010 DrawingManager::DrawingManager() 00011 { 00012 pLedStrip = NULL; 00013 isBusy = false; 00014 rawFillPayloadOverhangBytes = 0; 00015 } 00016 00017 void DrawingManager::Init(int numLeds, int splitPoint) 00018 { 00019 pLedStrip = new ledstrip(numLeds, splitPoint); 00020 Thread::wait(100); 00021 pLedStrip->Clear(); 00022 pLedStrip->ShowLeds(); 00023 00024 } 00025 00026 void DrawingManager::Clear() 00027 { 00028 // printf("CLEAR\r\n"); 00029 if (pLedStrip) 00030 pLedStrip->Clear(); 00031 } 00032 00033 void DrawingManager::RawFill(char* args, unsigned char* payload, int payloadLen, int payloadOffset) 00034 { 00035 // printf("RAWFILL %s payloadLen %d, payloadOffset %d\r\n", args, payloadLen, payloadOffset); 00036 int startLed = GetIntFromNameValPair(args, "start=", -1); 00037 if (startLed != -1 && payloadLen > 0) 00038 { 00039 // Include any overhang bytes from the last payload 00040 int numLeds = (rawFillPayloadOverhangBytes + payloadLen) / 3; 00041 int fromLed = startLed + (payloadOffset / 3); 00042 unsigned char newPayload[numLeds*3]; 00043 memcpy(newPayload, pRawFillPayloadOverhang, rawFillPayloadOverhangBytes); 00044 memcpy(newPayload+rawFillPayloadOverhangBytes, payload, numLeds*3-rawFillPayloadOverhangBytes); 00045 00046 // Send the data 00047 // printf("RAWFILL fromLed %d numLeds %d\r\n", fromLed, numLeds); 00048 // for (int i = 0; i < numLeds*3; i+=3) 00049 // { 00050 // printf("%02x %02x %02x\r\n", newPayload[i], newPayload[i+1], newPayload[i+2]); 00051 // } 00052 pLedStrip->RawFill(fromLed, numLeds, newPayload); 00053 00054 // Save any overhanging bytes for the next fill 00055 int overhangStart = (numLeds * 3) - rawFillPayloadOverhangBytes; 00056 rawFillPayloadOverhangBytes = rawFillPayloadOverhangBytes + payloadLen - (numLeds * 3); 00057 for (int i = 0; i < rawFillPayloadOverhangBytes; i++) 00058 { 00059 pRawFillPayloadOverhang[i] = payload[overhangStart + i]; 00060 } 00061 } 00062 } 00063 00064 void DrawingManager::Fill(char* args) 00065 { 00066 // printf("FILL %s\r\n", args); 00067 int startLed = GetIntFromNameValPair(args, "start=", -1); 00068 int numLeds = GetIntFromNameValPair(args, "len=", -1); 00069 int r1 = GetIntFromNameValPair(args, "r1=", -1); 00070 int g1 = GetIntFromNameValPair(args, "g1=", -1); 00071 int b1 = GetIntFromNameValPair(args, "b1=", -1); 00072 int r2 = GetIntFromNameValPair(args, "r2=", -1); 00073 int g2 = GetIntFromNameValPair(args, "g2=", -1); 00074 int b2 = GetIntFromNameValPair(args, "b2=", -1); 00075 if (startLed != -1 && numLeds != -1 && r1 != -1 && g1 != -1 && b1 != -1) 00076 { 00077 if (r2 == -1 || g2 == -1 || b2 == -1) 00078 pLedStrip->Fill(startLed, numLeds, r1, g1, b1); 00079 else 00080 pLedStrip->Fill(startLed, numLeds, r1, g1, b1, r2, g2, b2); 00081 } 00082 } 00083 00084 void DrawingManager::ShowLeds() 00085 { 00086 // printf("SHOWLEDS\r\n"); 00087 rawFillPayloadOverhangBytes = 0; 00088 if (pLedStrip) 00089 pLedStrip->ShowLeds(); 00090 } 00091 00092 void DrawingManager::DisplayIdle(unsigned int stepCount) 00093 { 00094 // Display a step in an auto sequence 00095 if (!pLedStrip) 00096 return; 00097 if (pLedStrip->IsBusy()) 00098 return; 00099 pLedStrip->Clear(); 00100 int numSnakes = 15; 00101 int ledsPerGroup = pLedStrip->GetNumLeds() / numSnakes; 00102 int snakeLen = 10; 00103 int snakeStep = stepCount % ledsPerGroup; 00104 int colrBase = (stepCount / ledsPerGroup); 00105 // Create a set of colourful snakes that roam around the wall 00106 for (int i = 0; i < numSnakes; i ++) 00107 { 00108 HsvColor hsv1(((colrBase + i) * 237) % 255, 128, 10); 00109 RgbColor rgb1(0,0,0); 00110 HsvToRgb(hsv1, rgb1); 00111 HsvColor hsv2(((colrBase + i + 27) * 13) % 255, 255, 255); 00112 RgbColor rgb2(0,0,0); 00113 HsvToRgb(hsv2, rgb2); 00114 pLedStrip->Fill((i*ledsPerGroup)+snakeStep,snakeLen/2, rgb1.r, rgb1.g, rgb1.b, rgb2.r, rgb2.g, rgb2.b); 00115 pLedStrip->Fill((i*ledsPerGroup)+snakeStep+snakeLen/2, snakeLen/2, rgb2.r, rgb2.g, rgb2.b, rgb1.r, rgb1.g, rgb1.b); 00116 } 00117 pLedStrip->ShowLeds(); 00118 } 00119 00120 int DrawingManager::GetIntFromNameValPair(char* buf, char* name, int invalidVal) 00121 { 00122 int val = invalidVal; 00123 char* pFnd = strstr(buf, name); 00124 if (pFnd) 00125 val = atoi(pFnd + strlen(name)); 00126 return val; 00127 } 00128
Generated on Wed Jul 13 2022 23:44:38 by
1.7.2