From 850a98ad5eefd334ff9a17a1fb168640b2f568d0 Mon Sep 17 00:00:00 2001 From: Martin Vladic Date: Fri, 9 Oct 2020 15:35:33 +0200 Subject: [PATCH] #64 --- src/eez/modules/psu/calibration.cpp | 37 +++++++++++++++++++++++++---- src/eez/modules/psu/calibration.h | 3 +-- src/eez/modules/psu/scpi/cal.cpp | 11 +++++---- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/eez/modules/psu/calibration.cpp b/src/eez/modules/psu/calibration.cpp index bf0d442c6..508ba8900 100644 --- a/src/eez/modules/psu/calibration.cpp +++ b/src/eez/modules/psu/calibration.cpp @@ -694,10 +694,39 @@ bool save() { return doSave(g_slotIndex, g_subchannelIndex); } -bool clear(Channel *channel) { - channel->calibrationEnable(false); - clearCalibrationConf(&channel->cal_conf); - return doSave(channel->slotIndex, channel->subchannelIndex); +bool clear(int slotIndex, int subchannelIndex, int *err) { + CalibrationConfiguration *calConf; + + Channel *channel = Channel::getBySlotIndex(slotIndex, subchannelIndex); + + if (channel) { + channel->calibrationEnable(false); + + calConf = &channel->cal_conf; + } else { + g_slots[slotIndex]->enableVoltageCalibration(subchannelIndex, false); + g_slots[slotIndex]->enableCurrentCalibration(subchannelIndex, false); + + calConf = g_slots[slotIndex]->getCalibrationConfiguration(subchannelIndex); + } + + if (!calConf) { + if (err) { + *err = SCPI_ERROR_HARDWARE_MISSING; + } + return false; + } + + clearCalibrationConf(calConf); + + if (!doSave(slotIndex, subchannelIndex)) { + if (err) { + *err = SCPI_ERROR_EXECUTION_ERROR; + } + return false; + } + + return true; } void clearCalibrationConf(CalibrationConfiguration *calConf) { diff --git a/src/eez/modules/psu/calibration.h b/src/eez/modules/psu/calibration.h index 75b93f59d..936892377 100644 --- a/src/eez/modules/psu/calibration.h +++ b/src/eez/modules/psu/calibration.h @@ -92,8 +92,7 @@ bool doSave(int slotIndex, int subchannelIndex); bool save(); /// Clear calibration parameters for the currently selected channel. -/// /param channel Selected channel -bool clear(Channel *channel); +bool clear(int slotIndex, int subchannelIndex, int *err); void clearCalibrationConf(CalibrationConfiguration *calConf); diff --git a/src/eez/modules/psu/scpi/cal.cpp b/src/eez/modules/psu/scpi/cal.cpp index c9d100c7d..5aa729815 100644 --- a/src/eez/modules/psu/scpi/cal.cpp +++ b/src/eez/modules/psu/scpi/cal.cpp @@ -133,13 +133,14 @@ scpi_result_t scpi_cmd_calibrationClear(scpi_t *context) { return SCPI_RES_ERR; } - Channel *channel = getSelectedPowerChannel(context); - if (!channel) { + SlotAndSubchannelIndex *slotAndSubchannelIndex = getSelectedChannel(context); + if (!slotAndSubchannelIndex) { return SCPI_RES_ERR; } - if (!calibration::clear(channel)) { - SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR); + int err; + if (!calibration::clear(slotAndSubchannelIndex->slotIndex, slotAndSubchannelIndex->subchannelIndex, &err)) { + SCPI_ErrorPush(context, err); return SCPI_RES_ERR; } @@ -419,4 +420,4 @@ scpi_result_t scpi_cmd_calibrationScreenInit(scpi_t *context) { } // namespace scpi } // namespace psu -} // namespace eez \ No newline at end of file +} // namespace eez