You are reading a single comment by @DrAzzy and its replies. Click here to read the full conversation.
  • Well I'll be damned. Works like a charm, despite the fact that it doesn't even try to look for the sync pulse, or expunge munged packets on the basis of pulses of the wrong length... Edit: oh ya, you do ditch received data on the basis of bad lengths - that makes more sense..

    It does still throw up the FIFO_FULL error flag though (also, you can just forget about typing stopListen if doing it interactively - while listening, it barely responds - i got 1 character in each time it successfully read a transmission)

    I guess the next step is to demonstrate two-way communication with a pair of them.

    
    var n="";
    var wr;
    
    function sigOff(e) {
      var d=e.time-e.lastTime;
      if (d>0.0004 && d<0.0013) n+=(d>0.0008)?1:0;
      else{
        if (n.length==32)  parseRx(n);
        n="";
      }
    }
    
    function parseRx(rcv) {
      console.log(rcv);
      var ext=parseInt(rcv.substr(24,4),2);
      var b2=parseInt(rcv.substr(16,8),2);
      var b1=parseInt(rcv.substr(8,8),2);
      var b0=parseInt(rcv.substr(0,8),2);
      var csc=parseInt(rcv.substr(28,4),2);
      ncsc=b0^b1^b2;
      ncsc=(ncsc&0x0F)^((ncsc>>4)&0x0F)^ext;
      console.log("B0:"+b0+" B1:"+b1+" B2:"+b2+" ext:"+ext+" csc:"+csc+" calccsc:"+ncsc);
      if (ncsc==csc) {
        clearWatch(wf);
        //processRx(b0,b1,b2,ext);
      } else {
        console.log("Bad checksum!");
      }
    }
    
    function startListen() {
      wf=setWatch(sigOff,C6,{repeat:true,edge:­"falling"});
      console.log("Listening started");
    }
    
    function stopListen() {
      clearWatch(wf);
      n="";
    }
    
    

    This is still not really suitable for remotely controlling the Espruino, since it practically hangs when not receiving - but it's certainly fine for receiving data that it's expecting, which I think is the more attractive use case anyway.

About

Avatar for DrAzzy @DrAzzy started