Rob Dobson / Mbed 2 deprecated SpideyWallWeb

Dependencies:   EthernetInterfacePlusHostname RdWebServer mbed-rtos mbed

Committer:
Bobty
Date:
Mon Aug 31 09:03:15 2015 +0000
Revision:
3:e5ea80fae61d
Parent:
1:362331cec9b7
Made ShowLeds an explicit command rather than automatic; Allow hostname to be set; Made sure HTTP response has keep-alive in it; Moved http_server into main loop (was in a separate thread); Added HSV fill command

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Bobty 1:362331cec9b7 1 #include "mbed.h"
Bobty 1:362331cec9b7 2 #include "cmdmsg.h"
Bobty 1:362331cec9b7 3 #include "ledstrip.h"
Bobty 1:362331cec9b7 4 //#define DETECT_LEDS
Bobty 1:362331cec9b7 5 #ifdef DETECT_LEDS
Bobty 1:362331cec9b7 6 #include "detectled.h"
Bobty 1:362331cec9b7 7 #endif
Bobty 1:362331cec9b7 8 //#define USE_SPIDEY_GEOM
Bobty 1:362331cec9b7 9 #ifdef USE_SPIDEY_GEOM
Bobty 1:362331cec9b7 10 #include "spideyGeometry.h"
Bobty 1:362331cec9b7 11 #endif
Bobty 1:362331cec9b7 12 /*
Bobty 1:362331cec9b7 13
Bobty 1:362331cec9b7 14 Message format is:
Bobty 1:362331cec9b7 15 <SEQ><CMD><CMD><CMD> ... <ZERO>
Bobty 1:362331cec9b7 16
Bobty 1:362331cec9b7 17 Where:
Bobty 1:362331cec9b7 18 <SEQ> is a two byte sequence count
Bobty 1:362331cec9b7 19 <CMD> is a series of bytes as follows:
Bobty 1:362331cec9b7 20 <LEN><COD><PARAMS>
Bobty 1:362331cec9b7 21
Bobty 1:362331cec9b7 22 Where:
Bobty 1:362331cec9b7 23 <LEN> is a two byte with value 1..65535 depicting msg len
Bobty 1:362331cec9b7 24 <COD> is a one byte command code - see below
Bobty 1:362331cec9b7 25 <PARAMS> are a series of bytes containing the parameters for the command
Bobty 1:362331cec9b7 26
Bobty 1:362331cec9b7 27 <COD> values:
Bobty 1:362331cec9b7 28
Bobty 1:362331cec9b7 29 NOTE MSB of COD is used to indicate that no response is required on success
Bobty 1:362331cec9b7 30 i.e. if MSB of COD is 1 then no response is required on success
Bobty 1:362331cec9b7 31
Bobty 1:362331cec9b7 32 (COD & 0x7f) ....
Bobty 1:362331cec9b7 33 0x01:
Bobty 1:362331cec9b7 34 Clear the entire strip
Bobty 3:e5ea80fae61d 35 There are no parameters
Bobty 1:362331cec9b7 36 0x02:
Bobty 1:362331cec9b7 37 Fill a series of leds with RGB values
Bobty 1:362331cec9b7 38 <PARAMS> := <START><NUM><RGB1><RGB2>
Bobty 1:362331cec9b7 39 Where:
Bobty 1:362331cec9b7 40 <START> is a two byte value (bigendian) for led to start series
Bobty 1:362331cec9b7 41 <NUM> is a two byte (bigendian) number of leds to set
Bobty 1:362331cec9b7 42 <RGB1> is the starting RGB value (24bits)
Bobty 1:362331cec9b7 43 <RGB2> is the ending RGB value (24bits) - OPTIONAL
Bobty 1:362331cec9b7 44 The RGB2 value is optional - the LEN value determines whether it is present or not
Bobty 1:362331cec9b7 45 - if present the colour values are interpolated (HSV) between RGB1 and RGB2
Bobty 1:362331cec9b7 46 - if not present all leds are set to colour RGB1
Bobty 1:362331cec9b7 47 0x03:
Bobty 1:362331cec9b7 48 Detect LED with opto-sensor (put opto-sensor on LED and run command)
Bobty 1:362331cec9b7 49 Sensor must be attached to p20 - currently using BPX65 with 470K pullup
Bobty 1:362331cec9b7 50 Returns string with LED number
Bobty 1:362331cec9b7 51 0x04:
Bobty 1:362331cec9b7 52 Set number of leds and split point
Bobty 1:362331cec9b7 53 <PARAMS> := <NUMLEDS><SPLITPOINT>
Bobty 1:362331cec9b7 54 Where:
Bobty 1:362331cec9b7 55 <NUMLEDS> is a two byte (bigendian) value for number of leds in strip
Bobty 1:362331cec9b7 56 <SPLITPOINT> is a two byte (bigendian) value for point at which DigitalOut(p10) is used instead of p12 for data
Bobty 1:362331cec9b7 57 (this is because the spidey wall is two parallel chains of LEDS)
Bobty 1:362331cec9b7 58 0x05:
Bobty 1:362331cec9b7 59 Raw RGB values for a series of leds
Bobty 1:362331cec9b7 60 <PARAMS> := <START><NUM><RGB1><RGB2><RGB2>....<RGBn>
Bobty 1:362331cec9b7 61 Where:
Bobty 1:362331cec9b7 62 <START> is a two byte value (bigendian) for led to start series
Bobty 1:362331cec9b7 63 <NUM> is a two byte (bigendian) number of leds to set
Bobty 1:362331cec9b7 64 <RGB1> is the RGB value for 1st LED (24bits)
Bobty 1:362331cec9b7 65 <RGB2> is the RGB value for 2nd LED (24bits)
Bobty 1:362331cec9b7 66 <RGBn> is the RGB value for nth LED (24bits)
Bobty 1:362331cec9b7 67 0x06:
Bobty 1:362331cec9b7 68 Set colour for leds on a pad
Bobty 1:362331cec9b7 69 <PARAMS> := <PAD><RGB1><RGB2>
Bobty 1:362331cec9b7 70 Where:
Bobty 1:362331cec9b7 71 <PAD> is the pad number (1 byte)
Bobty 1:362331cec9b7 72 <RGB1> is the starting RGB value (24bits)
Bobty 1:362331cec9b7 73 <RGB2> is the ending RGB value (24bits) - OPTIONAL
Bobty 1:362331cec9b7 74 The RGB2 value is optional - the LEN value determines whether it is present or not
Bobty 1:362331cec9b7 75 - if present the colour values are interpolated (HSV) between RGB1 and RGB2
Bobty 1:362331cec9b7 76 - if not present all leds are set to colour RGB1
Bobty 1:362331cec9b7 77 0x07:
Bobty 1:362331cec9b7 78 Set node and link info
Bobty 1:362331cec9b7 79 <PARAMS> := <NODE><NODEFLAGS><NODERGB><LINKIDX><LINKLEDSTART><LINKNUMLEDS><LINKRGB>
Bobty 1:362331cec9b7 80 Where:
Bobty 1:362331cec9b7 81 <NODE> is the node number (1 byte)
Bobty 1:362331cec9b7 82 <NODEFLAGS> LSB is 0 if the RGB value for the node is not to be changed, or 1 otherwise (1 byte)
Bobty 1:362331cec9b7 83 <NODERGB> is the RBG value for the leds in the node itself (3 bytes)
Bobty 1:362331cec9b7 84 <LINKIDX> is the index of the link (edge) from this node to control (1 byte)
Bobty 1:362331cec9b7 85 <LINKLEDSTART> is the LED along the link to start controlling (1 byte)
Bobty 1:362331cec9b7 86 <LINKNUMLEDS> is the number of LEDs to control (1 byte)
Bobty 1:362331cec9b7 87 <LINKRGB> is the colour to make the link LEDs (3 bytes)
Bobty 1:362331cec9b7 88
Bobty 3:e5ea80fae61d 89 0x08:
Bobty 3:e5ea80fae61d 90 Raw HSV values for a series of leds
Bobty 3:e5ea80fae61d 91 <PARAMS> := <START><NUM><HSV1><HSV2><HSV3>....<HSVn>
Bobty 3:e5ea80fae61d 92 Where:
Bobty 3:e5ea80fae61d 93 <START> is a two byte value (bigendian) for led to start series
Bobty 3:e5ea80fae61d 94 <NUM> is a two byte (bigendian) number of leds to set
Bobty 3:e5ea80fae61d 95 <HSV1> is the RGB value for 1st LED (16bits) - first 8 bits = H, upper 4 (bigendian) = S / 16, lower 4 = V / 16
Bobty 3:e5ea80fae61d 96 <HSV2> is the RGB value for 2nd LED
Bobty 3:e5ea80fae61d 97 <HSVn> is the RGB value for nth LED
Bobty 3:e5ea80fae61d 98
Bobty 3:e5ea80fae61d 99 0x09:
Bobty 3:e5ea80fae61d 100 ShowLeds
Bobty 3:e5ea80fae61d 101 Until this command is sent all other commands simply "paint" into the buffer and don't actually change the LEDs
Bobty 3:e5ea80fae61d 102 There are no parameters
Bobty 3:e5ea80fae61d 103
Bobty 1:362331cec9b7 104 */
Bobty 1:362331cec9b7 105
Bobty 1:362331cec9b7 106 #ifdef USE_SPIDEY_GEOM
Bobty 1:362331cec9b7 107 int cmdmsg::getLedNumFromSeq(const int* edgeLeds, int numLedsInSeq, int seqIdx)
Bobty 1:362331cec9b7 108 {
Bobty 1:362331cec9b7 109 if (seqIdx >= numLedsInSeq)
Bobty 1:362331cec9b7 110 return -1;
Bobty 1:362331cec9b7 111 int curSeqPos = 0;
Bobty 1:362331cec9b7 112 bool reverseSeq = false;
Bobty 1:362331cec9b7 113 for (int i = 0; i < MAX_SPIDEY_LINK_ELS/2; i++)
Bobty 1:362331cec9b7 114 {
Bobty 1:362331cec9b7 115 int startLedIdx = edgeLeds[i * 2];
Bobty 1:362331cec9b7 116 int endLedIdx = edgeLeds[i * 2 + 1];
Bobty 1:362331cec9b7 117 int nLeds = endLedIdx - startLedIdx + 1;
Bobty 1:362331cec9b7 118 if (startLedIdx > endLedIdx)
Bobty 1:362331cec9b7 119 {
Bobty 1:362331cec9b7 120 reverseSeq = true;
Bobty 1:362331cec9b7 121 nLeds = startLedIdx - endLedIdx + 1;
Bobty 1:362331cec9b7 122 }
Bobty 1:362331cec9b7 123 if (seqIdx - curSeqPos < nLeds)
Bobty 1:362331cec9b7 124 {
Bobty 1:362331cec9b7 125 if (reverseSeq)
Bobty 1:362331cec9b7 126 return startLedIdx - seqIdx;
Bobty 1:362331cec9b7 127 return startLedIdx + seqIdx;
Bobty 1:362331cec9b7 128 }
Bobty 1:362331cec9b7 129 curSeqPos = nLeds;
Bobty 1:362331cec9b7 130 }
Bobty 1:362331cec9b7 131 return -1;
Bobty 1:362331cec9b7 132 }
Bobty 1:362331cec9b7 133 #endif
Bobty 1:362331cec9b7 134
Bobty 1:362331cec9b7 135 char* cmdmsg::Interpret(const unsigned char* msg, int msgLen, ledstrip* pLedStrip)
Bobty 1:362331cec9b7 136 {
Bobty 1:362331cec9b7 137 // Get message details
Bobty 1:362331cec9b7 138 static char responseStr[50];
Bobty 1:362331cec9b7 139 unsigned char* ledStrip = pLedStrip->GetBuffer();
Bobty 1:362331cec9b7 140 int nBytesLeft = msgLen - 2;
Bobty 1:362331cec9b7 141 int seqCount = (msg[0] * 256) + msg[1];
Bobty 1:362331cec9b7 142 msg += 2;
Bobty 1:362331cec9b7 143 while (nBytesLeft > 0)
Bobty 1:362331cec9b7 144 {
Bobty 1:362331cec9b7 145 // Length of chunk
Bobty 1:362331cec9b7 146 int chunkLen = (msg[0] * 256) + msg[1];
Bobty 1:362331cec9b7 147 if (chunkLen == 0)
Bobty 1:362331cec9b7 148 break;
Bobty 1:362331cec9b7 149
Bobty 1:362331cec9b7 150 // Params length
Bobty 1:362331cec9b7 151 int paramsLen = chunkLen - 1;
Bobty 1:362331cec9b7 152 // printf("Chunklen = %d, Paramslen = %d\r\n", chunkLen, paramsLen);
Bobty 1:362331cec9b7 153
Bobty 1:362331cec9b7 154 // Command and whether response required on success
Bobty 1:362331cec9b7 155 int cmdCode = msg[2];
Bobty 1:362331cec9b7 156 if ((cmdCode & 0x80) == 0)
Bobty 1:362331cec9b7 157 sprintf(responseStr, "%04x OK", seqCount);
Bobty 1:362331cec9b7 158 else
Bobty 1:362331cec9b7 159 strcpy(responseStr, "");
Bobty 1:362331cec9b7 160
Bobty 1:362331cec9b7 161 // Move message pointer to assist in decoding the payload
Bobty 1:362331cec9b7 162 msg += 3;
Bobty 1:362331cec9b7 163 switch(cmdCode & 0x7f)
Bobty 1:362331cec9b7 164 {
Bobty 1:362331cec9b7 165 case 0x01: // Clear
Bobty 1:362331cec9b7 166 {
Bobty 1:362331cec9b7 167 // printf("Clear - nextbyte %d\r\n", msg[0]);
Bobty 1:362331cec9b7 168 pLedStrip->Clear();
Bobty 1:362331cec9b7 169 break;
Bobty 1:362331cec9b7 170 }
Bobty 1:362331cec9b7 171 case 0x02: // Fill
Bobty 1:362331cec9b7 172 {
Bobty 1:362331cec9b7 173 // printf("Fill\r\n");
Bobty 1:362331cec9b7 174
Bobty 1:362331cec9b7 175 int startLed = (msg[0] * 256) + msg[1];
Bobty 1:362331cec9b7 176 int numLeds = (msg[2] * 256) + msg[3];
Bobty 1:362331cec9b7 177 // printf("F Q%04x S%d N%d Pa%d Ln%d\r\n", seqCount, startLed, numLeds, paramsLen, msgLen);
Bobty 1:362331cec9b7 178 if (paramsLen == 10) // RGB2 is provided
Bobty 1:362331cec9b7 179 {
Bobty 1:362331cec9b7 180 pLedStrip->Fill(startLed, numLeds, msg[4], msg[5], msg[6], msg[7], msg[8], msg[9]);
Bobty 1:362331cec9b7 181 } else if (paramsLen == 7) // only RGB1 - so solid colour fill
Bobty 1:362331cec9b7 182 {
Bobty 1:362331cec9b7 183 pLedStrip->Fill(startLed, numLeds, msg[4], msg[5], msg[6]);
Bobty 1:362331cec9b7 184 }
Bobty 1:362331cec9b7 185 break;
Bobty 1:362331cec9b7 186 }
Bobty 1:362331cec9b7 187 case 0x03: // Detect LED
Bobty 1:362331cec9b7 188 {
Bobty 1:362331cec9b7 189 #ifdef DETECT_LEDS
Bobty 1:362331cec9b7 190 detectled ledDetector(p20);
Bobty 1:362331cec9b7 191 int selectedLed = ledDetector.DetectSelectedLed(pLedStrip);
Bobty 1:362331cec9b7 192 sprintf(responseStr, "%02x OK LED %d", seqCount, selectedLed);
Bobty 1:362331cec9b7 193 #endif
Bobty 1:362331cec9b7 194 break;
Bobty 1:362331cec9b7 195 }
Bobty 1:362331cec9b7 196 case 0x04: // Set numleds and splitpoint
Bobty 1:362331cec9b7 197 {
Bobty 1:362331cec9b7 198 // printf("Set numleds and splitpoint\r\n");
Bobty 1:362331cec9b7 199
Bobty 1:362331cec9b7 200 if (paramsLen == 4)
Bobty 1:362331cec9b7 201 {
Bobty 1:362331cec9b7 202 int numLeds = (msg[0] * 256) + msg[1];
Bobty 1:362331cec9b7 203 int splitPoint = (msg[2] * 256) + msg[3];
Bobty 1:362331cec9b7 204 pLedStrip->Resize(numLeds, splitPoint);
Bobty 1:362331cec9b7 205 }
Bobty 1:362331cec9b7 206 sprintf(responseStr, "%04x OK Resized", seqCount);
Bobty 1:362331cec9b7 207 break;
Bobty 1:362331cec9b7 208 }
Bobty 1:362331cec9b7 209 case 0x05: // Raw - set LEDs to RGB values from buffer
Bobty 1:362331cec9b7 210 {
Bobty 1:362331cec9b7 211 if (paramsLen > 4)
Bobty 1:362331cec9b7 212 {
Bobty 1:362331cec9b7 213 int startLed = (msg[0] * 256) + msg[1];
Bobty 1:362331cec9b7 214 int numLeds = (msg[2] * 256) + msg[3];
Bobty 1:362331cec9b7 215 if (paramsLen >= numLeds * 3 + 4)
Bobty 1:362331cec9b7 216 {
Bobty 1:362331cec9b7 217 pLedStrip->RawFill(startLed, numLeds, msg+4);
Bobty 1:362331cec9b7 218 // printf("R Q%04x S%d N%d Pa%d Ln%d\r\n", seqCount, startLed, numLeds, paramsLen, mMsgLen);
Bobty 1:362331cec9b7 219 }
Bobty 1:362331cec9b7 220 else
Bobty 1:362331cec9b7 221 {
Bobty 1:362331cec9b7 222 sprintf(responseStr, "%04x RAW FILL - BufLengthMismatch %d", seqCount, paramsLen);
Bobty 1:362331cec9b7 223 }
Bobty 1:362331cec9b7 224 }
Bobty 1:362331cec9b7 225 else
Bobty 1:362331cec9b7 226 {
Bobty 1:362331cec9b7 227 sprintf(responseStr, "%04x RAW FILL - ParamsLen Error %d", seqCount, paramsLen);
Bobty 1:362331cec9b7 228 }
Bobty 1:362331cec9b7 229 break;
Bobty 1:362331cec9b7 230 }
Bobty 1:362331cec9b7 231 case 0x06: // Set pad leds to a colour
Bobty 1:362331cec9b7 232 {
Bobty 1:362331cec9b7 233 #ifdef USE_SPIDEY_GEOM
Bobty 1:362331cec9b7 234 printf("Pad\r\n");
Bobty 1:362331cec9b7 235
Bobty 1:362331cec9b7 236 if (paramsLen > 2)
Bobty 1:362331cec9b7 237 {
Bobty 1:362331cec9b7 238 int padIdx = msg[0];
Bobty 1:362331cec9b7 239 if (padIdx < sizeof(_spideyPads)/sizeof(SpideyPadInfo))
Bobty 1:362331cec9b7 240 {
Bobty 1:362331cec9b7 241 int firstLed = _spideyPads[padIdx].padLeds[0];
Bobty 1:362331cec9b7 242 int numLeds = _spideyPads[padIdx].padLeds[1] - _spideyPads[padIdx].padLeds[0] + 1;
Bobty 1:362331cec9b7 243 if (paramsLen == 4) // Only 1 RGB value
Bobty 1:362331cec9b7 244 pLedStrip->Fill(firstLed, numLeds, msg[1], msg[2], msg[3]);
Bobty 1:362331cec9b7 245 else if (paramsLen == 7) // Two RGB values
Bobty 1:362331cec9b7 246 pLedStrip->Fill(firstLed, numLeds, msg[1], msg[2], msg[3], msg[4], msg[5], msg[6]);
Bobty 1:362331cec9b7 247 }
Bobty 1:362331cec9b7 248 }
Bobty 1:362331cec9b7 249 #endif
Bobty 1:362331cec9b7 250 break;
Bobty 1:362331cec9b7 251 }
Bobty 1:362331cec9b7 252 case 0x07: // Control node
Bobty 1:362331cec9b7 253 {
Bobty 1:362331cec9b7 254 #ifdef USE_SPIDEY_GEOM
Bobty 1:362331cec9b7 255 printf("Node\r\n");
Bobty 1:362331cec9b7 256
Bobty 1:362331cec9b7 257 if (paramsLen == 11)
Bobty 1:362331cec9b7 258 {
Bobty 1:362331cec9b7 259 int nodeIdx = msg[0];
Bobty 1:362331cec9b7 260 if (nodeIdx < sizeof(_spideyNodes)/sizeof(SpideyNodeInfo))
Bobty 1:362331cec9b7 261 {
Bobty 1:362331cec9b7 262 const SpideyNodeInfo& sni = _spideyNodes[nodeIdx];
Bobty 1:362331cec9b7 263
Bobty 1:362331cec9b7 264 // Handle the node leds
Bobty 1:362331cec9b7 265 printf("Node %d leds %d colour %d,%d,%d ... ", nodeIdx, sni.numNodeLeds, msg[2], msg[3], msg[4]);
Bobty 1:362331cec9b7 266 bool setNodeRGB = ((msg[1] & 0x01) != 0);
Bobty 1:362331cec9b7 267 if (setNodeRGB)
Bobty 1:362331cec9b7 268 {
Bobty 1:362331cec9b7 269 for (int i = 0; (i < sni.numNodeLeds) && (i < MAX_SPIDEY_NODE_LEDS); i++)
Bobty 1:362331cec9b7 270 {
Bobty 1:362331cec9b7 271 pLedStrip->Fill(sni.nodeLeds[i], 1, msg[2], msg[3], msg[4]);
Bobty 1:362331cec9b7 272 printf("Led %d", sni.nodeLeds[i]);
Bobty 1:362331cec9b7 273 }
Bobty 1:362331cec9b7 274 }
Bobty 1:362331cec9b7 275 printf("\r\n");
Bobty 1:362331cec9b7 276
Bobty 1:362331cec9b7 277 // Handle the link leds
Bobty 1:362331cec9b7 278 int linkIdx = msg[5];
Bobty 1:362331cec9b7 279 int linkLedStart = msg[6];
Bobty 1:362331cec9b7 280 int linkNumLeds = msg[7];
Bobty 1:362331cec9b7 281 printf("Link %d st %d num %d colour %d,%d,%d ... ", linkIdx, linkLedStart, linkNumLeds, msg[8], msg[9], msg[10]);
Bobty 1:362331cec9b7 282 if ((linkIdx < sni.numLinks) && (linkIdx < MAX_SPIDEY_NODE_LINKS))
Bobty 1:362331cec9b7 283 {
Bobty 1:362331cec9b7 284 const SpideyLinkInfo* pSli = sni.nodeLinks[linkIdx];
Bobty 1:362331cec9b7 285 for (int i = 0; i < linkNumLeds; i++)
Bobty 1:362331cec9b7 286 {
Bobty 1:362331cec9b7 287 int ledIdx = linkLedStart + i;
Bobty 1:362331cec9b7 288 int ledNumA = getLedNumFromSeq(pSli->edgeLedsA, pSli->edgeLengthA, ledIdx);
Bobty 1:362331cec9b7 289 if (ledNumA >= 0)
Bobty 1:362331cec9b7 290 {
Bobty 1:362331cec9b7 291 pLedStrip->Fill(ledNumA, 1, msg[8], msg[9], msg[10]);
Bobty 1:362331cec9b7 292 printf("A=%d/", ledNumA);
Bobty 1:362331cec9b7 293 }
Bobty 1:362331cec9b7 294 int ledNumB = getLedNumFromSeq(pSli->edgeLedsB, pSli->edgeLengthB, ledIdx);
Bobty 1:362331cec9b7 295 if (ledNumB >= 0)
Bobty 1:362331cec9b7 296 {
Bobty 1:362331cec9b7 297 pLedStrip->Fill(ledNumB, 1, msg[8], msg[9], msg[10]);
Bobty 1:362331cec9b7 298 printf("B=%d, ", ledNumB);
Bobty 1:362331cec9b7 299 }
Bobty 1:362331cec9b7 300 }
Bobty 1:362331cec9b7 301 }
Bobty 1:362331cec9b7 302 else
Bobty 1:362331cec9b7 303 {
Bobty 1:362331cec9b7 304 sprintf(responseStr, "%04x NODE - linkInvalid %d", seqCount, linkIdx);
Bobty 1:362331cec9b7 305 }
Bobty 1:362331cec9b7 306 printf("\r\n");
Bobty 1:362331cec9b7 307 }
Bobty 1:362331cec9b7 308 else
Bobty 1:362331cec9b7 309 {
Bobty 1:362331cec9b7 310 sprintf(responseStr, "%04x NODE - nodeInvalid %d", seqCount, nodeIdx);
Bobty 1:362331cec9b7 311 }
Bobty 1:362331cec9b7 312 }
Bobty 1:362331cec9b7 313 else
Bobty 1:362331cec9b7 314 {
Bobty 1:362331cec9b7 315 sprintf(responseStr, "%04x NODE - BufLengthMismatch %d", seqCount, paramsLen);
Bobty 1:362331cec9b7 316 }
Bobty 1:362331cec9b7 317 #endif
Bobty 1:362331cec9b7 318 break;
Bobty 1:362331cec9b7 319 }
Bobty 3:e5ea80fae61d 320 case 0x08: // Raw HSV
Bobty 3:e5ea80fae61d 321 {
Bobty 3:e5ea80fae61d 322 if (paramsLen > 4)
Bobty 3:e5ea80fae61d 323 {
Bobty 3:e5ea80fae61d 324 int startLed = (msg[0] * 256) + msg[1];
Bobty 3:e5ea80fae61d 325 int numLeds = (msg[2] * 256) + msg[3];
Bobty 3:e5ea80fae61d 326 if (paramsLen >= numLeds * 2 + 4)
Bobty 3:e5ea80fae61d 327 {
Bobty 3:e5ea80fae61d 328 pLedStrip->HsvFill(startLed, numLeds, msg+4);
Bobty 3:e5ea80fae61d 329 // printf("R Q%04x S%d N%d Pa%d\r\n", seqCount, startLed, numLeds, paramsLen);
Bobty 3:e5ea80fae61d 330 }
Bobty 3:e5ea80fae61d 331 else
Bobty 3:e5ea80fae61d 332 {
Bobty 3:e5ea80fae61d 333 sprintf(responseStr, "%04x HSV FILL - BufLengthMismatch %d", seqCount, paramsLen);
Bobty 3:e5ea80fae61d 334 }
Bobty 3:e5ea80fae61d 335 }
Bobty 3:e5ea80fae61d 336 else
Bobty 3:e5ea80fae61d 337 {
Bobty 3:e5ea80fae61d 338 sprintf(responseStr, "%04x HSV FILL - ParamsLen Error %d", seqCount, paramsLen);
Bobty 3:e5ea80fae61d 339 }
Bobty 3:e5ea80fae61d 340 break;
Bobty 3:e5ea80fae61d 341 }
Bobty 3:e5ea80fae61d 342 case 0x09: // ShowLeds
Bobty 3:e5ea80fae61d 343 {
Bobty 3:e5ea80fae61d 344 // printf("ShowLeds - nextbyte %d\r\n", msg[0]);
Bobty 3:e5ea80fae61d 345 pLedStrip->ShowLeds();
Bobty 3:e5ea80fae61d 346 break;
Bobty 3:e5ea80fae61d 347 }
Bobty 1:362331cec9b7 348 default:
Bobty 1:362331cec9b7 349 {
Bobty 1:362331cec9b7 350 sprintf(responseStr, "%04x CMD %02x UNKNOWN", seqCount, cmdCode);
Bobty 1:362331cec9b7 351 break;
Bobty 1:362331cec9b7 352 }
Bobty 1:362331cec9b7 353 }
Bobty 1:362331cec9b7 354
Bobty 1:362331cec9b7 355 // Move to next chunk
Bobty 1:362331cec9b7 356 nBytesLeft = nBytesLeft - chunkLen - 2;
Bobty 1:362331cec9b7 357 msg += paramsLen;
Bobty 1:362331cec9b7 358 // printf("Bytesleft = %d, msg[0] = %d\r\n", nBytesLeft, msg[0]);
Bobty 1:362331cec9b7 359 }
Bobty 1:362331cec9b7 360 return responseStr;
Bobty 1:362331cec9b7 361 }