Browse Source

Revert header button to Docker restart, remove TableControl Reset button

- Layout.tsx: Revert handleRestart to restart Docker containers (with confirmation)
- Layout.tsx: Change labels back to "Restart Docker"
- TableControlPage.tsx: Remove Reset button (keep only Home and Stop)
- TableControlPage.tsx: Remove handleSoftReset function
- TableControlPage.tsx: Remove client-side check blocking Home button

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
tuanchris 2 weeks ago
parent
commit
2f31e8f869

+ 8 - 8
frontend/src/components/layout/Layout.tsx

@@ -500,13 +500,13 @@ export function Layout() {
   }
   }
 
 
   const handleRestart = async () => {
   const handleRestart = async () => {
+    if (!confirm('Are you sure you want to restart Docker containers?')) return
+
     try {
     try {
-      // Force stop first to clear any stuck state
-      await apiClient.post('/force_stop')
-      await apiClient.post('/soft_reset')
-      toast.success('Reset sent. Homing required.')
+      await apiClient.post('/api/system/restart')
+      toast.success('Docker containers are restarting...')
     } catch {
     } catch {
-      toast.error('Failed to send reset')
+      toast.error('Failed to restart Docker containers')
     }
     }
   }
   }
 
 
@@ -1219,8 +1219,8 @@ export function Layout() {
               size="icon"
               size="icon"
               onClick={handleRestart}
               onClick={handleRestart}
               className="rounded-full text-amber-500 hover:text-amber-600"
               className="rounded-full text-amber-500 hover:text-amber-600"
-              aria-label="Reset Table"
-              title="Reset Table (requires homing)"
+              aria-label="Restart Docker"
+              title="Restart Docker"
             >
             >
               <span className="material-icons-outlined">restart_alt</span>
               <span className="material-icons-outlined">restart_alt</span>
             </Button>
             </Button>
@@ -1299,7 +1299,7 @@ export function Layout() {
                     className="flex items-center gap-3 w-full px-3 py-2 text-sm rounded-md hover:bg-accent transition-colors text-amber-500"
                     className="flex items-center gap-3 w-full px-3 py-2 text-sm rounded-md hover:bg-accent transition-colors text-amber-500"
                   >
                   >
                     <span className="material-icons-outlined text-xl">restart_alt</span>
                     <span className="material-icons-outlined text-xl">restart_alt</span>
-                    Reset Table
+                    Restart Docker
                   </button>
                   </button>
                   <button
                   <button
                     onClick={() => {
                     onClick={() => {

+ 1 - 32
frontend/src/pages/TableControlPage.tsx

@@ -147,7 +147,6 @@ export function TableControlPage() {
   }
   }
 
 
   const handleHome = async () => {
   const handleHome = async () => {
-    if (checkPatternRunning('home')) return
     try {
     try {
       await handleAction('home', '/send_home')
       await handleAction('home', '/send_home')
       toast.success('Moving to home position...')
       toast.success('Moving to home position...')
@@ -171,17 +170,6 @@ export function TableControlPage() {
     }
     }
   }
   }
 
 
-  const handleSoftReset = async () => {
-    try {
-      // Force stop first to clear any stuck state
-      await apiClient.post('/force_stop')
-      await handleAction('reset', '/soft_reset')
-      toast.success('Reset sent. Homing required.')
-    } catch {
-      toast.error('Failed to send reset')
-    }
-  }
-
   const handleMoveToCenter = async () => {
   const handleMoveToCenter = async () => {
     if (checkPatternRunning('move to center')) return
     if (checkPatternRunning('move to center')) return
     try {
     try {
@@ -418,7 +406,7 @@ export function TableControlPage() {
               <CardDescription>Calibrate or stop the table</CardDescription>
               <CardDescription>Calibrate or stop the table</CardDescription>
             </CardHeader>
             </CardHeader>
             <CardContent>
             <CardContent>
-              <div className="grid grid-cols-3 gap-3">
+              <div className="grid grid-cols-2 gap-3">
                 <Tooltip>
                 <Tooltip>
                   <TooltipTrigger asChild>
                   <TooltipTrigger asChild>
                     <Button
                     <Button
@@ -456,25 +444,6 @@ export function TableControlPage() {
                   </TooltipTrigger>
                   </TooltipTrigger>
                   <TooltipContent>Gracefully stop</TooltipContent>
                   <TooltipContent>Gracefully stop</TooltipContent>
                 </Tooltip>
                 </Tooltip>
-
-                <Tooltip>
-                  <TooltipTrigger asChild>
-                    <Button
-                      onClick={handleSoftReset}
-                      disabled={isLoading === 'reset'}
-                      variant="secondary"
-                      className="h-16 gap-1 flex-col items-center justify-center"
-                    >
-                      {isLoading === 'reset' ? (
-                        <span className="material-icons-outlined animate-spin text-2xl">sync</span>
-                      ) : (
-                        <span className="material-icons-outlined text-2xl">restart_alt</span>
-                      )}
-                      <span className="text-xs">Reset</span>
-                    </Button>
-                  </TooltipTrigger>
-                  <TooltipContent>Reset DLC32/ESP32, requires homing</TooltipContent>
-                </Tooltip>
               </div>
               </div>
             </CardContent>
             </CardContent>
           </Card>
           </Card>

+ 1 - 0
frontend/vite.config.ts

@@ -69,6 +69,7 @@ export default defineConfig({
       '/stop_execution': 'http://localhost:8080',
       '/stop_execution': 'http://localhost:8080',
       '/force_stop': 'http://localhost:8080',
       '/force_stop': 'http://localhost:8080',
       '/soft_reset': 'http://localhost:8080',
       '/soft_reset': 'http://localhost:8080',
+      '/controller_restart': 'http://localhost:8080',
       '/pause_execution': 'http://localhost:8080',
       '/pause_execution': 'http://localhost:8080',
       '/resume_execution': 'http://localhost:8080',
       '/resume_execution': 'http://localhost:8080',
       '/skip_pattern': 'http://localhost:8080',
       '/skip_pattern': 'http://localhost:8080',

+ 30 - 0
main.py

@@ -1695,6 +1695,36 @@ async def soft_reset():
         logger.error(f"Error sending soft reset: {e}")
         logger.error(f"Error sending soft reset: {e}")
         raise HTTPException(status_code=500, detail=str(e))
         raise HTTPException(status_code=500, detail=str(e))
 
 
+@app.post("/controller_restart")
+async def controller_restart():
+    """Send $System/Control=RESTART to restart the FluidNC controller."""
+    if not (state.conn and state.conn.is_connected()):
+        logger.warning("Attempted to restart controller without a connection")
+        raise HTTPException(status_code=400, detail="Connection not established")
+
+    try:
+        # Stop any running patterns first
+        await pattern_manager.stop_actions()
+
+        # Send the FluidNC restart command
+        from modules.connection.connection_manager import SerialConnection
+        restart_cmd = "$System/Control=RESTART\n"
+        if isinstance(state.conn, SerialConnection) and state.conn.ser:
+            state.conn.ser.write(restart_cmd.encode())
+            state.conn.ser.flush()
+            logger.info(f"Controller restart command sent via serial to {state.port}")
+        else:
+            state.conn.send(restart_cmd)
+            logger.info("Controller restart command sent via connection abstraction")
+
+        # Mark as needing homing since position is now unknown
+        state.is_homed = False
+
+        return {"success": True, "message": "Controller restart command sent. Homing required."}
+    except Exception as e:
+        logger.error(f"Error sending controller restart: {e}")
+        raise HTTPException(status_code=500, detail=str(e))
+
 @app.post("/send_home")
 @app.post("/send_home")
 async def send_home():
 async def send_home():
     try:
     try: