-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPOS-sender.js
More file actions
51 lines (40 loc) · 1.42 KB
/
Copy pathPOS-sender.js
File metadata and controls
51 lines (40 loc) · 1.42 KB
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
// shows various texts on a usb-serial Point-of-Sale 2x20 display
//
// POS has 2 lines with 20 chars each. Wraps around on end of line. Supports backspace and newline. \f clears screen (flickering) and ensures the cursor is at home
//
// lsusb
// Bus 001 Device 006: ID 0416:f012 Winbond Electronics Corp.
// modprobe usbserial vendor=0x0416 product=0xf012
// -> /dev/ttyACM0
//const chokidar = require('chokidar')
const winston = require('winston')
const fs = require('fs')
const fsa = fs.promises
module.exports = function(god, loggerName = 'POS', _mqttTopic = undefined) {
var self = {
controller: {},
mqttTopic: _mqttTopic ?? loggerName + '/',
init: function() {
this.logger = winston.loggers.get(loggerName)
god.preterminateListeners.push(this.onPreTerminate.bind(this))
god.terminateListeners.push(this.onTerminate.bind(this))
this.controller = require('./DisplayControl')(god, loggerName)
this.controller.fnUpdate = this.writeToPOS.bind(this)
this.controller.enable()
},
onPreTerminate: async function() {
god.mqtt && god.mqtt.publish(this.mqttTopic + 'text', 'Grag is gone')
},
onTerminate: async function() {
},
writeToPOS: async function (content) {
god.mqtt && god.mqtt.publish(this.mqttTopic + 'text', content)
this.logger.debug("Sending: %o", content)
},
addEntry: function(id, content) {
this.controller.addEntry(id, content)
}
}
self.init()
return self
}