'use client'; import { useState, useEffect } from 'react'; export default function RobotDashboard() { const streamUrl = 'http://172.17.19.107:8080/stream'; const [gamepadStatus, setGamepadStatus] = useState("Menunggu pemindaian..."); const [steering, setSteering] = useState({ x: 0, y: 0 }); // Fungsi untuk memaksa baca secara manual saat tombol diklik const forceScanGamepad = () => { if (typeof navigator !== "undefined" && navigator.getGamepads) { const gamepads = navigator.getGamepads(); let activeGp = null; for (let i = 0; i < gamepads.length; i++) { if (gamepads[i] !== null) { activeGp = gamepads[i]; break; } } if (activeGp) { setGamepadStatus(`đŸŸĸ SUKSES DITEMUKAN: ${activeGp.id.substring(0, 20)}`); } else { setGamepadStatus("🔴 TETAP KOSONG. Pastikan URL adalah localhost:3000!"); alert("Gamepad tidak terdeteksi oleh kode. Pastikan kamu membuka web via http://localhost:3000"); } } }; useEffect(() => { const interval = setInterval(() => { if (typeof navigator !== "undefined" && navigator.getGamepads) { const gamepads = navigator.getGamepads(); let activeGp = null; for (let i = 0; i < gamepads.length; i++) { if (gamepads[i] !== null) { activeGp = gamepads[i]; break; } } if (activeGp) { setGamepadStatus(`đŸŸĸ TERHUBUNG: ${activeGp.id.substring(0, 20)}...`); const rawX = activeGp.axes[0]; const rawY = activeGp.axes[1]; const x = Math.abs(rawX) > 0.15 ? Number(rawX.toFixed(2)) : 0; const y = Math.abs(rawY) > 0.15 ? Number(rawY.toFixed(2)) : 0; setSteering({ x, y }); } } }, 100); return () => clearInterval(interval); }, []); return (

Robot Vision Control

Live Feed

{/* eslint-disable-next-line @next/next/no-img-element */} Robot view

XBOX Controller

{gamepadStatus}
Left Analog Stick
X: {steering.x} Y: {steering.y}
); }