-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpage.h
179 lines (156 loc) · 5.91 KB
/
webpage.h
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
171
172
173
174
175
176
177
178
179
extern String WiFiAddr;
const char WEBPAGE[] PROGMEM = R"=====(
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<style>
// #screeen_backgroud{
// background-color: #818589;
// }
#joystick-area {
width: 200px;
height: 200px;
position: relative;
background-color: #ccc;
border-radius: 50%;
margin: 20px auto;
}
button {
border-radius: 15px;
width: 140px;
height: 40px;
margin: 5px;
font-weight: bold;
cursor: pointer;
}
#lightButton {
background-color: lightblue;
}
#captureButton {
background-color: #4CAF50;
color: white;
}
#recordButton {
background-color: #f44336;
color: white;
}
/* Custom Joystick CSS */
.nipple {
position: absolute;
width: 100px;
height: 100px;
background-color: purple;
border-radius: 50%;
margin: -50px 0 0 -50px;
}
</style>
</head>
<body id="screeen_backgroud">
<p align="center">
<img src="http://{IP address}:81/stream" style="width:100%; object-fit:cover;"> //Replace with your actual IP {IP address}
</p>
<div id="joystick-area"></div>
<p align="center">
<button id="lightButton" onclick="toggleLight()">Light OFF</button>
<button id="captureButton" onclick="captureImage()">Capture Image</button>
<button id="recordButton" onclick="toggleRecording()">Start Recording</button>
</p>
<!-- Embedded NippleJS -->
<script>
document.addEventListener('DOMContentLoaded', function() {
var joystickArea = document.getElementById('joystick-area');
var nipple = document.createElement('div');
nipple.className = 'nipple';
joystickArea.appendChild(nipple);
var startPos = { x: joystickArea.offsetWidth / 2, y: joystickArea.offsetHeight / 2 };
nipple.style.left = startPos.x + 'px';
nipple.style.top = startPos.y + 'px';
var joystick = {
x: startPos.x,
y: startPos.y,
isMoving: false
};
joystickArea.addEventListener('touchstart', function(event) {
joystick.isMoving = true;
});
joystickArea.addEventListener('touchmove', function(event) {
if (joystick.isMoving) {
var touch = event.touches[0];
var rect = joystickArea.getBoundingClientRect();
joystick.x = touch.clientX - rect.left;
joystick.y = touch.clientY - rect.top;
nipple.style.left = joystick.x + 'px';
nipple.style.top = joystick.y + 'px';
var direction = getDirection(startPos, { x: joystick.x, y: joystick.y });
if (direction) {
getsend(direction);
}
}
});
joystickArea.addEventListener('touchend', function(event) {
joystick.isMoving = false;
nipple.style.left = startPos.x + 'px';
nipple.style.top = startPos.y + 'px';
getsend('stop');
});
function getDirection(start, end) {
var dx = end.x - start.x;
var dy = end.y - start.y;
var angle = Math.atan2(dy, dx) * 180 / Math.PI;
if (angle >= -45 && angle < 45) return 'right';
if (angle >= 45 && angle < 135) return 'back';
if (angle >= -135 && angle < -45) return 'go';
return 'left';
}
function getsend(arg) {
var xhttp = new XMLHttpRequest();
xhttp.open('GET', arg + '?' + new Date().getTime(), true);
xhttp.send();
}
document.getElementById('lightButton').addEventListener('click', function() {
toggleLight();
});
document.getElementById('captureButton').addEventListener('click', function() {
captureImage();
});
document.getElementById('recordButton').addEventListener('click', function() {
toggleRecording();
});
var isLightOn = false;
var isRecording = false;
function toggleLight() {
isLightOn = !isLightOn;
var lightButton = document.getElementById('lightButton');
if (isLightOn) {
getsend('ledon');
lightButton.style.backgroundColor = 'pink';
lightButton.textContent = 'Light ON';
} else {
getsend('ledoff');
lightButton.style.backgroundColor = 'lightblue';
lightButton.textContent = 'Light OFF';
}
}
function captureImage() {
getsend('capture');
alert('Image captured!');
}
function toggleRecording() {
isRecording = !isRecording;
var recordButton = document.getElementById('recordButton');
if (isRecording) {
getsend('startrecord');
recordButton.textContent = 'Stop Recording';
recordButton.style.backgroundColor = '#e57373';
} else {
getsend('stoprecord');
recordButton.textContent = 'Start Recording';
recordButton.style.backgroundColor = '#f44336';
}
}
});
</script>
</body>
</html>
)=====";