diff --git a/app/page.tsx b/app/page.tsx index 55ccd51..e8e75c4 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -3,7 +3,6 @@ import { useState, useEffect, useRef } from 'react'; export default function RobotDashboard() { - // Sesuaikan dengan IP Raspberry Pi / Tailscale milikmu const PI_IP = '172.17.19.107'; const streamUrl = `http://${PI_IP}:8080/stream`; @@ -12,7 +11,6 @@ export default function RobotDashboard() { const [steering, setSteering] = useState({ x: 0, y: 0 }); const wsRef = useRef(null); - const keysRef = useRef({ up: false, down: false, left: false, right: false }); const forceScanGamepad = () => { @@ -69,10 +67,8 @@ export default function RobotDashboard() { if (activeGp) { const rawX = activeGp.axes[0]; - - // PERUBAHAN: Index 6 dan 7 sudah ditukar posisinya! - const maju = activeGp.buttons[6].value; // RT untuk maju (Index 6) - const mundur = activeGp.buttons[7].value; // LT untuk mundur (Index 7) + const maju = activeGp.buttons[6].value; // RT untuk maju + const mundur = activeGp.buttons[7].value; // LT untuk mundur const throttle = maju - mundur; currentX = Math.abs(rawX) > 0.15 ? Number(rawX.toFixed(2)) : 0; @@ -98,7 +94,15 @@ export default function RobotDashboard() { if (wsRef.current) wsRef.current.close(); }; }, [controlMode, PI_IP]); - + + // --- PERBAIKAN VISUALIZER --- + // Membatasi titik hijau agar tidak menembus batas lingkaran (radius 48px - setengah ukuran dot 12px) + const maxRadius = 36; + // Nilai input stik (-1 sampai 1) dikali dengan radius maksimal + const dotX = steering.x * maxRadius; + // Sumbu Y dibalik (* -1) karena di CSS titik Y=0 ada di atas, sedangkan maju (positif) inginnya ke atas + const dotY = steering.y * -1 * maxRadius; + return (
@@ -127,9 +131,18 @@ export default function RobotDashboard() { Live Feed -
+
+ {/* PERBAIKAN KAMERA HP: Menggunakan img standar dengan error fallback */} {/* eslint-disable-next-line @next/next/no-img-element */} - Robot view + Robot view { + e.currentTarget.style.display = 'none'; + e.currentTarget.parentElement!.innerHTML = '
Kamera gagal dimuat.
Pastikan Pi dan HP berada dalam jaringan Tailscale/Wi-Fi yang sama.
'; + }} + />
@@ -150,19 +163,20 @@ export default function RobotDashboard() {
Visualizer (X / Y)
-
-
-
+ + {/* PERBAIKAN VISUALIZER CSS */} +
+ {/* Grid Crosshair Tengah */} +
+
+ {/* Titik Hijau */}
+
X: {steering.x} Y: {steering.y}