-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
121 lines (94 loc) · 3.03 KB
/
script.js
File metadata and controls
121 lines (94 loc) · 3.03 KB
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
const rangeInput = document.getElementById("myRange");
const distanceSpan = document.getElementById("demo");
let animationFrameId;
let distance = 0;
function moveSlider() {
distance = 0;
animateSlider();
}
function animateSlider() {
let printval = 0;
printval += 1;
distance += 1;
rangeInput.value = distance;
distanceSpan.textContent = distance;
rangeInput.dispatchEvent(new Event("input"));
if (distance < 100) {
animationFrameId = requestAnimationFrame(animateSlider);
}
}
const customErrorPopup = document.getElementById("customErrorPopup");
const customErrorMessage = document.getElementById("customErrorMessage");
function showCustomError(message) {
customErrorMessage.innerText = message;
customErrorPopup.style.display = "block";
}
function hideCustomError() {
customErrorPopup.style.display = "none";
}
function stopSlider() {
cancelAnimationFrame(animationFrameId);
let targetDistance = distance + 15;
if (targetDistance < 300) {
showCustomError("Brakes Activated");
return;
}
function animateEStop() {
distance += 0.55;
rangeInput.value = distance;
distanceSpan.textContent = targetDistance;
rangeInput.dispatchEvent(new Event("input"));
if (distance < targetDistance) {
animationFrameId = requestAnimationFrame(animateEStop);
}
}
animateEStop();
}
function estopSlider() {
cancelAnimationFrame(animationFrameId);
let targetDistance = distance + 15;
function animateEStop() {
distance += 0.55;
rangeInput.value = distance;
distanceSpan.textContent = targetDistance;
rangeInput.dispatchEvent(new Event("input"));
if (distance < targetDistance) {
animationFrameId = requestAnimationFrame(animateEStop);
}
}
animateEStop();
}
document.querySelector(".button2").addEventListener("click", moveSlider);
document.querySelector(".button3").addEventListener("click", stopSlider);
document.querySelector(".button1").addEventListener("click", estopSlider);
// Getting Data From Server
document.addEventListener("DOMContentLoaded", function () {
const limtemp = document.getElementById("lim_temp");
const customErrorPopup = document.getElementById("customErrorPopup");
const customErrorMessage = document.getElementById("customErrorMessage");
function fetchSensorData() {
fetch("http://192.168.4.1/")
.then((response) => response.json())
.then((data) => {
console.log("Received data:", data);
limtemp.innerText = `${data.temperature_C.toFixed(2)}°C`; // Accessing the correct key
if (data.temperature_C > 70) {
showCustomError(
"Emergency Stop.Temperature exceeds 70°C."
);
}
})
.catch((error) => {
console.error("Error", error);
});
}
function showCustomError(message) {
customErrorMessage.innerText = message;
customErrorPopup.style.display = "block";
}
function hideCustomError() {
customErrorPopup.style.display = "none";
}
fetchSensorData();
setInterval(fetchSensorData, 10); // Fetch every 10 seconds
});