diff --git a/PrinterDev.js b/PrinterDev.js index cf7b5bb..70fdf9d 100644 --- a/PrinterDev.js +++ b/PrinterDev.js @@ -33,6 +33,9 @@ class PrinterDevice extends EventEmitter { if (chkSerial) { this._device = new escpos.Serial(this._serial) this._type = 'serial' + this._device.on('disconnect', () => { + self.emit('close') + }) } else { this._device = new escpos.Console() this._type = 'console' diff --git a/server.js b/server.js index 0624c5d..67114d0 100644 --- a/server.js +++ b/server.js @@ -66,9 +66,10 @@ if (setupMode) { Printer.feed = config.printer.feed await Printer.connect() - if (config.ble.enable) { - require('./ble') - } + Printer.on('close', ()=>{ + console.log('device disconnect') + }) + } if (router !== null) { @@ -91,12 +92,6 @@ localEvent.on('print', async str => { }) let systemStatus = { - ble: { - enable: false, - mac: '', - service: '', - characteristic: '' - }, printer: { connect: false, serial: '', @@ -107,13 +102,8 @@ let systemStatus = { secret: '' } -systemStatus.ble.enable = config.ble.enable systemStatus.secret = config.api.secret -if (config.ble.enable) { - systemStatus.ble.mac = await getBTAddr() - systemStatus.ble.service = config.ble.uuid.service - systemStatus.ble.characteristic = config.ble.uuid.characteristic -} + function getPrinterStatus() { systemStatus.printer.connect = Printer.isOpen systemStatus.printer.serial = Printer.serial @@ -148,17 +138,3 @@ ws.on('connection', async (client, req) => { } }) }) - -async function getBTAddr() { - let address = await new Promise((resolve, reject) => { - exec('bt-adapter -i | grep -i address', (err, sout, serr) => { - if (err) return resolve('') - resolve(sout) - }) - }) - - address = address.trim() - let arr = address.split(' ') - if (arr.length !== 2) return '' - return arr[1].trim() -} \ No newline at end of file diff --git a/views/dashboard/statusview.ejs b/views/dashboard/statusview.ejs index 13dfae0..3674064 100644 --- a/views/dashboard/statusview.ejs +++ b/views/dashboard/statusview.ejs @@ -3,7 +3,6 @@