Fix XToTime()

This commit is contained in:
Matt
2025-12-16 13:43:42 +00:00
parent a3d796da5a
commit c18fd152c7

View File

@@ -77,15 +77,19 @@ let viewTransform = {
// Helper to get total time (width of buffer in ms)
function getTotalTimeMs() {
const effectiveSampleRate = activeConfig.desiredRate < 1000
? activeConfig.desiredRate / lowRateState.targetCount
: activeConfig.desiredRate;
let msPerPoint;
// If we are in low-rate mode (peak detect), we emit 2 points (min/max)
// for every 'targetCount' samples of the hardware rate (which is 1kHz).
if (activeConfig.desiredRate < 1000) {
msPerPoint = lowRateState.targetCount / 2.0;
} else {
// Normal mode: 1 point = 1 sample
msPerPoint = 1000.0 / activeConfig.desiredRate;
}
const effectivePoints = (activeConfig.desiredRate < 1000)
? countPoints / (lowRateState.targetCount * 2)
: countPoints;
return (effectivePoints / effectiveSampleRate) * 1000;
// The total time displayed is simply the time-per-pixel * number-of-pixels
// assuming 1 pixel = 1 point at scale 1.0.
return msPerPoint * canvas.width;
}
// Helper to get max voltage
@@ -607,7 +611,8 @@ function loadStoredConfig() {
}
document.getElementById('reconnectBtn').addEventListener('click', connect);
document.querySelectorAll('#sampleRate, #bitWidth, #atten, #testHz, #triggerLevel').forEach(input => input.addEventListener('change', setParams));
document.querySelectorAll('#sampleRate, #bitWidth, #atten, #testHz').forEach(input => input.addEventListener('change', setParams));
triggerLevel.addEventListener('change', () => localStorage.setItem('esp32_adc_config', JSON.stringify(activeConfig)));
document.getElementById('resetBtn').addEventListener('click', () => {
localStorage.clear();
window.location.reload();