From 954fa3ceacdf215dbb3df337b7401adec83fe209 Mon Sep 17 00:00:00 2001 From: "[Valentino Heman Budiarto]" <[hemanvalentino@gmail.com]> Date: Fri, 31 Jul 2026 15:39:06 +0700 Subject: [PATCH] . --- app/page.tsx | 129 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 114 insertions(+), 15 deletions(-) diff --git a/app/page.tsx b/app/page.tsx index fd45a4d..345b178 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,21 +1,120 @@ -export default function Home() { - const streamUrl = "http://172.17.19.107:5000/video_feed"; +'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 ( -
- {/* Pastikan tag h1 ini utuh */} -

Robot FPV Dashboard

- -
- Live Camera Feed -
+
+
+
+

Robot Vision Control

+ +
- {/* Pastikan tag p ini utuh */} -

Menunggu koneksi Joystick...

+
+
+

+ + 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} +
+
+
+
+
+
); } \ No newline at end of file