-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
97 lines (84 loc) · 2.64 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Sanctuary</title>
<script src="/node_modules/msgflo-browser/dist/msgflo.js" type="text/javascript"></script>
<script src="/node_modules/flowtrace/browser/flowtrace.js" type="text/javascript"></script>
<script src="/tools/visualization.coffee" type="text/coffeescript"></script>
<script src="http://coffeescript.org/v2/browser-compiler/coffeescript.js" type="text/javascript"></script>
</head>
<body>
<object style='display:none' id="logo" type="image/svg+xml" data="./data/door.svg">No SVG support!</object>
<canvas id='out' height='255px' width='600px'></canvas>
<script type="text/javascript">
var setBrightness = function(brightness) {
var svg = document.getElementById("logo").contentDocument;
var groups = Array.from(svg.getElementsByTagName('g'));
var layers = groups.filter(function(e) {
var label = e.getAttribute('inkscape:label');
var toChange = label && label.indexOf('sign') == 0;
return toChange;
});
layers.map(function(l) {
console.log('l', l.style.opacity);
l.style.opacity = brightness.toString();
});
}
window.isOn = false;
var parseInput = function(data) {
const regex = /.*capacitance: (\d+)/g;
m = regex.exec(data);
if (m) {
var capacitance = parseInt(m[1]);
console.log(capacitance);
var threshold = 200;
if (!window.isOn && capacitance > threshold) {
setBrightness(0.7);
window.isOn = true;
} else if (window.isOn && capacitance < threshold) {
setBrightness(0.032);
window.isOn = false;
}
}
};
var LedParticipant = function() {
var def = {
component: "FakeLed",
inports: [
{ id: "in", type: "any" }
], outports: [
{ id: "out", type: "any" }
]
}
var role = 'fakeled';
var process = function(inport, indata, callback) {
try {
console.log('got data', indata);
parseInput(indata);
return callback('out', null, indata);
} catch (e) {
console.error(e);
return callback('error', null, e.message);
}
}
var msgflo = window.msgflo;
var address = "mqtt://localhost";
var client = new msgflo.mqtt.Client(address, {});
return new msgflo.participant.Participant(client, def, process, role);
}
var onLoad = function() {
var p = LedParticipant();
p.start(function(err) {
console.log('started', err);
});
}
//window.addEventListener('load', onLoad, false);
</script>
<style>
body {
background-color: black;
}
</style>
</body>
</html>