Initial commit

This commit is contained in:
2026-01-02 15:46:19 +09:00
commit f06f5e0f61
6 changed files with 1075 additions and 0 deletions

View File

@@ -0,0 +1,459 @@
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LoadCell 실시간 무게 측정</title>
<!-- Chart.js CDN -->
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>
<!-- Socket.IO CDN -->
<script src="https://cdn.socket.io/4.5.4/socket.io.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1400px;
margin: 0 auto;
}
.header {
text-align: center;
color: white;
margin-bottom: 30px;
}
.header h1 {
font-size: 2.5em;
margin-bottom: 10px;
}
.status {
display: inline-block;
padding: 8px 16px;
background: rgba(255, 255, 255, 0.2);
border-radius: 20px;
font-size: 0.9em;
}
.status.connected {
background: rgba(76, 175, 80, 0.8);
}
.main-grid {
display: grid;
grid-template-columns: 1fr 350px;
gap: 20px;
margin-bottom: 20px;
}
.card {
background: white;
border-radius: 15px;
padding: 25px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}
.chart-container {
position: relative;
height: 400px;
}
.current-weight {
text-align: center;
padding: 20px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border-radius: 10px;
margin-bottom: 20px;
}
.current-weight .value {
font-size: 3.5em;
font-weight: bold;
margin: 10px 0;
}
.current-weight .unit {
font-size: 1.2em;
opacity: 0.9;
}
.controls {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-top: 20px;
}
.btn {
padding: 12px 20px;
border: none;
border-radius: 8px;
font-size: 1em;
cursor: pointer;
transition: all 0.3s;
font-weight: 600;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}
.btn-primary {
background: #667eea;
color: white;
}
.btn-secondary {
background: #f0f0f0;
color: #333;
}
.btn-danger {
background: #e74c3c;
color: white;
}
.btn-success {
background: #4CAF50;
color: white;
}
.log-container {
background: #f8f9fa;
border-radius: 8px;
padding: 15px;
height: 200px;
overflow-y: auto;
font-family: 'Courier New', monospace;
font-size: 0.85em;
}
.log-item {
padding: 5px 0;
border-bottom: 1px solid #e0e0e0;
}
.stats-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 15px;
margin-top: 20px;
}
.stat-item {
text-align: center;
padding: 15px;
background: #f8f9fa;
border-radius: 8px;
}
.stat-label {
font-size: 0.9em;
color: #666;
margin-bottom: 5px;
}
.stat-value {
font-size: 1.8em;
font-weight: bold;
color: #333;
}
@media (max-width: 1024px) {
.main-grid {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div class="container">
<!-- Header -->
<div class="header">
<h1>LoadCell 실시간 무게 측정</h1>
<div class="status" id="connectionStatus">연결 대기 중...</div>
</div>
<!-- Main Grid -->
<div class="main-grid">
<!-- Chart Card -->
<div class="card">
<h2 style="margin-bottom: 20px;">실시간 무게 그래프</h2>
<div class="chart-container">
<canvas id="weightChart"></canvas>
</div>
</div>
<!-- Control Panel -->
<div class="card">
<h2 style="margin-bottom: 20px;">측정 정보</h2>
<!-- Current Weight Display -->
<div class="current-weight">
<div class="label">현재 무게</div>
<div class="value" id="currentWeight">0.0</div>
<div class="unit">g</div>
</div>
<!-- Statistics -->
<div class="stats-grid">
<div class="stat-item">
<div class="stat-label">최대값</div>
<div class="stat-value" id="maxWeight">0.0</div>
</div>
<div class="stat-item">
<div class="stat-label">평균값</div>
<div class="stat-value" id="avgWeight">0.0</div>
</div>
<div class="stat-item">
<div class="stat-label">측정 시간</div>
<div class="stat-value" id="measureTime">0.00<span style="font-size:0.5em"></span></div>
</div>
<div class="stat-item">
<div class="stat-label">측정 간격</div>
<div class="stat-value" id="measureDelay">10<span style="font-size:0.5em">ms</span></div>
</div>
</div>
<!-- 측정 속도 조절 -->
<div style="margin-top: 20px;">
<h3 style="margin-bottom: 10px; color: #666;">측정 속도 조절</h3>
<div style="display: flex; align-items: center; gap: 10px;">
<button class="btn btn-primary" onclick="sendCommand('-')" style="flex: 1; font-size: 1.5em;">-</button>
<div style="flex: 2; text-align: center; font-size: 0.9em; color: #666;">
느리게 / 빠르게
</div>
<button class="btn btn-primary" onclick="sendCommand('+')" style="flex: 1; font-size: 1.5em;">+</button>
</div>
</div>
<!-- Controls -->
<div class="controls">
<button class="btn btn-primary" onclick="sendCommand('c')">영점 조절</button>
<button class="btn btn-secondary" onclick="sendCommand('p')">일시정지</button>
<button class="btn btn-success" onclick="sendCommand('r')">재시작</button>
<button class="btn btn-danger" onclick="clearChart()">그래프 초기화</button>
</div>
</div>
</div>
<!-- Log Card -->
<div class="card">
<h2 style="margin-bottom: 15px;">시스템 로그</h2>
<div class="log-container" id="logContainer"></div>
</div>
</div>
<script>
// ===== Socket.IO 연결 =====
const socket = io();
// ===== Chart.js 설정 =====
const ctx = document.getElementById('weightChart').getContext('2d');
const maxDataPoints = 50; // 최대 데이터 포인트 수
const weightChart = new Chart(ctx, {
type: 'line',
data: {
labels: [],
datasets: [{
label: '무게 (g)',
data: [],
borderColor: '#667eea',
backgroundColor: 'rgba(102, 126, 234, 0.1)',
borderWidth: 2,
tension: 0.4,
fill: true,
pointRadius: 3,
pointHoverRadius: 5
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
animation: {
duration: 200
},
scales: {
x: {
display: true,
title: {
display: true,
text: '시간'
}
},
y: {
beginAtZero: true,
min: 0,
max: 5000, // 최대값 5kg(5000g)로 고정
title: {
display: true,
text: '무게 (g)'
}
}
},
plugins: {
legend: {
display: true,
position: 'top'
},
tooltip: {
enabled: true,
backgroundColor: 'rgba(0, 0, 0, 0.8)',
titleFont: {
size: 14,
weight: 'bold'
},
bodyFont: {
size: 13
},
padding: 12,
cornerRadius: 8,
displayColors: true,
callbacks: {
title: function(context) {
return '측정 시간: ' + context[0].label;
},
label: function(context) {
const value = context.parsed.y;
return '무게: ' + value.toFixed(2) + ' g';
}
}
}
}
}
});
// ===== 통계 변수 =====
let maxWeight = 0;
let totalWeight = 0;
let dataCount = 0;
// ===== Socket.IO 이벤트 핸들러 =====
socket.on('connect', function() {
updateConnectionStatus(true);
addLog('서버에 연결되었습니다.');
});
socket.on('disconnect', function() {
updateConnectionStatus(false);
addLog('서버 연결이 끊어졌습니다.');
});
socket.on('weight_data', function(data) {
const weight = data.weight;
const time = data.time || 0;
const delay = data.delay || 10;
const timestamp = new Date().toLocaleTimeString();
// 차트 업데이트
weightChart.data.labels.push(timestamp);
weightChart.data.datasets[0].data.push(weight);
// 최대 데이터 포인트 제한
if (weightChart.data.labels.length > maxDataPoints) {
weightChart.data.labels.shift();
weightChart.data.datasets[0].data.shift();
}
weightChart.update('none'); // 애니메이션 없이 업데이트
// 현재 무게 표시
document.getElementById('currentWeight').textContent = weight.toFixed(1);
// 측정 시간 표시
document.getElementById('measureTime').innerHTML = time.toFixed(2) + '<span style="font-size:0.5em">초</span>';
// 측정 간격 표시
document.getElementById('measureDelay').innerHTML = delay + '<span style="font-size:0.5em">ms</span>';
// 통계 업데이트
updateStats(weight);
});
socket.on('log_message', function(data) {
addLog(data.message);
});
// ===== 함수들 =====
function updateConnectionStatus(connected) {
const statusEl = document.getElementById('connectionStatus');
if (connected) {
statusEl.textContent = '연결됨';
statusEl.classList.add('connected');
} else {
statusEl.textContent = '연결 끊김';
statusEl.classList.remove('connected');
}
}
function updateStats(weight) {
// 최대값
if (weight > maxWeight) {
maxWeight = weight;
document.getElementById('maxWeight').textContent = maxWeight.toFixed(1);
}
// 평균값
totalWeight += weight;
dataCount++;
const avgWeight = totalWeight / dataCount;
document.getElementById('avgWeight').textContent = avgWeight.toFixed(1);
}
function sendCommand(cmd) {
socket.emit('send_command', { command: cmd });
}
function clearChart() {
weightChart.data.labels = [];
weightChart.data.datasets[0].data = [];
weightChart.update();
// 통계 초기화
maxWeight = 0;
totalWeight = 0;
dataCount = 0;
document.getElementById('maxWeight').textContent = '0.0';
document.getElementById('avgWeight').textContent = '0.0';
addLog('그래프 및 통계가 초기화되었습니다.');
}
function addLog(message) {
const logContainer = document.getElementById('logContainer');
const logItem = document.createElement('div');
logItem.className = 'log-item';
const timestamp = new Date().toLocaleTimeString();
logItem.textContent = `[${timestamp}] ${message}`;
logContainer.appendChild(logItem);
// 자동 스크롤
logContainer.scrollTop = logContainer.scrollHeight;
// 최대 100개 로그 유지
if (logContainer.children.length > 100) {
logContainer.removeChild(logContainer.firstChild);
}
}
</script>
</body>
</html>