-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsitioWebRodi.html
121 lines (115 loc) · 3.15 KB
/
sitioWebRodi.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
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>RoDI Control Interface</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
}
.control-panel {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 10px;
margin-bottom: 20px;
}
button {
padding: 20px;
font-size: 18px;
cursor: pointer;
border: none;
border-radius: 5px;
transition: background-color 0.3s;
}
button:hover {
opacity: 0.8;
}
#left, #right {
background-color: #4CAF50;
color: white;
}
#forward, #backward {
background-color: #2196F3;
color: white;
}
#stop {
background-color: #f44336;
color: white;
}
#get-distance, #get-line {
background-color: #FF9800;
color: white;
margin: 10px;
}
#sensor-data {
font-size: 18px;
margin-top: 20px;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
background-color: white;
}
</style>
</head>
<body>
<h1>RoDI Control Interface</h1>
<div class="control-panel">
<button id="left">←</button>
<button id="forward">↑</button>
<button id="right">→</button>
<button id="backward">↓</button>
<button id="stop">Parar</button>
</div>
<button id="get-distance">Distancia</button>
<button id="get-line">Sensor</button>
<div id="sensor-data">Datos del Sensor aqui</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
const buttons = document.querySelectorAll('.control-panel button');
const getDistanceBtn = document.getElementById('get-distance');
const getLineBtn = document.getElementById('get-line');
const sensorData = document.getElementById('sensor-data');
buttons.forEach(button => {
button.addEventListener('click', () => {
const command = button.id;
fetch('/control', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ command: command }),
})
.then(response => response.json())
.then(data => {
console.log('logrado:', data);
sensorData.textContent = `Command sent: ${command}`;
})
.catch((error) => {
console.error('error:', error);
sensorData.textContent = 'Error enviando comando';
});
});
});
function getSensorData(type) {
fetch(`/sensor?type=${type}`)
.then(response => response.json())
.then(data => {
sensorData.textContent = `${type.charAt(0).toUpperCase() + type.slice(1)} sensor: ${JSON.stringify(data)}`;
})
.catch((error) => {
console.error('Error:', error);
sensorData.textContent = 'Error consiguiendo datos del sensor';
});
}
getDistanceBtn.addEventListener('click', () => getSensorData('distancia'));
getLineBtn.addEventListener('click', () => getSensorData('linea'));
});
</script>
</body>
</html>