LCD.reverse = function (a) {
return h.map(function(b) {return (((b*0x0802&0x22110)|(b*0x8020&0x88440))*0x10101>>16)&0xFF;});
}
You can do it even faster with 64 bit maths (which Espruino supports) but it's something that I may be removing soon to make Espruino faster, smaller, and more JS compliant so I won't post that here ;)
Finally, you can use ArrayBuffers instead of Strings, and can predefine the code you want to add:
var preamble = E.toArrayBuffer("DIM\x00\x00\x80\x40");
LCD.flip = function () {
var d = new Uint8Array(this.buffer.length+preamble.length);
d.set(preamble,0);
d.set(this.buffer,preamble.length);
this.i2c.writeTo(0x27,d);
};
Hope that helps! I think I should probably add E.reverseByte as this comes up quite a lot. If that happens then you could be super fast and could just do: array.map(E.reverseByte)
Of course there's always the inline assembler too ;)
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I'd consider using
ArrayBuffer.map
. It's something that's on arrays in ES5, but has been extended to ArrayBuffers in ES6 (and Espruino :) ).But for bit reversal you can be faster as well - there's a fun (and scary) website here full of tricks: http://graphics.stanford.edu/~seander/bithacks.html
You can do it even faster with 64 bit maths (which Espruino supports) but it's something that I may be removing soon to make Espruino faster, smaller, and more JS compliant so I won't post that here ;)
Finally, you can use ArrayBuffers instead of Strings, and can predefine the code you want to add:
Hope that helps! I think I should probably add
E.reverseByte
as this comes up quite a lot. If that happens then you could be super fast and could just do:array.map(E.reverseByte)
Of course there's always the inline assembler too ;)