diff --git a/classCAN.py b/classCAN.py index 5af231e..e7bf2c2 100644 --- a/classCAN.py +++ b/classCAN.py @@ -132,7 +132,7 @@ class CANBackend: "MV08": 100 * data[6] / 255, }) - elif cob_id == 0x2AB and len(data) >= 7: + elif cob_id == 0x2B2 and len(data) >= 7: self.latest_data[2].update({ "PU2_STATE" : data[0], "Conductivity_Feed" : int.from_bytes(data[1:3], 'little') / 100.0, diff --git a/main.py b/main.py index 2e3f901..addd49d 100644 --- a/main.py +++ b/main.py @@ -31,7 +31,9 @@ if platform.system() in ["Darwin"]: # macOS or Windows else: from classCAN import CANBackend # Your real backend - logging.basicConfig(level=logging.ERROR) + logging.basicConfig(level=logging.INFO) + +logging.getLogger("uvicorn.access").setLevel(logging.WARNING) app = FastAPI() app.add_middleware(SessionMiddleware, secret_key="your_super_secret_key") @@ -169,10 +171,10 @@ def monitor_page(request: Request): @app.post("/connect_toggle") def connect_toggle(): - logging.info("Toggling CAN connection...") - print("CONNECTING") + logging.info(f"Toggling CAN connection, CAN is {can_backend.connected}") if can_backend.connected: can_backend.shutdown() + logging.info("Shutting down CAN connection...") return {"connected": False} else: success = can_backend.connect() @@ -250,7 +252,6 @@ async def update_latest_data(): @app.get("/monitor") async def get_monitor_data(pu_number: Optional[float] = Query(None)): - print(f"pu_number is {pu_number}") if pu_number is not None: return latest_data.get(f"PU_{pu_number}", {}) else: diff --git a/templates/control.html b/templates/control.html index c4aec24..8099053 100644 --- a/templates/control.html +++ b/templates/control.html @@ -1,5 +1,6 @@ + @@ -17,6 +18,7 @@ display: flex; flex-direction: column; } + .header { background-color: #1e1e1e; padding: 10px 20px; @@ -24,6 +26,7 @@ justify-content: space-between; align-items: center; } + .connect-button { background-color: #ff4444; color: white; @@ -36,9 +39,11 @@ align-items: center; gap: 10px; } + .connected { background-color: #00C851; } + .container { display: flex; flex: 1; @@ -46,17 +51,21 @@ overflow-x: hidden; box-sizing: border-box; } - .left-panel, .right-panel { + + .left-panel, + .right-panel { flex: 1; padding: 20px; overflow-y: auto; } + .left-panel { background-color: #1e1e1e; display: flex; flex-direction: column; gap: 10px; } + .mode-block { background-color: #333; padding: 15px; @@ -65,10 +74,12 @@ flex-direction: column; gap: 10px; } + .pu-buttons { display: flex; gap: 10px; } + .mode-block button { background-color: #4285F4; color: white; @@ -80,39 +91,49 @@ transition: background-color 0.3s; flex: 1; } + .mode-block button:hover { background-color: #3367d6; } + .mode-block button.active { background-color: #00C851; } + .mode-block button.in-progress { background-color: #ffcc00; color: #000; } + .mode-block button.ready { background-color: #00C851; color: #fff; } + .mode-block button.disabled { background-color: #777; cursor: not-allowed; } + .in-progress { background-color: yellow !important; color: black !important; } + .ready { background-color: orange !important; color: black !important; } + .production { background-color: green !important; color: white !important; } + .pu-status { margin-top: 20px; } + .pu-item { background-color: #333; padding: 10px; @@ -122,24 +143,28 @@ justify-content: space-between; align-items: center; } + .monitor-block { background-color: #333; padding: 15px; border-radius: 5px; margin-bottom: 15px; } + .monitor-values { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 10px; } + .monitor-value { background-color: #444; padding: 10px; text-align: center; border-radius: 5px; } + .slider-container { background-color: #1e1e1e; padding: 10px; @@ -147,12 +172,14 @@ color: #fff; width: 95%; } + .slider-container label { font-size: 1.2rem; font-weight: bold; margin-bottom: 10px; display: block; } + .slider-values { display: flex; justify-content: space-between; @@ -161,10 +188,12 @@ width: 100%; overflow: hidden; } + .slider-values span#currentValue { font-weight: bold; color: #00bfff; } + .slider { width: 100%; height: 8px; @@ -174,13 +203,16 @@ appearance: none; cursor: pointer; } - .slider::-webkit-slider-thumb, .slider::-moz-range-thumb { + + .slider::-webkit-slider-thumb, + .slider::-moz-range-thumb { height: 18px; width: 18px; background: #007bff; border-radius: 50%; cursor: pointer; } + .monitor-link { color: white; background-color: #007bff; @@ -189,14 +221,17 @@ text-decoration: none; font-weight: bold; } + .monitor-link:hover { background-color: #0056b3; } + .monitor-pu-buttons { display: flex; gap: 10px; margin: 10px; } + .monitor-pu-buttons a { color: white; background-color: #007bff; @@ -205,287 +240,303 @@ text-decoration: none; font-weight: bold; } + .monitor-pu-buttons a:hover { background-color: #0056b3; } + .button-group { - margin-top: 10px; - display: flex; - justify-content: space-around; + margin-top: 10px; + display: flex; + justify-content: space-around; } + .button-group button { - padding: 8px 16px; - font-size: 1rem; - border-radius: 8px; - background-color: #008CBA; - color: white; - border: none; - cursor: pointer; + padding: 8px 16px; + font-size: 1rem; + border-radius: 8px; + background-color: #008CBA; + color: white; + border: none; + cursor: pointer; } + .button-group button:hover { - background-color: #005f6b; + background-color: #005f6b; } + -
-

Hydraulic Machine Control

-
- - - Monitor All PUs - +
+

Hydraulic Machine Control

+ +
- -
-
-
-
-
- - - +
+
+
+
+ + + +
+
+
+
+ + + +
+
+
+
+ + + +
+
+
+ +
+ 0.5 + 2.5 + 3.5 +
+ +
+
+ +
+
+
PU 1: Offline
+
PU 2: Offline
+
PU 3: Offline
+
+
+ + +
-
-
- - - +
+
+

Q Perm

+
+
#1
0.0 L/h
+
#2
0.0 L/h
+
#3
0.0 L/h
+
-
-
-
- - - +
+

P Dilute

+
+
#1
0.0 bar
+
#2
0.0 bar
+
#3
0.0 bar
+
-
-
- -
- 0.5 - 2.5 - 3.5 +
+

Cdilute

+
+
#1
0.0 µS/cm
+
#2
0.0 µS/cm
+
#3
0.0 µS/cm
+
- -
-
- -
-
-
PU 1: Offline
-
PU 2: Offline
-
PU 3: Offline
-
-
- - - -
-
-
-
-

Q Perm

-
-
#1
0.0 L/h
-
#2
0.0 L/h
-
#3
0.0 L/h
-
-
-
-

P Dilute

-
-
#1
0.0 bar
-
#2
0.0 bar
-
#3
0.0 bar
-
-
-
-

Cdilute

-
-
#1
0.0 µS/cm
-
#2
0.0 µS/cm
-
#3
0.0 µS/cm
-
-
-
-

Pro

-
-
#1
0.0 units
-
#2
0.0 units
-
#3
0.0 units
+
+

Pro

+
+
#1
0.0 units
+
#2
0.0 units
+
#3
0.0 units
+
-
- + for (const [fieldId, unit] of Object.entries(fields)) { + const container = document.getElementById(fieldId); + if (!container) continue; + + const valueElements = container.querySelectorAll('.monitor-value'); + + puLabels.forEach((puLabel, index) => { + const puData = allData[puLabel]; + const value = puData && fieldId in puData ? puData[fieldId] : 0.0; + if (valueElements[index]) { + valueElements[index].innerHTML = `#${index + 1}
${value.toFixed(1)} ${unit}`; + } + }); + } + } catch (error) { + console.error('Error fetching monitor data:', error); + } + } + + setInterval(getConnectionStatus, 1000); + getConnectionStatus(); + + setInterval(fetchMonitorData, 1000); + fetchMonitorData(); + - + + \ No newline at end of file