forked from anthonywebb/sprinkler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iodebug.js
69 lines (59 loc) · 1.43 KB
/
iodebug.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
// Copyrigth (C) Pascal Martin, 2014.
//
// NAME
//
// iodebug - a module to hide the absence of hardware interface.
//
// SYNOPSYS
//
// This module implements a subset of the bonescript interface for the
// purpose of debug. It is used if the bonescript module is not accessible.
//
//
// DESCRIPTION
//
// var io = require('./iodebug');
//
// io.pinMode (pin, mode);
//
// io.digitalWrite (pin, value);
//
// io.digitalRead (pin);
//
// io.attachInterrupt (pin, flag, edge, callback);
//
var piodb = null;
function debugLog (text) {
console.log ('[DEBUG] Iodebug: '+text);
}
exports.LOW = 0;
exports.HIGH = 1;
exports.FALLING = 2;
exports.RAISING = 3;
exports.INPUT = 4;
exports.OUTPUT = 5;
var constantSymbol = ['LOW', 'HIGH', 'FALLING', 'RAISING', 'INPUT', 'OUTPUT'];
function constant2string (value) {
if (value == null) {
return '(null)';
}
try {
return constantSymbol[value];
}
catch (err) {
return '#'+value;
}
}
exports.pinMode = function (pin, mode) {
debugLog ('pinMode ('+pin+', '+constant2string(mode)+')');
}
exports.digitalWrite = function (pin, value) {
debugLog ('digitalWrite ('+pin+', '+constant2string(value)+')');
}
exports.digitalRead = function (pin) {
//debugLog ('digitalRead ('+pin+')');
return 0;
}
exports.attachInterrupt = function (pin, flag, edge, callback) {
debugLog ('attachInterrupt ('+pin+', '+flag+', '+constant2string(edge)+', '+callback+')');
}