This repository has been archived by the owner on Apr 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
heatrun.js
121 lines (106 loc) · 3.78 KB
/
heatrun.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
var util = require('util');
var async = require("async");
var Arduinode = require("../arduinode").Arduinode;
var portName = "/dev/tty.usbmodem1411";
var event_count = 0;
var error_count = 0;
var read_count = 0;
var print = false;
var arduinode = new Arduinode(portName, function(err, result){
if(err){
console.log(err);
process.exit(1);
}
// Mega ADKで最初のコマンドでエラーが必ず発生するので
// 一発ダミーリードをしてから実行する.
arduinode.analogRead(0, function(err, reuslt){
heatrun();
});
arduinode.on("event", function(data){
event_count++;
if(print){
console.log(data);
}
});
});
function heatrun(){
async.series(stream_init_tasks, function(err, results){
if(err){
error_count++;
}
for(var i = 0; i < results.length; i++){
console.log(results[i]);
}
async.forever(function(cb){
async.series(read_tasks, function(err, results){
if(err){
error_count++;
}
read_count++;
if(print){
for(var i = 0; i < results.length; i++){
console.log(results[i]);
}
}
cb();
});
});
});
}
var stream_init_tasks = [
function(cb) { arduinode.digitalRead(0, cb); }, // Mega用ダミーコマンド
function(cb) { arduinode.digitalStreamOn(0, 500, cb); },
function(cb) { arduinode.digitalStreamOn(1, 500, cb); },
function(cb) { arduinode.digitalStreamOn(2, 500, cb); },
function(cb) { arduinode.digitalStreamOn(3, 500, cb); },
function(cb) { arduinode.digitalStreamOn(4, 500, cb); },
function(cb) { arduinode.digitalStreamOn(5, 500, cb); },
function(cb) { arduinode.digitalStreamOn(6, 500, cb); },
function(cb) { arduinode.digitalStreamOn(7, 500, cb); },
function(cb) { arduinode.digitalStreamOn(8, 500, cb); },
function(cb) { arduinode.digitalStreamOn(9, 500, cb); },
function(cb) { arduinode.digitalStreamOn(10, 500, cb); },
function(cb) { arduinode.digitalStreamOn(11, 500, cb); },
function(cb) { arduinode.digitalStreamOn(12, 500, cb); },
function(cb) { arduinode.digitalStreamOn(13, 500, cb); },
function(cb) { arduinode.analogStreamOn(0, 500, cb); },
function(cb) { arduinode.analogStreamOn(1, 500, cb); },
function(cb) { arduinode.analogStreamOn(2, 500, cb); },
function(cb) { arduinode.analogStreamOn(3, 500, cb); },
function(cb) { arduinode.analogStreamOn(4, 500, cb); },
function(cb) { arduinode.analogStreamOn(5, 500, cb); }
];
var read_tasks = [
function(cb){ arduinode.analogRead(0, cb); },
function(cb){ arduinode.analogRead(1, cb); },
function(cb){ arduinode.analogRead(2, cb); },
function(cb){ arduinode.analogRead(3, cb); },
function(cb){ arduinode.analogRead(4, cb); },
function(cb){ arduinode.analogRead(5, cb); },
function(cb){ arduinode.digitalRead(0, cb); },
function(cb){ arduinode.digitalRead(1, cb); },
function(cb){ arduinode.digitalRead(2, cb); },
function(cb){ arduinode.digitalRead(3, cb); },
function(cb){ arduinode.digitalRead(4, cb); },
function(cb){ arduinode.digitalRead(5, cb); },
function(cb){ arduinode.digitalRead(6, cb); },
function(cb){ arduinode.digitalRead(7, cb); },
function(cb){ arduinode.digitalRead(8, cb); },
function(cb){ arduinode.digitalRead(9, cb); },
function(cb){ arduinode.digitalRead(10, cb); },
function(cb){ arduinode.digitalRead(11, cb); },
function(cb){ arduinode.digitalRead(12, cb); },
function(cb){ arduinode.digitalRead(13, cb); }
];
var readline = require('readline');
var rl = readline.createInterface(process.stdin, process.stdout);
rl.on("line", function(line){
console.log("read : " + read_count);
console.log("event : " + event_count);
console.log("error : " + error_count );
if(print){
print = false;
}else{
print = true;
}
});