-
Notifications
You must be signed in to change notification settings - Fork 1
/
evm.js
92 lines (90 loc) · 1.82 KB
/
evm.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
81
82
83
84
85
86
87
88
89
90
var dataUpload=require("./uplink");
var mraa=require("mraa");
var LCD = require("jsupm_i2clcd");
var closed;
var ready=false;
var myLCD = new LCD.Jhd1313m1(6, 0x3E, 0x62);
myLCD.setCursor(0,1);
var x = new mraa.Gpio(13);
var y = new mraa.Gpio(12);
var z = new mraa.Gpio(11);
var green=new mraa.Gpio(10);
var red=new mraa.Gpio(9);
x.dir(mraa.DIR_IN);
y.dir(mraa.DIR_IN);
z.dir(mraa.DIR_IN);
green.dir(mraa.DIR_OUT);
red.dir(mraa.DIR_OUT);
green.write(0);
red.write(1);
myLCD.write("Waiting for user data");
dataUpload.checkUser("12345").then(function(value){
ready=!value;
runner();
watchPanel();
green.write(1);
red.write(0);
myLCD.clear();
myLCD.setCursor(0,1);
myLCD.write("Vote now");
},function(value){
ready=!value;
runner();
watchPanel();
green.write(0);
red.write(1);
myLCD.clear();
myLCD.setCursor(0,1);
myLCD.write("Connection Failed");
});
var watchPanel = function(){
if(ready){
x.isr(mraa.EDGE_RISING,function(){
console.log("pin 0 pressed");
if(ready){
dataUpload.updateVote("qwerty","12345");
green.write(0);
red.write(1);
myLCD.clear();
myLCD.setCursor(0,1);
myLCD.write("You have successfully voted");
clearInterval(closed);
ready=false;
}
});
y.isr(mraa.EDGE_RISING,function(){
console.log("pin 1 pressed");
if(ready){
dataUpload.updateVote("asdfg","12345");
green.write(0);
red.write(1);
myLCD.clear();
myLCD.setCursor(0,1);
myLCD.write("You have successfully voted");
clearInterval(closed);
ready=false;
}
});
z.isr(mraa.EDGE_RISING,function(){
console.log("pin 2 pressed");
if(ready){
dataUpload.updateVote("zxcvb","12345");
green.write(0);
red.write(1);
clearInterval(closed);
myLCD.clear();
myLCD.setCursor(0,1);
myLCD.write("You have successfully voted");
ready=false;
}
});
}
else{
clearInterval(closed);
}
};
var runner= function(){
closed=setInterval(function(){
console.log("runner is running");
},5000);
};