-
Notifications
You must be signed in to change notification settings - Fork 7
/
screenSetWifi.js
168 lines (129 loc) · 3.79 KB
/
screenSetWifi.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
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
/*
Developed by: Eduardo Zola - Zola Lab 2015 - www.zolalab.com.br - [email protected]
Screen Set Wifi Library
Copyright (c) 2015 Eduardo Zola. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
*/
var TXT = "";
var XBIN = "";
var box;
var TEXTO;
var cnt = 0;
var sz = 0;
var lastBit;
var thisBit;
var funcFinishPublic;
window.rtimeOut=function(callback,delay){
var dateNow=Date.now,
requestAnimation=window.requestAnimationFrame,
start=dateNow(),
stop,
timeoutFunc=function(){
dateNow()-start<delay?stop||requestAnimation(timeoutFunc):callback()
};
requestAnimation(timeoutFunc);
return{
clear:function(){stop=1}
}
}
function Transfer(but,funcFinish)
{
funcFinishPublic = funcFinish;
var pbar1 = document.getElementById("pbar1");
var pbar2 = document.getElementById("pbar2");
pbar1.value = 0;
pbar2.value = 0;
but.innerText = "Stop";
if(window.transf) {window.transf = false;cnt=sz;but.innerText="Transfer";return;};
box = document.getElementById("box");
var ssid = document.getElementById("ssid").value;
var pwd = document.getElementById("pwd").value;
ssid = ssid.trim();
pwd = pwd.trim();
if(ssid == "" || pwd == "") return;
var PULSES = 0;
TXT = ""
TXT = TXT + ">"+ssid+ String.fromCharCode(10);
TXT = TXT + pwd + String.fromCharCode(10);
TXT = TXT + String.fromCharCode(crc(TXT));
XBIN = binary(TXT) + "0";
cnt = 0;
sz = XBIN.length;
pbar1.max = sz;
pbar2.max = sz;
window.transf = true;
lastBit = 0;
setTimeout(send,1000);
}
function send()
{
if(!window.transf || cnt > sz) {box.style.backgroundColor="#000000";funcFinishPublic();return;};
thisBit = XBIN[cnt];
cnt++;
pbar1.value = cnt;
pbar2.value = cnt;
if(thisBit != lastBit)
{
if(thisBit == "1") box.style.backgroundColor="#FFFFFF"; else box.style.backgroundColor="#000000";
lastBit = thisBit;
// setTimeout("send()",34);
rtimeOut(send,34);
}
else
{
if(thisBit == "1") box.style.backgroundColor="#000000"; else box.style.backgroundColor="#FFFFFF";
lastBit = thisBit;
// setTimeout("goColor();",200);
rtimeOut(goColor,204);
}
}
function goColor()
{
if(thisBit == "1") box.style.backgroundColor="#FFFFFF"; else box.style.backgroundColor="#000000";
// setTimeout("send()",34);
rtimeOut(send,34);
}
function binary(input)
{
output = "";
for (i=0; i < input.length; i++)
{
bin = input[i].charCodeAt(0).toString(2);
ln = 8-bin.length;
zeros = "";
for(j=0;j<ln;j++) zeros = zeros + "0";
bin = zeros + bin;
output += bin;
}
return(output);
}
function dec2binary(dec)
{
bin = (dec >>> 0).toString(2);
ln = 8-bin.length;
zeros = "";
for(j=0;j<ln;j++) zeros = zeros + "0";
bin = zeros + bin;
return(bin);
}
function crc(str)
{
var xcrc = 0;
var qtd = str.length;
v1 = str.charCodeAt(0);
for(var i = 1;i<qtd;i++)
{
v2 = str.charCodeAt(i);
if(v2 > v1) xcrc += (v2-v1); else xcrc += (v1-v2);
if(xcrc > 255) xcrc -= 255;
v1 = v2;
}
return(xcrc);
};