-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
131 lines (124 loc) · 3.81 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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
body {
background-color: white;
color: black;
width: 40pc;
padding: 5px;
}
.wrapper {
width: 400px;
height: auto;
margin: 0 auto;
position: relative;
border: 1px solid #999;
padding: 5px;
}
.console {
width: 380px;
height: auto;
margin: 0 auto;
position: relative;
display: flex;
border: 1px solid #999;
padding: 5px;
}
.screen {
width: 20pc;
height: auto;
margin: 0 auto;
position: relative;
padding: 5px;
}
.commPort {
width: 60pc;
height: auto;
margin: 0 auto;
position: relative;
display: inline-block;
padding: 5px;
}
.textBox {
font-family: Verdana, Geneva, Tahoma, sans-serif;
padding: 5px;
}
.textInput {
width: 200px;
padding: 5px;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="console">
<div class="screen">
<div class="textBox" id="onOrOff"></div>
<button onclick="setScreen()">Screen</button>
</div>
<div class="commPort">
<input class="textInput" id="textBox" type="text"/>
</div>
</div>
<script>
let status;
let timer;
function getStatus() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
// server returns Off or On
document.getElementById("onOrOff").innerHTML = this.responseText;
}
};
xhttp.open("GET", "get_status", true);
xhttp.send();
}
function setScreen() {
// get status
let s = document.getElementById("onOrOff").innerHTML;
// toggle
status = (s == "Off") ? 1 : 0;
//
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
// server returns Off or On
let r = this.responseText;
document.getElementById("onOrOff").innerHTML = r;
// stop timer if screen off
(r == "On") ? startTimer() : stopTimer();
}
};
xhttp.open("GET", "set_screen?screen=" + status, true);
xhttp.send();
}
function setText () {
let t = document.getElementById("textBox").value;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.status == 200) {
console.log("ok");
} else {
console.log("error");
}
};
xhttp.open("GET", "set_text?text=" + t, true);
xhttp.send();
}
function startTimer() {
timer = setInterval(function () {
setText();
}, 2000);
}
function stopTimer() {
clearInterval(timer);
}
// c'est parti
getStatus();
</script>
</div>
</body>
</html>