-
Notifications
You must be signed in to change notification settings - Fork 48
/
index.js
executable file
·67 lines (50 loc) · 2.07 KB
/
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
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
/*
* Copyright 2016, Maxime Journaux <journaux.maxime@gmail.com>
* This work is free. You can redistribute it and/or modify it under the
* terms of the Do What The Fuck You Want To Public License, Version 2,
* as published by Sam Hocevar.
* See http://www.wtfpl.net for more details.
*/
var path = require("path");
var util = require("util");
var ledmatrix = require(path.join(__dirname, "build", "Release", "node-rpi-rgb-led-matrix.node"));
var LedMatrix = ledmatrix.LedMatrix;
LedMatrix.prototype._scroll = LedMatrix.prototype.scroll;
LedMatrix.prototype.scroll = function(params, callback) {
var startx = params.x >= 0 ? params.x : 0;
if(startx > this.getWidth()) startx = 0;
var starty = params.y >= 0 ? params.y : 0;
if(starty > this.getHeight()) starty = 0;
var width = params.width >= 0 ? params.width : 0;
if(width > this.getWidth()) width = this.getWidth();
var height = params.y >= 0 ? params.height : 0;
if(height > this.getHeight()) height = this.getHeight();
var speed = params.speed || 50;
if(speed <= 0) speed = 50;
var loop = params.loop || 1;
if(loop < 0) loop = 1;
var direction = params.direction || LedMatrix.SCROLL_TO_LEFT;
if(direction != LedMatrix.SCROLL_TO_LEFT && direction != LedMatrix.SCROLL_TO_RIGHT
&& direction != LedMatrix.SCROLL_TO_TOP && direction != LedMatrix.SCROLL_TO_BOTTOM) {
direction = LedMatrix.SCROLL_TO_LEFT;
}
callback = callback || function(){};
this._scroll(callback, startx, starty, width, height, direction, speed, loop);
}
LedMatrix.prototype.scroll2Left = function(params, callback) {
params.direction = LedMatrix.SCROLL_TO_LEFT;
this.scroll(params, callback);
}
LedMatrix.prototype.scroll2Right = function(params, callback) {
params.direction = LedMatrix.SCROLL_TO_RIGHT;
this.scroll(params, callback);
}
LedMatrix.prototype.scroll2Top = function(params, callback) {
params.direction = LedMatrix.SCROLL_TO_TOP;
this.scroll(params, callback);
}
LedMatrix.prototype.scroll2Bottom = function(params, callback) {
params.direction = LedMatrix.SCROLL_TO_BOTTOM;
this.scroll(params, callback);
}
module.exports = LedMatrix;