Skip to content

Commit

Permalink
flow fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Nov 17, 2021
1 parent be2eb2a commit ddbfb93
Show file tree
Hide file tree
Showing 13 changed files with 376 additions and 223 deletions.
18 changes: 9 additions & 9 deletions modular-psu-firmware.eez-project
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@
"scpiDocFolder": "docs\\SCPI reference guide\\Commands",
"imports": [
{
"projectFilePath": "src\\eez\\modules\\psu\\psu.eez-project"
"projectFilePath": "src\\bb3\\psu\\psu.eez-project"
},
{
"projectFilePath": "src\\eez\\modules\\simulator\\simulator.eez-project"
"projectFilePath": "src\\bb3\\simulator\\simulator.eez-project"
},
{
"projectFilePath": "src\\eez\\modules\\dib-dcp405\\dib-dcp405.eez-project"
"projectFilePath": "src\\bb3\\dib-dcp405\\dib-dcp405.eez-project"
},
{
"projectFilePath": "src\\eez\\modules\\dib-dcm220\\dib-dcm220.eez-project"
"projectFilePath": "src\\bb3\\dib-dcm220\\dib-dcm220.eez-project"
},
{
"projectFilePath": "src\\eez\\modules\\dib-dcm224\\dib-dcm224.eez-project"
"projectFilePath": "src\\bb3\\dib-dcm224\\dib-dcm224.eez-project"
},
{
"projectFilePath": "src\\eez\\modules\\dib-mio168\\dib-mio168.eez-project"
"projectFilePath": "src\\bb3\\dib-mio168\\dib-mio168.eez-project"
},
{
"projectFilePath": "src\\eez\\modules\\dib-smx46\\dib-smx46.eez-project"
"projectFilePath": "src\\bb3\\dib-smx46\\dib-smx46.eez-project"
},
{
"projectFilePath": "src\\eez\\modules\\dib-prel6\\dib-prel6.eez-project"
"projectFilePath": "src\\bb3\\dib-prel6\\dib-prel6.eez-project"
},
{
"projectFilePath": "src\\eez\\modules\\dib-mux14d\\dib-mux14d.eez-project"
"projectFilePath": "src\\bb3\\dib-mux14d\\dib-mux14d.eez-project"
}
]
},
Expand Down
23 changes: 16 additions & 7 deletions src/bb3/psu/gui/keypad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1094,21 +1094,30 @@ void NumericKeypad::ok() {

return;
} else {
double value = getValue();
float value = (float)getValue();
if (isNaN(value)) {
sound::playBeep();
return;
}

if (!isNaN(m_options.min) && (float)value < m_options.min && !(value == 0 && m_options.allowZero)) {
psuErrorMessage(0, MakeLessThenMinMessageValue(m_options.min, m_startValue));
float EPSILON = 1E-9f;

if (!isNaN(m_options.min) && value < m_options.min && !(value == 0 && m_options.allowZero)) {
if (value < m_options.min - EPSILON) {
psuErrorMessage(0, MakeLessThenMinMessageValue(m_options.min, m_startValue));
return;
}
value = m_options.min;
} else if (!isNaN(m_options.max) && value > m_options.max) {
psuErrorMessage(0, MakeGreaterThenMaxMessageValue(m_options.max, m_startValue));
} else {
m_okFloatCallback((float)value);
return;
if (value > m_options.max + EPSILON) {
psuErrorMessage(0, MakeGreaterThenMaxMessageValue(m_options.max, m_startValue));
return;
}
value = m_options.max;
}

m_okFloatCallback((float)value);

return;
}
}
Expand Down
16 changes: 9 additions & 7 deletions src/eez/flow/components/scpi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ struct ScpiComponentExecutionState : public ComponenentExecutionState {

stringAppendString(commandOrQueryText, sizeof(commandOrQueryText), "\n");
scripting::executeScpiFromFlow(commandOrQueryText);

g_scpiResultIsReady = true;
g_waitingForScpiResult = nullptr;
return true;
}
return false;
}
Expand Down Expand Up @@ -168,7 +164,9 @@ void executeScpiComponent(FlowState *flowState, unsigned componentIndex) {
valueStr
);
} else if (scpiComponentExecutionState->op == SCPI_PART_QUERY_WITH_ASSIGNMENT) {
logScpiQuery(flowState, componentIndex, scpiComponentExecutionState->commandOrQueryText);
if (!scpiComponentExecutionState->g_waitingForScpiResult) {
logScpiQuery(flowState, componentIndex, scpiComponentExecutionState->commandOrQueryText);
}

if (!scpiComponentExecutionState->scpi()) {
if (!addToQueue(flowState, componentIndex)) {
Expand Down Expand Up @@ -228,7 +226,9 @@ void executeScpiComponent(FlowState *flowState, unsigned componentIndex) {

assignValue(flowState, componentIndex, dstValue, srcValue);
} else if (scpiComponentExecutionState->op == SCPI_PART_QUERY) {
logScpiQuery(flowState, componentIndex, scpiComponentExecutionState->commandOrQueryText);
if (!scpiComponentExecutionState->g_waitingForScpiResult) {
logScpiQuery(flowState, componentIndex, scpiComponentExecutionState->commandOrQueryText);
}

if (!scpiComponentExecutionState->scpi()) {
if (!addToQueue(flowState, componentIndex)) {
Expand All @@ -254,7 +254,9 @@ void executeScpiComponent(FlowState *flowState, unsigned componentIndex) {

scpiComponentExecutionState->commandOrQueryText[0] = 0;
} else if (scpiComponentExecutionState->op == SCPI_PART_COMMAND) {
logScpiCommand(flowState, componentIndex, scpiComponentExecutionState->commandOrQueryText);
if (!scpiComponentExecutionState->g_waitingForScpiResult) {
logScpiCommand(flowState, componentIndex, scpiComponentExecutionState->commandOrQueryText);
}

if (!scpiComponentExecutionState->scpi()) {
if (!addToQueue(flowState, componentIndex)) {
Expand Down
95 changes: 20 additions & 75 deletions src/eez/flow/flow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ using namespace eez::gui;
namespace eez {
namespace flow {

static const uint32_t FLOW_TICK_MAX_DURATION_MS = 500;
static const uint32_t FLOW_TICK_MAX_DURATION_MS = 20;

FlowState *g_mainPageFlowState;

Expand Down Expand Up @@ -183,115 +183,60 @@ void executeFlowAction(const gui::WidgetCursor &widgetCursor, int16_t actionId)
void dataOperation(int16_t dataId, DataOperationEnum operation, const gui::WidgetCursor &widgetCursor, Value &value) {
auto flowState = widgetCursor.flowState;

dataId = -dataId - 1;
auto flowDataId = -dataId - 1;

auto assets = flowState->assets;
auto flow = flowState->flow;

if (dataId >= 0 && dataId < (int16_t)flow->widgetDataItems.count) {
if (flowDataId >= 0 && flowDataId < (int16_t)flow->widgetDataItems.count) {
WidgetDataItem *widgetDataItem = flow->widgetDataItems.item(assets, flowDataId);
auto component = flow->components.item(assets, widgetDataItem->componentIndex);

if (operation == DATA_OPERATION_GET) {
getValue(dataId, widgetCursor, value);
getValue(flowDataId, widgetCursor, value);
if (component->type == WIDGET_TYPE_INPUT && dataId == widgetCursor.widget->data) {
value = getInputWidgetData(widgetCursor, value);
}
} else if (operation == DATA_OPERATION_COUNT) {
Value arrayValue;
getValue(dataId, widgetCursor, arrayValue);
getValue(flowDataId, widgetCursor, arrayValue);
if (arrayValue.getType() == VALUE_TYPE_ARRAY) {
value = arrayValue.arrayValue->arraySize;
} else {
value = 0;
}
} else if (operation == DATA_OPERATION_GET_MIN) {
WidgetDataItem *widgetDataItem = flow->widgetDataItems.item(assets, dataId);
auto component = flow->components.item(assets, widgetDataItem->componentIndex);
if (component->type == WIDGET_TYPE_INPUT) {
auto inputWidget = (InputWidget *)widgetCursor.widget;
auto inputWidgetExecutionState = (InputWidgetExecutionState *)flowState->componenentExecutionStates[inputWidget->componentIndex];
Value unitValue;
Value minValue;
if (inputWidgetExecutionState) {
unitValue = inputWidgetExecutionState->unit;
minValue = inputWidgetExecutionState->min;
} else {
unitValue = get(widgetCursor, inputWidget->unit);
minValue = get(widgetCursor, inputWidget->min);
}
Unit unit = getUnitFromName(unitValue.toString(0x5049bd52).getString());
value = Value(minValue.toFloat(), unit);
value = getInputWidgetMin(widgetCursor);
}
} else if (operation == DATA_OPERATION_GET_MAX) {
WidgetDataItem *widgetDataItem = flow->widgetDataItems.item(assets, dataId);
auto component = flow->components.item(assets, widgetDataItem->componentIndex);
if (component->type == WIDGET_TYPE_INPUT) {
auto inputWidget = (InputWidget *)widgetCursor.widget;
auto inputWidgetExecutionState = (InputWidgetExecutionState *)flowState->componenentExecutionStates[inputWidget->componentIndex];
Value unitValue;
Value maxValue;
if (inputWidgetExecutionState) {
unitValue = inputWidgetExecutionState->unit;
maxValue = inputWidgetExecutionState->max;
} else {
unitValue = get(widgetCursor, inputWidget->unit);
maxValue = get(widgetCursor, inputWidget->max);
}
Unit unit = getUnitFromName(unitValue.toString(0x5049bd52).getString());
value = Value(maxValue.toFloat(), unit);
value = getInputWidgetMax(widgetCursor);
}
} else if (operation == DATA_OPERATION_GET_PRECISION) {
WidgetDataItem *widgetDataItem = flow->widgetDataItems.item(assets, dataId);
auto component = flow->components.item(assets, widgetDataItem->componentIndex);
if (component->type == WIDGET_TYPE_INPUT) {
auto inputWidget = (InputWidget *)widgetCursor.widget;
auto inputWidgetExecutionState = (InputWidgetExecutionState *)flowState->componenentExecutionStates[inputWidget->componentIndex];
Value unitValue;
Value precisionValue;
if (inputWidgetExecutionState) {
unitValue = inputWidgetExecutionState->unit;
precisionValue = inputWidgetExecutionState->precision;
} else {
unitValue = get(widgetCursor, inputWidget->unit);
precisionValue = get(widgetCursor, inputWidget->precision);
}
Unit unit = getUnitFromName(unitValue.toString(0x5049bd52).getString());
value = Value(precisionValue.toFloat(), unit);
value = getInputWidgetPrecision(widgetCursor);
}
} else if (operation == DATA_OPERATION_GET_UNIT) {
WidgetDataItem *widgetDataItem = flow->widgetDataItems.item(assets, dataId);
auto component = flow->components.item(assets, widgetDataItem->componentIndex);
if (component->type == WIDGET_TYPE_INPUT) {
auto inputWidget = (InputWidget *)widgetCursor.widget;
auto inputWidgetExecutionState = (InputWidgetExecutionState *)flowState->componenentExecutionStates[inputWidget->componentIndex];
Value unitValue;
if (inputWidgetExecutionState) {
unitValue = inputWidgetExecutionState->unit;
} else {
unitValue = get(widgetCursor, inputWidget->unit);
}
Unit unit = getUnitFromName(unitValue.toString(0x5049bd52).getString());
value = unit;
value = getBaseUnit(getInputWidgetUnit(widgetCursor));
}
} else if (operation == DATA_OPERATION_SET) {
WidgetDataItem *widgetDataItem = flow->widgetDataItems.item(assets, dataId);
auto component = flow->components.item(assets, widgetDataItem->componentIndex);
if (component->type == WIDGET_TYPE_INPUT) {
auto inputWidget = (InputWidget *)widgetCursor.widget;
if (inputWidget->flags & INPUT_WIDGET_TYPE_NUMBER) {
auto inputWidgetExecutionState = (InputWidgetExecutionState *)flowState->componenentExecutionStates[inputWidget->componentIndex];
Value precisionValue;
if (inputWidgetExecutionState) {
precisionValue = inputWidgetExecutionState->precision;
} else {
precisionValue = get(widgetCursor, inputWidget->precision);
}

Value precisionValue = getInputWidgetPrecision(widgetCursor);
float precision = precisionValue.toFloat();
float valueFloat = value.toFloat();
setValue(dataId, widgetCursor, Value(roundPrec(valueFloat, precision), VALUE_TYPE_FLOAT));
Unit unit = getInputWidgetUnit(widgetCursor);
setValue(flowDataId, widgetCursor, Value(roundPrec(valueFloat, precision) / getUnitBase10(unit), VALUE_TYPE_FLOAT));
} else {
setValue(dataId, widgetCursor, value);
setValue(flowDataId, widgetCursor, value);
}

scripting::executeFlowAction(widgetCursor, inputWidget->action);
} else {
setValue(dataId, widgetCursor, value);
setValue(flowDataId, widgetCursor, value);
}
}
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/eez/gui/app_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ bool AppContext::isWidgetActionEnabled(const WidgetCursor &widgetCursor) {
if (action) {
if (widget->type == WIDGET_TYPE_BUTTON) {
auto buttonWidget = (const ButtonWidget *)widget;
if (!get(widgetCursor, buttonWidget->enabled).getInt()) {
auto enabled = get(widgetCursor, buttonWidget->enabled);
if (!(enabled.getType() == VALUE_TYPE_UNDEFINED || enabled.getInt() ? 1 : 0)) {
return false;
}
}
Expand Down
36 changes: 21 additions & 15 deletions src/eez/gui/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1018,20 +1018,16 @@ float Value::toFloat(int *err) const {
}

int32_t Value::toInt32(int *err) const {
if (type == VALUE_TYPE_VALUE_PTR) {
return pValueValue->toInt32(err);
}

if (err) {
*err = 0;
}

if (type == VALUE_TYPE_DOUBLE) {
return (int32_t)doubleValue;
if (type == VALUE_TYPE_INT32 || type == VALUE_TYPE_BOOLEAN) {
return int32Value;
}

if (type == VALUE_TYPE_FLOAT) {
return (int32_t)floatValue;
if (type == VALUE_TYPE_UINT32) {
return (int32_t)uint32Value;
}

if (type == VALUE_TYPE_INT8) {
Expand All @@ -1048,20 +1044,25 @@ int32_t Value::toInt32(int *err) const {
return uint16Value;
}

if (type == VALUE_TYPE_INT32 || type == VALUE_TYPE_BOOLEAN) {
return int32Value;
}
if (type == VALUE_TYPE_UINT32) {
return (int32_t)uint32Value;
}

if (type == VALUE_TYPE_INT64) {
return (int32_t)int64Value;
}
if (type == VALUE_TYPE_UINT64) {
return (int32_t)uint64Value;
}

if (type == VALUE_TYPE_VALUE_PTR) {
return pValueValue->toInt32(err);
}

if (type == VALUE_TYPE_DOUBLE) {
return (int32_t)doubleValue;
}

if (type == VALUE_TYPE_FLOAT) {
return (int32_t)floatValue;
}

if (type == VALUE_TYPE_STRING) {
return (int64_t)atoi(strValue);
}
Expand Down Expand Up @@ -1143,6 +1144,10 @@ bool Value::toBool(int *err) const {
*err = 0;
}

if (type == VALUE_TYPE_UNDEFINED || type == VALUE_TYPE_NULL) {
return false;
}

if (type == VALUE_TYPE_DOUBLE) {
return doubleValue != 0;
}
Expand Down Expand Up @@ -1191,6 +1196,7 @@ bool Value::toBool(int *err) const {
if (err) {
*err = 1;
}

return false;
}

Expand Down
3 changes: 2 additions & 1 deletion src/eez/gui/widgets/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ DrawFunctionType BUTTON_draw = [](const WidgetCursor &widgetCursor) {
auto widget = (const ButtonWidget *)widgetCursor.widget;

widgetCursor.currentState->size = sizeof(WidgetState);
widgetCursor.currentState->flags.enabled = get(widgetCursor, widget->enabled).getInt() ? 1 : 0;
auto enabled = get(widgetCursor, widget->enabled);
widgetCursor.currentState->flags.enabled = enabled.getType() == VALUE_TYPE_UNDEFINED || get(widgetCursor, widget->enabled).getInt() ? 1 : 0;

const Style *style = getStyle(widgetCursor.currentState->flags.enabled ? widget->style : widget->disabledStyle);

Expand Down
Loading

0 comments on commit ddbfb93

Please sign in to comment.