Skip to content

Commit

Permalink
#63
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Oct 13, 2020
1 parent 2c6037c commit 5dff6a0
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 24 deletions.
42 changes: 23 additions & 19 deletions src/eez/modules/psu/calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions src/eez/modules/psu/calibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
9 changes: 9 additions & 0 deletions src/eez/modules/psu/psu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/eez/modules/psu/psu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 0 additions & 4 deletions src/eez/tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/eez/tasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5dff6a0

Please sign in to comment.