update
This commit is contained in:
parent
4127182174
commit
dd38ede4ed
@ -33,6 +33,9 @@ class PrinterDevice extends EventEmitter {
|
|||||||
if (chkSerial) {
|
if (chkSerial) {
|
||||||
this._device = new escpos.Serial(this._serial)
|
this._device = new escpos.Serial(this._serial)
|
||||||
this._type = 'serial'
|
this._type = 'serial'
|
||||||
|
this._device.on('disconnect', () => {
|
||||||
|
self.emit('close')
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
this._device = new escpos.Console()
|
this._device = new escpos.Console()
|
||||||
this._type = 'console'
|
this._type = 'console'
|
||||||
|
34
server.js
34
server.js
@ -66,9 +66,10 @@ if (setupMode) {
|
|||||||
Printer.feed = config.printer.feed
|
Printer.feed = config.printer.feed
|
||||||
await Printer.connect()
|
await Printer.connect()
|
||||||
|
|
||||||
if (config.ble.enable) {
|
Printer.on('close', ()=>{
|
||||||
require('./ble')
|
console.log('device disconnect')
|
||||||
}
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (router !== null) {
|
if (router !== null) {
|
||||||
@ -91,12 +92,6 @@ localEvent.on('print', async str => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
let systemStatus = {
|
let systemStatus = {
|
||||||
ble: {
|
|
||||||
enable: false,
|
|
||||||
mac: '',
|
|
||||||
service: '',
|
|
||||||
characteristic: ''
|
|
||||||
},
|
|
||||||
printer: {
|
printer: {
|
||||||
connect: false,
|
connect: false,
|
||||||
serial: '',
|
serial: '',
|
||||||
@ -107,13 +102,8 @@ let systemStatus = {
|
|||||||
secret: ''
|
secret: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
systemStatus.ble.enable = config.ble.enable
|
|
||||||
systemStatus.secret = config.api.secret
|
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() {
|
function getPrinterStatus() {
|
||||||
systemStatus.printer.connect = Printer.isOpen
|
systemStatus.printer.connect = Printer.isOpen
|
||||||
systemStatus.printer.serial = Printer.serial
|
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()
|
|
||||||
}
|
|
@ -3,7 +3,6 @@
|
|||||||
<div class="column sixteen wide t-right">
|
<div class="column sixteen wide t-right">
|
||||||
<div class="ui segment">
|
<div class="ui segment">
|
||||||
<button class="ui button mini" type="button" id="gen-api-qr">Generate API QR</button>
|
<button class="ui button mini" type="button" id="gen-api-qr">Generate API QR</button>
|
||||||
<button class="ui button mini" type="button" id="gen-ble-qr">Generate BLE QR</button>
|
|
||||||
<button class="ui button mini red" type="button" id="dev-reboot">Reboot</button>
|
<button class="ui button mini red" type="button" id="dev-reboot">Reboot</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -20,30 +19,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="column eight wide">
|
|
||||||
<div class="segment ui">
|
|
||||||
<h4 class="ui header dividing">藍芽狀態</h4>
|
|
||||||
<div class="ui divided list">
|
|
||||||
<div class="item">
|
|
||||||
<div class="ui horizontal label basic">啟用狀態</div>
|
|
||||||
<div class="description t-right" id="en-ble">On</div>
|
|
||||||
</div>
|
|
||||||
<div class="item">
|
|
||||||
<div class="ui horizontal label basic">Mac Address</div>
|
|
||||||
<div class="description t-right" id="ble-mac"></div>
|
|
||||||
</div>
|
|
||||||
<div class="item">
|
|
||||||
<div class="ui horizontal label basic">ServiceUUID</div>
|
|
||||||
<div class="description t-right" id="ble-service"></div>
|
|
||||||
</div>
|
|
||||||
<div class="item">
|
|
||||||
<div class="ui horizontal label basic">CharacteristicUUID</div>
|
|
||||||
<div class="description t-right" id="ble-character"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="column eight wide">
|
<div class="column eight wide">
|
||||||
<div class="segment ui">
|
<div class="segment ui">
|
||||||
<h4 class="ui header dividing">印表機狀態</h4>
|
<h4 class="ui header dividing">印表機狀態</h4>
|
||||||
@ -137,14 +112,6 @@
|
|||||||
case 'status':
|
case 'status':
|
||||||
console.log(data)
|
console.log(data)
|
||||||
let d = data.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 = d.secret
|
||||||
$('#apikey').text(apikey)
|
$('#apikey').text(apikey)
|
||||||
@ -163,16 +130,15 @@
|
|||||||
|
|
||||||
connectSocket()
|
connectSocket()
|
||||||
|
|
||||||
$('#gen-ble-qr, #gen-api-qr').click(function () {
|
$('#gen-api-qr').click(function () {
|
||||||
let qrdiv = document.querySelector('div#qr')
|
let qrdiv = document.querySelector('div#qr')
|
||||||
qrdiv.innerHTML = ''
|
qrdiv.innerHTML = ''
|
||||||
let qr = new QRCode(qrdiv, {
|
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",
|
colorDark: "#000000",
|
||||||
colorLight: "#ffffff",
|
colorLight: "#ffffff",
|
||||||
correctLevel: QRCode.CorrectLevel.L
|
correctLevel: QRCode.CorrectLevel.L
|
||||||
})
|
})
|
||||||
// qr.makeCode(JSON.stringify(setting, null, 2))
|
|
||||||
$('#qr-dimmer').dimmer('show')
|
$('#qr-dimmer').dimmer('show')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user