• In order to write to an LCD screen, I need to send over I2C a 1024 byte buffer, prefixed with "DIM\x00\x00\x80\x40". The only way I know to do this is to convert the buffer to a string, by looping over it one character at a time, and then just add the two together.

    exports.connect = function(i2c) {
    
      var LCD = Graphics.createArrayBuffer(128,64,1);
      LCD.i2c=i2c;
      LCD.flip = function () {
        this.i2c.writeTo(0x27,"DIM\x00\x00\x80\x40"+this.atos(this.buffer)); 
      };  
    
      LCD.atos= function (a) {
        var s = "";
        for (var j in a) { 
          s+=String.fromCharCode(j);  
        }
        return s };
      }
      return LCD;
    };
    

    This is slow enough that the flip() function would take a fraction of a second to return - but the display wants the bits in each byte to be in the opposite order than what the Espruino normally outputs them as... So I've been doing this, and it works, but it takes about a second to return.... Any thoughts on how to do this better?

    exports.connect = function(i2c) {
      var LCD = Graphics.createArrayBuffer(128,64,1);
      LCD.i2c=i2c;
      LCD.flip = function () {
        this.i2c.writeTo(0x27,"DIM\x00\x00\x80\x40"+this.reverse(this.buffer)); 
      };  
    
      LCD.reverse = function (a) {
        var s = "";
        for (var h in a) { 
          var i=a[h];                                                                                  
          j=(i>>7|(i>>5&0x02)|(i>>3&0x04)|(i>>1&0x08)|(i<<1&0x10)|(i<<3&0x20)|(i<<5&0x40)|(i<<7&0x80));
          s+=String.fromCharCode(j);  
        }
        return s };
      }
      return LCD;
    };
    

    Thanks in advance...

About

Avatar for DrAzzy @DrAzzy started