Avatar for user6837

user6837

Member since Apr 2014 • Last active May 2014
  • 3 conversations
  • 13 comments

Most recent activity

  • in Interfacing
    Avatar for user6837

    Hi Moka,

    Yes, I had like that, this was just a desperate attempt to make it faster , right now, I am able to get 1 screen every 0.59 seconds which is barely usable.

  • in JavaScript
    Avatar for user6837

    In the end I dumped the 32 X 32 bmp into Uint32Arrays, here is the code:

    var image = require("fs").readFile("GIF/blue.bmp", "binary");
    image = image.substr(54,image.length);
    if (image.length==4096){
      var bytes = new Uint8Array(4096);
      for (var j=0;j<4096;j++){ 
        //bytes[j]=Math.round(image[j].charCodeA­t()*TONES/256);
        bytes[j]=image[j].charCodeAt();
        //console.log(image[j].charCodeAt());
      }
    }
    if (image.length==3072){
      var c = 0;
      var bytes = new Uint8Array(4096);
      for (var j=0;j<3072;j++){
        if ((c+1)%4==0){
          bytes[c]=128;
          c+=1;
        } else {
          //bytes[j]=Math.round(image[j].charCodeA­t()*TONES/256);
          bytes[c]=image[j].charCodeAt();
          
          //console.log(image[j].charCodeAt());
        }
        c+=1;
      }
    }
    
  • in Interfacing
    Avatar for user6837

    Same result.

  • in Interfacing
    Avatar for user6837

    It seems that what is empty on the left is filled with Ones, and consider the number negative, how do I avoid this?

  • in Interfacing
    Avatar for user6837

    Hi,

    I am using this:

    digitalWrite([B8,B8,B5,B6,B7],8|(((((col­&0x80808000)>>15)*0x4081)>>14)&7));
    

    The data from the file comes as

    BB,GG,RR,AA
    Blue Green Red Gamma
    

    The issue I am facing is that it works as long as I have as blue >128 other wise something funny happens, I don't really know what, here is the full code and some sample files.

    var TONES=1;
    console.log(getTime());
     var image = require("fs").readFile("GIF/blue.bmp", "binary");
    image = image.substr(54,image.length);
    if (image.length==4096){
      var bytes = new Uint8Array(4096);
      for (var j=0;j<4096;j++){ 
        //bytes[j]=Math.round(image[j].charCodeA­t()*TONES/256);
        bytes[j]=image[j].charCodeAt();
        //console.log(image[j].charCodeAt());
      }
    }
    if (image.length==3072){
      var c = 0;
      var bytes = new Uint8Array(4096);
      for (var j=0;j<3072;j++){
        if ((c+1)%4==0){
          bytes[c]=128;
          c+=1;
        } else {
          //bytes[j]=Math.round(image[j].charCodeA­t()*TONES/256);
          bytes[c]=image[j].charCodeAt();
          
          //console.log(image[j].charCodeAt());
        }
        c+=1;
      }
    }
    console.log(getTime());
    console.log(process.memory());
    image='';
    console.log(process.memory());
    console.log(bytes);
    
    
    function rcolor(x){
      return (TONES*x/256);
    }
    
    function clock(){
      digitalWrite(B8,1);
      digitalWrite(B8,0);
    }
    
    function latch(){
      digitalWrite([B9,B9],1);
    }
    
    //function linea(y){
    //  return (y-1)*128;
    //}
    function linea(y){
      if (y==1) {return 0;}
      if (y==2) {return 128;}
      if (y==3) {return 256;}
      if (y==4) {return 384;}
      if (y==5) {return 512;}
      if (y==6) {return 640;}
      if (y==7) {return 768;}
      if (y==8) {return 896;}
      if (y==9) {return 1024;}
      if (y==10) {return 1152;}
      if (y==11) {return 1280;}
      if (y==12) {return 1408;}
      if (y==13) {return 1536;}
      if (y==14) {return 1664;}
      if (y==15) {return 1792;}
      if (y==16) {return 1920;}
      if (y==17) {return 2048;}
      if (y==18) {return 2176;}
      if (y==19) {return 2304;}
      if (y==20) {return 2432;}
      if (y==21) {return 2560;}
      if (y==22) {return 2688;}
      if (y==23) {return 2816;}
      if (y==24) {return 2944;}
      if (y==25) {return 3072;}
      if (y==26) {return 3200;}
      if (y==27) {return 3328;}
      if (y==28) {return 3456;}
      if (y==29) {return 3584;}
      if (y==30) {return 3712;}
      if (y==31) {return 3840;}
      if (y==32) {return 3968;}
    }
    
    function toled(){
      var c=0;
      var v=0;
      var abcd = 0;
      for (var f=0;f<TONES;f++){
        for (var i=32;i>24;i--){
          digitalWrite(B13,1);
          abcd=32-i+1;
          y=linea(i);
          z=y+127;
          w=linea(i-8);
          x=w+127;
          /*for (var k=y;k<z+1;k=k+4){
            //if(rcolor(bytes[k])>c){
            if(bytes[k]>c){
              digitalWrite(LED3,1);
            } else {
              digitalWrite(LED3,0);
            }
            //if(rcolor(bytes[k+1])>c){
            if(bytes[k+1]>c){
              digitalWrite(LED2,1);
            } else {
              digitalWrite(LED2,0);
            }
            //if(rcolor(bytes[k+2])>c){
            if(bytes[k+2]>c){
              digitalWrite(LED1,1);
            } else {
              digitalWrite(LED1,0);
            }
            clock();
            w+=4;
            c+=1;
          }*/
        var words = new Uint32Array(bytes.buffer,y,(z-y)/4);
          //console.log(words);
          [].forEach.call(words,function(col){
            digitalWrite([B8,B8,B5,B6,B7],8|(((((col­&0x80808000)>>15)*0x4081)>>14)&7));
            console.log(col.toString(16),' - ',(col&0x80808000).toString(16));
          });
        latch();
    
        }
        c=0;
        for (var i=16;i>8;i--){
          digitalWrite(B13,1);
          abcd=32-i+1;
          y=linea(i);
          z=y+127;
          w=linea(i-8);
          x=w+127;
          /*for (var k=y;k<z+1;k=k+4){
            //if(rcolor(bytes[k])>c){
            if(bytes[k]>c){
              digitalWrite(B5,1);
            } else {
              digitalWrite(B5,0);
            }
            //if(rcolor(bytes[k+1])>c){
            if(bytes[k+1]>c){
              digitalWrite(B6,1);
            } else {
              digitalWrite(B6,0);
            }
            //if(rcolor(bytes[k+2])>c){
            if(bytes[k+2]>c){
              digitalWrite(B7,1);
            } else {
              digitalWrite(B7,0);
            }
            clock();
            w+=4;
            c+=1;
          }*/
        var words = new Uint32Array(bytes.buffer,y,(z-y)/4);
          //console.log(words);
          [].forEach.call(words,function(col){
            digitalWrite([B8,B8,LED3,LED2,LED1],8|((­(((col&0x80808000)>>15)*0x4081)>>14)&7))­;
          console.log(col.toString(16),' - ',(col&0x80808000).toString(16));
          });
        latch();
    
        }
      }
    }
    
    
    
    function onInit(){
      while (digitalRead(BTN1) == 0){
      var t =getTime();
      toled();
      console.log(' sale ', t - getTime());
      }
      console.log(process.memory());
    }
    
  • in Interfacing
    Avatar for user6837

    Hi Gordon, thanks, I 've been really trying to understand the logic on the bitwise operations so I could adjust something similar to get alike results in terms of time, but I don't really get it, according to my understanding the (*) and the shift both operations are equivalent to divide within 127 so why not just divide, perhaps I don't really get it at all, also on the digitalWrite for multiple pins on which order gets executed, from right to left?

    I really appreciate your feedback.

    Thnx

  • in Interfacing
    Avatar for user6837

    It would hold the last bit you send, it doesn't have internal pwm so basically you do the pwm by sending the screen over and over, so the source comes with 256 tones for each color, but on the first lines I make the conversion to the amount of tones I would use, in this case I chose 2 to get the times I posted above.

    Thnx for your response but I do not really understood the code you share wonder if you could explain a little more what it does, I am just beginning with Espruino and Javascript.

  • in Interfacing
    Avatar for user6837

    Using the attached as a test image with the following code, I ve got times of 1.43 seconds to fill a screen, however disabling the pin outputs the time falls down to 0.96 seconds, so I am sure more can be done to be optimized probably using assembler as the logic is actually quite simple, I expect this to be useful to someone with more skills that can improve it or changed to make it usable.

    //pin B2 as B1
    //pin B3 as G1
    //pin B4 as R1
    //pin B5 as B2
    //pin B6 as G2
    //pin B7 as G3
    //pin B8 as clock
    //pin b9 as Latch
    //pin b13 as OE
    var TONES=1;
    console.log(getTime());
     var image = require("fs").readFile("GIF/wizardcity00­001.bmp", "binary");
    image = image.substr(54,image.length);
    var bytes = new Uint8Array(4096);
    for (var j=0;j<4096;j++){ 
      bytes[j]=Math.round(image[j].charCodeAt(­)*TONES/256);
    }
    console.log(getTime());
    console.log(process.memory());
    image='';
    console.log(process.memory());
    
    
    function rcolor(x){
      return (TONES*x/256);
    }
    
    function clock(){
      digitalWrite(B8,1);
      digitalWrite(B8,0);
    }
    
    function latch(){
      digitalWrite(B9,1);
      digitalWrite(B9,0);
    }
    
    //function linea(y){
    //  return (y-1)*128;
    //}
    function linea(y){
      if (y==1) {return 0;}
      if (y==2) {return 128;}
      if (y==3) {return 256;}
      if (y==4) {return 384;}
      if (y==5) {return 512;}
      if (y==6) {return 640;}
      if (y==7) {return 768;}
      if (y==8) {return 896;}
      if (y==9) {return 1024;}
      if (y==10) {return 1152;}
      if (y==11) {return 1280;}
      if (y==12) {return 1408;}
      if (y==13) {return 1536;}
      if (y==14) {return 1664;}
      if (y==15) {return 1792;}
      if (y==16) {return 1920;}
      if (y==17) {return 2048;}
      if (y==18) {return 2176;}
      if (y==19) {return 2304;}
      if (y==20) {return 2432;}
      if (y==21) {return 2560;}
      if (y==22) {return 2688;}
      if (y==23) {return 2816;}
      if (y==24) {return 2944;}
      if (y==25) {return 3072;}
      if (y==26) {return 3200;}
      if (y==27) {return 3328;}
      if (y==28) {return 3456;}
      if (y==29) {return 3584;}
      if (y==30) {return 3712;}
      if (y==31) {return 3840;}
      if (y==32) {return 3968;}
    }
    
    function toled(){
      var c=0;
      var v=0;
      var abcd = 0;
      for (var f=0;f<TONES;f++){
        for (var i=32;i>24;i--){
          digitalWrite(B13,1);
          abcd=32-i+1;
          y=linea(i);
          z=y+127;
          w=linea(i-8);
          x=w+127;
          for (var k=y;k<z+1;k=k+4){
            //if(rcolor(bytes[k])>c){
            if(bytes[k]>c){
              digitalWrite(B2,1);
            } else {
              digitalWrite(B2,0);
            }
            //if(rcolor(bytes[k+1])>c){
            if(bytes[k+1]>c){
              digitalWrite(B3,1);
            } else {
              digitalWrite(B3,0);
            }
            //if(rcolor(bytes[k+2])>c){
            if(bytes[k+2]>c){
              digitalWrite(B4,1);
            } else {
              digitalWrite(B4,0);
            }
            clock();
            w+=4;
            c+=1;
          }
        latch();
        }
        c=0;
        for (var i=16;i>8;i--){
          digitalWrite(B13,1);
          abcd=32-i+1;
          y=linea(i);
          z=y+127;
          w=linea(i-8);
          x=w+127;
          for (var k=y;k<z+1;k=k+4){
            //if(rcolor(bytes[k])>c){
            if(bytes[k]>c){
              digitalWrite(B5,1);
            } else {
              digitalWrite(B5,0);
            }
            //if(rcolor(bytes[k+1])>c){
            if(bytes[k+1]>c){
              digitalWrite(B6,1);
            } else {
              digitalWrite(B6,0);
            }
            //if(rcolor(bytes[k+2])>c){
            if(bytes[k+2]>c){
              digitalWrite(B7,1);
            } else {
              digitalWrite(B7,0);
            }
            clock();
            w+=4;
            c+=1;
          }
        latch();
        }
      }
    }
    
    
    
    function onInit(){
      while (digitalRead(BTN1) == 0){
      var t =getTime();
      toled();
      console.log(' out ', t - getTime());
      }
      console.log(process.memory());
    }  
    
Actions