I’m trying to wrap my head around this problem and have gotten stuck. I’m trying to link my imp up to a 64 pixel long string of WS2801 chips/leds. I’m attempting to post an array of values via an html form and have the imp update the strip with these colors over spi. I have a little explaining to do and my questions are at the bottom of this. Thank you in advance for your help.
Basically I have a html form posting an array of html hex colors. I have 64 inputs similar to this:
<input type="color" name="value[1]" value="#636F57"> <input type="color" name="value[2]" value="#636F57"> ...
I’m trying to figure out the structure of the input I will be receiving so I can parse and write it out to spi. Here’s my sample code trying to figure this out:
`
class LedInput extends InputPort
{
numPixels = 64;
currentPixel = 0;
constructor()
{
// Call the base constructor first
base.constructor("array", "array");
}
function set(value)
{
//output point A
server.log(typeof value);
foreach (val in value)
{
//output point B
server.log(typeof value.a);
}
}
}
// Register with the server
imp.configure(“Web Color”, [ LedInput() ], []);
// End of code.
`
According to http://devwiki.electricimp.com/doku.php?id=httpapi:
If you send url-encoded fields e.g. value[a] = 1, you'll get a table on your imp like {a = 1}.
If you’ve made it this far, thank you
Here are my questions/problems:
- At output point A, the type is reported as array. Shouldn't this be a table?
- At output point B, the type is reported as null. Am I iterating through this the right way?
- Any suggestions, or examples I missed in my searches? Would you recommend any changes?
After I get this sorted out, I plan to start following the advice posted here to write this data via spi:
http://forums.electricimp.com/discussion/197/electric-imp-out-of-memory-crashing/p1