Skip to content

Commit

Permalink
#64
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Oct 9, 2020
1 parent e3d43c0 commit a366d59
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
37 changes: 33 additions & 4 deletions src/eez/modules/psu/calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions src/eez/modules/psu/calibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
11 changes: 6 additions & 5 deletions src/eez/modules/psu/scpi/cal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -419,4 +420,4 @@ scpi_result_t scpi_cmd_calibrationScreenInit(scpi_t *context) {

} // namespace scpi
} // namespace psu
} // namespace eez
} // namespace eez

0 comments on commit a366d59

Please sign in to comment.