xenecode Claude Opus 5 commited on
Commit
aec3a91
·
1 Parent(s): 2e573ce

Redesign control panel with dark industrial theme

Browse files

- Scale the 8x8 scan grid to fit any screen height
- Show socket connection and data age in a status strip
- Use pointer events so long press works on touchscreens
- Add undo toast after ignoring a cell
- Replace full-screen barrier warning with a banner that keeps Stop reachable

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

frontend/public/index.html CHANGED
@@ -1,5 +1,5 @@
1
  <!doctype html>
2
- <html lang="en">
3
  <head>
4
  <meta charset="UTF-8" />
5
  <meta name="viewport" content="width=device-width,initial-scale=1" />
 
1
  <!doctype html>
2
+ <html lang="tr">
3
  <head>
4
  <meta charset="UTF-8" />
5
  <meta name="viewport" content="width=device-width,initial-scale=1" />
frontend/src/components/3DTrace.js CHANGED
@@ -31,7 +31,7 @@ function ThreeDTrace({ containerRef, joints }) {
31
 
32
  // Sahne - mat arka plan
33
  const scene = new THREE.Scene();
34
- scene.background = new THREE.Color(0x2d2d30);
35
 
36
  // Sahne birimi metre (URDF ile aynı)
37
  const camera = new THREE.PerspectiveCamera(
@@ -59,7 +59,7 @@ function ThreeDTrace({ containerRef, joints }) {
59
  controls.update();
60
 
61
  // Zemin: 10 cm'lik ızgara ve robot gölgesi
62
- scene.add(new THREE.GridHelper(2, 20, 0x8a8a8a, 0x505050));
63
  const ground = new THREE.Mesh(
64
  new THREE.PlaneGeometry(4, 4),
65
  new THREE.ShadowMaterial({ opacity: 0.35 })
@@ -134,7 +134,7 @@ function ThreeDTrace({ containerRef, joints }) {
134
  flange.add(
135
  new THREE.Mesh(
136
  new THREE.SphereGeometry(0.008, 16, 12),
137
- new THREE.MeshBasicMaterial({ color: 0xff4500 })
138
  )
139
  );
140
  robot.links.wrist3_link.add(flange);
 
31
 
32
  // Sahne - mat arka plan
33
  const scene = new THREE.Scene();
34
+ scene.background = new THREE.Color(0x16181b);
35
 
36
  // Sahne birimi metre (URDF ile aynı)
37
  const camera = new THREE.PerspectiveCamera(
 
59
  controls.update();
60
 
61
  // Zemin: 10 cm'lik ızgara ve robot gölgesi
62
+ scene.add(new THREE.GridHelper(2, 20, 0x5c626b, 0x2c3036));
63
  const ground = new THREE.Mesh(
64
  new THREE.PlaneGeometry(4, 4),
65
  new THREE.ShadowMaterial({ opacity: 0.35 })
 
134
  flange.add(
135
  new THREE.Mesh(
136
  new THREE.SphereGeometry(0.008, 16, 12),
137
+ new THREE.MeshBasicMaterial({ color: 0xf97316 })
138
  )
139
  );
140
  robot.links.wrist3_link.add(flange);
frontend/src/components/Navbar.js CHANGED
@@ -1,35 +1,41 @@
1
  import React from 'react';
2
- import { Link } from 'react-router-dom';
 
 
 
 
 
 
3
 
4
  const Navbar = () => {
5
  return (
6
- <nav className="bg-navbar-bg text-navbar-text h-16 shadow-md sticky top-0 z-50 transition-colors duration-300">
7
- <div className="max-w-7xl mx-auto flex justify-between items-center h-full px-6 md:px-10">
8
- <Link
9
- to="/"
10
- className="text-2xl md:text-3xl font-bold tracking-tight text-white hover:text-navbar-accent transition-colors"
11
- >
12
- Jaguar Interface
13
- </Link>
14
- <ul className="flex space-x-6 text-sm md:text-base font-medium">
15
- <li>
16
- <Link
17
- to="/dashboard"
18
- className="text-navbar-text hover:text-navbar-accent transition-colors"
19
- >
20
- Dashboard
21
- </Link>
22
- </li>
23
- <li>
24
- <Link
25
- to="/debug"
26
- className="text-navbar-text hover:text-navbar-accent transition-colors"
27
  >
28
- Debug Panel
29
- </Link>
30
  </li>
31
- </ul>
32
- </div>
33
  </nav>
34
  );
35
  };
 
1
  import React from 'react';
2
+ import { NavLink } from 'react-router-dom';
3
+
4
+ const LINKS = [
5
+ { to: '/', label: 'Kontrol', end: true },
6
+ { to: '/dashboard', label: 'Pano' },
7
+ { to: '/debug', label: 'Tanılama' },
8
+ ];
9
 
10
  const Navbar = () => {
11
  return (
12
+ <nav className="sticky top-0 z-50 flex h-12 items-center justify-between border-b border-hmi-line bg-hmi-bg px-4 font-hmi text-hmi-text">
13
+ <NavLink
14
+ to="/"
15
+ className="flex items-center gap-2.5 text-hmi-text hover:text-hmi-text"
16
+ >
17
+ <span className="h-3 w-3 bg-hmi-accent" aria-hidden="true" />
18
+ <span className="text-base font-bold uppercase tracking-[0.2em]">Jaguar</span>
19
+ </NavLink>
20
+ <ul className="flex h-full">
21
+ {LINKS.map(({ to, label, end }) => (
22
+ <li key={to} className="h-full">
23
+ <NavLink
24
+ to={to}
25
+ end={end}
26
+ className={({ isActive }) =>
27
+ `flex h-full items-center border-b-2 px-4 text-sm font-semibold uppercase tracking-[0.1em] transition-colors ${
28
+ isActive
29
+ ? 'border-hmi-accent text-hmi-text hover:text-hmi-text'
30
+ : 'border-transparent text-hmi-muted hover:text-hmi-text'
31
+ }`
32
+ }
33
  >
34
+ {label}
35
+ </NavLink>
36
  </li>
37
+ ))}
38
+ </ul>
39
  </nav>
40
  );
41
  };
frontend/src/components/ScanTrace.js CHANGED
@@ -1,261 +1,279 @@
1
- import React, { useEffect, useState } from 'react';
2
  import { apiService } from '../services/api.service';
3
- import { toast } from 'react-toastify';
4
  import 'react-toastify/dist/ReactToastify.css';
5
- import { ToastContainer } from 'react-toastify';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  const ScanTrace = ({ onScan }) => {
8
- const [rectangles, setRectangles] = useState([]);
9
- const [ignoredPointsInput, setIgnoredPointsInput] = useState([]);
10
- const [internalData, setInternalData] = useState("blank");
11
- const [hoveredCell, setHoveredCell] = useState(null);
12
- const [pressedCell, setPressedCell] = useState(null);
13
- const [pressTimer, setPressTimer] = useState(null);
14
- const [isLongPressing, setIsLongPressing] = useState(false);
15
-
16
- // 64 adet kutusunu oluştur (8x8)
17
- useEffect(() => {
18
- const initialRectangles = Array.from({ length: 64 }, (_, i) => ({
19
- id: String(i),
20
- row: Math.floor(i / 8),
21
- col: i % 8,
22
- fill: 'inactive',
23
- isIgnored: false,
24
- }));
25
- setRectangles(initialRectangles);
26
- }, []);
27
 
28
- // API'den renk bilgisini periyodik olarak al ve güncelle
29
  useEffect(() => {
 
 
30
  const fetchColors = async () => {
31
  try {
32
  const data = await apiService.getColors();
33
- setRectangles((prevRects) =>
34
- prevRects.map((rect, idx) => ({
35
- ...rect,
36
- fill: data.colors[idx] || 'inactive',
37
- }))
38
- );
 
 
 
 
 
 
 
 
 
 
39
  } catch (error) {
40
  console.log('Renkler alınırken hata oluştu:', error);
41
- setTimeout(fetchColors, 5000);
42
  }
43
  };
44
 
45
  fetchColors();
46
- const interval = setInterval(fetchColors, 200);
47
- return () => clearInterval(interval);
 
 
 
48
  }, []);
49
 
50
  useEffect(() => {
51
- if (internalData !== "blank") {
52
  onScan(internalData);
53
  }
54
  }, [internalData, onScan]);
55
 
56
- // Renk mapping fonksiyonu
57
- const getColorClass = (fill, isIgnored, isPressed = false, isLongPressing = false) => {
58
- if (isIgnored) return 'bg-slate-900 border-slate-700';
59
-
60
- // Basılı tutma görsel geri bildirimi
61
- if (isPressed && isLongPressing) {
62
- return 'bg-purple-600 border-purple-400 ring-2 ring-purple-300';
63
- }
64
- if (isPressed) {
65
- return 'bg-orange-500 border-orange-400';
66
- }
67
-
68
- switch(fill) {
69
- case 'yellow': return 'bg-yellow-500 border-yellow-400';
70
- case 'green': return 'bg-green-500 border-green-400';
71
- case 'blue': return 'bg-blue-500 border-blue-400';
72
- case 'red': return 'bg-red-500 border-red-400';
73
- case 'black': return 'bg-slate-900 border-slate-700';
74
- case 'white': return 'bg-white border-slate-300 text-slate-800';
75
- default: return 'bg-slate-600 border-slate-500';
76
- }
77
- };
78
 
79
- // Mouse down - basılı tutma başlangıcı
80
- const handleMouseDown = (id) => {
81
- setPressedCell(id);
82
-
83
- const timer = setTimeout(() => {
84
- setIsLongPressing(true);
85
- // Titreşim efekti (destekleniyorsa)
86
- if (navigator.vibrate) {
87
- navigator.vibrate(50);
88
- }
89
- }, 600); // 600ms sonra long press
90
-
91
- setPressTimer(timer);
92
- };
93
 
94
- // Mouse up - basılı tutma bitişi
95
- const handleMouseUp = (id) => {
96
- if (pressTimer) {
97
- clearTimeout(pressTimer);
98
- setPressTimer(null);
99
- }
100
-
101
- if (isLongPressing) {
102
- // Uzun basma - Index ayarlama
103
- handleSetIndex(id);
104
- } else if (pressedCell === id) {
105
- // Kısa basma - Ignore
106
- handleIgnoreToggle(id);
107
  }
108
 
109
- setPressedCell(null);
110
- setIsLongPressing(false);
111
- };
 
 
112
 
113
- // Mouse leave - basılı tutma iptal
114
- const handleMouseLeave = (id) => {
115
- setHoveredCell(null);
116
- // Basılı tutma devam etsin (iptal etme yok)
117
- };
118
 
119
- // Mouse enter
120
- const handleMouseEnter = (id) => {
121
- setHoveredCell(id);
122
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
 
124
- // Ignore toggle işlemi
125
- const handleIgnoreToggle = (id) => {
126
- // Easter egg kontrolü
127
- if (JSON.stringify(ignoredPointsInput) === JSON.stringify([19, 23, 20, 0, 2])) {
128
- toast.success("🎉 Easter egg keşfedildi!");
129
- setInternalData("Easter egg :)");
130
- } else {
131
- setInternalData("");
132
  }
133
-
134
- // Hücre durumunu güncelle
135
- setRectangles((prevRects) =>
136
- prevRects.map((rect) =>
137
- rect.id === id
138
- ? { ...rect, isIgnored: !rect.isIgnored }
139
- : rect
140
- )
141
- );
142
 
143
- // Ignored points listesini güncelle ve API'ye gönder
144
- handleSendIgnoredPoints(id);
 
 
 
145
  };
146
 
147
- // Index ayarlama işlemi (eski çift tıklama)
148
- const handleSetIndex = async(id) => {
149
- try {
150
- const response = await apiService.setIndex(id);
151
- toast.success(`Index ${id} ayarlandı`);
152
- }
153
- catch (error) {
154
- toast.error("Hata oluştu: " + error);
155
- }
 
 
 
 
 
 
156
  };
157
 
158
- // Ignored points listesini güncelle ve API'ye gönder
159
- const handleSendIgnoredPoints = async (action) => {
160
- try {
161
- const numericAction = parseInt(action, 10);
162
- const newPoints = ignoredPointsInput.includes(numericAction)
163
- ? ignoredPointsInput.filter((index) => index !== numericAction)
164
- : [...ignoredPointsInput, numericAction];
165
-
166
- setIgnoredPointsInput(newPoints);
167
-
168
- await apiService.controlScan({ ignored_index_list: newPoints });
169
- } catch (error) {
170
- toast.error(error);
 
171
  }
172
  };
173
 
 
 
 
174
  return (
175
- <div className="h-full bg-slate-800 rounded-lg border border-slate-700">
176
  <ToastContainer
177
- position="top-right"
178
  autoClose={3000}
179
- newestOnTop={true}
180
- closeOnClick={true}
181
- pauseOnHover={true}
182
  theme="dark"
183
- style={{
184
- zIndex: 9999,
185
- }}
186
  closeButton={false}
187
  />
188
 
189
- {/* Header Info */}
190
- <div className="flex justify-between items-center mb-4">
191
- <div className="flex items-center space-x-4">
192
- <div className="text-sm text-slate-400">
193
- {ignoredPointsInput.length > 0 && `${ignoredPointsInput.length} nokta yok sayılıyor`}
194
- </div>
 
195
  </div>
196
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
  </div>
198
 
199
- {/* 8x8 Grid */}
200
- <div className="grid grid-cols-8 gap-2 h-[calc(100%-80px)] p-2">
201
- {rectangles.map((rect) => (
202
- <div
203
- key={rect.id}
204
- onMouseDown={() => handleMouseDown(rect.id)}
205
- onMouseUp={() => handleMouseUp(rect.id)}
206
- onMouseEnter={() => handleMouseEnter(rect.id)}
207
- onMouseLeave={() => handleMouseLeave(rect.id)}
208
- className={`
209
- relative flex items-center justify-center cursor-pointer rounded-lg border-2
210
- transition-all duration-300 touch-manipulation font-mono font-semibold select-none
211
- ${getColorClass(rect.fill, rect.isIgnored, pressedCell === rect.id, isLongPressing && pressedCell === rect.id)}
212
- ${rect.fill === 'yellow' ? 'animate-pulse' : ''}
213
- ${hoveredCell === rect.id ? 'transform scale-110 shadow-lg z-10' : ''}
214
- ${rect.isIgnored ? 'opacity-75 ring-2 ring-slate-700' : ''}
215
- ${pressedCell === rect.id ? 'transform scale-95' : ''}
216
- ${isLongPressing && pressedCell === rect.id ? 'animate-pulse' : ''}
217
- hover:shadow-xl
218
- `}
219
- style={{
220
- minHeight: '40px',
221
- boxShadow: hoveredCell === rect.id
222
- ? '0 8px 25px rgba(0,0,0,0.3), 0 0 0 1px rgba(255,255,255,0.1)'
223
- : '0 2px 8px rgba(0,0,0,0.2)',
224
- }}
225
- >
226
- {/* Cell Number */}
227
- <span className={`
228
- ${rect.fill === 'white' ? 'text-slate-800' : 'text-white'}
229
- ${hoveredCell === rect.id ? 'font-bold' : ''}
230
- ${isLongPressing && pressedCell === rect.id ? 'text-white font-bold' : ''}
231
- text-2xl
232
- `}>
233
- {rect.id}
234
- </span>
235
-
236
- {/* Ignored Indicator */}
237
- {rect.isIgnored && (
238
- <div className="absolute -top-1 -right-1 w-3 h-3 bg-slate-900 rounded-full border-2 border-white">
239
- <span className="text-[8px] text-white flex items-center justify-center h-full">×</span>
240
- </div>
241
- )}
242
-
243
- {/* Active Pulse Ring */}
244
- {rect.fill === 'yellow' && (
245
- <div className="absolute inset-0 rounded-lg border-2 border-yellow-300 animate-ping opacity-30"></div>
246
- )}
247
-
248
- {/* Long Press Indicator */}
249
- {isLongPressing && pressedCell === rect.id && (
250
- <div className="absolute inset-0 rounded-lg border-2 border-purple-300 animate-ping opacity-50"></div>
251
- )}
252
- </div>
253
- ))}
254
  </div>
255
 
256
- {/* Bottom Info */}
257
- <div className="mt-3 flex justify-between items-center text-xs text-slate-400">
258
- <span>Kısa tıklama: Yok say | Basılı tutma: Index ayarla</span>
 
259
  </div>
260
  </div>
261
  );
 
1
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
2
  import { apiService } from '../services/api.service';
3
+ import { toast, ToastContainer } from 'react-toastify';
4
  import 'react-toastify/dist/ReactToastify.css';
5
+
6
+ const GRID_SIZE = 8;
7
+ const CELL_COUNT = GRID_SIZE * GRID_SIZE;
8
+ const LONG_PRESS_MS = 600;
9
+ const COLOR_POLL_MS = 200;
10
+ const EASTER_EGG = [19, 23, 20, 0, 2];
11
+
12
+ // Backend'in gönderdiği renk kodu → hücre durumu
13
+ const STATE_BY_FILL = {
14
+ yellow: 'active',
15
+ gray: 'pending',
16
+ green: 'pass',
17
+ red: 'fail',
18
+ };
19
+
20
+ // Durumlar renk + ikon ile ayrılır (renk körlüğü için yalnız renge güvenme)
21
+ const CELL_STATES = {
22
+ active: { label: 'Aktif', className: 'bg-hmi-warn border-hmi-warn text-hmi-bg hmi-active-ring', icon: '▶' },
23
+ pending: { label: 'Bekliyor', className: 'bg-hmi-raised border-hmi-line text-hmi-text', icon: null },
24
+ pass: { label: 'Geçer', className: 'bg-hmi-ok border-hmi-ok text-hmi-bg', icon: '✓' },
25
+ fail: { label: 'Hatalı', className: 'bg-hmi-err border-hmi-err text-hmi-bg', icon: '✕' },
26
+ ignored: { label: 'Yok say', className: 'hmi-hatch border-dashed border-hmi-muted text-hmi-muted', icon: '⊘' },
27
+ };
28
+
29
+ const LEGEND_ORDER = ['active', 'pending', 'pass', 'fail', 'ignored'];
30
 
31
  const ScanTrace = ({ onScan }) => {
32
+ const [fills, setFills] = useState(() => Array(CELL_COUNT).fill('gray'));
33
+ const [ignored, setIgnored] = useState([]);
34
+ const [internalData, setInternalData] = useState('blank');
35
+ const [pressedIndex, setPressedIndex] = useState(null);
36
+ const [longPressed, setLongPressed] = useState(false);
37
+
38
+ // Toast'taki "Geri al" gibi gecikmeli çağrılar güncel listeyi görsün diye ref
39
+ const ignoredRef = useRef([]);
40
+ const seededRef = useRef(false);
41
+ const pressRef = useRef({ index: null, timer: null, long: false });
 
 
 
 
 
 
 
 
 
42
 
43
+ // Hücre renklerini periyodik olarak al
44
  useEffect(() => {
45
+ let cancelled = false;
46
+
47
  const fetchColors = async () => {
48
  try {
49
  const data = await apiService.getColors();
50
+ if (cancelled) return;
51
+ const colors = data.colors || [];
52
+
53
+ // Sayfa yenilendiğinde backend'deki yok sayma listesini devral
54
+ if (!seededRef.current) {
55
+ seededRef.current = true;
56
+ const fromBackend = colors
57
+ .map((color, index) => (color === 'black' ? index : null))
58
+ .filter((index) => index !== null);
59
+ if (fromBackend.length && !ignoredRef.current.length) {
60
+ ignoredRef.current = fromBackend;
61
+ setIgnored(fromBackend);
62
+ }
63
+ }
64
+
65
+ setFills(Array.from({ length: CELL_COUNT }, (_, i) => colors[i] || 'gray'));
66
  } catch (error) {
67
  console.log('Renkler alınırken hata oluştu:', error);
 
68
  }
69
  };
70
 
71
  fetchColors();
72
+ const interval = setInterval(fetchColors, COLOR_POLL_MS);
73
+ return () => {
74
+ cancelled = true;
75
+ clearInterval(interval);
76
+ };
77
  }, []);
78
 
79
  useEffect(() => {
80
+ if (internalData !== 'blank') {
81
  onScan(internalData);
82
  }
83
  }, [internalData, onScan]);
84
 
85
+ useEffect(() => () => clearTimeout(pressRef.current.timer), []);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
+ const toggleIgnore = useCallback((index) => {
88
+ const current = ignoredRef.current;
89
+ const wasIgnored = current.includes(index);
90
+ const next = wasIgnored ? current.filter((i) => i !== index) : [...current, index];
 
 
 
 
 
 
 
 
 
 
91
 
92
+ if (JSON.stringify(current) === JSON.stringify(EASTER_EGG)) {
93
+ toast.success('🎉 Easter egg keşfedildi!');
94
+ setInternalData('Easter egg :)');
95
+ } else {
96
+ setInternalData('');
 
 
 
 
 
 
 
 
97
  }
98
 
99
+ ignoredRef.current = next;
100
+ setIgnored(next);
101
+ apiService
102
+ .controlScan({ ignored_index_list: next })
103
+ .catch((error) => toast.error(`Yok sayma listesi gönderilemedi: ${error.message}`));
104
 
105
+ return !wasIgnored;
106
+ }, []);
 
 
 
107
 
108
+ const handleTap = useCallback((index) => {
109
+ const nowIgnored = toggleIgnore(index);
110
+ toast(
111
+ ({ closeToast }) => (
112
+ <div className="flex items-center justify-between gap-4">
113
+ <span>
114
+ <span className="font-mono font-semibold">{index}</span>{' '}
115
+ {nowIgnored ? 'yok sayıldı' : 'taramaya geri alındı'}
116
+ </span>
117
+ <button
118
+ type="button"
119
+ onClick={() => {
120
+ toggleIgnore(index);
121
+ closeToast();
122
+ }}
123
+ className="min-h-[40px] shrink-0 border border-hmi-accent px-3 text-sm font-semibold uppercase tracking-wider text-hmi-accent active:bg-hmi-accent active:text-hmi-bg"
124
+ >
125
+ Geri al
126
+ </button>
127
+ </div>
128
+ ),
129
+ { autoClose: 5000 }
130
+ );
131
+ }, [toggleIgnore]);
132
 
133
+ const handleSetIndex = useCallback(async (index) => {
134
+ try {
135
+ await apiService.setIndex(String(index));
136
+ toast.success(`Index ${index} ayarlandı`);
137
+ } catch (error) {
138
+ toast.error(`Index ayarlanamadı: ${error.message}`);
 
 
139
  }
140
+ }, []);
 
 
 
 
 
 
 
 
141
 
142
+ const resetPress = () => {
143
+ clearTimeout(pressRef.current.timer);
144
+ pressRef.current = { index: null, timer: null, long: false };
145
+ setPressedIndex(null);
146
+ setLongPressed(false);
147
  };
148
 
149
+ // Pointer olayları fare, kalem ve dokunmatiği birlikte karşılar
150
+ const handlePointerDown = (event, index) => {
151
+ if (event.button !== 0) return;
152
+ event.currentTarget.setPointerCapture?.(event.pointerId);
153
+ clearTimeout(pressRef.current.timer);
154
+
155
+ const timer = setTimeout(() => {
156
+ pressRef.current.long = true;
157
+ setLongPressed(true);
158
+ navigator.vibrate?.(50);
159
+ }, LONG_PRESS_MS);
160
+
161
+ pressRef.current = { index, timer, long: false };
162
+ setPressedIndex(index);
163
+ setLongPressed(false);
164
  };
165
 
166
+ const handlePointerUp = (event, index) => {
167
+ const { index: pressed, long } = pressRef.current;
168
+ const rect = event.currentTarget.getBoundingClientRect();
169
+ // Parmak hücrenin dışına kaydırıldıysa işlemi iptal et
170
+ const inside =
171
+ event.clientX >= rect.left && event.clientX <= rect.right &&
172
+ event.clientY >= rect.top && event.clientY <= rect.bottom;
173
+ resetPress();
174
+
175
+ if (pressed !== index || !inside) return;
176
+ if (long) {
177
+ handleSetIndex(index);
178
+ } else {
179
+ handleTap(index);
180
  }
181
  };
182
 
183
+ const cellState = (index) =>
184
+ ignored.includes(index) ? 'ignored' : STATE_BY_FILL[fills[index]] || 'pending';
185
+
186
  return (
187
+ <div className="flex h-full min-h-0 flex-col">
188
  <ToastContainer
189
+ position="bottom-right"
190
  autoClose={3000}
191
+ newestOnTop
192
+ closeOnClick={false}
193
+ pauseOnHover
194
  theme="dark"
 
 
 
195
  closeButton={false}
196
  />
197
 
198
+ {/* Başlık ve lejant */}
199
+ <div className="flex flex-wrap items-center justify-between gap-x-6 gap-y-2 border-b border-hmi-line px-4 py-2.5">
200
+ <div className="flex items-baseline gap-3">
201
+ <span className="text-sm font-semibold uppercase tracking-[0.14em]">Tarama izleme</span>
202
+ {ignored.length > 0 && (
203
+ <span className="font-mono text-xs text-hmi-muted">{ignored.length} nokta yok sayılıyor</span>
204
+ )}
205
  </div>
206
+ <ul className="flex flex-wrap items-center gap-x-4 gap-y-1">
207
+ {LEGEND_ORDER.map((key) => {
208
+ const state = CELL_STATES[key];
209
+ return (
210
+ <li key={key} className="flex items-center gap-1.5 text-sm text-hmi-muted">
211
+ <span
212
+ className={`flex h-5 w-5 items-center justify-center border text-[10px] font-bold leading-none ${state.className.replace('hmi-active-ring', '')}`}
213
+ aria-hidden="true"
214
+ >
215
+ {state.icon}
216
+ </span>
217
+ {state.label}
218
+ </li>
219
+ );
220
+ })}
221
+ </ul>
222
  </div>
223
 
224
+ {/* 8x8 ızgara: panelin kısa kenarına göre kare olarak ölçeklenir, asla taşmaz */}
225
+ <div className="flex min-h-0 flex-1 items-center justify-center px-3 py-3" style={{ containerType: 'size' }}>
226
+ <div
227
+ className="grid gap-1.5"
228
+ style={{
229
+ gridTemplateColumns: `repeat(${GRID_SIZE}, minmax(0, 1fr))`,
230
+ gridTemplateRows: `repeat(${GRID_SIZE}, minmax(0, 1fr))`,
231
+ width: 'min(100cqw, 100cqh)',
232
+ height: 'min(100cqw, 100cqh)',
233
+ fontSize: `calc(min(100cqw, 100cqh) / ${GRID_SIZE} * 0.34)`,
234
+ }}
235
+ >
236
+ {Array.from({ length: CELL_COUNT }, (_, index) => {
237
+ const key = cellState(index);
238
+ const state = CELL_STATES[key];
239
+ const pressed = pressedIndex === index;
240
+
241
+ return (
242
+ <button
243
+ key={index}
244
+ type="button"
245
+ aria-label={`Nokta ${index}: ${state.label}`}
246
+ onPointerDown={(event) => handlePointerDown(event, index)}
247
+ onPointerUp={(event) => handlePointerUp(event, index)}
248
+ onPointerCancel={resetPress}
249
+ onContextMenu={(event) => event.preventDefault()}
250
+ className={`relative flex select-none items-center justify-center overflow-hidden border-2 font-mono font-bold leading-none touch-manipulation transition-[filter,transform] duration-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-hmi-accent [@media(hover:hover)]:hover:brightness-110 ${state.className} ${pressed ? 'scale-[0.94] brightness-90' : ''}`}
251
+ >
252
+ {index}
253
+ {state.icon && (
254
+ <span className="absolute right-[6%] top-[4%] text-[0.45em] leading-none" aria-hidden="true">
255
+ {state.icon}
256
+ </span>
257
+ )}
258
+
259
+ {/* Basılı tutma ilerlemesi: dolunca index ayarlanır */}
260
+ {pressed && (
261
+ <span
262
+ className={`absolute inset-x-0 bottom-0 h-1.5 ${longPressed ? 'bg-hmi-text' : 'bg-hmi-accent hmi-press-progress'}`}
263
+ style={{ animationDuration: `${LONG_PRESS_MS}ms` }}
264
+ aria-hidden="true"
265
+ />
266
+ )}
267
+ </button>
268
+ );
269
+ })}
270
+ </div>
 
 
 
 
 
 
 
 
271
  </div>
272
 
273
+ <div className="border-t border-hmi-line px-4 py-2 text-sm text-hmi-muted">
274
+ <span className="font-semibold text-hmi-text">Dokun:</span> yok say / geri al
275
+ <span className="mx-3 text-hmi-line">|</span>
276
+ <span className="font-semibold text-hmi-text">Basılı tut:</span> index ayarla
277
  </div>
278
  </div>
279
  );
frontend/src/index.css CHANGED
@@ -21,3 +21,60 @@ body {
21
  ::-webkit-scrollbar-thumb {
22
  @apply bg-white rounded-full;
23
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  ::-webkit-scrollbar-thumb {
22
  @apply bg-white rounded-full;
23
  }
24
+
25
+ /* Operatör paneli (koyu endüstriyel tema) */
26
+ @layer components {
27
+ /* Yok sayılan hücre: renkten bağımsız çapraz tarama deseni */
28
+ .hmi-hatch {
29
+ background-color: theme('colors.hmi.panel');
30
+ background-image: repeating-linear-gradient(
31
+ 135deg,
32
+ rgba(145, 151, 160, 0.28) 0 2px,
33
+ transparent 2px 9px
34
+ );
35
+ }
36
+
37
+ /* Aktif hücre: hücrenin kendisi değil, dış çerçevesi yanıp söner */
38
+ .hmi-active-ring {
39
+ animation: hmi-ring 1.2s ease-in-out infinite;
40
+ }
41
+
42
+ .hmi-press-progress {
43
+ animation-name: hmi-progress;
44
+ animation-timing-function: linear;
45
+ animation-fill-mode: forwards;
46
+ }
47
+ }
48
+
49
+ @keyframes hmi-ring {
50
+ 0%, 100% { box-shadow: 0 0 0 2px theme('colors.hmi.bg'), 0 0 0 5px rgba(250, 204, 21, 1); }
51
+ 50% { box-shadow: 0 0 0 2px theme('colors.hmi.bg'), 0 0 0 5px rgba(250, 204, 21, 0.1); }
52
+ }
53
+
54
+ @keyframes hmi-progress {
55
+ from { width: 0; }
56
+ to { width: 100%; }
57
+ }
58
+
59
+ @media (prefers-reduced-motion: reduce) {
60
+ .hmi-active-ring {
61
+ animation: none;
62
+ box-shadow: 0 0 0 2px theme('colors.hmi.bg'), 0 0 0 5px theme('colors.hmi.warn');
63
+ }
64
+ }
65
+
66
+ /* Bildirimler panelle aynı dilde: köşesiz, çerçeveli */
67
+ .Toastify {
68
+ --toastify-color-dark: theme('colors.hmi.raised');
69
+ --toastify-text-color-dark: theme('colors.hmi.text');
70
+ --toastify-color-success: theme('colors.hmi.ok');
71
+ --toastify-color-error: theme('colors.hmi.err');
72
+ --toastify-color-progress-dark: theme('colors.hmi.accent');
73
+ --toastify-font-family: inherit;
74
+ }
75
+
76
+ .Toastify .Toastify__toast {
77
+ border-radius: 0;
78
+ border: 1px solid theme('colors.hmi.line');
79
+ font-size: 15px;
80
+ }
frontend/src/pages/ControlPanel.js CHANGED
@@ -1,80 +1,121 @@
1
  import React, { useState, useEffect, useRef, useCallback } from 'react';
2
- import { apiService } from '../services/api.service';
3
- import { INTERVALS, API_BASE_URL } from '../constants/api';
4
- import Button from '../components/Button';
5
- import LoadingSpinner from '../components/LoadingSpinner';
6
  import io from 'socket.io-client';
7
- import ScanTrace from '../components/ScanTrace';
8
  import { toast } from 'react-toastify';
9
  import 'react-toastify/dist/ReactToastify.css';
 
 
 
10
  import ThreeDTrace from '../components/3DTrace';
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  const ControlPanel = () => {
13
- const [message, setMessage] = useState('');
14
  const [loading, setLoading] = useState(true);
15
  const [status, setStatus] = useState({});
16
  const [traceValue, setTraceValue] = useState(null);
17
- const [connectionError, setConnectionError] = useState(false);
 
 
18
  const containerRef = useRef();
19
- const socketRef = useRef();
20
 
21
- // Memoized API call
22
- const fetchMessage = useCallback(async () => {
23
  try {
24
- setConnectionError(false);
25
- const data = await apiService.getHelloMessage();
26
- setMessage(data.message);
27
- setLoading(false);
28
  } catch (error) {
29
- setMessage('API ile iletişim kurulamadı.');
30
- setConnectionError(true);
31
  setLoading(false);
32
  }
33
  }, []);
34
 
35
- // Initialize API connection
36
  useEffect(() => {
37
- fetchMessage();
38
- const intervalId = setInterval(fetchMessage, INTERVALS.HELLO_MESSAGE);
39
  return () => clearInterval(intervalId);
40
- }, [fetchMessage]);
 
 
 
 
 
 
41
 
42
- // WebSocket connection
43
  useEffect(() => {
44
- const socketConnection = io(API_BASE_URL, {
45
  timeout: 5000,
46
  reconnectionAttempts: 5,
47
  reconnectionDelay: 1000,
48
- transports: ['websocket', 'polling']
49
  });
50
 
51
- socketRef.current = socketConnection;
52
-
53
- socketConnection.on('robot_status', (data) => {
54
  setStatus(data);
 
55
  setLoading(false);
56
- setConnectionError(false);
57
  });
58
 
59
- socketConnection.on('connect', () => {
60
- setConnectionError(false);
 
61
  });
62
 
63
- socketConnection.on('connect_error', (err) => {
64
  console.error('WebSocket connection error:', err);
65
- toast.error(`Bağlantı hatası: ${err.message}`);
66
- setConnectionError(true);
 
67
  setLoading(false);
68
  });
69
 
70
- socketConnection.on('disconnect', () => {
71
- setConnectionError(true);
72
  });
73
 
74
  return () => {
75
- if (socketConnection) {
76
- socketConnection.disconnect();
77
- }
78
  };
79
  }, []);
80
 
@@ -82,7 +123,7 @@ const ControlPanel = () => {
82
  try {
83
  const response = await apiService.controlScan({
84
  message: 'START',
85
- alt_button: altButton
86
  });
87
 
88
  if (response.status === 200) {
@@ -108,195 +149,139 @@ const ControlPanel = () => {
108
  setTraceValue(newValue);
109
  }, []);
110
 
111
- // Loading state
112
  if (loading) {
113
  return (
114
- <div className="min-h-screen bg-gray-50 flex items-center justify-center">
115
- <div className="text-center space-y-6">
116
- <LoadingSpinner text="Sistem başlatılıyor..." />
117
- <div className="w-80 h-1 bg-gray-200 rounded-full overflow-hidden">
118
- <div className="h-full bg-blue-600 rounded-full animate-pulse w-3/5"></div>
119
- </div>
120
- </div>
121
  </div>
122
  );
123
  }
124
 
125
- // Safety barrier warning
126
- if (!status.DI14 || !status.DI15) {
127
- return (
128
- <div className="fixed inset-0 flex items-center justify-center bg-red-500 z-50">
129
- <div className="text-center text-white p-12">
130
- <div className="text-8xl mb-8 animate-pulse">⚠️</div>
131
- <h1 className="text-6xl font-bold mb-6">UYARI!</h1>
132
- <p className="text-4xl font-medium">Işık bariyerinin önünde engel var!</p>
133
- </div>
134
- </div>
135
- );
 
 
 
 
 
 
 
 
136
  }
137
 
138
  return (
139
- <div className="h-full bg-slate-900 text-white overflow-hidden">
140
-
141
- {/* Main Content */}
142
- <div className="grid grid-cols-5 gap-3 px-4 h-[calc(100vh-64px)]">
143
- {/* Scan Monitoring - Takes 3 columns */}
144
- <div className="col-span-3 mt-5 bg-white rounded-lg shadow-sm border border-gray-100 overflow-hidden">
145
- <div className="p-2 border-b border-gray-100">
146
- <h2 className="text-m font-semibold text-gray-900">Tarama İzleme</h2>
147
- {/* Legend */}
148
- <div className="flex items-center space-x-3 text-xs">
149
- <div className="flex items-center space-x-1">
150
- <div className="w-5 h-5 bg-yellow-500 rounded"></div>
151
- <span className="text-xl text-black">Aktif</span>
152
- </div>
153
- <div className="flex items-center space-x-1">
154
- <div className="w-5 h-5 bg-slate-600 rounded"></div>
155
- <span className=" text-xl text-black">Bekliyor</span>
156
- </div>
157
- <div className="flex items-center space-x-1">
158
- <div className="w-5 h-5 bg-slate-900 rounded border border-slate-700"></div>
159
- <span className="text-xl text-black">Yok Say</span>
160
- </div>
161
- <div className="flex items-center space-x-1">
162
- <div className="w-5 h-5 bg-red-500 rounded border border-slate-700"></div>
163
- <span className=" text-xl text-black">Hatalı</span>
164
- </div>
165
- <div className="flex items-center space-x-1">
166
- <div className="w-5 h-5 bg-green-500 rounded border border-slate-700"></div>
167
- <span className="text-xl text-black">Geçer</span>
168
- </div>
169
- </div>
170
- </div>
171
-
172
-
173
- <div className="p-1 h-[calc(100%-40px)]">
174
- <div className="w-full h-full bg-gray-50 rounded border border-dashed border-gray-200 overflow-hidden">
175
- <ScanTrace onScan={handleTraceChange} />
176
- </div>
177
  </div>
178
  </div>
 
179
 
180
- {/* Right Panel - Takes 2 columns */}
181
- <div className="col-span-2 h-full flex flex-col">
182
-
183
- {/* Top Half - System Status and Controls side by side */}
184
- <div className="grid grid-cols-2 gap-2 h-1/2 mb-2">
185
-
186
- {/* System Status Card */}
187
- <div className="bg-white rounded-lg shadow-sm border border-gray-100 mt-5 p-3 flex flex-col">
188
- <h3 className="text-m font-semibold text-gray-900 mb-3">Sistem Durumu</h3>
189
-
190
- <div className="grid grid-cols-1 gap-2 text-sm flex-1">
191
-
192
- {/* TCP Status */}
193
- <div className="flex items-center justify-between p-2 bg-gray-50 rounded">
194
- <span className="text-gray-700 font-medium">TCP</span>
195
- <div className={`w-3 h-3 rounded-full ${status?.TCP ? 'bg-green-400' : 'bg-red-400'}`}></div>
196
- </div>
197
-
198
- {/* Part Held Status */}
199
- <div className="flex items-center justify-between p-2 bg-gray-50 rounded">
200
- <span className="text-gray-700 font-medium">Parça</span>
201
- <div className={`w-3 h-3 rounded-full ${!status?.DI0 ? 'bg-green-400' : 'bg-gray-300'}`}></div>
202
- </div>
203
-
204
- {/* Mode Status */}
205
- <div className="flex items-center justify-between p-2 bg-gray-50 rounded">
206
- <span className="text-gray-700 font-medium">Mod</span>
207
- <span className={`px-2 py-1 rounded text-sm font-medium ${status?.MODE === 2 ? 'bg-blue-100 text-blue-800' : 'bg-gray-100 text-gray-800'
208
- }`}>
209
- {status?.MODE === 0 ? "Auto" : "Manuel"}
210
- </span>
211
- </div>
212
 
213
- {/* Coordinates */}
214
- {status?.TCP && (
215
- <div className="p-2 bg-blue-50 rounded">
216
- <div className="font-mono text-sm text-blue-800 space-y-1">
217
- <div>X: {Math.round(status.TCP.x * 10) / 10}</div>
218
- <div>Y: {Math.round(status.TCP.y * 10) / 10}</div>
219
- <div>Z: {Math.round(status.TCP.z * 10) / 10}</div>
220
- </div>
221
- </div>
222
- )}
223
 
224
- </div>
225
- </div>
 
 
226
 
227
- {/* Control Buttons Card */}
228
- <div className="bg-white rounded-lg shadow-sm border border-gray-100 mt-5 p-2 flex flex-col">
229
- <h3 className="text-m font-semibold text-gray-900 mt-1 mb-14">Kontroller</h3>
230
- <div className="space-y-5 flex-1">
231
 
 
 
 
 
 
232
  {!traceValue && (
233
  <button
 
234
  onClick={() => handleStartScan(true)}
235
- className="w-full py-5 px-6 bg-purple-600 hover:bg-purple-700 text-white rounded text-sm font-medium
236
- transition-all duration-200 transform hover:scale-105 touch-manipulation shadow-lg"
237
  >
238
- Arayüzden Başlat
239
  </button>
240
  )}
241
-
242
  <button
 
243
  onClick={() => handleStartScan(false)}
244
- disabled={status?.scan_active}
245
- className="w-full py-5 px-6 bg-green-600 hover:bg-green-700 disabled:bg-gray-300
246
- text-white rounded text-sm font-medium transition-all duration-200
247
- transform hover:scale-105 disabled:transform-none touch-manipulation shadow-lg
248
- disabled:cursor-not-allowed"
249
- >
250
- Tarama Başlat
251
- </button>
252
-
253
- <button
254
- onClick={handleStopScan}
255
- disabled={!status?.scan_active}
256
- className="w-full py-5 px-6 bg-red-600 hover:bg-red-700 disabled:bg-gray-300
257
- text-white rounded text-sm font-medium transition-all duration-200
258
- transform hover:scale-105 disabled:transform-none touch-manipulation shadow-lg
259
- disabled:cursor-not-allowed"
260
  >
261
- Tarama Durdur
262
  </button>
263
-
264
  </div>
265
- </div>
266
- </div>
267
-
268
- {/* Bottom Half - 3D Trace Card */}
269
- {status?.TCP && (
270
- <div className="bg-white rounded-lg shadow-sm border border-gray-100 p-1 flex flex-col h-1/2">
271
 
272
- <div
273
- ref={containerRef}
274
- className="w-full h-full"
 
 
275
  >
276
- <ThreeDTrace
277
- containerRef={containerRef}
278
- joints={status.JOINTS}
279
- />
280
- </div>
281
  </div>
282
- )}
283
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  </div>
285
  </div>
286
-
287
- {/* TCP Warning when no data */}
288
- {!status?.TCP && (
289
- <div className="fixed bottom-3 right-3 bg-amber-100 border border-amber-200 rounded p-2 shadow-lg">
290
- <div className="flex items-center space-x-2">
291
- <span className="text-sm">📡</span>
292
- <div>
293
- <p className="text-xs font-medium text-amber-900">TCP verisi bekleniyor</p>
294
- <p className="text-xs text-amber-700">Robot bağlantısını kontrol edin</p>
295
- </div>
296
- </div>
297
- </div>
298
- )}
299
-
300
  </div>
301
  );
302
  };
 
1
  import React, { useState, useEffect, useRef, useCallback } from 'react';
 
 
 
 
2
  import io from 'socket.io-client';
 
3
  import { toast } from 'react-toastify';
4
  import 'react-toastify/dist/ReactToastify.css';
5
+ import { apiService } from '../services/api.service';
6
+ import { INTERVALS, API_BASE_URL } from '../constants/api';
7
+ import ScanTrace from '../components/ScanTrace';
8
  import ThreeDTrace from '../components/3DTrace';
9
 
10
+ // Bu süre boyunca robot_status gelmezse ekrandaki veri "eski" sayılır
11
+ const STALE_AFTER_MS = 3000;
12
+
13
+ const TONE = {
14
+ ok: { dot: 'bg-hmi-ok', text: 'text-hmi-ok' },
15
+ err: { dot: 'bg-hmi-err', text: 'text-hmi-err' },
16
+ warn: { dot: 'bg-hmi-warn', text: 'text-hmi-warn' },
17
+ accent: { dot: 'bg-hmi-accent', text: 'text-hmi-accent' },
18
+ neutral: { dot: 'bg-hmi-muted', text: 'text-hmi-text' },
19
+ };
20
+
21
+ const POSE_FIELDS = [
22
+ { key: 'x', label: 'X', unit: 'mm' },
23
+ { key: 'y', label: 'Y', unit: 'mm' },
24
+ { key: 'z', label: 'Z', unit: 'mm' },
25
+ { key: 'rx', label: 'RX', unit: '°' },
26
+ { key: 'ry', label: 'RY', unit: '°' },
27
+ { key: 'rz', label: 'RZ', unit: '°' },
28
+ ];
29
+
30
+ const BUTTON_BASE =
31
+ 'flex items-center justify-center gap-2 border-2 px-4 font-semibold uppercase tracking-[0.08em] ' +
32
+ 'select-none touch-manipulation transition-colors active:translate-y-px disabled:cursor-not-allowed disabled:active:translate-y-0 ' +
33
+ 'focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-hmi-accent';
34
+
35
+ const PanelTitle = ({ children, aside }) => (
36
+ <div className="flex items-center justify-between px-3 py-2">
37
+ <span className="text-xs font-semibold uppercase tracking-[0.14em] text-hmi-muted">{children}</span>
38
+ {aside}
39
+ </div>
40
+ );
41
+
42
+ const StatusItem = ({ label, value, tone = 'neutral', dimmed = false }) => (
43
+ <div className={`flex min-w-0 items-center gap-2 border-l border-hmi-line px-4 first:border-l-0 ${dimmed ? 'opacity-40' : ''}`}>
44
+ <span className={`h-2.5 w-2.5 shrink-0 ${TONE[tone].dot}`} aria-hidden="true" />
45
+ <span className="whitespace-nowrap text-[11px] font-medium uppercase tracking-[0.12em] text-hmi-muted">{label}</span>
46
+ <span className={`truncate font-mono text-sm font-semibold uppercase ${TONE[tone].text}`}>{value}</span>
47
+ </div>
48
+ );
49
+
50
+ const formatValue = (value) =>
51
+ typeof value === 'number' ? value.toFixed(1) : '—';
52
+
53
  const ControlPanel = () => {
 
54
  const [loading, setLoading] = useState(true);
55
  const [status, setStatus] = useState({});
56
  const [traceValue, setTraceValue] = useState(null);
57
+ const [socketConnected, setSocketConnected] = useState(false);
58
+ const [lastUpdate, setLastUpdate] = useState(null);
59
+ const [now, setNow] = useState(Date.now());
60
  const containerRef = useRef();
 
61
 
62
+ // API erişilebilirliği (ilk yükleme ekranını kapatmak için)
63
+ const checkApi = useCallback(async () => {
64
  try {
65
+ await apiService.getHelloMessage();
 
 
 
66
  } catch (error) {
67
+ // Bağlantı durumu socket üzerinden gösterilir
68
+ } finally {
69
  setLoading(false);
70
  }
71
  }, []);
72
 
 
73
  useEffect(() => {
74
+ checkApi();
75
+ const intervalId = setInterval(checkApi, INTERVALS.HELLO_MESSAGE);
76
  return () => clearInterval(intervalId);
77
+ }, [checkApi]);
78
+
79
+ // Veri yaşını saniyede bir yeniden hesapla
80
+ useEffect(() => {
81
+ const tick = setInterval(() => setNow(Date.now()), 1000);
82
+ return () => clearInterval(tick);
83
+ }, []);
84
 
85
+ // WebSocket bağlantısı
86
  useEffect(() => {
87
+ const socket = io(API_BASE_URL, {
88
  timeout: 5000,
89
  reconnectionAttempts: 5,
90
  reconnectionDelay: 1000,
91
+ transports: ['websocket', 'polling'],
92
  });
93
 
94
+ socket.on('robot_status', (data) => {
 
 
95
  setStatus(data);
96
+ setLastUpdate(Date.now());
97
  setLoading(false);
 
98
  });
99
 
100
+ socket.on('connect', () => {
101
+ setSocketConnected(true);
102
+ toast.dismiss('socket-error');
103
  });
104
 
105
+ socket.on('connect_error', (err) => {
106
  console.error('WebSocket connection error:', err);
107
+ // Her yeniden deneme yeni bildirim açmasın
108
+ toast.error(`Bağlantı hatası: ${err.message}`, { toastId: 'socket-error' });
109
+ setSocketConnected(false);
110
  setLoading(false);
111
  });
112
 
113
+ socket.on('disconnect', () => {
114
+ setSocketConnected(false);
115
  });
116
 
117
  return () => {
118
+ socket.disconnect();
 
 
119
  };
120
  }, []);
121
 
 
123
  try {
124
  const response = await apiService.controlScan({
125
  message: 'START',
126
+ alt_button: altButton,
127
  });
128
 
129
  if (response.status === 200) {
 
149
  setTraceValue(newValue);
150
  }, []);
151
 
 
152
  if (loading) {
153
  return (
154
+ <div className="flex h-[calc(100dvh-3rem)] flex-col items-center justify-center gap-5 bg-hmi-bg font-hmi text-hmi-text">
155
+ <div className="h-10 w-10 animate-spin border-4 border-hmi-line border-t-hmi-accent" />
156
+ <span className="text-sm font-semibold uppercase tracking-[0.14em] text-hmi-muted">Sistem başlatılıyor</span>
 
 
 
 
157
  </div>
158
  );
159
  }
160
 
161
+ const hasData = lastUpdate !== null;
162
+ const ageSeconds = hasData ? Math.max(0, Math.floor((now - lastUpdate) / 1000)) : null;
163
+ const live = socketConnected && hasData && now - lastUpdate < STALE_AFTER_MS;
164
+ const barrierBlocked = hasData && (!status.DI14 || !status.DI15);
165
+ const scanActive = Boolean(status?.scan_active);
166
+ const tcp = status?.TCP;
167
+
168
+ let connection;
169
+ if (live) {
170
+ connection = { value: 'Canlı', tone: 'ok' };
171
+ } else if (!hasData) {
172
+ connection = socketConnected
173
+ ? { value: 'Veri bekleniyor', tone: 'warn' }
174
+ : { value: 'Bağlantı yok', tone: 'err' };
175
+ } else {
176
+ connection = {
177
+ value: `${socketConnected ? 'Veri gelmiyor' : 'Bağlantı yok'} · ${ageSeconds} sn`,
178
+ tone: 'err',
179
+ };
180
  }
181
 
182
  return (
183
+ <div className="flex h-[calc(100dvh-3rem)] flex-col gap-2 overflow-hidden bg-hmi-bg px-2 pb-2 pt-2 font-hmi text-hmi-text">
184
+
185
+ {/* Işık bariyeri: tüm ekranı kaplamaz, Durdur butonu erişilebilir kalır */}
186
+ {barrierBlocked && (
187
+ <div role="alert" className="flex items-center gap-4 border-2 border-red-400 bg-red-600 px-5 py-3 text-white">
188
+ <span className="animate-pulse text-4xl font-black leading-none" aria-hidden="true">⚠</span>
189
+ <div>
190
+ <div className="text-2xl font-bold uppercase tracking-wide">Işık bariyeri kesildi</div>
191
+ <div className="text-base">Işık bariyerinin önünde engel var. Engeli kaldırın.</div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  </div>
193
  </div>
194
+ )}
195
 
196
+ {/* Durum şeridi */}
197
+ <div className="flex min-h-[44px] flex-wrap items-center gap-y-2 border border-hmi-line bg-hmi-panel py-2">
198
+ <StatusItem label="Bağlantı" value={connection.value} tone={connection.tone} />
199
+ <StatusItem label="Robot verisi" value={tcp ? 'Var' : 'Yok'} tone={tcp ? 'ok' : 'err'} dimmed={!live} />
200
+ <StatusItem label="Parça" value={!status?.DI0 ? 'Var' : 'Yok'} tone={!status?.DI0 ? 'ok' : 'neutral'} dimmed={!live} />
201
+ <StatusItem label="Mod" value={status?.MODE === 0 ? 'Otomatik' : 'Manuel'} tone={status?.MODE === 0 ? 'accent' : 'warn'} dimmed={!live} />
202
+ <StatusItem label="Tarama" value={scanActive ? 'Aktif' : 'Beklemede'} tone={scanActive ? 'warn' : 'neutral'} dimmed={!live} />
203
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
 
205
+ <div className="grid min-h-0 flex-1 grid-cols-[minmax(0,1fr)_minmax(300px,36%)] gap-2">
 
 
 
 
 
 
 
 
 
206
 
207
+ {/* Tarama ızgarası */}
208
+ <section className="min-h-0 border border-hmi-line bg-hmi-panel">
209
+ <ScanTrace onScan={handleTraceChange} />
210
+ </section>
211
 
212
+ <div className="flex min-h-0 flex-col gap-2">
 
 
 
213
 
214
+ {/* Kontroller: Durdur her zaman en büyük ve en altta sabit */}
215
+ <section className="border border-hmi-line bg-hmi-panel">
216
+ <PanelTitle>Kontroller</PanelTitle>
217
+ <div className="grid gap-2 px-3 pb-3">
218
+ <div className={`grid gap-2 ${!traceValue ? 'grid-cols-2' : 'grid-cols-1'}`}>
219
  {!traceValue && (
220
  <button
221
+ type="button"
222
  onClick={() => handleStartScan(true)}
223
+ className={`${BUTTON_BASE} min-h-[64px] border-hmi-accent bg-transparent text-sm text-hmi-accent active:bg-hmi-accent active:text-hmi-bg [@media(hover:hover)]:hover:bg-hmi-accent/10`}
 
224
  >
225
+ Arayüzden başlat
226
  </button>
227
  )}
 
228
  <button
229
+ type="button"
230
  onClick={() => handleStartScan(false)}
231
+ disabled={scanActive}
232
+ className={`${BUTTON_BASE} min-h-[64px] border-hmi-ok bg-hmi-ok text-sm text-hmi-bg [@media(hover:hover)]:hover:brightness-110 disabled:border-hmi-line disabled:bg-transparent disabled:text-hmi-muted disabled:hover:brightness-100`}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
  >
234
+ <span aria-hidden="true">▶</span> Tarama başlat
235
  </button>
 
236
  </div>
 
 
 
 
 
 
237
 
238
+ <button
239
+ type="button"
240
+ onClick={handleStopScan}
241
+ disabled={!scanActive}
242
+ className={`${BUTTON_BASE} min-h-[84px] border-red-600 bg-red-600 text-xl text-white [@media(hover:hover)]:hover:bg-red-500 disabled:border-dashed disabled:border-hmi-line disabled:bg-transparent disabled:text-hmi-muted`}
243
  >
244
+ <span className="h-4 w-4 bg-current" aria-hidden="true" /> Tarama durdur
245
+ </button>
 
 
 
246
  </div>
247
+ </section>
248
+
249
+ {/* TCP konumu */}
250
+ <section className={`border border-hmi-line bg-hmi-panel transition-opacity ${live ? '' : 'opacity-50'}`}>
251
+ <PanelTitle
252
+ aside={!live && hasData && (
253
+ <span className="border border-hmi-err px-1.5 text-[11px] font-semibold uppercase tracking-wider text-hmi-err">
254
+ Eski veri
255
+ </span>
256
+ )}
257
+ >
258
+ TCP konumu
259
+ </PanelTitle>
260
+ <dl className="grid grid-cols-3 gap-px border-t border-hmi-line bg-hmi-line">
261
+ {POSE_FIELDS.map(({ key, label, unit }) => (
262
+ <div key={key} className="bg-hmi-panel px-3 py-2">
263
+ <dt className="text-[11px] font-medium uppercase tracking-[0.12em] text-hmi-muted">
264
+ {label} <span className="normal-case tracking-normal">{unit}</span>
265
+ </dt>
266
+ <dd className="font-mono text-lg font-semibold tabular-nums">{formatValue(tcp?.[key])}</dd>
267
+ </div>
268
+ ))}
269
+ </dl>
270
+ </section>
271
+
272
+ {/* 3D robot görünümü */}
273
+ <section className="relative min-h-[160px] flex-1 overflow-hidden border border-hmi-line bg-hmi-panel">
274
+ <div ref={containerRef} className="absolute inset-0" />
275
+ {hasData && <ThreeDTrace containerRef={containerRef} joints={status.JOINTS} />}
276
+ {!tcp && (
277
+ <div className="absolute inset-0 flex flex-col items-center justify-center gap-1 bg-hmi-panel/85 text-center">
278
+ <span className="text-sm font-semibold uppercase tracking-[0.12em] text-hmi-warn">Robot verisi bekleniyor</span>
279
+ <span className="text-sm text-hmi-muted">Robot bağlantısını kontrol edin</span>
280
+ </div>
281
+ )}
282
+ </section>
283
  </div>
284
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
285
  </div>
286
  );
287
  };
frontend/tailwind.config.js CHANGED
@@ -8,6 +8,23 @@ module.exports = {
8
  'navbar-text': '#f4f4f4',
9
  'navbar-accent': '#db4d34',
10
  'jaguar-blue': '#007bff',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  },
12
  },
13
  },
 
8
  'navbar-text': '#f4f4f4',
9
  'navbar-accent': '#db4d34',
10
  'jaguar-blue': '#007bff',
11
+ // Operatör paneli (koyu endüstriyel tema)
12
+ hmi: {
13
+ bg: '#0e0f11',
14
+ panel: '#16181b',
15
+ raised: '#1f2226',
16
+ line: '#2c3036',
17
+ text: '#e8e6e1',
18
+ muted: '#9197a0',
19
+ accent: '#f97316',
20
+ ok: '#4ade80',
21
+ err: '#f87171',
22
+ warn: '#facc15',
23
+ },
24
+ },
25
+ fontFamily: {
26
+ hmi: ['"Inter"', '"Segoe UI"', 'Roboto', '"Helvetica Neue"', 'Arial', 'sans-serif'],
27
+ mono: ['"JetBrains Mono"', '"DejaVu Sans Mono"', 'ui-monospace', 'Menlo', 'Consolas', 'monospace'],
28
  },
29
  },
30
  },