Last active
February 6, 2017 15:01
-
-
Save linktohack/ba3a3306fe1378cdb7999d84cccc357d to your computer and use it in GitHub Desktop.
NFC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var nfc = require('nfc').nfc; | |
var util = require('util'); | |
var Badge = { | |
logging: true, | |
read: function(callback) { | |
var Badge = this; | |
var i = 0; | |
Badge.logging && console.log('nfc.version(): ' + util.inspect(nfc.version(), { depth: null })); | |
Badge.logging && console.log('nfc.scan(): ' + util.inspect(nfc.scan(), { depth: null })); | |
var loop = function() { | |
var device = new nfc.NFC(); | |
device.on('read', function(tag) { | |
Badge.logging && console.log(++i, tag.uid); | |
callback(tag); | |
}); | |
device.on('stopped', function() { | |
Badge.logging && console.log('rebooting'); | |
setTimeout(loop, 1000); | |
}); | |
device.start(); | |
}; | |
loop(); | |
} | |
}; | |
Badge.logging = false; | |
Badge.read(function(tag) { | |
console.log('tag', tag.uid); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment