UNPKG

rc522-c7z

Version:

Node.js package for Rapsberry Pi & RC522 RFID Reader combo, with TypeScript support

48 lines 1.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const child_process_1 = require("child_process"); const path = require("path"); const readline = require("readline"); let registeredCallback = null; let child = null; let mainProcessShutdown = false; let initChildProcess = () => { const tmp = path.join(__dirname, 'rc522_output.js'); child = child_process_1.spawn('node', [tmp]); let linereader = readline.createInterface(child.stdout, child.stdin); linereader.on('line', (rfidTagSerialNumber) => { if (!(registeredCallback instanceof Function)) { return; } registeredCallback(rfidTagSerialNumber); }); child.on('close', () => { if (mainProcessShutdown) { return; } initChildProcess(); }); }; process.once('SIGTERM', () => { process.exit(0); }); process.once('SIGINT', () => { process.exit(0); }); process.once('exit', () => { mainProcessShutdown = true; child.kill(); }); process.once('uncaughtException', (error) => { if (process.listeners('uncaughtException').length === 0) { mainProcessShutdown = true; child.kill(); throw error; } }); initChildProcess(); function listen(callback) { registeredCallback = callback; } exports.listen = listen; //# sourceMappingURL=index.js.map