forked from mcreed/raspberry-preserve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
76 lines (60 loc) · 1.44 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
68
69
70
71
72
73
74
75
76
var util = require('util');
var Gpio = require('onoff').Gpio,
led1 = new Gpio(17, 'out'),
led2 = new Gpio(18, 'out'),
led3 = new Gpio(22, 'out'),
led4 = new Gpio(23, 'out');
var BTSync = require('bittorrent-sync'),
btsync = new BTSync({
host: '0.0.0.0',
port: 8888,
username: 'YOURUSERNAME',
password: 'YOURPASSWORD'
});
var transferring = false;
var currentLed = 1;
var transferCheck = setInterval(function(){
btsync.getSpeed(function(err, data) {
// What's hapnin?
//console.log(data);
//if (err) throw err;
if(data.download > 0 || data.upload > 0){
transferring = true;
}
if(transferring){
// Cycle LEDs to show activity
if(currentLed == 1){
led1.writeSync(1);
led2.writeSync(1);
led4.writeSync(1);
led3.writeSync(0);
currentLed++;
} else if(currentLed == 2){
led1.writeSync(0);
led2.writeSync(1);
led4.writeSync(1);
led3.writeSync(1);
currentLed++;
} else if(currentLed == 3){
led1.writeSync(1);
led2.writeSync(0);
led4.writeSync(1);
led3.writeSync(1);
currentLed++;
} else if(currentLed == 4){
led1.writeSync(1);
led2.writeSync(1);
led4.writeSync(0);
led3.writeSync(1);
currentLed = 1;
}
} else {
// Turn LEDs on solid.
led1.writeSync(1);
led2.writeSync(1);
led3.writeSync(1);
led4.writeSync(1);
//led1.unexport(); // Unexport GPIO and free resources
}
});
}, 200);