// Get the GPIO device by its configured name or index from the "device" controlconstGpioDevice=Gpio.device(device.value);// Event handler for GPIO "trigger" events — fires when the device receives an input signalGpioDevice.on('trigger',e=>{console.log('Gpio on trigger',e);// Read the page number from the "triggerPage" controlconstraw=triggerPage.value;// Validate that the value is a finite numberif(!Number.isFinite(Number(raw))){console.warn('[TakeIn] Invalid page number:',raw);return;}// Convert to an integer and format as a 4-digit string (e.g., "0005")constpage=String(Math.trunc(Number(raw))).padStart(4,'0');try{// Execute a "Take In" command for the specified page in the active program profileApi.profile.program.takeIn(page);}catch(err){console.error('[TakeIn] Api.profile.program.takeIn failed:',err);}});// Event handler for the "Simulate" button click — simulates a GPIO input triggersimulate.onClick=()=>{constinput=Number(num_GpioInput.value);// Input channel numberif(!Number.isFinite(input)){console.warn('[GPIO] Invalid input channel for simulate');return;}console.log(`SIMULATE INPUT ON GPIO INPUT ${input}`);// Trigger a simulated signal on the specified input channelGpioDevice.simulate(input);};// Event handler for the "Write" button click — sends a value to a GPIO output channelsimulate1.onClick=()=>{constoutput=Number(num_GpioInput1.value);// Output channel numberconstvalue=Boolean(writeValue.value);// Boolean value to set (true/false)if(!Number.isFinite(output)){console.warn('[GPIO] Invalid output channel for write');return;}console.log(`[GPIO] WRITE to output ${output}: ${value}`);// Write the specified value to the selected GPIO output channelGpioDevice.write(output,value);};