-
Notifications
You must be signed in to change notification settings - Fork 0
/
flasher.html
169 lines (164 loc) · 4.53 KB
/
flasher.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<html>
<head>
<style type="text/css">
body {
font-family: Verdana;
font-size:12pt;
color: grey;
}
#light {
width: 300px;
height: 300px;
background-color: rgb(0,0,0);
}
</style>
</head>
<body>
<div id="output" style="position: absolute; top: 15px; left: 30px;"></div>
<div id="light" style="position: absolute; top: 50px"></div>
<div style="position: absolute; top: 45px; left: 320px; text-align: right;"><form>
Acces Point SSID:
<input id="SSID" type="text" style="margin: 7px" value="your SSIDname">
<br>
Password:
<input id="PASS" type="text" style="margin: 7px" value="yourWIFIpass">
<br>
ID Token:
<input id="TOKEN" type="text" style="margin: 7px" value="yourToken">
<br>
<input id="start" type="button" value="Start" style="height:28px; width:120px; margin: 12px" onclick="load();" />
</form></div>
<script type="text/javascript" charset="utf-8">
var gamma = 2.0;
var levelNum = 9;
var MIN = 0;
var MAX = levelNum -2;
var REPEAT = levelNum -1;
var previousDigit = levelNum + 1;
var checksum = 0;
var period = 120;
var queue = [];
var payload = "";
var index = 0;
var myInterval;
lightElement = document.getElementById('light');
function getColor(value, levelNum) {
var previous = (value * (255.0/(levelNum - 1)));
var final = 255.0 * Math.pow((previous / 255.0), (1.0 / gamma));
return 'rgb('+Math.round(final)+','+Math.round(final)+','+Math.round(final)+')';
}
// Fills div with the requested color value
function paint(colorValue) {
lightElement.style.setProperty('background-color', getColor(colorValue, levelNum));
if (index > 18){
if ((index - 18) % 3 == 0) {
var div = document.getElementById('output');
div.innerHTML = div.innerHTML.concat(payload.slice(0,1));
payload = payload.slice(1, payload.length);
}
}
};
function outDigit(digit) {
digit = parseInt(digit);
if (digit == previousDigit) {
previousDigit = levelNum + 1;
queue.push(REPEAT);
} else {
queue.push(digit);
previousDigit = digit
}
};
function ramp(valores) {
for (var i = 0; i < valores; i++) {
queue.push(i);
}
};
function sendChar(char) {
checksum = checksum + char.charCodeAt(0);
char = char.charCodeAt(0).toString(8);
while (char.length < 3) {
char = "0".concat(char)
}
for (var i = 0; i < char.length; i++) {
outDigit(char[i]);
}
}
function sendWord(word) {
payload = payload.concat(word);
for (var i = 0; i < word.length; i++) {
sendChar(word[i]);
}
}
function sendChecksum() {
var toSend = checksum.toString(8);
while (toSend.length < 6) {
toSend = "0".concat(toSend);
}
for (var i = 0; i < toSend.length; i++) {
outDigit(toSend[i]);
}
console.log("checksum: " + toSend);
}
function start(){
if (document.getElementById("start").value == "Start") {
document.getElementById("start").value = "Stop";
document.getElementById('output').innerHTML = "";
console.log(queue);
myInterval = window.setInterval(function() {
paint(queue[index]);
index = index + 1;
if (index >= queue.length) {
window.clearInterval(myInterval);
start();
}
}, period );
} else {
document.getElementById("start").value = "Start";
window.clearInterval(myInterval);
paint(MIN);
}
}
function INIT() {
queue.push(MAX, REPEAT);
ramp(levelNum);
queue.push(MIN, REPEAT, MIN, REPEAT);
}
function STX() {
outDigit(0);
outDigit(0);
outDigit(2);
}
function newLine() {
outDigit(0);
outDigit(1);
outDigit(2);
}
function ETX() {
outDigit(0);
outDigit(0);
outDigit(3);
}
function EOT() {
outDigit(0);
outDigit(0);
outDigit(4);
}
function load() {
queue = [];
payload = "";
checksum = 0;
index = 0;
INIT();
STX();
sendWord("auth\n");
sendWord(document.getElementById("SSID").value + "\n"); //We should validate text input here
sendWord(document.getElementById("PASS").value + "\n");
sendWord(document.getElementById("TOKEN").value + "\n");
ETX();
sendChecksum();
EOT();
start();
}
</script>
</body>
</html>