@@ -25,17 +25,14 @@ <h2 class="card-title text-2xl">Setup EchoKit via Bluetooth</h2>
2525 Connect to EchoKit
2626 </ button >
2727
28- < div id ="controlPanel " class ="hidden space-y-4 ">
28+ < div id ="controlPanel " class ="space-y-4 ">
2929 < div class ="flex gap-2 ">
3030 < button class ="btn btn-outline flex-1 " id ="loadAllButton ">
3131 🔄 Load Configuration
3232 </ button >
3333 < button class ="btn btn-primary flex-1 " id ="saveAllButton " disabled >
3434 💾 Save Changes
3535 </ button >
36- < button class ="btn btn-warning " id ="resetButton ">
37- 🔄 Reset
38- </ button >
3936 </ div >
4037
4138 < div class ="card bg-base-100 border border-base-300 ">
@@ -113,6 +110,19 @@ <h3 class="card-title text-lg">Background Image</h3>
113110 </ div >
114111 </ div >
115112
113+ <!-- Reset not supported modal dialog -->
114+ < dialog id ="resetNotSupportedModal " class ="modal ">
115+ < div class ="modal-box ">
116+ < h3 class ="font-bold text-lg "> ⚠️ Device Reset Required</ h3 >
117+ < p class ="py-4 "> Device does not support this operation, please reset by pressing k0 on the device</ p >
118+ < div class ="modal-action ">
119+ < form method ="dialog ">
120+ < button class ="btn btn-primary "> OK</ button >
121+ </ form >
122+ </ div >
123+ </ div >
124+ </ dialog >
125+
116126 < script >
117127 // UUIDs
118128 const SERVICE_ID = "623fa3e2-631b-4f8f-a6e7-a7b09c03e7e0" ;
@@ -137,7 +147,6 @@ <h3 class="card-title text-lg">Background Image</h3>
137147 const connectionStatus = document . getElementById ( 'connectionStatus' ) ;
138148 const loadAllButton = document . getElementById ( 'loadAllButton' ) ;
139149 const saveAllButton = document . getElementById ( 'saveAllButton' ) ;
140- const resetButton = document . getElementById ( 'resetButton' ) ;
141150 const ssidInput = document . getElementById ( 'ssidInput' ) ;
142151 const passInput = document . getElementById ( 'passInput' ) ;
143152 const serverUrlInput = document . getElementById ( 'serverUrlInput' ) ;
@@ -151,6 +160,7 @@ <h3 class="card-title text-lg">Background Image</h3>
151160 const clearBgButton = document . getElementById ( 'clearBgButton' ) ;
152161 const notificationToast = document . getElementById ( 'notificationToast' ) ;
153162 const toastMessage = document . getElementById ( 'toastMessage' ) ;
163+ const resetNotSupportedModal = document . getElementById ( 'resetNotSupportedModal' ) ;
154164
155165 // Track modified fields
156166 const modifiedFields = {
@@ -264,10 +274,9 @@ <h3 class="card-title text-lg">Background Image</h3>
264274 // Update UI
265275 isConnected = true ;
266276 updateConnectionStatus ( ) ;
267-
268- // display the main UI
269- controlPanel . classList . remove ( 'hidden' ) ;
270277 connectButton . textContent = 'Disconnect' ;
278+ connectButton . classList . remove ( 'btn-primary' ) ;
279+ connectButton . classList . add ( 'btn-error' ) ;
271280
272281 // Process the disconnect event
273282 device . addEventListener ( 'gattserverdisconnected' , handleDisconnection ) ;
@@ -299,8 +308,9 @@ <h3 class="card-title text-lg">Background Image</h3>
299308 function handleDisconnection ( ) {
300309 isConnected = false ;
301310 updateConnectionStatus ( ) ;
302- controlPanel . classList . add ( 'hidden' ) ;
303311 connectButton . textContent = 'Connect to EchoKit' ;
312+ connectButton . classList . remove ( 'btn-error' ) ;
313+ connectButton . classList . add ( 'btn-primary' ) ;
304314 device = null ;
305315 server = null ;
306316 service = null ;
@@ -313,13 +323,39 @@ <h3 class="card-title text-lg">Background Image</h3>
313323 statusIndicator . classList . remove ( 'badge-error' ) ;
314324 statusIndicator . classList . add ( 'badge-success' ) ;
315325 connectionStatus . textContent = 'Connected' ;
326+ enableControls ( ) ;
316327 } else {
317328 statusIndicator . classList . remove ( 'badge-success' ) ;
318329 statusIndicator . classList . add ( 'badge-error' ) ;
319330 connectionStatus . textContent = 'Disconnected' ;
331+ disableControls ( ) ;
320332 }
321333 }
322334
335+ // Enable all controls
336+ function enableControls ( ) {
337+ loadAllButton . disabled = false ;
338+ ssidInput . disabled = false ;
339+ passInput . disabled = false ;
340+ serverUrlInput . disabled = false ;
341+ backgroundImage . disabled = false ;
342+ clearBgButton . disabled = false ;
343+ controlPanel . classList . remove ( 'opacity-50' , 'pointer-events-none' ) ;
344+ }
345+
346+ // Disable all controls
347+ function disableControls ( ) {
348+ loadAllButton . disabled = true ;
349+ saveAllButton . disabled = true ;
350+ ssidInput . disabled = true ;
351+ passInput . disabled = true ;
352+ serverUrlInput . disabled = true ;
353+ backgroundImage . disabled = true ;
354+ writeBgButton . disabled = true ;
355+ clearBgButton . disabled = true ;
356+ controlPanel . classList . add ( 'opacity-50' , 'pointer-events-none' ) ;
357+ }
358+
323359 // Reads Characteristic
324360 async function readCharacteristic ( characteristicId , inputElement ) {
325361 if ( ! isConnected || ! service ) {
@@ -405,6 +441,19 @@ <h3 class="card-title text-lg">Background Image</h3>
405441 }
406442
407443 showNotification ( 'Success' , `Saved ${ savedCount } changes` ) ;
444+
445+ // Try to reset device after saving
446+ try {
447+ saveAllButton . textContent = 'Resetting...' ;
448+ const characteristic = await service . getCharacteristic ( RESET_ID ) ;
449+ const encoder = new TextEncoder ( ) ;
450+ const data = encoder . encode ( 'RESET' ) ;
451+ await characteristic . writeValue ( data ) ;
452+ showNotification ( 'Success' , 'Device reset command sent' ) ;
453+ } catch ( resetError ) {
454+ console . error ( 'Reset failed:' , resetError ) ;
455+ resetNotSupportedModal . showModal ( ) ;
456+ }
408457 } catch ( error ) {
409458 console . error ( 'Save modifications failed:' , error ) ;
410459 showNotification ( 'Error' , 'Save modifications failed' , true ) ;
@@ -432,7 +481,7 @@ <h3 class="card-title text-lg">Background Image</h3>
432481 showNotification ( 'Success' , 'Device reset command sent' ) ;
433482 } catch ( error ) {
434483 console . error ( 'Reset failed:' , error ) ;
435- showNotification ( 'Error' , 'Device does not support this operation, please reset by pressing k0 on the device' , true ) ;
484+ resetNotSupportedModal . showModal ( ) ;
436485 } finally {
437486 resetButton . disabled = false ;
438487 resetButton . textContent = '🔄 Reset' ;
@@ -539,10 +588,6 @@ <h3 class="card-title text-lg">Background Image</h3>
539588 saveAllModifications ( ) ;
540589 } ) ;
541590
542- resetButton . addEventListener ( 'click' , ( ) => {
543- resetDevice ( ) ;
544- } ) ;
545-
546591 // Listen for input changes
547592 ssidInput . addEventListener ( 'input' , ( ) => {
548593 markFieldAsModified ( 'ssid' , ssidTitle ) ;
@@ -569,7 +614,10 @@ <h3 class="card-title text-lg">Background Image</h3>
569614 showNotification ( 'Error' , 'Your browser does not support the Web Bluetooth API. Please use Chrome or Edge' , true ) ;
570615 connectButton . disabled = true ;
571616 }
617+
618+ // Initialize controls as disabled
619+ disableControls ( ) ;
572620 </ script >
573621</ body >
574622
575- </ html >
623+ </ html >
0 commit comments