From dd38ede4ed241bfddaf033f6c2897c33553b426c Mon Sep 17 00:00:00 2001 From: Jay Date: Fri, 15 Dec 2017 22:58:04 +0800 Subject: [PATCH] update --- PrinterDev.js | 3 +++ server.js | 34 +++++------------------------- views/dashboard/statusview.ejs | 38 ++-------------------------------- 3 files changed, 10 insertions(+), 65 deletions(-) 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 @@
-
@@ -20,30 +19,6 @@ -
-
-

藍芽狀態

-
-
-
啟用狀態
-
On
-
-
-
Mac Address
-
-
-
-
ServiceUUID
-
-
-
-
CharacteristicUUID
-
-
-
-
-
-

印表機狀態

@@ -137,14 +112,6 @@ case 'status': console.log(data) let d = data.data - $('#en-ble').text(d.ble.enable ? 'On' : 'Off') - $('#ble-mac').text(d.ble.mac) - $('#ble-service').text(d.ble.service) - $('#ble-character').text(d.ble.characteristic) - - setting.mac = d.ble.mac - setting.service = d.ble.service - setting.characteristic = d.ble.characteristic apikey = d.secret $('#apikey').text(apikey) @@ -163,16 +130,15 @@ connectSocket() - $('#gen-ble-qr, #gen-api-qr').click(function () { + $('#gen-api-qr').click(function () { let qrdiv = document.querySelector('div#qr') qrdiv.innerHTML = '' let qr = new QRCode(qrdiv, { - text: this.id === 'gen-ble-qr' ? JSON.stringify(setting, null, 2) : JSON.stringify({ apikey }, null, 2), + text: JSON.stringify({ apikey }, null, 2), colorDark: "#000000", colorLight: "#ffffff", correctLevel: QRCode.CorrectLevel.L }) - // qr.makeCode(JSON.stringify(setting, null, 2)) $('#qr-dimmer').dimmer('show') })