transform a ArrayBuffer to an array

Posted on
  • Hello,

    i'm trying to work with arrayBuffer but i'm bad...
    I'm using exemple in the graphics library at Internal Use

    require("Font4x7").add(Graphics);
    var g = Graphics.createArrayBuffer(5,7,1, {zigzag:true});
    g.setFont4x7();
    g.drawString("hello",compteur,0);
    
    Graphics.prototype.print = function() {
      for (var y=0;y<this.getHeight();y++)
        console.log(new Uint8Array(this.buffer,this.getWidth()*y­,this.getWidth()));
    };
    

    when i use the g.print()it does not produce an array of 0 and 1...
    but that...

    new Uint8Array([112, 240, 199, 7, 4])
    new Uint8Array(5)
    new Uint8Array(5)
    new Uint8Array(5)
    new Uint8Array(5)
    new Uint8Array(5)
    new Uint8Array(5)
    

    i would like to send via Serial an array of row and colum as in the exemple of print()

    thanks for you help

  • The issue is that you're using 1 bit per pixel, so 8 bits are in each byte - and you're trying to retrieve bytes. If you used:

    var g = Graphics.createArrayBuffer(5,7,8, {zigzag:true});
    

    Then I'm pretty sure that'll work fine. I'm not sure what you're planning but you may find you don't want the zigzag:true either, as that will make alternate scanlines reversed.

  • Hye, Gordon
    I need of a byte array (0,1) (pixel OFF, pixel ON) row by raw.
    the matrix is on/off not in 8bits.
    or i do not understand what is an arrayBuffer...

    in your example it is suppose to do that (it's exactly what i need to transfer to my display via serial):

    //0,0,0,0,0,0,0,0
    //0,1,1,0,0,0,1,1
    //0,1,1,0,0,0,1,1
    //0,0,1,1,0,1,1,0
    //0,0,0,1,1,1,0,0
    //0,0,1,1,0,1,1,0
    //0,1,1,0,0,0,1,1
    //0,1,1,0,0,0,1,1
    

    it does not... why?

  • Graphics.prototype.print = function() {
      for (var y=0;y<this.getHeight();y++)
        console.log(new Uint8Array(this.buffer,this.getWidth()*y­,this.getWidth()).toString());
    };
    var g = Graphics.createArrayBuffer(8,8,8);
    g.setColor(1);
    g.drawString("X",0,0);
    g.print();
    
     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v95.43 Copyright 2017 G.Williams
    >1,0,1,0,0,0,0,0
    1,0,1,0,0,0,0,0
    0,1,0,0,0,0,0,0
    1,0,1,0,0,0,0,0
    1,0,1,0,0,0,0,0
    0,0,0,0,0,0,0,0
    0,0,0,0,0,0,0,0
    0,0,0,0,0,0,0,0
    

    I added .toString because now it outputs new Uint8Array([0,0,0,0,0,0,0,0]) as new Uint8Array(8) to save space.

    And the output is different because the default font has changed.

  • Hello,
    As i enable to control the flipdot hannio' display ( see forum) with an espruino.
    I'm trying to communicate to an arduino which control the display.
    Spi and i2c are in use in the arduino so i do with serial. It's not really good (i suppose i'm trying comm to fast) but i'm able iniate a com between the boards...
    I'm able to transfer array, but at the moment, not the arrayBuffer.

    Regards

  • Ahh - try Serial.println(new Uint8Array(...).toString()). I'd have thought that would output something like 0,0,1,0,0,1,0,0\r\n that should be pretty easy to receive.

  • yes, great the use of println()... there is a final CR, easy to detect to call the refresh display function.
    thanks.

    é.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

transform a ArrayBuffer to an array

Posted by Avatar for Mrbbp @Mrbbp

Actions