-
Notifications
You must be signed in to change notification settings - Fork 0
/
thermalprinter.js
93 lines (80 loc) · 2.36 KB
/
thermalprinter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const Datastore = require("nedb")
let db = new Datastore({ filename: 'data/stories.db', autoload: true})
const util = require('util');
const exec = util.promisify(require('child_process').exec);
const SerialPort = require('serialport'),
serialPort = new SerialPort('/dev/ttyUSB0', {
baudRate: 9600,
charset: 0
}),
Printer = require('thermalprinter')
const qrcode = async (doc) => {
// let cmd = `qrencode -s 6 -l H -o - "${doc.story.URL}" | lp -o fit-to-page`
let id = (doc._id < 10) ? `0${doc._id}` : doc._id
let cmd = `lp data/qrcodes/story-${id}.png`
const { stdout, stderr } = await exec(cmd);
}
serialPort.on('open',() => {
printer = new Printer(serialPort)
printer.reset()
printer.on('ready', () => {
console.log('we are all ready...')
// printer.hasPaper((paper) => {
// console.log(paper)
// process.exit()
// })
// PROBLEME: 16
db.findOne({_id:16}, async (err, doc) => {
if (err) return
let story = doc.story
// fix special characters
story.title = story.title.replaceAll('’','\047')
story.text = story.text.replaceAll('’','\047')
story.text = story.text.replaceAll('“', '\042')
story.text = story.text.replaceAll('”', '\042')
await printer
.printLine('')
.bold(true)
.center()
.printLine(story.title)
.print()
await qrcode(doc)
printer
.printLine('')
.bold(true)
.center()
.printLine(story.title)
.bold(false)
.printLine(`by ${story.author}`)
.left()
.bold(false)
// .printLine('')
.printLine(`...${story.text}...`)
.printLine('')
.center()
.printLine(`by ${story.author}`)
.printLine('')
// .left()
// .printImage(qrcode)
.print(async () => {
// await qrcode(doc)
process.exit();
})
})
// let title = 'Erasmos` Blues'
// title = title.replace('`','\047')
// let qrcode = 'data/qrcodes/story-01.png'
// printer
// .printLine('')
// .printLine(title)
// .printLine('')
// .barcode(Printer.BARCODE_TYPES.UPCA, '123456789012')
// .printLine('fr text - éü')
// .printImage(qrcode)
// .printLine('')
// .print(async () => {
// console.log("printing done...")
// process.exit();
// })
})
})