-
Notifications
You must be signed in to change notification settings - Fork 1
/
aureliusscript.js
80 lines (65 loc) · 1.69 KB
/
aureliusscript.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
78
79
80
// Get all the node modules
var gm = require('gm');
var i2c = require('i2c-bus');
var mpu = require('i2c-mpu6050');
var gpio = require('pi-gpio');
var cam = require('raspicam');
var audio = require('modules/audio.js');
var camera = require('modules/camera.js')
var compare = require('modules/compare.js');
var img1 = '/home/pi/src/compareImg.jpg';
var img2 = '/home/pi/src/originalImg.jpg';
// ==================
// SETUP I2C - MPU650
// get address from raspberry using 'sudo i2cdetect -y 1'
var address = 0x68;
var i2c1 = i2c.openSync(1);
var mpuSensor = new mpu(i2c1, address);
var readMpu = function() {
mpuData = mpuSensor.readSync();
console.log(mpuData);
}
// ======================
// SETUP GPIO - IR SENSOR
var pin = 12;
var returnValue;
//var i = 0;
//var size = 1000;
//var gpioData = new Array(size);
function readGpio(callback) {
// open connection to the gpio pin
gpio.open(pin, "input", function(err) {
// read the value of the pin
gpio.read(pin, function(err, value) {
// if the value is 1, set returnValue as true and log in console
gpio.close(pin);
callback(value === 1);
//console.log(returnValue);
//close pin connection
});
});
};
// ==============
// SETUP RASPICAM
var camOptions = {
mode: "photo",
encoding: "jpg",
quality: 10,
output: "compareImg.jpg"
};
camera.setup(camOptions);
function runAurelius() {
readGpio(function(value) {
if (!value)
setTimeout(runAurelius, 20);
return
camera.takeSnapshot(camOptions) {
compare.compareFiles(img1, img2, function(equal) {
if (!equal) return
audio.playAudioFile('audio.wav');
});
}
});
};
// runAurelius on Startup
runAurelius();