From 495ab6fe64d6d4ba76dbafc2e9c78c15e9a1e9a0 Mon Sep 17 00:00:00 2001 From: Martin Vladic Date: Sat, 30 Jan 2021 12:41:56 +0100 Subject: [PATCH] #123 --- src/eez/modules/psu/channel_dispatcher.cpp | 2 +- src/eez/modules/psu/gui/psu.cpp | 27 +++++++------ src/eez/mp.cpp | 44 ++++++++++++---------- src/eez/util.cpp | 10 +++++ src/eez/util.h | 1 + 5 files changed, 49 insertions(+), 35 deletions(-) diff --git a/src/eez/modules/psu/channel_dispatcher.cpp b/src/eez/modules/psu/channel_dispatcher.cpp index 550d82101..4566fd568 100644 --- a/src/eez/modules/psu/channel_dispatcher.cpp +++ b/src/eez/modules/psu/channel_dispatcher.cpp @@ -645,7 +645,7 @@ float getUMaxOvpLevel(const Channel &channel) { float getUProtectionLevel(const Channel &channel) { if (channel.channelIndex < 2 && g_couplingType == COUPLING_TYPE_SERIES) { - return Channel::get(0).prot_conf.u_level + Channel::get(1).prot_conf.u_level; + return Channel::get(0).prot_conf.u_level + Channel::get(1).prot_conf.u_level + 0.01; } return channel.prot_conf.u_level; } diff --git a/src/eez/modules/psu/gui/psu.cpp b/src/eez/modules/psu/gui/psu.cpp index f79041889..9414068d2 100644 --- a/src/eez/modules/psu/gui/psu.cpp +++ b/src/eez/modules/psu/gui/psu.cpp @@ -931,21 +931,19 @@ bool PsuAppContext::dialogOpen(int *err) { } DialogActionResult PsuAppContext::dialogAction(uint32_t timeoutMs, const char *&selectedActionName) { - if (timeoutMs == 0) { - timeoutMs = 1000; - } - timeoutMs = millis() + timeoutMs; - - while ((int32_t)(millis() - timeoutMs) < 0) { - if (g_externalActionId != ACTION_ID_NONE) { - break; - } - - if (!isPageOnStack(getExternalAssetsFirstPageId())) { - break; - } + if (timeoutMs != 0) { + timeoutMs = millis() + timeoutMs; + if (timeoutMs == 0) { + timeoutMs = 1; + } + } - osDelay(5); + while ( + (timeoutMs == 0 || (int32_t)(millis() - timeoutMs) < 0) && + g_externalActionId == ACTION_ID_NONE && + isPageOnStack(getExternalAssetsFirstPageId()) + ) { + osDelay(5); } if (g_externalActionId != ACTION_ID_NONE) { @@ -957,6 +955,7 @@ DialogActionResult PsuAppContext::dialogAction(uint32_t timeoutMs, const char *& return isPageOnStack(getExternalAssetsFirstPageId()) ? DIALOG_ACTION_RESULT_TIMEOUT : DIALOG_ACTION_RESULT_EXIT; } + void PsuAppContext::dialogResetDataItemValues() { for (uint32_t i = 0; i < MAX_NUM_EXTERNAL_DATA_ITEM_VALUES; i++) { g_externalDataItemValues[i].value = Value(); diff --git a/src/eez/mp.cpp b/src/eez/mp.cpp index 065cddd8f..75b84f445 100644 --- a/src/eez/mp.cpp +++ b/src/eez/mp.cpp @@ -318,29 +318,33 @@ bool scpi(const char *commandOrQueryText, const char **resultText, size_t *resul // DebugTrace("> %s\n", commandOrQueryText); g_scpiDataLen = 0; - g_lastError = 0; -#if 1 - g_commandOrQueryText = commandOrQueryText; - sendMessageToLowPriorityThread(MP_EXECUTE_SCPI); - - static const uint32_t SCPI_TIMEOUT = 3000; - - while (true) { - osEvent event = osMessageGet(g_mpMessageQueueId, SCPI_TIMEOUT); - if (event.status == osEventMessage && event.value.v == QUEUE_MESSAGE_SCPI_RESULT) { - break; - } else { - static char g_scpiError[48]; - snprintf(g_scpiError, sizeof(g_scpiError), "SCPI timeout"); - mp_raise_ValueError(g_scpiError); - } + bool executeInLowPriorityThread = true; + if (startsWithNoCase(commandOrQueryText, "DISP:INPUT?") || startsWithNoCase(commandOrQueryText, "DISP:DIALOG:ACTION?")) { + executeInLowPriorityThread = false; + } + + if (executeInLowPriorityThread) { + g_commandOrQueryText = commandOrQueryText; + sendMessageToLowPriorityThread(MP_EXECUTE_SCPI); + + static const uint32_t SCPI_TIMEOUT = 3000; + + while (true) { + osEvent event = osMessageGet(g_mpMessageQueueId, SCPI_TIMEOUT); + if (event.status == osEventMessage && event.value.v == QUEUE_MESSAGE_SCPI_RESULT) { + break; + } else { + static char g_scpiError[48]; + snprintf(g_scpiError, sizeof(g_scpiError), "SCPI timeout"); + mp_raise_ValueError(g_scpiError); + } + } + } else { + input(g_scpiContext, (const char *)commandOrQueryText, strlen(commandOrQueryText)); + input(g_scpiContext, "\r\n", 2); } -#else - input(g_scpiContext, (const char *)commandOrQueryText, strlen(commandOrQueryText)); - input(g_scpiContext, "\r\n", 2); -#endif if (g_lastError != 0) { static char g_scpiError[48]; diff --git a/src/eez/util.cpp b/src/eez/util.cpp index 9a30a1bd2..ba87a3bdc 100644 --- a/src/eez/util.cpp +++ b/src/eez/util.cpp @@ -567,6 +567,16 @@ bool startsWith(const char *str, const char *prefix) { return strncmp(str, prefix, prefixLen) == 0; } +bool startsWithNoCase(const char *str, const char *prefix) { + if (!str || !prefix) + return false; + size_t strLen = strlen(str); + size_t prefixLen = strlen(prefix); + if (prefixLen > strLen) + return false; + return strncicmp(str, prefix, prefixLen) == 0; +} + bool endsWith(const char *str, const char *suffix) { if (!str || !suffix) return false; diff --git a/src/eez/util.h b/src/eez/util.h index 2f6880e79..39be906ef 100644 --- a/src/eez/util.h +++ b/src/eez/util.h @@ -124,6 +124,7 @@ int strcicmp(char const *a, char const *b); int strncicmp(char const *a, char const *b, int n); bool isStringEmpty(char const *a); bool startsWith(const char *str, const char *prefix); +bool startsWithNoCase(const char *str, const char *prefix); bool endsWith(const char *str, const char *suffix); bool endsWithNoCase(const char *str, const char *suffix);