Skip to content

Commit 76b8806

Browse files
committed
flow support assets
1 parent 722c98c commit 76b8806

22 files changed

+639
-407
lines changed

src/eez/flow.cpp

Lines changed: 126 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,139 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19+
#include <stdio.h>
20+
1921
#include <eez/flow.h>
2022
#include <eez/flow_defs_v3.h>
2123

22-
#include <eez/gui/assets.h>
24+
using namespace eez::gui;
2325

2426
namespace eez {
2527
namespace flow {
2628

27-
void run() {
29+
static Assets *g_assets;
30+
31+
static const unsigned QUEUE_SIZE = 100;
32+
static struct {
33+
unsigned flowIndex;
34+
unsigned componentIndex;
35+
} g_queue[QUEUE_SIZE];
36+
static unsigned g_queueHead;
37+
static unsigned g_queueTail;
38+
static bool g_queueIsFull = false;
39+
40+
void addToQueue(unsigned flowIndex, unsigned componentIndex) {
41+
g_queue[g_queueTail].flowIndex = flowIndex;
42+
g_queue[g_queueTail].componentIndex = componentIndex;
43+
44+
g_queueTail = (g_queueTail + 1) % QUEUE_SIZE;
45+
46+
if (g_queueHead == g_queueTail) {
47+
g_queueIsFull = true;
48+
}
49+
}
50+
51+
bool removeFromQueue(unsigned &flowIndex, unsigned &componentIndex) {
52+
if (g_queueHead == g_queueTail && !g_queueIsFull) {
53+
return false;
54+
}
55+
56+
flowIndex = g_queue[g_queueHead].flowIndex;
57+
componentIndex = g_queue[g_queueHead].componentIndex;
58+
59+
g_queueHead = (g_queueHead + 1) % QUEUE_SIZE;
60+
g_queueIsFull = false;
61+
62+
return true;
63+
}
64+
65+
bool allInputsDefined(FlowDefinition &flowDefinition, unsigned flowIndex, unsigned componentIndex) {
66+
auto &flow = flowDefinition.flows.first[flowIndex];
67+
auto &component = flow.components.first[componentIndex];
68+
69+
for (unsigned inputIndex = 0; inputIndex < component.inputs.count; inputIndex++) {
70+
auto &componentInput = component.inputs.first[inputIndex];
71+
72+
auto valueIndex = componentInput.values.first[0].valueIndex;
73+
74+
auto &value = flowDefinition.flowValues.first[valueIndex];
75+
if (value.header.type == FLOW_VALUE_TYPE_UNDEFINED) {
76+
return false;
77+
}
78+
}
79+
80+
return true;
81+
}
82+
83+
unsigned start(Assets *assets) {
84+
FlowDefinition &flowDefinition = *assets->flowDefinition;
85+
if (flowDefinition.flows.count == 0) {
86+
return 0;
87+
}
88+
89+
g_assets = assets;
90+
91+
unsigned flowIndex = 0;
92+
93+
const Flow &flow = flowDefinition.flows.first[flowIndex];
94+
for (unsigned componentIndex = 0; componentIndex < flow.components.count; componentIndex++) {
95+
if (allInputsDefined(flowDefinition, flowIndex, componentIndex)) {
96+
addToQueue(flowIndex, componentIndex);
97+
}
98+
}
99+
100+
return 1;
101+
}
102+
103+
void executeComponent(FlowDefinition &flowDefinition, unsigned flowIndex, unsigned componentIndex) {
104+
printf("Execute component %d\n", componentIndex);
105+
}
106+
107+
void tick(unsigned flowHandle) {
108+
if (flowHandle != 1) {
109+
return;
110+
}
111+
112+
Assets *assets = g_assets;
113+
FlowDefinition &flowDefinition = *assets->flowDefinition;
114+
115+
unsigned flowIndex;
116+
unsigned componentIndex;
117+
if (removeFromQueue(flowIndex, componentIndex)) {
118+
executeComponent(flowDefinition, flowIndex, componentIndex);
119+
}
120+
}
121+
122+
123+
void dumpFlow(FlowDefinition &flowDefinition) {
124+
// printf("Flows:\n");
125+
// for (unsigned i = 0; i < flowDefinition.flows.count; i++) {
126+
// printf("\t%d:\n", i);
127+
// const Flow &flow = flowDefinition.flows.first[i];
128+
// for (unsigned j = 0; j < flow.components.count; j++) {
129+
// const Component &component = flow.components.first[j];
130+
// printf("\t\t%d\n", j);
131+
// printf("\t\t\tType: %d\n", (int)component.type);
132+
133+
// printf("\t\t\tInputs:\n");
134+
// for (unsigned k = 0; k < component.inputs.count; k++) {
135+
// const ComponentInput &componentInput = component.inputs.first[k];
136+
// printf("\t\t\t\t%d\n", componentInput.values.count);
137+
// }
138+
139+
// printf("\t\t\tOutputs:\n");
140+
// for (unsigned k = 0; k < component.outputs.count; k++) {
141+
// const ComponentOutput &componentOutput = component.outputs.first[k];
142+
// printf("\t\t\t\t%d\n", componentOutput.connections.count);
143+
// }
144+
// }
145+
// }
146+
147+
// printf("Values:\n");
148+
// for (unsigned i = 0; i < flowDefinition.flowValues.count; i++) {
149+
// const FlowValue &flowValue = flowDefinition.flowValues.first[i];
150+
// printf("\t%d: %d\n", i, (int)flowValue.header.type);
151+
// }
28152
}
29153

30154
} // namespace flow

src/eez/flow.h

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,59 +18,13 @@
1818

1919
#pragma once
2020

21-
#include <stdint.h>
22-
#include <eez/gui/assets_ptr.h>
21+
#include <eez/gui/assets.h>
2322

2423
namespace eez {
25-
26-
namespace gui {
27-
struct Assets;
28-
}
29-
3024
namespace flow {
3125

32-
template <typename T>
33-
struct List {
34-
uint32_t count;
35-
AssetsPtr<T> first;
36-
};
37-
38-
struct ComponentInput {
39-
uint8_t count;
40-
uint16_t valueIndex[255];
41-
};
42-
43-
struct Connection {
44-
uint16_t targetComponentIndex;
45-
uint8_t targetInputIndex;
46-
};
47-
48-
struct ComponentOutput {
49-
uint8_t count;
50-
Connection connections[255];
51-
};
52-
53-
struct Component {
54-
uint16_t type;
55-
List<ComponentInput> inputs;
56-
List<ComponentOutput> outputs;
57-
AssetsPtr<const void> specific;
58-
};
59-
60-
struct Flow {
61-
List<const Component> flows;
62-
};
63-
64-
struct Value {
65-
uint8_t type;
66-
};
67-
68-
struct FlowDefinition {
69-
List<const Flow> flows;
70-
List<Value> values;
71-
};
72-
73-
void run();
26+
unsigned start(eez::gui::Assets *assets);
27+
void tick(unsigned flowHandle);
7428

7529
} // flow
7630
} // eez

src/eez/gui/app_context.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ bool AppContext::canExecuteActionWhenTouchedOutsideOfActivePage(int pageId, int
276276
void AppContext::onPageTouch(const WidgetCursor &foundWidget, Event &touchEvent) {
277277
int activePageId = getActivePageId();
278278
if (activePageId != PAGE_ID_NONE && !isPageInternal(activePageId)) {
279-
const Widget *page = getPageWidget(activePageId);
280-
const PageWidget *pageSpecific = GET_WIDGET_PROPERTY(page, specific, const PageWidget *);
279+
auto page = getPageWidget(activePageId);
280+
auto pageSpecific = GET_WIDGET_PROPERTY(page, specific, const PageWidget *);
281281
if ((pageSpecific->flags & CLOSE_PAGE_IF_TOUCHED_OUTSIDE_FLAG) != 0) {
282282
if (!pointInsideRect(touchEvent.x, touchEvent.y, foundWidget.appContext->rect.x + page->x, foundWidget.appContext->rect.y + page->y, page->w, page->h)) {
283283
int activePageId = getActivePageId();

0 commit comments

Comments
 (0)