-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
77 lines (61 loc) · 1.87 KB
/
app.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
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
const matrix = require('rpi-led-matrix');
//const { createCanvas, loadImage } = require('canvas')
//const canvas = createCanvas(128, 64)
var indexRouter = require('./routes/index');
var demoRouter = require('./routes/demo');
var app = express();
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use('/', indexRouter);
app.use('/demo', demoRouter)
// catch 404 and forward to error handler
app.use(function (req, res, next) {
next(createError(404));
});
// error handler
app.use(function (err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
});
//*************************** */
// Create RGBMATRIX object and configure it
//
//**************************** */
const matrixOptions = {
...matrix.LedMatrix.defaultMatrixOptions(),
rows: 64,
cols: 64,
chainLength: 2,
hardwareMapping: matrix.GpioMapping.Regular,
parallel: 1,
}
console.log("matrix options: ", JSON.stringify(matrixOptions, null, 2))
const runtimeOptions = {
...matrix.LedMatrix.defaultRuntimeOptions(),
gpioSlowdown: 4,
dropPrivileges: matrix.RuntimeFlag.Off
}
const rgbmatrix = new matrix.LedMatrix(matrixOptions, runtimeOptions);
rgbmatrix.brightness(50).sync();
app.set("matrix", rgbmatrix);
/************************************
* Initiate Konva Objects
*
************************************/
var Konva = require('konva');
var stage = new Konva.Stage({
width: rgbmatrix.width(),
height: rgbmatrix.height(),
});
app.set("stage", stage)
module.exports = app;