You are reading a single comment by @JumJum and its replies. Click here to read the full conversation.
  • I'm working on a small object for 8*8 matrix of WS2812.
    The project is right now developed for ESP8266, but my problems are more general for Espruino (hope so).
    Based on @nkolban video a VM for ESP8266 is running, and a lot of testing runs fine.
    Since I'm a newbie in this, I learned a lot but still run into problems.
    Actual there are 2 problems, and if somebody could give me a hint, ....

    • JSON wrapper with more than 4 parameters (in my case setPixel(row,column,red,green,blue)) gives a warning during compiling. Sooner or later this will be changed to use a color instead of three values, therefore its not a big problem. Anyway, if somebody like me uses tons of args in the future, ...
    • main problem is right now how to read my pixelbuffer (uint8array), change some values and store back.

    Some code snippets:

    • create the buffer

      JsVar *buf = jswrap_arrayBuffer_constructor(192); //192 is 8 rows with 8 columns having rgb
      jsvUnlock2(jsvAddNamedChild(parent,buf,"­buffer"),buf); // I can see the buffer after that
      
      
    • read buffer inside a function like setPixel

      JsVar *buf = jsvObjectGetChild(parent,"buffer",false)­; //read buffer
      JSV_GET_AS_CHAR_ARRAY(pixels,dataLength,­buf); //convert to char Array
      uint8_t *p = (uint8_t *)pixels;//get a pointer to that
      
    • doing changes like a fill

      for(int i = 0; i < 64;i++){ //loop over all fields to set colors
      *p++ = (char) green; *p++ = (char) red......
      
    • and last not least store the changes back. I did only find a way by creating an JsVar for string, then convert to ArrayBuffer. This, obviously has problems with colorvalue of zero.

      JsVar *bufb = jsvNewFromString(pixels); //convert to JsVar-string, and get the zero problem (end of string)
      JsVar *bufa = jsvNewArrayBufferFromString(bufb,0); //did not find a function to create this from char array directly 
      jsvSetNamedChild(parent,bufa,"buffer");
      
About

Avatar for JumJum @JumJum started