Updated escpos_example.jpg screenshot. Implemented qr.js buffer toggle, Implemented ESC/POS Scan to Connect. Optimized ESC/POS layout. Implemented qr.js error logging

This commit is contained in:
Glenn de Haan
2024-09-21 13:41:10 +02:00
parent 706e4b95b7
commit da15cf9e34
3 changed files with 40 additions and 7 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 212 KiB

After

Width:  |  Height:  |  Size: 1.3 MiB

View File

@@ -186,9 +186,24 @@ module.exports = {
printer.println(`${voucher.code.slice(0, 5)}-${voucher.code.slice(5)}`);
printer.setTextNormal();
printer.newLine();
printer.newLine();
printer.newLine();
if(variables.unifiSsid) {
printer.newLine();
printer.newLine();
printer.newLine();
printer.alignLeft();
printer.print('Connect to: ');
printer.setTypeFontB();
printer.setTextSize(1, 1);
printer.print(variables.unifiSsid);
printer.setTextNormal();
printer.print(' or,');
printer.newLine();
printer.println('Scan to connect:');
printer.alignCenter();
await printer.printImageBuffer(await qr(true));
}
printer.newLine();
printer.newLine();

View File

@@ -6,17 +6,35 @@ const QRCode = require('qrcode');
/**
* Import own modules
*/
const log = require('./log');
const variables = require('./variables');
/**
* Generates a QR code from the UniFi SSID (Scan to Connect)
*
* @param buffer
* @return {Promise<unknown>}
*/
module.exports = () => {
module.exports = (buffer = false) => {
return new Promise((resolve) => {
QRCode.toDataURL(`WIFI:S:${variables.unifiSsid};T:;P:;;`, (err, url) => {
resolve(url);
});
if(!buffer) {
QRCode.toDataURL(`WIFI:S:${variables.unifiSsid};T:;P:;;`, { version: 4, errorCorrectionLevel: 'Q' }, (err, url) => {
if(err) {
log.error(`[Qr] Error while generating code!`);
log.error(err);
}
resolve(url);
});
} else {
QRCode.toBuffer(`WIFI:S:${variables.unifiSsid};T:;P:;;`, { version: 4, errorCorrectionLevel: 'Q' }, (err, buffer) => {
if(err) {
log.error(`[Qr] Error while generating code!`);
log.error(err);
}
resolve(buffer);
});
}
});
};