9393 .gamepad-main-button {
9494 grid-column : span 2 ;
9595 }
96+ .gamepad-reset-button {
97+ background-color : # cb2c2c ;
98+ }
99+ .gamepad-reset-button : hover {
100+ background-color : # 942121 ;
101+ }
96102 .gamepad-separator {
97103 height : 1px ;
98104 background-color : # ddd ;
@@ -230,14 +236,32 @@ <h1>Quadrotor Gamepad Controller</h1>
230236 this . callbacks = { }
231237 this . gamepad_index = null
232238 this . gamepad_poller = null
233- // window.addEventListener('gamepadconnected', () => {
234- // const gamepad_details = event.gamepad || event;
235- // const status_element = document.getElementById('gamepad-status');
236- // this.gamepad_index = gamepad_details.index;
237- // status_element.textContent = 'Gamepad connected: ' + gamepad_details.id;
238- // status_element.className = 'gamepad-connected';
239- // document.querySelectorAll('.gamepad-mapping-button').forEach((btn) => { btn.disabled = false; });
240- // });
239+ const reset_button = document . createElement ( 'button' ) ;
240+ reset_button . classList . add ( 'gamepad-mapping-button' ) ;
241+ reset_button . classList . add ( 'gamepad-button' ) ;
242+ reset_button . classList . add ( 'gamepad-reset-button' )
243+ reset_button . textContent = "Reset" ;
244+ reset_button . onclick = ( ) => {
245+ const gamepad = this . get_gamepad ( ) ;
246+ if ( gamepad === null ) return ;
247+ this . gamepad_index = null
248+ this . control_map = { }
249+ this . callbacks = { }
250+ const status_element = document . getElementById ( 'gamepad-status' ) ;
251+ status_element . textContent = 'No gamepad connected' ;
252+ status_element . className = 'gamepad-disconnected' ;
253+ let gamepad_config = localStorage . getItem ( 'gamepad_config' ) ;
254+ gamepad_config = gamepad_config !== null ? JSON . parse ( gamepad_config ) : null ;
255+ if ( gamepad_config !== null ) {
256+ delete gamepad_config [ gamepad . id ] ;
257+ localStorage . setItem ( 'gamepad_config' , JSON . stringify ( gamepad_config ) ) ;
258+ }
259+ document . querySelectorAll ( '.gamepad-mapping-button' ) . forEach ( ( btn ) => { btn . disabled = true ; } ) ;
260+ this . render_live_view ( )
261+ } ;
262+ document . getElementById ( "gamepad-button-container" ) . appendChild ( reset_button ) ;
263+
264+
241265 for ( const channel in gamepad_interface ) {
242266 const details = gamepad_interface [ channel ] ;
243267 const button = document . createElement ( 'button' ) ;
@@ -258,6 +282,10 @@ <h1>Quadrotor Gamepad Controller</h1>
258282 // localStorage.setItem('quadrotorGamepadMap', JSON.stringify(controlMap));
259283 document . querySelectorAll ( '.gamepad-mapping-button' ) . forEach ( ( btn ) => { btn . disabled = false ; } ) ;
260284 this . mapper = null
285+ let gamepad_config = localStorage . getItem ( 'gamepad_config' ) ;
286+ gamepad_config = gamepad_config !== null ? JSON . parse ( gamepad_config ) : { } ;
287+ gamepad_config [ gamepad . id ] = this . control_map ;
288+ localStorage . setItem ( 'gamepad_config' , JSON . stringify ( gamepad_config ) ) ;
261289 this . render_live_view ( )
262290 } ) ;
263291 }
@@ -278,6 +306,13 @@ <h1>Quadrotor Gamepad Controller</h1>
278306 status_element . textContent = 'Gamepad connected: ' + gp . id ;
279307 status_element . className = 'gamepad-connected' ;
280308 document . querySelectorAll ( '.gamepad-mapping-button' ) . forEach ( ( btn ) => { btn . disabled = false ; } ) ;
309+ let gamepad_config = localStorage . getItem ( 'gamepad_config' ) ;
310+ gamepad_config = gamepad_config !== null ? JSON . parse ( gamepad_config ) : { } ;
311+ gamepad_config = gp . id in gamepad_config ? gamepad_config [ gp . id ] : null ;
312+ if ( gamepad_config !== null ) {
313+ this . control_map = gamepad_config ;
314+ this . render_live_view ( )
315+ }
281316 break ;
282317 }
283318 }
0 commit comments