Skip to content

Commit 85082b3

Browse files
committed
fix status polling data, null checks, settle timing, dac sweep edge case
1 parent d1edd99 commit 85082b3

3 files changed

Lines changed: 26 additions & 15 deletions

File tree

Software/web-server/static/js/calibration.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ class CalibrationManager {
1414
camera1: false,
1515
camera2: false
1616
};
17-
this.calibrationResults = {}; // Store results from calibration API
17+
this.calibrationResults = {};
18+
this.strobePollingTimer = null;
1819

1920
this.init();
2021
this.setupPageCleanup();
@@ -796,7 +797,7 @@ class CalibrationManager {
796797

797798
if (status.dac_setting !== undefined) {
798799
document.getElementById('strobe-result-dac').textContent =
799-
'0x' + status.dac_setting.toString(16).toUpperCase().padStart(4, '0');
800+
'0x' + status.dac_setting.toString(16).toUpperCase().padStart(2, '0');
800801
}
801802
if (status.led_current !== undefined) {
802803
document.getElementById('strobe-result-current').textContent = status.led_current.toFixed(2) + ' A';
@@ -873,10 +874,10 @@ class CalibrationManager {
873874
grid.innerHTML = '';
874875

875876
const items = [
876-
{ label: 'LDO Voltage', value: data.ldo_voltage !== undefined ? data.ldo_voltage.toFixed(3) + ' V' : '--' },
877-
{ label: 'LED Current', value: data.led_current !== undefined ? data.led_current.toFixed(3) + ' A' : '--' },
878-
{ label: 'ADC CH0 Raw', value: data.adc_ch0_raw !== undefined ? data.adc_ch0_raw.toString() : '--' },
879-
{ label: 'ADC CH1 Raw', value: data.adc_ch1_raw !== undefined ? data.adc_ch1_raw.toString() : '--' }
877+
{ label: 'LDO Voltage', value: data.ldo_voltage != null ? data.ldo_voltage.toFixed(2) + ' V' : '--' },
878+
{ label: 'LED Current', value: data.led_current != null ? data.led_current.toFixed(2) + ' A' : '--' },
879+
{ label: 'ADC CH0 Raw', value: data.adc_ch0_raw != null ? data.adc_ch0_raw : '--' },
880+
{ label: 'ADC CH1 Raw', value: data.adc_ch1_raw != null ? data.adc_ch1_raw : '--' }
880881
];
881882

882883
items.forEach(item => {

Software/web-server/strobe_calibration_manager.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def _close_hardware(self):
108108
try:
109109
if name == "diag":
110110
resource.off()
111+
time.sleep(0.1)
111112
resource.close()
112113
except Exception:
113114
logger.debug(f"Error closing {name}", exc_info=True)
@@ -260,7 +261,7 @@ def _calibrate(self, target_current: float):
260261
current_dac -= 1
261262

262263
# Edge cases — sweep ran off either end
263-
if current_dac < self.DAC_MIN:
264+
if current_dac <= self.DAC_MIN:
264265
logger.debug(f"Reached DAC_MIN without crossing target")
265266
return False, -1, -1
266267
if current_dac >= self.DAC_MAX:
@@ -310,6 +311,9 @@ async def start_calibration(self, led_type: str = "v3",
310311
overwrite: bool = False) -> Dict[str, Any]:
311312
"""Run full strobe calibration. Blocking I/O is offloaded to a thread."""
312313

314+
if self.status.get("state") == "calibrating":
315+
return {"status": "error", "message": "Calibration already in progress"}
316+
313317
# Validate board version
314318
board_version = self.config_manager.get_config("gs_config.strobing.kConnectionBoardVersion")
315319
if board_version is None or int(board_version) != 3:
@@ -353,16 +357,22 @@ def _run_calibration_sync(self, target: float) -> Dict[str, Any]:
353357

354358
if success and final_dac > 0:
355359
self.config_manager.set_config(self.DAC_CONFIG_KEY, final_dac)
356-
self.status = {"state": "complete", "progress": 100,
357-
"message": f"DAC={final_dac:#04x}, current={led_current:.2f}A"}
358-
return {"status": "success", "dac_setting": final_dac,
359-
"led_current": round(led_current, 2)}
360+
self.status = {
361+
"state": "complete", "progress": 100,
362+
"message": f"DAC=0x{final_dac:02X}, current={led_current:.2f}A",
363+
"dac_setting": final_dac,
364+
"led_current": round(led_current, 2),
365+
}
366+
return self.status
367+
elif self._cancel_requested:
368+
self.status = {"state": "cancelled", "progress": 0,
369+
"message": "Calibration cancelled by user"}
370+
return self.status
360371
else:
361372
self._set_dac(self.SAFE_DAC_VALUE)
362373
self.status = {"state": "failed", "progress": 0,
363374
"message": "Calibration failed — DAC set to safe fallback"}
364-
return {"status": "failed",
365-
"message": "Calibration failed. DAC set to safe fallback."}
375+
return self.status
366376

367377
except Exception as e:
368378
logger.error(f"Calibration exception: {e}")

Software/web-server/tests/test_strobe_calibration_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ async def test_allows_overwrite_with_flag(self, _sleep):
632632
mgr._calibrate = Mock(return_value=(True, 0x80, 9.5))
633633

634634
result = await mgr.start_calibration(led_type="v3", overwrite=True)
635-
assert result["status"] == "success"
635+
assert result["state"] == "complete"
636636

637637
@pytest.mark.asyncio
638638
@patch("strobe_calibration_manager.time.sleep")
@@ -748,7 +748,7 @@ async def test_sets_safe_dac_on_failure(self, _sleep):
748748
mgr._set_dac = lambda v: dac_calls.append(v)
749749

750750
result = await mgr.start_calibration(led_type="v3")
751-
assert result["status"] == "failed"
751+
assert result["state"] == "failed"
752752
assert 0x96 in dac_calls
753753

754754
@pytest.mark.asyncio

0 commit comments

Comments
 (0)