Skip to content

Commit

Permalink
Updated escpos_example.jpg screenshot. Implemented qr.js buffer toggl…
Browse files Browse the repository at this point in the history
…e, Implemented ESC/POS Scan to Connect. Optimized ESC/POS layout. Implemented qr.js error logging
  • Loading branch information
glenndehaan committed Sep 21, 2024
1 parent 706e4b9 commit da15cf9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
Binary file modified .docs/images/escpos_example.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 18 additions & 3 deletions modules/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
26 changes: 22 additions & 4 deletions modules/qr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
});
};

0 comments on commit da15cf9

Please sign in to comment.