From 5dff6a0be7aa03ea00229f052a0b728e013d30ca Mon Sep 17 00:00:00 2001 From: Martin Vladic Date: Fri, 9 Oct 2020 14:28:15 +0200 Subject: [PATCH] #63 --- src/eez/modules/psu/calibration.cpp | 42 ++++++++++++++++------------- src/eez/modules/psu/calibration.h | 2 ++ src/eez/modules/psu/psu.cpp | 9 +++++++ src/eez/modules/psu/psu.h | 1 + src/eez/tasks.cpp | 4 --- src/eez/tasks.h | 2 +- 6 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/eez/modules/psu/calibration.cpp b/src/eez/modules/psu/calibration.cpp index 47aebe184..bf0d442c6 100644 --- a/src/eez/modules/psu/calibration.cpp +++ b/src/eez/modules/psu/calibration.cpp @@ -115,17 +115,21 @@ void Value::setDacValue(float value) { if (type == CALIBRATION_VALUE_U) { if (channel) { - channel->setVoltage(value); - channel->setCurrent(channel->params.U_CAL_I_SET); + channel_dispatcher::setVoltage(*channel, value); + channel_dispatcher::setCurrent(*channel, channel->params.U_CAL_I_SET); } else { channel_dispatcher::setVoltage(g_slotIndex, g_subchannelIndex, value, nullptr); } } else { - channel->setCurrent(value); - if (type == CALIBRATION_VALUE_I_HI_RANGE) { - channel->setVoltage(channel->params.I_CAL_U_SET); + if (channel) { + channel_dispatcher::setCurrent(*channel, value); + if (type == CALIBRATION_VALUE_I_HI_RANGE) { + channel_dispatcher::setVoltage(*channel, channel->params.I_CAL_U_SET); + } else { + channel_dispatcher::setVoltage(*channel, channel->params.I_LOW_RANGE_CAL_U_SET); + } } else { - channel->setVoltage(channel->params.I_LOW_RANGE_CAL_U_SET); + // TODO } } } @@ -365,18 +369,18 @@ float getAdcValue(CalibrationValueType valueType) { void setVoltage(float value) { Channel *channel = Channel::getBySlotIndex(g_slotIndex, g_subchannelIndex); if (channel) { - channel->setVoltage(value); + channel_dispatcher::setVoltage(*channel, value); } else { - g_slots[g_slotIndex]->setVoltage(g_subchannelIndex, value, nullptr); + channel_dispatcher::setVoltage(g_slotIndex, g_subchannelIndex, value, nullptr); } } void setCurrent(float value) { Channel *channel = Channel::getBySlotIndex(g_slotIndex, g_subchannelIndex); if (channel) { - channel->setCurrent(value); + channel_dispatcher::setCurrent(*channel, value); } else { - g_slots[g_slotIndex]->setCurrent(g_subchannelIndex, value, nullptr); + channel_dispatcher::setCurrent(g_slotIndex, g_subchannelIndex, value, nullptr); } } @@ -647,17 +651,17 @@ bool canSave(int16_t &scpiErr, int16_t *uiErr) { } bool doSave(int slotIndex, int subchannelIndex) { - if (!isLowPriorityThread()) { - sendMessageToLowPriorityThread(THREAD_MESSAGE_SAVE_CHANNEL_CALIBRATION, (slotIndex << 8) | subchannelIndex); - return true; - } + static bool result; - Channel *channel = Channel::getBySlotIndex(slotIndex, subchannelIndex); - if (channel) { - return persist_conf::saveChannelCalibration(*channel); - } else { - return persist_conf::saveChannelCalibration(slotIndex, subchannelIndex); + result = false; + + if (!isPsuThread()) { + sendMessageToPsu(PSU_MESSAGE_SAVE_CHANNEL_CALIBRATION, (slotIndex << 8) | subchannelIndex); + return result; } + + result = persist_conf::saveChannelCalibration(slotIndex, subchannelIndex); + return result; } bool save() { diff --git a/src/eez/modules/psu/calibration.h b/src/eez/modules/psu/calibration.h index d440515e1..75b93f59d 100644 --- a/src/eez/modules/psu/calibration.h +++ b/src/eez/modules/psu/calibration.h @@ -86,6 +86,8 @@ void setRemark(const char *value, size_t len); /// Are all calibration parameters entered? bool canSave(int16_t &scpiErr, int16_t *uiErr = nullptr); +bool doSave(int slotIndex, int subchannelIndex); + /// Save calibration parameters entered during calibration procedure. bool save(); diff --git a/src/eez/modules/psu/psu.cpp b/src/eez/modules/psu/psu.cpp index 03e7dcb7f..8bb48c9ee 100644 --- a/src/eez/modules/psu/psu.cpp +++ b/src/eez/modules/psu/psu.cpp @@ -512,6 +512,11 @@ float PsuModule::getProfileISet(uint8_t *buffer) { return parameters->i_set; } +CalibrationConfiguration *PsuModule::getCalibrationConfiguration(int subchannelIndex) { + Channel *channel = Channel::getBySlotIndex(slotIndex, subchannelIndex); + return &channel->cal_conf; +} + //////////////////////////////////////////////////////////////////////////////// void init() { @@ -566,6 +571,10 @@ void onThreadMessage(uint8_t type, uint32_t param) { calibration::start(slotIndex, subchannelIndex); } else if (type == PSU_MESSAGE_CALIBRATION_SELECT_CURRENT_RANGE) { calibration::selectCurrentRange((int8_t)param); + } else if (type == PSU_MESSAGE_SAVE_CHANNEL_CALIBRATION) { + int slotIndex = param >> 8; + int subchannelIndex = param & 0xFF; + calibration::doSave(slotIndex, subchannelIndex); } else if (type == PSU_MESSAGE_CALIBRATION_STOP) { calibration::stop(); } else if (type == PSU_MESSAGE_FLASH_SLAVE_START) { diff --git a/src/eez/modules/psu/psu.h b/src/eez/modules/psu/psu.h index 41b3c9a7a..199501676 100644 --- a/src/eez/modules/psu/psu.h +++ b/src/eez/modules/psu/psu.h @@ -72,6 +72,7 @@ struct PsuModule : public Module { bool getProfileOutputEnable(uint8_t *buffer) override; float getProfileUSet(uint8_t *buffer) override; float getProfileISet(uint8_t *buffer) override; + CalibrationConfiguration *getCalibrationConfiguration(int subchannelIndex) override; }; /// Channel binary flags stored in profile. diff --git a/src/eez/tasks.cpp b/src/eez/tasks.cpp index e7d6e1a8f..b8eac5214 100644 --- a/src/eez/tasks.cpp +++ b/src/eez/tasks.cpp @@ -387,10 +387,6 @@ void lowPriorityThreadOneIter() { #endif else if (type == THREAD_MESSAGE_GENERATE_ERROR) { generateError(param); - } else if (type == THREAD_MESSAGE_SAVE_CHANNEL_CALIBRATION) { - int slotIndex = param >> 8; - int subchannelIndex = param & 0xFF; - persist_conf::saveChannelCalibration(slotIndex, subchannelIndex); } else if (type >= THREAD_MESSAGE_MODULE_SPECIFIC) { int slotIndex = param & 0xff; g_slots[slotIndex]->onLowPriorityThreadMessage(type, param); diff --git a/src/eez/tasks.h b/src/eez/tasks.h index 2fe62430b..a2be7e596 100644 --- a/src/eez/tasks.h +++ b/src/eez/tasks.h @@ -45,6 +45,7 @@ enum HighPriorityThreadMessage { PSU_MESSAGE_RESET_CHANNELS_HISTORY, PSU_MESSAGE_CALIBRATION_START, PSU_MESSAGE_CALIBRATION_SELECT_CURRENT_RANGE, + PSU_MESSAGE_SAVE_CHANNEL_CALIBRATION, PSU_MESSAGE_CALIBRATION_STOP, PSU_MESSAGE_FLASH_SLAVE_START, PSU_MESSAGE_FLASH_SLAVE_LEAVE_BOOTLOADER_MODE, @@ -110,7 +111,6 @@ enum LowPriorityThreadMessage { THREAD_MESSAGE_USBD_MSC_DATAIN, THREAD_MESSAGE_USBD_MSC_DATAOUT, THREAD_MESSAGE_GENERATE_ERROR, - THREAD_MESSAGE_SAVE_CHANNEL_CALIBRATION, // this must be at the end THREAD_MESSAGE_MODULE_SPECIFIC