1/*jslint node:true, vars:true, bitwise:true, unparam:true */ 2/*jshint unused:true */ 3/* 4* Author: Zion Orent <zorent@ics.com> 5* Copyright (c) 2015 Intel Corporation. 6* 7* Permission is hereby granted, free of charge, to any person obtaining 8* a copy of this software and associated documentation files (the 9* "Software"), to deal in the Software without restriction, including 10* without limitation the rights to use, copy, modify, merge, publish, 11* distribute, sublicense, and/or sell copies of the Software, and to 12* permit persons to whom the Software is furnished to do so, subject to 13* the following conditions: 14* 15* The above copyright notice and this permission notice shall be 16* included in all copies or substantial portions of the Software. 17* 18* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25*/ 26var fingerprint_lib = require('jsupm_zfm20'); 27 28// Instantiate a ZFM20 Fingerprint reader on UART 0 29var myFingerprintSensor = new fingerprint_lib.ZFM20(0); 30 31// make sure port is initialized properly. 57600 baud is the default. 32if (!myFingerprintSensor.setupTty(fingerprint_lib.int_B57600)) 33{ 34 console.log("Failed to setup tty port parameters"); 35 process.exit(1); 36} 37 38// how many valid stored templates (fingerprints) do we have? 39console.log("Total stored templates: " + myFingerprintSensor.getNumTemplates()); 40console.log(" "); 41 42// now spin waiting for a fingerprint to successfully image 43console.log("Waiting for finger print..."); 44 45while (myFingerprintSensor.generateImage() == fingerprint_lib.ZFM20.ERR_NO_FINGER) 46 ; 47 48// in theory, we have an image 49console.log("Image captured, converting..."); 50 51var rv = myFingerprintSensor.image2Tz(1); 52if (rv != fingerprint_lib.ZFM20.ERR_OK) 53{ 54 console.log("Image conversion failed with error code " + rv); 55 process.exit(1); 56} 57 58console.log("Image conversion succeeded."); 59console.log("Searching database..."); 60 61var myid = new fingerprint_lib.uint16Array(0); 62myid.setitem(0, 0); 63var myscore = new fingerprint_lib.uint16Array(0); 64myscore.setitem(0, 0); 65 66// we search for a print matching slot 1, where we stored our last 67// converted fingerprint 68rv = myFingerprintSensor.search(1, myid, myscore) 69if (rv != fingerprint_lib.ZFM20.ERR_OK) 70{ 71 if (rv == fingerprint_lib.ZFM20.ERR_FP_NOTFOUND) 72 { 73 console.log("Finger Print not found"); 74 process.exit(0); 75 } 76 else 77 { 78 console.log("Search failed with error code " + rv); 79 process.exit(1); 80 } 81} 82 83console.log("Fingerprint found!"); 84console.log("ID: " + myid.getitem(0) + ", Score: " + myscore.getitem(0)); 85 86 87// Print message when exiting 88function exit() 89{ 90 myFingerprintSensor = null; 91 fingerprint_lib.cleanUp(); 92 fingerprint_lib = null; 93 console.log("Exiting"); 94 process.exit(0); 95} 96process.on('SIGINT', exit); 97process.on('exit', exit); 98