• It's because the Uint8Array is a 'view' of the original array rather than a new array. You're trying to make it go past the end of the existing array, so if you set bytes in it they're ignored.

    I guess the best you could do is:

    var last=new Uint8Array(84+2);
    last.set(new Uint8Array(this.buffer,i*84,84+2));
    last[84]=this.buffer[0];
    last[85]=this.buffer[1];
    spi.send(last, ce); 
    

    Or, you could set CE manually, which is probably better (in fact you may not even have to bother):

    ce.reset();
    spi.send(new Uint8Array(this.buffer,i*84,84+2)); 
    spi.send(new Uint8Array(this.buffer,0,2)); 
    ce.set();
    

    Looks like this isn't 100% JS compliant though - in proper JS there seems to be a difference between:

    new Uint8Array(uint8Array,i*84,84+2) // silently ignores first and second arguments, returns a *copy* of uint8Array
    new Uint8Array(uint8Array.buffer,i*84,84+2) // does what Espruino does - creates a view
    

    I guess I should probably change the drivers over and then tweak Espruino's implementation - I prefer my version though ;)

    By the way, on my LCD it works great without the extra 2 bytes, so I wonder whether it's just some driver chips that have the issue - or maybe it's something to do with initialisation.

About

Avatar for Gordon @Gordon started