Merge branch 'feature/remove_ble' into develop
This commit is contained in:
commit
01a4bcfb23
@ -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'
|
||||
|
34
server.js
34
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()
|
||||
}
|
@ -3,7 +3,6 @@
|
||||
<div class="column sixteen wide t-right">
|
||||
<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-ble-qr">Generate BLE QR</button>
|
||||
<button class="ui button mini red" type="button" id="dev-reboot">Reboot</button>
|
||||
</div>
|
||||
</div>
|
||||
@ -20,30 +19,6 @@
|
||||
</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="segment ui">
|
||||
<h4 class="ui header dividing">印表機狀態</h4>
|
||||
@ -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')
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user