Skip to content

Commit

Permalink
Implemented: [LVGL] Support for native event handlers with user prope…
Browse files Browse the repository at this point in the history
…rties #657
  • Loading branch information
mvladic committed Dec 5, 2024
1 parent f09f348 commit 295c572
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 46 deletions.
Binary file modified packages/project-editor/flow/runtime/lvgl_runtime_v8.3.wasm
Binary file not shown.
Binary file modified packages/project-editor/flow/runtime/lvgl_runtime_v9.0.wasm
Binary file not shown.
111 changes: 67 additions & 44 deletions resources/eez-framework-amalgamation/eez-flow.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Autogenerated on December 3, 2024 1:49:44 PM from eez-framework commit 4d56ee77aa136e9b1b8bdb4c66ce286aece09938 */
/* Autogenerated on December 5, 2024 1:54:23 PM from eez-framework commit b9f6a088bb5b661c7c1f12674818b1bf10629907 */
/*
* eez-framework
*
Expand Down Expand Up @@ -7374,8 +7374,9 @@ static const void *getLvglImageByName(const char *name) {
}
return 0;
}
static lv_event_t *g_currentLVGLEvent;
static void executeLvglAction(int actionIndex) {
g_actions[actionIndex](0);
g_actions[actionIndex](g_currentLVGLEvent);
}
void eez_flow_init_themes(const char **themeNames, size_t numThemes, void (*changeColorTheme)(uint32_t themeIndex)) {
g_themeNames = themeNames;
Expand Down Expand Up @@ -7497,50 +7498,57 @@ extern "C" void flowPropagateValueUint32(void *flowState, unsigned componentInde
eez::flow::propagateValue((eez::flow::FlowState *)flowState, componentIndex, outputIndex, eez::Value(value, eez::VALUE_TYPE_UINT32));
}
extern "C" void flowPropagateValueLVGLEvent(void *flowState, unsigned componentIndex, unsigned outputIndex, lv_event_t *event) {
lv_event_code_t event_code = lv_event_get_code(event);
uint32_t code = (uint32_t)event_code;
void *currentTarget = (void *)lv_event_get_current_target(event);
void *target = (void *)lv_event_get_target(event);
void *userDataPointer = lv_event_get_user_data(event);
int32_t userData = *((int32_t*)(&userDataPointer));
uint32_t key = 0;
if (event_code == LV_EVENT_KEY || (event_code == LV_EVENT_VALUE_CHANGED &&
#if LVGL_VERSION_MAJOR >= 9
lv_obj_check_type((lv_obj_t*)target, &lv_buttonmatrix_class)
#else
lv_obj_check_type((lv_obj_t*)target, &lv_btnmatrix_class)
#endif
)) {
uint32_t *param = (uint32_t *)lv_event_get_param(event);
key = param ? *param : 0;
}
int32_t gestureDir = (int32_t)LV_DIR_NONE;
if (event_code == LV_EVENT_GESTURE) {
#if LVGL_VERSION_MAJOR >= 9
lv_indev_wait_release(lv_indev_active());
#else
lv_indev_wait_release(lv_indev_get_act());
#endif
gestureDir = (int32_t)lv_indev_get_gesture_dir(
#if LVGL_VERSION_MAJOR >= 9
lv_indev_active()
#else
lv_indev_get_act()
#endif
if (eez::flow::hasAnyDataConnection((eez::flow::FlowState *)flowState, componentIndex, outputIndex)) {
lv_event_code_t event_code = lv_event_get_code(event);
uint32_t code = (uint32_t)event_code;
void *currentTarget = (void *)lv_event_get_current_target(event);
void *target = (void *)lv_event_get_target(event);
void *userDataPointer = lv_event_get_user_data(event);
int32_t userData = *((int32_t*)(&userDataPointer));
uint32_t key = 0;
if (event_code == LV_EVENT_KEY || (event_code == LV_EVENT_VALUE_CHANGED &&
#if LVGL_VERSION_MAJOR >= 9
lv_obj_check_type((lv_obj_t*)target, &lv_buttonmatrix_class)
#else
lv_obj_check_type((lv_obj_t*)target, &lv_btnmatrix_class)
#endif
)) {
uint32_t *param = (uint32_t *)lv_event_get_param(event);
key = param ? *param : 0;
}
int32_t gestureDir = (int32_t)LV_DIR_NONE;
if (event_code == LV_EVENT_GESTURE) {
#if LVGL_VERSION_MAJOR >= 9
lv_indev_wait_release(lv_indev_active());
#else
lv_indev_wait_release(lv_indev_get_act());
#endif
gestureDir = (int32_t)lv_indev_get_gesture_dir(
#if LVGL_VERSION_MAJOR >= 9
lv_indev_active()
#else
lv_indev_get_act()
#endif
);
}
int32_t rotaryDiff = 0;
#if LVGL_VERSION_MAJOR >= 9
if (event_code == LV_EVENT_ROTARY) {
rotaryDiff = lv_event_get_rotary_diff(event);
}
#endif
eez::flow::propagateValue(
(eez::flow::FlowState *)flowState, componentIndex, outputIndex,
eez::Value::makeLVGLEventRef(
code, currentTarget, target, userData, key, gestureDir, rotaryDiff, 0xe7f23624
)
);
} else {
eez::flow::propagateValue((eez::flow::FlowState *)flowState, componentIndex, outputIndex);
}
int32_t rotaryDiff = 0;
#if LVGL_VERSION_MAJOR >= 9
if (event_code == LV_EVENT_ROTARY) {
rotaryDiff = lv_event_get_rotary_diff(event);
}
#endif
eez::flow::propagateValue(
(eez::flow::FlowState *)flowState, componentIndex, outputIndex,
eez::Value::makeLVGLEventRef(
code, currentTarget, target, userData, key, gestureDir, rotaryDiff, 0xe7f23624
)
);
g_currentLVGLEvent = event;
eez::flow::tick();
g_currentLVGLEvent = 0;
}
#ifndef EEZ_LVGL_TEMP_STRING_BUFFER_SIZE
#define EEZ_LVGL_TEMP_STRING_BUFFER_SIZE 1024
Expand Down Expand Up @@ -10308,6 +10316,21 @@ void propagateValueThroughSeqout(FlowState *flowState, unsigned componentIndex)
}
}
}
bool hasAnyDataConnection(FlowState *flowState, unsigned componentIndex, unsigned outputIndex) {
if ((int)componentIndex == -1) {
return false;
}
auto component = flowState->flow->components[componentIndex];
auto componentOutput = component->outputs[outputIndex];
for (unsigned connectionIndex = 0; connectionIndex < componentOutput->connections.count; connectionIndex++) {
auto connection = componentOutput->connections[connectionIndex];
auto isDataInput = !(flowState->flow->componentInputs[connection->targetInputIndex] & COMPONENT_INPUT_FLAG_IS_SEQ_INPUT);
if (isDataInput) {
return true;
}
}
return false;
}
#if EEZ_OPTION_GUI
void getValue(uint16_t dataId, DataOperationEnum operation, const WidgetCursor &widgetCursor, Value &value) {
if (!isFlowStopped()) {
Expand Down
3 changes: 2 additions & 1 deletion resources/eez-framework-amalgamation/eez-flow.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Autogenerated on December 3, 2024 1:49:44 PM from eez-framework commit 4d56ee77aa136e9b1b8bdb4c66ce286aece09938 */
/* Autogenerated on December 5, 2024 1:54:23 PM from eez-framework commit b9f6a088bb5b661c7c1f12674818b1bf10629907 */
/*
* eez-framework
*
Expand Down Expand Up @@ -2359,6 +2359,7 @@ void resetSequenceInputs(FlowState *flowState);
void propagateValue(FlowState *flowState, unsigned componentIndex, unsigned outputIndex, const Value &value);
void propagateValue(FlowState *flowState, unsigned componentIndex, unsigned outputIndex);
void propagateValueThroughSeqout(FlowState *flowState, unsigned componentIndex);
bool hasAnyDataConnection(FlowState *flowState, unsigned componentIndex, unsigned outputIndex);
#if EEZ_OPTION_GUI
void getValue(uint16_t dataId, DataOperationEnum operation, const WidgetCursor &widgetCursor, Value &value);
void setValue(uint16_t dataId, const WidgetCursor &widgetCursor, const Value& value);
Expand Down

0 comments on commit 295c572

Please sign in to comment.