This commit is contained in:
Your Name
2025-05-23 17:43:45 +02:00
parent c6a8b02c38
commit 122763a4e5
2 changed files with 180 additions and 4 deletions

View File

@@ -248,7 +248,34 @@
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
</div>
</div>
</div>
<!-- Envea Detection Modal -->
<div class="modal fade" id="enveaDetectionModal" tabindex="-1" aria-labelledby="enveaDetectionModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="enveaDetectionModalLabel">Envea Sondes Detection</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div id="detectionProgress" class="text-center" style="display: none;">
<div class="spinner-border text-primary" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<p class="mt-2">Scanning ports for Envea devices...</p>
</div>
<div id="detectionResults">
<p>Click "Start Detection" to scan for connected Envea devices.</p>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="startDetectionBtn" onclick="startEnveaDetection()">Start Detection</button>
</div>
</div>
</div>
</div>
</main>
@@ -706,7 +733,7 @@ function add_sondeEnveaContainer() {
$('#advanced_options').append('<div id="sondes_envea_div" class="input-group mt-4 border p-3 rounded"><legend>Sondes Envea</legend><p>Plouf</p></div>');
} else {
// Clear existing content if container exists
$('#sondes_envea_div').html('<legend>Sondes Envea</legend>');
$('#sondes_envea_div').html('<legend>Sondes Envea <button type="button" class="btn btn-sm btn-info ms-2" onclick="detectEnveaSondes()">Detect Devices</button></legend>');
$('#envea_table').html('<table class="table table-striped table-bordered">'+
'<thead><tr><th scope="col">Software</th><th scope="col">Hardware (PCB)</th></tr></thead>'+
'<tbody>' +
@@ -738,7 +765,7 @@ function add_sondeEnveaContainer() {
<option value="ttyAMA5" ${sonde.port === 'ttyAMA5' ? 'selected' : ''}>ttyAMA5</option>
</select>
<input type="number" class="form-control" placeholder="Coefficient" value="${sonde.coefficient}"
id="${sondeId}_coefficient" readonly style="background-color: #f8f9fa;">
id="${sondeId}_coefficient" onchange="updateSondeCoefficientWithConfirm(${sonde.id}, this.value, this)">
</div>
`;
@@ -936,6 +963,23 @@ function updateSondePort(id, port) {
});
}
function updateSondeCoefficientWithConfirm(id, coefficient, inputElement) {
// Store the previous value in case user cancels
const previousValue = inputElement.getAttribute('data-previous-value') || inputElement.defaultValue;
// Show confirmation dialog
const confirmed = confirm(`Are you sure you want to change the coefficient to ${coefficient}?\n\nThis will affect sensor calibration and data accuracy.`);
if (confirmed) {
// Store the new value as previous for next time
inputElement.setAttribute('data-previous-value', coefficient);
updateSondeCoefficient(id, coefficient);
} else {
// Revert to previous value
inputElement.value = previousValue;
}
}
function updateSondeCoefficient(id, coefficient) {
console.log(`Updating sonde ${id} coefficient to: ${coefficient}`);
const toastLiveExample = document.getElementById('liveToast');
@@ -1242,6 +1286,131 @@ function toggleService(serviceName, enable) {
});
}
/*
_____ ____ _ _ _
| ____|_ ____ _____ __ _ | _ \ ___| |_ ___ ___| |_(_) ___ _ __
| _| | '_ \ \ / / _ \/ _` | | | | |/ _ \ __/ _ \/ __| __| |/ _ \| '_ \
| |___| | | \ V / __/ (_| | | |_| | __/ || __/ (__| |_| | (_) | | | |
|_____|_| |_|\_/ \___|\__,_| |____/ \___|\__\___|\___|\__|_|\___/|_| |_|
*/
function detectEnveaSondes() {
console.log("Opening Envea detection modal");
const modal = new bootstrap.Modal(document.getElementById('enveaDetectionModal'));
modal.show();
// Reset modal content
document.getElementById('detectionProgress').style.display = 'none';
document.getElementById('detectionResults').innerHTML = '<p>Click "Start Detection" to scan for connected Envea devices.</p>';
document.getElementById('startDetectionBtn').style.display = 'inline-block';
}
function startEnveaDetection() {
console.log("Starting Envea device detection");
// Show progress spinner
document.getElementById('detectionProgress').style.display = 'block';
document.getElementById('detectionResults').innerHTML = '';
document.getElementById('startDetectionBtn').style.display = 'none';
// Test the three ports: ttyAMA3, ttyAMA4, ttyAMA5
const ports = ['ttyAMA3', 'ttyAMA4', 'ttyAMA5'];
let completedTests = 0;
let results = [];
ports.forEach(function(port, index) {
$.ajax({
url: `launcher.php?type=detect_envea_device&port=${port}`,
dataType: 'json',
method: 'GET',
cache: false,
timeout: 10000, // 10 second timeout per port
success: function(response) {
console.log(`Detection result for ${port}:`, response);
results[index] = {
port: port,
success: response.success,
data: response.data || '',
error: response.error || '',
detected: response.detected || false,
device_info: response.device_info || ''
};
completedTests++;
if (completedTests === ports.length) {
displayDetectionResults(results);
}
},
error: function(xhr, status, error) {
console.error(`Detection failed for ${port}:`, error);
results[index] = {
port: port,
success: false,
data: '',
error: `Request failed: ${error}`,
detected: false,
device_info: ''
};
completedTests++;
if (completedTests === ports.length) {
displayDetectionResults(results);
}
}
});
});
}
function displayDetectionResults(results) {
console.log("Displaying detection results:", results);
// Hide progress spinner
document.getElementById('detectionProgress').style.display = 'none';
let htmlContent = '<h6>Detection Results:</h6>';
htmlContent += '<div class="table-responsive">';
htmlContent += '<table class="table table-sm table-striped">';
htmlContent += '<thead><tr><th>Port</th><th>Status</th><th>Device Info</th><th>Raw Data</th></tr></thead>';
htmlContent += '<tbody>';
results.forEach(function(result) {
const statusBadge = result.detected ?
'<span class="badge bg-success">Device Detected</span>' :
result.success ?
'<span class="badge bg-warning">No Device</span>' :
'<span class="badge bg-danger">Error</span>';
const deviceInfo = result.device_info || (result.detected ? 'Envea Device' : 'None');
const rawData = result.data ? result.data.substring(0, 50) + (result.data.length > 50 ? '...' : '') : 'No data';
htmlContent += `<tr>
<td><strong>${result.port}</strong></td>
<td>${statusBadge}</td>
<td>${deviceInfo}</td>
<td><small class="text-muted">${rawData}</small></td>
</tr>`;
if (result.error) {
htmlContent += `<tr><td colspan="4"><small class="text-danger">Error: ${result.error}</small></td></tr>`;
}
});
htmlContent += '</tbody></table></div>';
// Add summary
const detectedCount = results.filter(r => r.detected).length;
htmlContent += `<div class="alert alert-info mt-3">
<strong>Summary:</strong> ${detectedCount} device(s) detected out of ${results.length} ports tested.
</div>`;
document.getElementById('detectionResults').innerHTML = htmlContent;
document.getElementById('startDetectionBtn').style.display = 'inline-block';
document.getElementById('startDetectionBtn').textContent = 'Scan Again';
}
</script>