-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreview.html
More file actions
264 lines (229 loc) · 14 KB
/
preview.html
File metadata and controls
264 lines (229 loc) · 14 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
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>VW CDC V2 Debugger</title>
<style>
:root { --bg: #121212; --panel: #1e1e1e; --text: #e0e0e0; --accent: #0288D1; --accent-hover: #0277bd; }
* { box-sizing: border-box; }
body { background: var(--bg); color: var(--text); font-family: -apple-system, system-ui, sans-serif; margin: 0; padding: 0; display: flex; flex-direction: column; height: 100vh; }
header { background: var(--panel); padding: 10px 15px; box-shadow: 0 2px 6px rgba(0,0,0,0.4); z-index: 10; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.title { margin: 0; font-size: 1.1rem; font-weight: 600; color: #fff; }
.tab-btn { background: #333; color: #ccc; border: none; padding: 8px 16px; border-radius: 6px; cursor: pointer; font-size: 0.9rem; transition: 0.2s; flex-grow: 1; text-align: center; }
.tab-btn.active { background: var(--accent); color: white; font-weight: 600; }
.controls { display: flex; gap: 8px; flex-wrap: wrap; width: 100%; }
@media(min-width: 600px) {
.controls { width: auto; flex-wrap: nowrap; }
.tab-btn { flex-grow: 0; }
.title { flex-grow: 1; }
}
.tab-content { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.tab-content.active { display: flex; }
.log-box { flex: 1; padding: 12px; overflow-y: auto; background: #000; font-family: 'Consolas', 'Courier New', monospace; font-size: 0.9rem; line-height: 1.4; scroll-behavior: smooth; border-bottom: 2px solid #333; }
.log-line { margin: 0 0 4px 0; border-bottom: 1px dashed #222; padding-bottom: 2px; word-wrap: break-word; }
.log-info { color: #81C784; }
.log-debug { color: #FFB74D; }
.log-sys { color: #64B5F6; }
.log-raw { color: #9E9E9E; font-size: 0.85rem; }
.log-tx { color: #E57373; font-weight: bold; }
.terminal-input-area { background: #1a1a1a; display: flex; padding: 10px; gap: 10px; align-items: center; }
.terminal-prompt { color: #64B5F6; font-family: monospace; font-weight: bold; font-size: 1.1rem; }
input[type="text"] { flex: 1; padding: 10px; background: #000; border: 1px solid #444; color: #81C784; font-family: monospace; border-radius: 4px; font-size: 1rem; }
input[type="text"]:focus { outline: none; border-color: var(--accent); }
button.action { background: var(--accent); color: white; border: none; padding: 10px 20px; border-radius: 4px; cursor: pointer; font-family: monospace; font-size: 1rem; font-weight: bold; }
button.action:hover { background: var(--accent-hover); }
button.danger { background: #d32f2f; color: white; border: none; padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 0.8rem;}
.panel-area { background: #1a1a1a; border-bottom: 2px solid #333; flex: 0 0 auto; max-height: 45vh; overflow-y: auto; padding: 10px; }
details { background: #222; padding: 8px 12px; border-radius: 6px; margin-bottom: 8px; border: 1px solid #333; }
summary { color:#64B5F6; cursor:pointer; font-weight:bold; outline: none; }
.detail-row { display: flex; gap: 10px; margin-top: 10px; align-items: center; flex-wrap: wrap; }
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: #000; }
::-webkit-scrollbar-thumb { background: #444; border-radius: 4px; }
</style>
<script>const isPreview = true;</script>
</head>
<body>
<header>
<div class="title">CDCESP32 V2</div>
<div class="controls">
<button class="tab-btn active" onclick="switchTab('main')">System</button>
<button class="tab-btn" onclick="switchTab('cdc')">CDC Raw</button>
<button class="danger" onclick="clearCurrentLog()">Clear Log</button>
<a href="/update" style="color:#fa0; font-weight:bold; margin-left:5px; text-decoration:none; padding:8px 0;">OTA UPDATE</a>
</div>
</header>
<div id="tab-main" class="tab-content active">
<!-- Панель управления (сверху) -->
<div class="panel-area">
<div style="display:flex; justify-content: space-between; align-items:center; margin-bottom: 10px; padding: 0 5px;">
<span style="color:#aaa;">State: <strong id="ui_state" style="color:#fff;">UNKNOWN</strong></span>
<div style="display:flex; gap:5px;">
<button class="action" style="padding:6px 10px; font-size:0.8rem;" onclick="sendCustomAT('AT+STAT')">Refresh</button>
<button class="action" style="padding:6px 10px; font-size:0.8rem;" onclick="sendCustomAT('AT+BACKWARD')">⏮</button>
<button class="action" style="padding:6px 10px; font-size:0.8rem;" onclick="sendCustomAT('AT+PLAYPAUSE')">⏯</button>
<button class="action" style="padding:6px 10px; font-size:0.8rem;" onclick="sendCustomAT('AT+FORWARD')">⏭</button>
</div>
</div>
<details>
<summary>Paired Devices</summary>
<div style="margin-top: 10px;">
<button class="action" style="padding: 4px 10px; font-size: 0.8rem; margin-bottom: 10px;" onclick="requestPairedList()">Refresh List</button>
<div id="pairedList" style="font-size: 0.9rem;"></div>
</div>
</details>
<details>
<summary>Configuration & Hardware</summary>
<div class="detail-row">
<label style="color:#aaa; width:45px;">Name:</label>
<input type="text" id="btName" value="VW_BT1026" style="flex:1; padding:6px;">
<button class="action" style="padding:6px 12px; font-size:0.9rem;" onclick="sendCustomAT('AT+NAME=' + document.getElementById('btName').value)">Set</button>
</div>
<div class="detail-row">
<label style="color:#aaa; width:45px;">COD:</label>
<input type="text" id="btCod" value="240404" style="flex:1; padding:6px;">
<button class="action" style="padding:6px 12px; font-size:0.9rem;" onclick="sendCustomAT('AT+COD=' + document.getElementById('btCod').value)">Set</button>
</div>
<div class="detail-row" style="margin-top:15px; border-top: 1px dashed #444; padding-top: 10px;">
<button class="action" style="padding:6px 10px; font-size:0.8rem;" onclick="sendCustomAT('AT+MAC?')">Get MAC</button>
<button class="action" style="padding:6px 10px; font-size:0.8rem;" onclick="sendCustomAT('AT+VOL=12')">Vol Max</button>
<button class="danger" style="margin-left:auto;" onclick="if(confirm('Reboot Module?')) sendCustomAT('AT+REBOOT')">Reboot</button>
<button class="danger" onclick="if(confirm('Run Factory Setup?')) sendCustomAT('AT+FACTORY')">Factory Setup</button>
</div>
</details>
</div>
<!-- Терминал логов (снизу) -->
<div id="log-sys" class="log-box">
<div class="log-line log-sys">[SYS] WebUI Started. WiFi AP: VW-BT1026D (12345678)</div>
<div class="log-line log-info">[INFO] CDC Task Initialized. SPI Heartbeat active.</div>
<div class="log-line log-debug">[DEBUG] BT Module Boot Sequence...</div>
<div class="log-line log-info">[BT] Music PLAYING</div>
</div>
<div class="terminal-input-area">
<span class="terminal-prompt">$></span>
<input type="text" id="atInput" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" placeholder="AT+VER" onkeypress="if(event.key === 'Enter') sendAT()">
<button class="action" onclick="sendAT()">SEND</button>
</div>
</div>
<!-- Вкладка 2: CDC RAW логи -->
<div id="tab-cdc" class="tab-content">
<div id="log-cdc" class="log-box"></div>
</div>
<script>
const elLogs = document.getElementById('log-sys');
const elCdc = document.getElementById('log-cdc');
let currentTabId = 'main';
let ws;
setTimeout(() => handleWSMessage("[BT] Music PLAYING"), 100);
function switchTab(tabId) {
currentTabId = tabId;
document.querySelectorAll('.tab-content').forEach(el => el.classList.remove('active'));
document.querySelectorAll('.tab-btn').forEach(el => el.classList.remove('active'));
document.getElementById('tab-' + tabId).classList.add('active');
event.currentTarget.classList.add('active');
}
function clearCurrentLog() {
if(currentTabId === 'main') elLogs.innerHTML = '';
if(currentTabId === 'cdc') elCdc.innerHTML = '';
}
function requestPairedList() {
document.getElementById('pairedList').innerHTML = '<div style="color:#fa0;">Fetching devices...</div>';
sendCustomAT('AT+PLIST');
if(typeof isPreview !== 'undefined') {
setTimeout(() => {
handleWSMessage("[BT RX] +PLIST:1,AABBCCDDEE01,My iPhone");
handleWSMessage("[BT RX] +PLIST:2,112233445566,Wife Phone");
}, 600);
}
}
function deleteDevice(mac) {
if(confirm('Delete device ' + mac + '?')) {
sendCustomAT('AT+PDELD=' + mac);
setTimeout(requestPairedList, 1000);
}
}
function sendCustomAT(cmd) {
const input = document.getElementById('atInput');
input.value = cmd;
sendAT();
}
function sendAT() {
const input = document.getElementById('atInput');
const cmd = input.value.trim();
if(!cmd) return;
const pEcho = document.createElement('div');
pEcho.className = 'log-line log-tx';
pEcho.textContent = "> " + cmd;
elLogs.appendChild(pEcho);
elLogs.scrollTop = elLogs.scrollHeight;
if(typeof isPreview !== 'undefined') {
input.value = '';
input.focus();
setTimeout(() => handleWSMessage("OK"), 300);
return;
}
fetch('/api/at_cmd?cmd=' + encodeURIComponent(cmd)).then(res => {
input.value = '';
input.focus();
});
}
function handleWSMessage(text) {
if(text.includes('Music PLAYING')) document.getElementById('ui_state').innerText = "PLAYING";
if(text.includes('Music PAUSED')) document.getElementById('ui_state').innerText = "PAUSED";
if(text.includes('Music STOPPED') || text.includes('A2DP Connected')) document.getElementById('ui_state').innerText = "A2DP CONNECTED";
if(text.includes('Call Active!')) document.getElementById('ui_state').innerText = "CALL ACTIVE";
if(text.includes('Incoming Call!')) document.getElementById('ui_state').innerText = "INCOMING CALL";
if(text.includes('Disconnected') && text.includes('[BT]')) document.getElementById('ui_state').innerText = "DISCONNECTED";
if(text.includes('+PLIST:')) {
const match = text.match(/\+PLIST:\s*(\d+),([^,]+),(.*)/);
if(match && match.length >= 4) {
const mac = match[2];
const name = match[3];
const listContainer = document.getElementById('pairedList');
if(listContainer.innerHTML.includes('Fetching')) {
listContainer.innerHTML = '';
}
const item = document.createElement('div');
item.style.cssText = "display:flex; justify-content:space-between; padding:8px 0; border-bottom:1px dashed #444; align-items:center;";
item.innerHTML = `
<div>
<strong style="color:#81C784;">${name}</strong>
<div style="color:#888; font-size:0.8rem;">MAC: ${mac}</div>
</div>
<button class="danger" style="padding:4px 8px;" onclick="deleteDevice('${mac}')">Delete</button>
`;
listContainer.appendChild(item);
}
return;
}
if(typeof isPreview !== 'undefined' && text.startsWith('[BT RX]')) return;
const p = document.createElement('div');
if(text.startsWith('[CDC RAW]')) {
p.className = 'log-line log-raw';
p.textContent = text.replace('[CDC RAW] ', '');
elCdc.appendChild(p);
if(elCdc.childNodes.length > 200) elCdc.removeChild(elCdc.firstChild);
elCdc.scrollTop = elCdc.scrollHeight;
} else {
let cssClass = 'log-info';
if(text.includes('[DEBUG]')) cssClass = 'log-debug';
if(text.includes('[SYS]')) cssClass = 'log-sys';
if(text.includes('[BT TX]')) cssClass = 'log-tx';
p.className = 'log-line ' + cssClass;
p.textContent = text;
elLogs.appendChild(p);
if(elLogs.childNodes.length > 200) elLogs.removeChild(elLogs.firstChild);
elLogs.scrollTop = elLogs.scrollHeight;
}
}
function connectWS() {
if(typeof isPreview !== 'undefined') return;
ws = new WebSocket('ws://' + window.location.hostname + ':81/');
ws.onmessage = function(e) { handleWSMessage(e.data); };
ws.onclose = function() { setTimeout(connectWS, 2000); };
}
window.onload = connectWS;
</script>
</body>
</html>