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// This example demonstrates registering a fingerprint on the zfm20 39// module. The procedure is as follows: 40// 41// 1. get an image, store it in characteristics buffer 1 42// 2. get another image, store it in characteristics buffer 2 43// 3. store the image, assuming the two fingerprints match 44 45// first, we need to register our address and password 46myFingerprintSensor.setPassword(fingerprint_lib.ZFM20_DEFAULT_PASSWORD); 47myFingerprintSensor.setAddress(fingerprint_lib.ZFM20_DEFAULT_ADDRESS); 48 49// now verify the password. If this fails, any other commands 50// will be ignored, so we just bail. 51if (myFingerprintSensor.verifyPassword()) 52 console.log("Password verified."); 53else 54{ 55 console.log("Password verification failed."); 56 process.exit(1); 57} 58 59console.log(" "); 60 61// get the first image 62console.log("Place a finger on the sensor."); 63while (myFingerprintSensor.generateImage() != fingerprint_lib.ZFM20.ERR_OK) 64 ; 65 66// in theory, we have an image 67console.log("Image captured, converting..."); 68 69var rv = myFingerprintSensor.image2Tz(1); 70 71if (rv != fingerprint_lib.ZFM20.ERR_OK) 72{ 73 console.log("Image conversion failed with error code " + rv); 74 process.exit(1) 75} 76 77console.log("Image conversion succeeded, remove finger."); 78setTimeout(function() 79{ 80 while (myFingerprintSensor.generateImage() != fingerprint_lib.ZFM20.ERR_NO_FINGER) 81 ; 82 83 console.log(" "); 84 console.log("Now place the same finger on the sensor."); 85 86 while (myFingerprintSensor.generateImage() == fingerprint_lib.ZFM20.ERR_NO_FINGER) 87 ; 88 89 console.log("Image captured, converting..."); 90 91 // save this one in slot 2 92 rv = myFingerprintSensor.image2Tz(2) 93 if (rv != fingerprint_lib.ZFM20.ERR_OK) 94 { 95 console.log("Image conversion failed with error code %d" + rv); 96 process.exit(1); 97 } 98 99 console.log("Image conversion succeeded, remove finger."); 100 console.log(" "); 101 102 console.log("Storing fingerprint at id 1"); 103 104 // create the model 105 rv = myFingerprintSensor.createModel() 106 if (rv != fingerprint_lib.ZFM20.ERR_OK) 107 { 108 if (rv == fingerprint_lib.ZFM20.ERR_FP_ENROLLMISMATCH) 109 console.log("Fingerprints did not match."); 110 else 111 console.log("createModel failed with error code " + rv); 112 process.exit(1); 113 } 114 115 // now store it, we hard code the id (second arg) to 1 here 116 rv = myFingerprintSensor.storeModel(1, 1); 117 if (rv != fingerprint_lib.ZFM20.ERR_OK) 118 { 119 console.log("storeModel failed with error code " + rv); 120 process.exit(1); 121 } 122 123 console.log(" "); 124 console.log("Fingerprint stored at id 1."); 125}, 1000); 126 127// Print message when exiting 128function exit() 129{ 130 myFingerprintSensor = null; 131 fingerprint_lib.cleanUp(); 132 fingerprint_lib = null; 133 console.log("Exiting"); 134 process.exit(0); 135} 136process.on('exit', exit); 137process.on('SIGINT', exit); 138