-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_2.html
170 lines (151 loc) · 7.05 KB
/
index_2.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
170
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Wall-E motion page</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
outline: none;
}
button {
border: none;
background: transparent;
}
body {
width: 100%;
height: 100vh;
background: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIj48ZGVmcz48cGF0dGVybiBpZD0icGF0dGVybiIgd2lkdGg9IjQ2LjE5IiBoZWlnaHQ9IjQwIiB2aWV3Qm94PSIwIDAgMzQuNjQxMDE2MTUxMzc3NTUsMzAiIHBhdHRlcm5Vbml0cz0idXNlclNwYWNlT25Vc2UiIHBhdHRlcm5UcmFuc2Zvcm09InJvdGF0ZSgxMzUpICI+PHJlY3QgaWQ9InBhdHRlcm4tYmFja2dyb3VuZCIgd2lkdGg9IjQwMCUiIGhlaWdodD0iNDAwJSIgZm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zUuNTUgMTAuMjVMLTM1LjU1IDE5Ljc1TC0yNy4zMiAyNC41TC0xOS4wOSAxOS43NXpNLTEuNzcgLTE5Ljc1TC0xMCAtMjQuNUwtMTguMjMgLTE5Ljc1TC0xOC4yMyAtMTAuMjVMLTEwIC01LjVMLTEuNzcgLTEwLjI1ek0zMi44NyAtMTkuNzVMMjQuNjQgLTI0LjVMMTYuNDEgLTE5Ljc1TDE2LjQxIC0xMC4yNUwyNC42NCAtNS41TDMyLjg3IC0xMC4yNXpNNTAuMTkgMTAuMjVMNDEuOTYgNS41TDMzLjczIDEwLjI1TDMzLjczIDE5Ljc1TDQxLjk2IDI0LjVMNTAuMTkgMTkuNzV6TTE1LjU1IDEwLjI1TDcuMzIgNS41TC0wLjkxIDEwLjI1TC0wLjkxIDE5Ljc1TDcuMzIgMjQuNUwxNS41NSAxOS43NXoiPjwvcGF0aD48L3BhdHRlcm4+ICA8L2RlZnM+IDxyZWN0IGZpbGw9InVybCgjcGF0dGVybikiIGhlaWdodD0iMTAwJSIgd2lkdGg9IjEwMCUiPjwvcmVjdD48L3N2Zz4=");
display: flex;
justify-content: center;
align-items: center;
}
main {
background-color: rgba(0, 150 , 136 , 0.7);
/* backdrop-filter: blur(2px); */
color: purple;
min-width: 35%;
padding: 2em;
height: 90vh;
border-radius: 10px;
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
font-weight: 100;
}
#one{
width: 100px;
height: 50px;
color: aqua;
background-color: purple;
cursor: pointer;
}
#two{
width: 100px;
height: 50px;
color: aqua;
background-color: purple;
cursor: pointer;
}
#three{
width: 100px;
height: 50px;
background-color: purple;
color: aqua;
cursor: pointer;
}
#four{
width: 100px;
height: 50px;
color: aqua;
background-color: purple;
cursor: pointer;
}
</style>
</head>
<body>
<main>
<h1>Motion of Wall-E</h1>
<div class="button-group">
<button class="button" type="button" id="one"> forward </button>
<button class="button" type="button" id="two"> backwards </button>
<button class="button" type="button" id="three"> left </button>
<button class="button" type="button" id="four"> right </button>
</div>
</main>
<script>
let inpArray = document.querySelectorAll("input[type='number']");
function submitVals() {
const data = {};
data["one"] = parseInt(document.getElementById("one").value);
data["two"] = parseInt(document.getElementById("two").value);
data["three"] = parseInt(document.getElementById("three").value);
data["four"] = parseInt(document.getElementById("four").value);
let finaldata = JSON.stringify(data);
console.log(finaldata);
let xhr = new XMLHttpRequest();
// Vedant!
let url = "/api/v1/pid";
// open a connection
xhr.open("POST", url, true);
// Set the request header i.e. which type of content you are sending
xhr.setRequestHeader("Content-Type", "application/json");
// Create a state change callback
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status == 400) {
console.log("Success!");
} else {
console.log(xhr.status);
}
// Print received data from server
}
};
// Sending data with the request
xhr.send(finaldata);
}
for (let i = 0; i < inpArray.length; i++) {
inpArray[i].addEventListener("change", submitVals);
}
let decrementButtons = document.querySelectorAll(
".button-group button:first-of-type"
);
let incrementButtons = document.querySelectorAll(
".button-group button:last-of-type"
);
function decrementVal(e) {
let test = e.target.parentNode.children[2].value;
if (!isNaN(Number(test))) {
e.target.parentNode.children[2].value = String(
(Number(test) - 0.01).toFixed(3)
);
submitVals();
} else {
e.target.parentNode.children[2].value = "0.000";
}
}
function incrementVal(e) {
let test = e.target.parentNode.children[2].value;
if (!isNaN(Number(test))) {
e.target.parentNode.children[2].value = String(
(Number(test) + 0.01).toFixed(3)
);
submitVals();
} else {
e.target.parentNode.children[2].value = "0.000";
}
}
for (button of decrementButtons) {
button.addEventListener("click", decrementVal);
}
for (button of incrementButtons) {
button.addEventListener("click", incrementVal);
}
</script>
</body>
</html>