Skip to content

Commit

Permalink
show page component in applet
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Nov 18, 2021
1 parent ddbfb93 commit 92cac3a
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/bb3/psu/dlog_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,20 +224,20 @@ void stateManagment() {
auto isExecuting = dlog_record::isExecuting();
if (!isExecuting && g_wasExecuting) {
if (psu::gui::isPageOnStack(PAGE_ID_DLOG_VIEW)) {
if (psu::gui::isPageOnStack(getExternalAssetsFirstPageId())) {
if (psu::gui::isExternalPageActive()) {
psu::gui::removePageFromStack(PAGE_ID_DLOG_VIEW);
} else {
openFile(dlog_record::getLatestFilePath());
}
} else {
if (psu::gui::isPageOnStack(getExternalAssetsFirstPageId())) {
if (psu::gui::isExternalPageActive()) {
} else {
gui::showPage(PAGE_ID_DLOG_VIEW);
openFile(dlog_record::getLatestFilePath());
}
}
} else if (isExecuting && !g_wasExecuting) {
if (!psu::gui::isPageOnStack(getExternalAssetsFirstPageId())) {
if (!psu::gui::isExternalPageActive()) {
g_showLatest = true;
if (!psu::gui::isPageOnStack(PAGE_ID_DLOG_VIEW)) {
gui::showPage(PAGE_ID_DLOG_VIEW);
Expand Down
14 changes: 7 additions & 7 deletions src/bb3/psu/gui/psu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,15 +956,15 @@ void PsuAppContext::doShowIntegerInput() {

bool PsuAppContext::dialogOpen(int *err) {
if (osThreadGetId() == g_guiTaskHandle) {
if (!isPageOnStack(getExternalAssetsFirstPageId())) {
if (!isExternalPageActive()) {
dialogResetDataItemValues();
pushPage(getExternalAssetsFirstPageId());
pushPage(getExternalAssetsMainPageId());
}
} else {
sendMessageToGuiThread(GUI_QUEUE_MESSAGE_TYPE_DIALOG_OPEN);
do {
osDelay(1);
} while (!isPageOnStack(getExternalAssetsFirstPageId()));
} while (!isExternalPageActive());
}
return true;
}
Expand All @@ -980,7 +980,7 @@ DialogActionResult PsuAppContext::dialogAction(uint32_t timeoutMs, const char *&
while (
(timeoutMs == 0 || (int32_t)(millis() - timeoutMs) < 0) &&
g_externalActionId == ACTION_ID_NONE &&
isPageOnStack(getExternalAssetsFirstPageId())
isExternalPageActive()
) {
osDelay(5);
}
Expand All @@ -991,7 +991,7 @@ DialogActionResult PsuAppContext::dialogAction(uint32_t timeoutMs, const char *&
return DIALOG_ACTION_RESULT_SELECTED_ACTION;
}

return isPageOnStack(getExternalAssetsFirstPageId()) ? DIALOG_ACTION_RESULT_TIMEOUT : DIALOG_ACTION_RESULT_EXIT;
return isExternalPageActive() ? DIALOG_ACTION_RESULT_TIMEOUT : DIALOG_ACTION_RESULT_EXIT;
}


Expand Down Expand Up @@ -1031,8 +1031,8 @@ void PsuAppContext::dialogSetDataItemValue(int16_t dataId, const char *str) {

void PsuAppContext::dialogClose() {
if (osThreadGetId() == g_guiTaskHandle) {
if (isPageOnStack(getExternalAssetsFirstPageId())) {
removePageFromStack(getExternalAssetsFirstPageId());
if (isExternalPageActive()) {
removePageFromStack(getExternalAssetsMainPageId());
}
} else {
sendMessageToGuiThread(GUI_QUEUE_MESSAGE_TYPE_DIALOG_CLOSE);
Expand Down
4 changes: 4 additions & 0 deletions src/bb3/psu/gui/psu.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ inline int getActivePageId() {
return g_psuAppContext.getActivePageId();
}

inline bool isExternalPageActive() {
return getActivePageId() < 0;
}

inline Page *getActivePage() {
return g_psuAppContext.getActivePage();
}
Expand Down
3 changes: 3 additions & 0 deletions src/eez/flow/components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void executeErrorComponent(FlowState *flowState, unsigned componentIndex);
void executeCatchErrorComponent(FlowState *flowState, unsigned componentIndex);
void executeLoopComponent(FlowState *flowState, unsigned componentIndex);
void executeScpiComponent(FlowState *flowState, unsigned componentIndex);
void executeShowPageComponent(FlowState *flowState, unsigned componentIndex);

void executeComponent(FlowState *flowState, unsigned componentIndex) {
auto component = flowState->flow->components.item(flowState->assets, componentIndex);
Expand Down Expand Up @@ -85,6 +86,8 @@ void executeComponent(FlowState *flowState, unsigned componentIndex) {
executeLoopComponent(flowState, componentIndex);
} else if (component->type == defs_v3::COMPONENT_TYPE_SCPIACTION) {
executeScpiComponent(flowState, componentIndex);
} else if (component->type == defs_v3::COMPONENT_TYPE_SHOW_PAGE_ACTION) {
executeShowPageComponent(flowState, componentIndex);
} else {
char errorMessage[100];
snprintf(errorMessage, sizeof(errorMessage), "Unknown component at index = %d, type = %d\n", componentIndex, component->type);
Expand Down
44 changes: 44 additions & 0 deletions src/eez/flow/components/show_page.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* EEZ Modular Firmware
* Copyright (C) 2021-present, Envox d.o.o.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <eez/flow/components.h>
#include <eez/flow/debugger.h>

#include <bb3/psu/gui/psu.h>

using namespace eez::gui;

namespace eez {
namespace flow {

struct ShowPageActionComponent : public Component {
int16_t page;
};

void executeShowPageComponent(FlowState *flowState, unsigned componentIndex) {
auto assets = flowState->assets;
auto component = (ShowPageActionComponent *)flowState->flow->components.item(assets, componentIndex);

eez::psu::gui::replacePage(component->page);
onPageChanged(component->page);

propagateValueThroughSeqout(flowState, componentIndex);
}

} // namespace flow
} // namespace eez
14 changes: 13 additions & 1 deletion src/eez/flow/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ enum MessagesToDebugger {

MESSAGE_TO_DEBUGGER_FLOW_STATE_ERROR, // FLOW_STATE_INDEX, COMPONENT_INDEX, ERROR_MESSAGE

MESSAGE_TO_DEBUGGER_LOG // LOG_ITEM_TYPE, FLOW_STATE_INDEX, COMPONENT_INDEX, MESSAGE
MESSAGE_TO_DEBUGGER_LOG, // LOG_ITEM_TYPE, FLOW_STATE_INDEX, COMPONENT_INDEX, MESSAGE

MESSAGE_TO_DEBUGGER_PAGE_CHANGED // PAGE_ID
};

enum MessagesFromDebugger {
Expand Down Expand Up @@ -587,5 +588,16 @@ void logScpiQueryResult(FlowState *flowState, unsigned componentIndex, const cha
}
}

void onPageChanged(int pageId) {
if (g_debuggerIsConnected) {
char buffer[100];
snprintf(buffer, sizeof(buffer), "%d\t%d\n",
MESSAGE_TO_DEBUGGER_PAGE_CHANGED,
-pageId - 1
);
eez::mcu::ethernet::writeDebuggerBuffer(buffer, strlen(buffer));
}
}

} // namespace flow
} // namespace eez
2 changes: 2 additions & 0 deletions src/eez/flow/debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@ void logScpiCommand(FlowState *flowState, unsigned componentIndex, const char *c
void logScpiQuery(FlowState *flowState, unsigned componentIndex, const char *query);
void logScpiQueryResult(FlowState *flowState, unsigned componentIndex, const char *resultText, size_t resultTextLen);

void onPageChanged(int pageId);

} // flow
} // eez
21 changes: 16 additions & 5 deletions src/eez/flow/flow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ static const uint32_t FLOW_TICK_MAX_DURATION_MS = 20;

FlowState *g_mainPageFlowState;

static const uint32_t MAX_PAGES = 10;
FlowState *g_pagesFlowState[MAX_PAGES];

////////////////////////////////////////////////////////////////////////////////

unsigned start(Assets *assets) {
Expand All @@ -48,7 +51,6 @@ unsigned start(Assets *assets) {
return 0;
}


g_lastFlowStateIndex = 0;

queueInit();
Expand All @@ -59,7 +61,10 @@ unsigned start(Assets *assets) {

onStarted(assets);

g_mainPageFlowState = initPageFlowState(assets, 0, nullptr, 0);
for (uint32_t i = 0; i < assets->pages.count; i++) {
g_pagesFlowState[i] = initPageFlowState(assets, i, nullptr, 0);
}
g_mainPageFlowState = g_pagesFlowState[0];

return 1;
}
Expand Down Expand Up @@ -120,12 +125,18 @@ void tick() {

void stop() {
if (g_mainPageFlowState) {
freeFlowState(g_mainPageFlowState);
for (unsigned i = 0; i < MAX_PAGES && g_pagesFlowState[i]; i++) {
freeFlowState(g_pagesFlowState[i]);
}
g_mainPageFlowState = nullptr;
}
}

FlowState *getFlowState(int16_t pageId, const WidgetCursor &widgetCursor) {
if (!g_mainPageFlowState) {
return nullptr;
}

pageId = -pageId - 1;

if (widgetCursor.widget && widgetCursor.widget->type == WIDGET_TYPE_LAYOUT_VIEW) {
Expand Down Expand Up @@ -157,8 +168,8 @@ FlowState *getFlowState(int16_t pageId, const WidgetCursor &widgetCursor) {
return layoutViewWidgetExecutionState->flowState;
}
}
return g_mainPageFlowState;

return g_pagesFlowState[pageId];
}

void executeFlowAction(const gui::WidgetCursor &widgetCursor, int16_t actionId) {
Expand Down
2 changes: 1 addition & 1 deletion src/eez/gui/assets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ const uint16_t *getColors() {
return g_mainAssets->colorsDefinition.ptr(g_mainAssets)->colors.ptr(g_mainAssets);
}

int getExternalAssetsFirstPageId() {
int getExternalAssetsMainPageId() {
return -1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/eez/gui/assets.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ const uint32_t getThemeColorsCount(int themeIndex);
const uint16_t *getThemeColors(int themeIndex);
const uint16_t *getColors();

int getExternalAssetsFirstPageId();
int getExternalAssetsMainPageId();

const char *getActionName(const WidgetCursor &widgetCursor, int16_t actionId);
int16_t getDataIdFromName(const WidgetCursor &widgetCursor, const char *name);
Expand Down
2 changes: 1 addition & 1 deletion src/eez/scripting/scripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ bool startScript(const char *filePath, int *err) {
void doStopScript() {
g_state = STATE_STOPPING;

while (psu::gui::isPageOnStack(getExternalAssetsFirstPageId())) {
while (psu::gui::isExternalPageActive()) {
psu::gui::popPage();
osDelay(5);
}
Expand Down

0 comments on commit 92cac3a

Please sign in to comment.