Rob Dobson / Mbed 2 deprecated SpideyWallWeb

Dependencies:   EthernetInterfacePlusHostname RdWebServer mbed-rtos mbed

Committer:
Bobty
Date:
Mon Aug 31 15:21:47 2015 +0000
Revision:
4:b521815f2657
Parent:
3:e5ea80fae61d
Child:
5:910909f34907
Tidied up and removed unnecessary code

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 1:362331cec9b7 8
Bobty 2:99eb4c6e9ea4 9 DrawingManager::DrawingManager()
Bobty 1:362331cec9b7 10 {
Bobty 2:99eb4c6e9ea4 11 pLedStrip = NULL;
Bobty 1:362331cec9b7 12 isBusy = false;
Bobty 1:362331cec9b7 13 }
Bobty 1:362331cec9b7 14
Bobty 4:b521815f2657 15 void DrawingManager::Init(int numLeds, int splitPoint)
Bobty 1:362331cec9b7 16 {
Bobty 2:99eb4c6e9ea4 17 pLedStrip = new ledstrip(numLeds, splitPoint);
Bobty 2:99eb4c6e9ea4 18 Thread::wait(100);
Bobty 2:99eb4c6e9ea4 19 pLedStrip->Clear();
Bobty 2:99eb4c6e9ea4 20 pLedStrip->ShowLeds();
Bobty 2:99eb4c6e9ea4 21
Bobty 1:362331cec9b7 22 }
Bobty 1:362331cec9b7 23
Bobty 4:b521815f2657 24 void DrawingManager::Clear()
Bobty 4:b521815f2657 25 {
Bobty 4:b521815f2657 26 // printf("CLEAR\r\n");
Bobty 4:b521815f2657 27 if (pLedStrip)
Bobty 4:b521815f2657 28 pLedStrip->Clear();
Bobty 4:b521815f2657 29 }
Bobty 4:b521815f2657 30
Bobty 4:b521815f2657 31 void DrawingManager::RawFill(char* args, unsigned char* payload, int payloadLen, int payloadOffset)
Bobty 1:362331cec9b7 32 {
Bobty 4:b521815f2657 33 // printf("RAWFILL %s payloadLen %d, payloadOffset %d\r\n", args, payloadLen, payloadOffset);
Bobty 4:b521815f2657 34 int startLed = GetIntFromNameValPair(args, "start=", -1);
Bobty 4:b521815f2657 35 if (startLed != -1 && payloadLen > 0)
Bobty 4:b521815f2657 36 {
Bobty 4:b521815f2657 37 int numLeds = payloadLen / 3;
Bobty 4:b521815f2657 38 int fromLed = startLed + (payloadOffset / 3);
Bobty 4:b521815f2657 39 // printf("RAWFILL fromLed %d numLeds %d\r\n", fromLed, numLeds);
Bobty 4:b521815f2657 40 pLedStrip->RawFill(fromLed, numLeds, payload);
Bobty 4:b521815f2657 41 }
Bobty 1:362331cec9b7 42 }
Bobty 1:362331cec9b7 43
Bobty 4:b521815f2657 44 void DrawingManager::Fill(char* args)
Bobty 1:362331cec9b7 45 {
Bobty 4:b521815f2657 46 // printf("FILL %s\r\n", args);
Bobty 4:b521815f2657 47 int startLed = GetIntFromNameValPair(args, "start=", -1);
Bobty 4:b521815f2657 48 int numLeds = GetIntFromNameValPair(args, "len=", -1);
Bobty 4:b521815f2657 49 int r1 = GetIntFromNameValPair(args, "r1=", -1);
Bobty 4:b521815f2657 50 int g1 = GetIntFromNameValPair(args, "g1=", -1);
Bobty 4:b521815f2657 51 int b1 = GetIntFromNameValPair(args, "b1=", -1);
Bobty 4:b521815f2657 52 int r2 = GetIntFromNameValPair(args, "r2=", -1);
Bobty 4:b521815f2657 53 int g2 = GetIntFromNameValPair(args, "g2=", -1);
Bobty 4:b521815f2657 54 int b2 = GetIntFromNameValPair(args, "b2=", -1);
Bobty 4:b521815f2657 55 if (startLed != -1 && numLeds != -1 && r1 != -1 && g1 != -1 && b1 != -1)
Bobty 4:b521815f2657 56 {
Bobty 4:b521815f2657 57 if (r2 == -1 || g2 == -1 || b2 == -1)
Bobty 4:b521815f2657 58 pLedStrip->Fill(startLed, numLeds, r1, g1, b1);
Bobty 4:b521815f2657 59 else
Bobty 4:b521815f2657 60 pLedStrip->Fill(startLed, numLeds, r1, g1, b1, r2, g2, b2);
Bobty 4:b521815f2657 61 }
Bobty 1:362331cec9b7 62 }
Bobty 4:b521815f2657 63
Bobty 4:b521815f2657 64 void DrawingManager::ShowLeds()
Bobty 4:b521815f2657 65 {
Bobty 4:b521815f2657 66 // printf("SHOWLEDS\r\n");
Bobty 4:b521815f2657 67 if (pLedStrip)
Bobty 4:b521815f2657 68 pLedStrip->ShowLeds();
Bobty 4:b521815f2657 69 }
Bobty 4:b521815f2657 70
Bobty 4:b521815f2657 71 int DrawingManager::GetIntFromNameValPair(char* buf, char* name, int invalidVal)
Bobty 4:b521815f2657 72 {
Bobty 4:b521815f2657 73 int val = invalidVal;
Bobty 4:b521815f2657 74 char* pFnd = strstr(buf, name);
Bobty 4:b521815f2657 75 if (pFnd)
Bobty 4:b521815f2657 76 val = atoi(pFnd + strlen(name));
Bobty 4:b521815f2657 77 return val;
Bobty 4:b521815f2657 78 }