• I'm just copying a some code here from a PM. @ChrisB was asking about the Adafruit fingerprint sensor...

    Connections:

    Reader Espruino
    Vin / power input (Red) Vbat
    TD / Data output TTL Logical (green) C11
    RD / Data input TTL logical (white) C10
    GND (black) GND

    The module itself needs writing to that it can cope with the 'timeout' used by Adafruit's module while still allowing tasks to run in the background - so it needs to use callbacks...

    So far, the initial suggested module looks like:

    receivedData=[];
    Serial4.setup(57600);
    Serial4.onData(function (e) { receivedData.push(e.data.charCodeAt(0)); });
    
    var C = {
    OK: 0x00,
    PACKETRECIEVEERR: 0x01,
    NOFINGER: 0x02,
    IMAGEFAIL: 0x03,
    IMAGEMESS: 0x06,
    FEATUREFAIL: 0x07,
    NOMATCH: 0x08,
    NOTFOUND: 0x09,
    ENROLLMISMATCH: 0x0A,
    BADLOCATION: 0x0B,
    DBRANGEFAIL: 0x0C,
    UPLOADFEATUREFAIL: 0x0D,
    PACKETRESPONSEFAIL: 0x0E,
    UPLOADFAIL: 0x0F,
    DELETEFAIL: 0x10,
    DBCLEARFAIL: 0x11,
    PASSFAIL: 0x13,
    INVALIDIMAGE: 0x15,
    FLASHERR: 0x18,
    INVALIDREG: 0x1A,
    ADDRCODE: 0x20,
    PASSVERIFY: 0x21,
    STARTCODE: 0xEF01,
    COMMANDPACKET: 0x1,
    DATAPACKET: 0x2,
    ACKPACKET: 0x7,
    ENDDATAPACKET: 0x8,
    TIMEOUT: 0xFF,
    BADPACKET: 0xFE,
    GETIMAGE: 0x01,
    IMAGE2TZ: 0x02,
    REGMODEL: 0x05,
    STORE: 0x06,
    EMPTY: 0x0D,
    VERIFYPASSWORD: 0x13,
    HISPEEDSEARCH: 0x1B,
    TEMPLATECOUNT: 0x1D
    };
    
    var thePassword = 0;
    var theAddress = 0xFFFFFFFF;
    
    function writePacket(addr, packetType, packet) {
      var len = packet.length+2;
      Serial4.write([
            (C.STARTCODE >> 8) & 0xFF), 
            C.STARTCODE & 0xFF,
            (addr >> 24) & 0xFF,
            (addr >> 16) & 0xFF,
            (addr >> 8) & 0xFF,
            addr & 0xFF,
            packetType,
            (len >> 8) & 0xFF,
            len &0xFF]);
      
      var sum = (len>>8) + (len&0xFF) + packetType;
      Serial4.write(packet);
      for (var i in packet) sum += packet[i];
      Serial4.write([(sum>>8)&0xFF, sum&0xFF])
    }
    
    function getReply(callback) {
      receivedData=[];
      setTimeout(function() {
       // do some checks here?
       callback(receivedData);
      }, 500); // 500ms
    }
    
    
    function verifyPassword(callback) {
      var packet = [
        C.VERIFYPASSWORD, 
        (thePassword >> 24) & 0xFF, 
        (thePassword >> 16) & 0xFF,
        (thePassword >> 8) & 0xFF, 
        thePassword & 0xFF
      ];
      writePacket(theAddress, C.COMMANDPACKET, packet);
      getReply(function(packet) {
       callback((packet[0] == C.ACKPACKET) && (packet[1] == C.OK));
      });    
    }
    
About

Avatar for Gordon @Gordon started