-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (32 loc) · 903 Bytes
/
index.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
/* jshint undef: true, node: true, esnext: true, asi: true */
'use strict'
const {send, json} = require('micro'),
Oled = require('oled-i2c-bus'),
i2c = require('i2c-bus'),
font = require('oled-font-5x7'),
c = require('./conf/config.js')
let i2cBus = i2c.openSync(1)
let opts = {
width: c.WIDTH,
height: c.HEIGHT,
address: c.I2C_ADDR
}
let oled = new Oled(i2cBus, opts)
oled.turnOnDisplay()
oled.clearDisplay()
module.exports = async (req, res) => {
const body = await json(req)
let text = body.text,
status = 200,
data = {}
if (!text) {
status = 400
data.msg = 'Bad Request. No text property specified in the query.'
} else {
oled.setCursor(1, 1)
oled.clearDisplay()
oled.writeString(font, 1, text, 1, true)
data.msg = 'Ok. Text sent to the screen.'
}
send(res, status, data)
}