Skip to content

Commit

Permalink
gui refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Feb 1, 2020
1 parent af447d1 commit fa92881
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 151 deletions.
7 changes: 4 additions & 3 deletions src/eez/firmware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include <eez/modules/psu/ethernet.h>
#include <eez/modules/psu/ntp.h>
#endif
#include <eez/modules/psu/gui/psu.h>

#if OPTION_FAN
#include <eez/modules/aux_ps/fan.h>
Expand Down Expand Up @@ -183,7 +184,7 @@ void boot() {
psu::persist_conf::init();

#if OPTION_DISPLAY
eez::gui::showWelcomePage();
eez::psu::gui::showWelcomePage();
#endif

#if defined(EEZ_PLATFORM_STM32)
Expand Down Expand Up @@ -333,7 +334,7 @@ void shutdown() {
using namespace psu;

if (osThreadGetId() != g_psuTaskHandle) {
gui::showSavingPage();
psu::gui::showSavingPage();
osMessagePut(g_psuMessageQueueId, PSU_QUEUE_MESSAGE(PSU_QUEUE_MESSAGE_TYPE_SHUTDOWN, 0), osWaitForever);
return;
}
Expand Down Expand Up @@ -380,7 +381,7 @@ void shutdown() {

g_shutdown = true;
} else {
gui::showShutdownPage();
psu::gui::showShutdownPage();

#if defined(EEZ_PLATFORM_SIMULATOR)
osDelay(100);
Expand Down
27 changes: 10 additions & 17 deletions src/eez/gui/app_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
#include <eez/gui/widgets/button.h>

#include <eez/modules/psu/psu.h>
#include <eez/modules/psu/devices.h>
#include <eez/modules/psu/idle.h>
#include <eez/modules/psu/gui/psu.h>

#define CONF_GUI_TOAST_DURATION_MS 2000L

Expand Down Expand Up @@ -94,21 +92,6 @@ bool AppContext::isWidgetActionEnabled(const WidgetCursor &widgetCursor) {
AppContext *saved = g_appContext;
g_appContext = this;

if (isFrontPanelLocked()) {
int activePageId = getActivePageId();
if (activePageId == PAGE_ID_KEYPAD ||
activePageId == PAGE_ID_TOUCH_CALIBRATION_YES_NO ||
activePageId == PAGE_ID_TOUCH_CALIBRATION_YES_NO_CANCEL) {
g_appContext = saved;
return true;
}

if (widget->action != ACTION_ID_SYS_FRONT_PANEL_UNLOCK) {
g_appContext = saved;
return false;
}
}

if (widget->type == WIDGET_TYPE_BUTTON) {
const ButtonWidget *buttonWidget = GET_WIDGET_PROPERTY(widget, specific, const ButtonWidget *);
if (!data::get(widgetCursor.cursor, buttonWidget->enabled).getInt()) {
Expand Down Expand Up @@ -301,6 +284,16 @@ bool AppContext::isActiveWidget(const WidgetCursor &widgetCursor) {
}

void AppContext::onPageTouch(const WidgetCursor &foundWidget, Event &touchEvent) {
int activePageId = getActivePageId();
if (!isPageInternal(activePageId)) {
const Widget *page = getPageWidget(activePageId);
const PageWidget *pageSpecific = GET_WIDGET_PROPERTY(page, specific, const PageWidget *);
if ((pageSpecific->flags & CLOSE_PAGE_IF_TOUCHED_OUTSIDE_FLAG) != 0) {
if (!pointInsideRect(touchEvent.x, touchEvent.y, g_appContext->x + page->x, g_appContext->y + page->y, page->w, page->h)) {
popPage();
}
}
}
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion src/eez/gui/app_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class AppContext {

virtual bool isAutoRepeatAction(int action);

bool isWidgetActionEnabled(const WidgetCursor &widgetCursor);
virtual bool isWidgetActionEnabled(const WidgetCursor &widgetCursor);

void updateAppView(WidgetCursor &widgetCursor);

Expand Down
31 changes: 0 additions & 31 deletions src/eez/gui/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

#include <eez/modules/psu/psu.h>
#include <eez/modules/psu/idle.h>
#include <eez/modules/psu/persist_conf.h>
#include <eez/modules/psu/gui/psu.h>

#define CONF_GUI_LONG_TOUCH_TIMEOUT 1000000L // 1s
#define CONF_GUI_KEYPAD_FIRST_AUTO_REPEAT_DELAY 300000L // 300ms
Expand Down Expand Up @@ -125,29 +123,6 @@ void onWidgetDefaultTouch(const WidgetCursor &widgetCursor, Event &touchEvent) {
}

void onPageTouch(const WidgetCursor &foundWidget, Event &touchEvent) {
int activePageId = getActivePageId();

if (touchEvent.type == EVENT_TYPE_LONG_TOUCH) {
if (activePageId == INTERNAL_PAGE_ID_NONE || activePageId == PAGE_ID_STANDBY) {
// wake up on long touch
psu::changePowerState(true);
} else if (activePageId == PAGE_ID_DISPLAY_OFF) {
// turn ON display on long touch
psu::persist_conf::setDisplayState(1);
}
} else if (touchEvent.type == EVENT_TYPE_EXTRA_LONG_TOUCH) {
// start touch screen calibration in case of really long touch
showPage(PAGE_ID_TOUCH_CALIBRATION_INTRO);
} else if (!isPageInternal(activePageId)) {
const Widget *page = getPageWidget(activePageId);
const PageWidget *pageSpecific = GET_WIDGET_PROPERTY(page, specific, const PageWidget *);
if ((pageSpecific->flags & CLOSE_PAGE_IF_TOUCHED_OUTSIDE_FLAG) != 0) {
if (!pointInsideRect(touchEvent.x, touchEvent.y, g_appContext->x + page->x, g_appContext->y + page->y, page->w, page->h)) {
popPage();
}
}
}

g_appContext->onPageTouch(foundWidget, touchEvent);
}

Expand Down Expand Up @@ -214,12 +189,6 @@ void processTouchEvent(EventType type) {
m_onTouchFunction = getTouchFunction(m_foundWidgetAtDown);

if (!m_onTouchFunction) {
if (isFrontPanelLocked()) {
auto savedAppContext = g_appContext;
g_appContext = &psu::gui::g_psuAppContext;
errorMessage("Front panel is locked!");
g_appContext = savedAppContext;
}
m_onTouchFunction = onPageTouch;
}
}
Expand Down
55 changes: 0 additions & 55 deletions src/eez/gui/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@

#include <eez/modules/psu/psu.h>
#include <eez/modules/psu/persist_conf.h>
#include <eez/modules/psu/gui/psu.h>
#include <eez/modules/psu/gui/password.h>

#define CONF_GUI_BLINK_TIME 400 // 400ms

Expand Down Expand Up @@ -232,59 +230,6 @@ void executeAction(int actionId) {

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

void showWelcomePage() {
psu::gui::g_psuAppContext.showPageOnNextIter(PAGE_ID_WELCOME);
}

void showEnteringStandbyPage() {
psu::gui::g_psuAppContext.showPageOnNextIter(PAGE_ID_ENTERING_STANDBY);
}

void showStandbyPage() {
psu::gui::g_psuAppContext.showPageOnNextIter(PAGE_ID_STANDBY);
}

void showSavingPage() {
psu::gui::g_psuAppContext.showPageOnNextIter(PAGE_ID_SAVING);
}

void showShutdownPage() {
psu::gui::g_psuAppContext.showPageOnNextIter(PAGE_ID_SHUTDOWN);
}

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

static void doUnlockFrontPanel() {
popPage();

psu::persist_conf::lockFrontPanel(false);
infoMessage("Front panel is unlocked!");
}

static void checkPasswordToUnlockFrontPanel() {
psu::gui::checkPassword("Password: ", psu::persist_conf::devConf.systemPassword, doUnlockFrontPanel);
}

void lockFrontPanel() {
psu::persist_conf::lockFrontPanel(true);
infoMessage("Front panel is locked!");
}

void unlockFrontPanel() {
if (strlen(psu::persist_conf::devConf.systemPassword) > 0) {
checkPasswordToUnlockFrontPanel();
} else {
psu::persist_conf::lockFrontPanel(false);
infoMessage("Front panel is unlocked!");
}
}

bool isFrontPanelLocked() {
return psu::g_rlState != psu::RL_STATE_LOCAL;
}

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

using namespace mcu::display;

AnimationState g_animationState;
Expand Down
10 changes: 0 additions & 10 deletions src/eez/gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,9 @@ void executeAction(int actionId);

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

void showWelcomePage();
void showStandbyPage();
void showEnteringStandbyPage();
void showSavingPage();
void showShutdownPage();

void standBy();
void reset();

void lockFrontPanel();
void unlockFrontPanel();
bool isFrontPanelLocked();

enum Buffer {
BUFFER_OLD,
BUFFER_NEW,
Expand Down
Loading

0 comments on commit fa92881

Please sign in to comment.