-
Notifications
You must be signed in to change notification settings - Fork 0
/
raspcam.js
74 lines (59 loc) · 1.57 KB
/
raspcam.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
/* MODULES */
var exec = require("child_process").exec;
var logger = require("./logger.js");
var options = "-w 640 -h 480 -q 10 ";
/* VARIABLES */
/* FUNCTIONS */
function takePictureQuick() {
exec("raspistill --nopreview -w 640 -h 480 -q 10 -o " + __dirname + "/pic.jpg -t 9999999 -tl 1000 -th 0:0:0", function(error, stdout, stderr) {
logger.logDebug("takePictureQuick:" + error);
});
}
exports.takePictureQuick = takePictureQuick;
function takePicture() {
exec("raspistill --nopreview " + options + "-o " + __dirname + "/pic.jpg -t 9999999 -tl 1000 -th 0:0:0", function(error, stdout, stderr) {
if(error) {
if(("" + error).indexOf("mmal") > -1) {
logger.logDebug("takePicture couldn't take picture. Trying again");
stopAll();
takePicture();
}
}
});
}
exports.takePicture = takePicture;
function stopAll() {
exec("pkill -f raspi", function(error, stdout, stderr) {
});
}
exports.stopAll = stopAll;
function setOptionsString(newOptions) {
var optionsString = "";
Object.keys(newOptions).forEach(function(key) {
switch(key) {
case "night":
if(newOptions[key] === true) {
optionsString += "-ex night ";
}
break;
case "width":
optionsString += "-w " + newOptions[key] + " ";
break;
case "height":
optionsString += "-h " + newOptions[key] + " ";
break;
case "quality":
optionsString += "-q " + newOptions[key] + " ";
break;
default:
break;
}
});
options = optionsString;
}
exports.setOptionsString = setOptionsString;
function restart() {
stopAll();
takePicture();
}
exports.restart = restart;