Rob Dobson / Mbed 2 deprecated SpideyWallWeb

Dependencies:   EthernetInterfacePlusHostname RdWebServer mbed-rtos mbed

Committer:
Bobty
Date:
Tue Sep 01 15:53:52 2015 +0000
Revision:
5:910909f34907
Parent:
4:b521815f2657
Child:
6:8df79fe1afcd
Added an idle handler so there is something to show when nothing is being sent over HTTP

Who changed what in which revision?

UserRevisionLine numberNew 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 1:362331cec9b7 14 }
Bobty 1:362331cec9b7 15
Bobty 4:b521815f2657 16 void DrawingManager::Init(int numLeds, int splitPoint)
Bobty 1:362331cec9b7 17 {
Bobty 2:99eb4c6e9ea4 18 pLedStrip = new ledstrip(numLeds, splitPoint);
Bobty 2:99eb4c6e9ea4 19 Thread::wait(100);
Bobty 2:99eb4c6e9ea4 20 pLedStrip->Clear();
Bobty 2:99eb4c6e9ea4 21 pLedStrip->ShowLeds();
Bobty 2:99eb4c6e9ea4 22
Bobty 1:362331cec9b7 23 }
Bobty 1:362331cec9b7 24
Bobty 4:b521815f2657 25 void DrawingManager::Clear()
Bobty 4:b521815f2657 26 {
Bobty 4:b521815f2657 27 // printf("CLEAR\r\n");
Bobty 4:b521815f2657 28 if (pLedStrip)
Bobty 4:b521815f2657 29 pLedStrip->Clear();
Bobty 4:b521815f2657 30 }
Bobty 4:b521815f2657 31
Bobty 4:b521815f2657 32 void DrawingManager::RawFill(char* args, unsigned char* payload, int payloadLen, int payloadOffset)
Bobty 1:362331cec9b7 33 {
Bobty 4:b521815f2657 34 // printf("RAWFILL %s payloadLen %d, payloadOffset %d\r\n", args, payloadLen, payloadOffset);
Bobty 4:b521815f2657 35 int startLed = GetIntFromNameValPair(args, "start=", -1);
Bobty 4:b521815f2657 36 if (startLed != -1 && payloadLen > 0)
Bobty 4:b521815f2657 37 {
Bobty 4:b521815f2657 38 int numLeds = payloadLen / 3;
Bobty 4:b521815f2657 39 int fromLed = startLed + (payloadOffset / 3);
Bobty 4:b521815f2657 40 // printf("RAWFILL fromLed %d numLeds %d\r\n", fromLed, numLeds);
Bobty 4:b521815f2657 41 pLedStrip->RawFill(fromLed, numLeds, payload);
Bobty 4:b521815f2657 42 }
Bobty 1:362331cec9b7 43 }
Bobty 1:362331cec9b7 44
Bobty 4:b521815f2657 45 void DrawingManager::Fill(char* args)
Bobty 1:362331cec9b7 46 {
Bobty 4:b521815f2657 47 // printf("FILL %s\r\n", args);
Bobty 4:b521815f2657 48 int startLed = GetIntFromNameValPair(args, "start=", -1);
Bobty 4:b521815f2657 49 int numLeds = GetIntFromNameValPair(args, "len=", -1);
Bobty 4:b521815f2657 50 int r1 = GetIntFromNameValPair(args, "r1=", -1);
Bobty 4:b521815f2657 51 int g1 = GetIntFromNameValPair(args, "g1=", -1);
Bobty 4:b521815f2657 52 int b1 = GetIntFromNameValPair(args, "b1=", -1);
Bobty 4:b521815f2657 53 int r2 = GetIntFromNameValPair(args, "r2=", -1);
Bobty 4:b521815f2657 54 int g2 = GetIntFromNameValPair(args, "g2=", -1);
Bobty 4:b521815f2657 55 int b2 = GetIntFromNameValPair(args, "b2=", -1);
Bobty 4:b521815f2657 56 if (startLed != -1 && numLeds != -1 && r1 != -1 && g1 != -1 && b1 != -1)
Bobty 4:b521815f2657 57 {
Bobty 4:b521815f2657 58 if (r2 == -1 || g2 == -1 || b2 == -1)
Bobty 4:b521815f2657 59 pLedStrip->Fill(startLed, numLeds, r1, g1, b1);
Bobty 4:b521815f2657 60 else
Bobty 4:b521815f2657 61 pLedStrip->Fill(startLed, numLeds, r1, g1, b1, r2, g2, b2);
Bobty 4:b521815f2657 62 }
Bobty 1:362331cec9b7 63 }
Bobty 4:b521815f2657 64
Bobty 4:b521815f2657 65 void DrawingManager::ShowLeds()
Bobty 4:b521815f2657 66 {
Bobty 4:b521815f2657 67 // printf("SHOWLEDS\r\n");
Bobty 4:b521815f2657 68 if (pLedStrip)
Bobty 4:b521815f2657 69 pLedStrip->ShowLeds();
Bobty 4:b521815f2657 70 }
Bobty 4:b521815f2657 71
Bobty 5:910909f34907 72 void DrawingManager::DisplayIdle(unsigned int stepCount)
Bobty 5:910909f34907 73 {
Bobty 5:910909f34907 74 // Display a step in an auto sequence
Bobty 5:910909f34907 75 if (!pLedStrip)
Bobty 5:910909f34907 76 return;
Bobty 5:910909f34907 77 if (pLedStrip->IsBusy())
Bobty 5:910909f34907 78 return;
Bobty 5:910909f34907 79 pLedStrip->Clear();
Bobty 5:910909f34907 80 int ledsPerGroup = pLedStrip->GetNumLeds() / 10;
Bobty 5:910909f34907 81 for (int i = 0; i < pLedStrip->GetNumLeds(); i += ledsPerGroup)
Bobty 5:910909f34907 82 {
Bobty 5:910909f34907 83 RgbColor colrVal((stepCount * 7) + (i * 23) % 64, (stepCount * 17) + 77 + (i * 3) % 64, (stepCount * 37) + 117 + (i * 13) % 64);
Bobty 5:910909f34907 84 RgbColor colrVal2((stepCount * 17) + (i * 33) % 64, (stepCount * 3) + 13 + (i * 13) % 64, (stepCount * 77) + 11 + (i * 23) % 64);
Bobty 5:910909f34907 85 pLedStrip->Fill(i,ledsPerGroup,colrVal.r, colrVal.g, colrVal.b, colrVal2.r, colrVal2.g, colrVal2.b);
Bobty 5:910909f34907 86 }
Bobty 5:910909f34907 87 pLedStrip->ShowLeds();
Bobty 5:910909f34907 88 }
Bobty 5:910909f34907 89
Bobty 4:b521815f2657 90 int DrawingManager::GetIntFromNameValPair(char* buf, char* name, int invalidVal)
Bobty 4:b521815f2657 91 {
Bobty 4:b521815f2657 92 int val = invalidVal;
Bobty 4:b521815f2657 93 char* pFnd = strstr(buf, name);
Bobty 4:b521815f2657 94 if (pFnd)
Bobty 4:b521815f2657 95 val = atoi(pFnd + strlen(name));
Bobty 4:b521815f2657 96 return val;
Bobty 4:b521815f2657 97 }
Bobty 5:910909f34907 98