Skip to content

Commit

Permalink
user switch and jpeg screenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Nov 15, 2019
1 parent dadd1ee commit afab979
Show file tree
Hide file tree
Showing 45 changed files with 1,295 additions and 258 deletions.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,18 @@ set(header_eez_libs_sd_fat
list (APPEND header_files ${header_eez_libs_sd_fat})
source_group("eez\\libs\\sd_fat" FILES ${src_eez_libs_sd_fat} ${header_eez_libs_sd_fat})

set(src_eez_libs_image
src/eez/libs/image/jpeg_encode.cpp
src/eez/libs/image/toojpeg.cpp
)
list (APPEND src_files ${src_eez_libs_image})
set(header_eez_libs_image
src/eez/libs/image/jpeg_encode.h
src/eez/libs/image/toojpeg.h
)
list (APPEND header_files ${src_eez_libs_image})
source_group("eez\\libs\\image" FILES ${src_eez_libs_image} ${header_eez_libs_image})

set(src_eez_modules_aux_ps
src/eez/modules/aux_ps/fan.cpp
src/eez/modules/aux_ps/pid.cpp
Expand Down
3 changes: 3 additions & 0 deletions modular-psu-firmware.eez-project
Original file line number Diff line number Diff line change
Expand Up @@ -2450,6 +2450,9 @@
},
{
"name": "show_recordings_view"
},
{
"name": "select_user_switch_action"
}
],
"extensionDefinitions": [
Expand Down
74 changes: 66 additions & 8 deletions src/eez/gui/action_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,24 +991,82 @@ void action_scripts_next_page() {
}

void action_user_switch_clicked() {
#if OPTION_ENCODER

#if EEZ_PLATFORM_SIMULATOR
AppContext *saved = g_appContext;
g_appContext = &psu::gui::g_psuAppContext;
#endif

if (getActivePageId() == PAGE_ID_EDIT_MODE_STEP) {
psu::gui::edit_mode_step::switchToNextStepIndex();
} else {
mcu::encoder::switchEncoderMode();
psu::gui::edit_mode_step::showCurrentEncoderMode();
switch (persist_conf::devConf.userSwitchAction) {
case persist_conf::USER_SWITCH_ACTION_NONE:
break;

case persist_conf::USER_SWITCH_ACTION_ENCODER_STEP:
#if OPTION_ENCODER
if (getActivePageId() == PAGE_ID_EDIT_MODE_STEP) {
psu::gui::edit_mode_step::switchToNextStepIndex();
} else {
mcu::encoder::switchEncoderMode();
psu::gui::edit_mode_step::showCurrentEncoderMode();
}
#endif
break;

case persist_conf::USER_SWITCH_ACTION_SCREENSHOT:
#if OPTION_SD_CARD
using namespace scpi;
osMessagePut(g_scpiMessageQueueId, SCPI_QUEUE_MESSAGE(SCPI_QUEUE_MESSAGE_TARGET_NONE, SCPI_QUEUE_MESSAGE_SCREENSHOT, 0), osWaitForever);
#endif
break;

case persist_conf::USER_SWITCH_ACTION_MANUAL_TRIGGER:
action_trigger_generate_manual();
break;

case persist_conf::USER_SWITCH_ACTION_OUTPUT_ENABLE:
for (int i = 0; i < CH_NUM; ++i) {
Channel &channel = Channel::get(i);
if (channel.flags.trackingEnabled) {
channel_dispatcher::outputEnable(channel, !channel.isOutputEnabled());
return;
}
}
infoMessage("Tracking is not enabled.");
break;

case persist_conf::USER_SWITCH_ACTION_HOME:
if (g_appContext->getNumPagesOnStack() > 1) {
action_show_previous_page();
} else {
showMainPage();
}
break;

case persist_conf::USER_SWITCH_ACTION_INHIBIT:
io_pins::setIsInhibitedByUser(!io_pins::getIsInhibitedByUser());
break;

case persist_conf::USER_SWITCH_ACTION_SELECTED_ACTION:
// TODO
break;
}
}

void onSetUserSwitchAction(uint16_t value) {
popPage();
persist_conf::setUserSwitchAction((persist_conf::UserSwitchAction)value);
}

void action_select_user_switch_action() {
#if EEZ_PLATFORM_SIMULATOR
g_appContext = saved;
AppContext *saved = g_appContext;
g_appContext = &psu::gui::g_psuAppContext;
#endif

clearFoundWidgetAtDown();
pushSelectFromEnumPage(g_userSwitchActionEnumDefinition, persist_conf::devConf.userSwitchAction, nullptr, onSetUserSwitchAction);

#if EEZ_PLATFORM_SIMULATOR
g_appContext = saved;
#endif
}

Expand Down
13 changes: 13 additions & 0 deletions src/eez/gui/app_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ void AppContext::stateManagment() {
return;
}
}

if (m_showInfoMessageOnNextIter) {
gui::infoMessage(m_showInfoMessageOnNextIter);
m_showInfoMessageOnNextIter = nullptr;
}
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -420,6 +425,14 @@ void AppContext::updateAppView(WidgetCursor &widgetCursor) {
}
}

int AppContext::getLongTouchActionHook(const WidgetCursor &widgetCursor) {
return ACTION_ID_NONE;
}

void AppContext::infoMessage(const char *message) {
m_showInfoMessageOnNextIter = message;
}

} // namespace gui
} // namespace eez

Expand Down
17 changes: 13 additions & 4 deletions src/eez/gui/app_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,15 @@ class AppContext {

void updateAppView(WidgetCursor &widgetCursor);

protected:
virtual int getMainPageId() = 0;
virtual void onPageChanged(int previousPageId, int activePageId);
virtual int getLongTouchActionHook(const WidgetCursor &widgetCursor);

int getNumPagesOnStack() {
return m_pageNavigationStackPointer + 1;
}

//
void infoMessage(const char *message);

protected:
PageOnStack m_pageNavigationStack[CONF_GUI_PAGE_NAVIGATION_STACK_SIZE];
int m_pageNavigationStackPointer = 0;
int m_activePageIndex;
Expand All @@ -119,6 +123,11 @@ class AppContext {

SelectFromEnumPage m_selectFromEnumPage;

const char *m_showInfoMessageOnNextIter;

virtual int getMainPageId() = 0;
virtual void onPageChanged(int previousPageId, int activePageId);

void doShowPage(int index, Page *page, int previousPageId);
void setPage(int pageId);

Expand Down
6 changes: 5 additions & 1 deletion src/eez/gui/dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ void pushToastMessage(ToastMessagePage *toastMessage) {
}

void infoMessage(const char *message) {
pushToastMessage(ToastMessagePage::create(INFO_TOAST, message));
if (osThreadGetId() != g_guiTaskHandle) {
eez::psu::gui::g_psuAppContext.infoMessage(message);
} else {
pushToastMessage(ToastMessagePage::create(INFO_TOAST, message));
}
}

void infoMessage(data::Value value) {
Expand Down
14 changes: 14 additions & 0 deletions src/eez/gui/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ WidgetCursor &getFoundWidgetAtDown() {
return m_foundWidgetAtDown;
}

void clearFoundWidgetAtDown() {
m_foundWidgetAtDown = WidgetCursor();
}

bool isActiveWidget(const WidgetCursor &widgetCursor) {
if (widgetCursor.appContext->isActiveWidget(widgetCursor)) {
return true;
Expand All @@ -77,6 +81,10 @@ int getAction(const WidgetCursor &widgetCursor) {
}

void onWidgetDefaultTouch(const WidgetCursor &widgetCursor, Event &touchEvent) {
if (!widgetCursor.widget) {
return;
}

if (touchEvent.type == EVENT_TYPE_TOUCH_DOWN) {
m_touchActionExecuted = false;
m_touchActionExecutedAtDown = false;
Expand Down Expand Up @@ -105,6 +113,12 @@ void onWidgetDefaultTouch(const WidgetCursor &widgetCursor, Event &touchEvent) {
m_touchActionExecuted = true;
executeAction(action);
}
} else if (touchEvent.type == EVENT_TYPE_LONG_TOUCH) {
m_touchActionExecuted = true;
int action = widgetCursor.appContext->getLongTouchActionHook(widgetCursor);
if (action != ACTION_ID_NONE) {
executeAction(action);
}
} else if (touchEvent.type == EVENT_TYPE_TOUCH_UP) {
if (!m_touchActionExecutedAtDown) {
m_activeWidget = 0;
Expand Down
4 changes: 4 additions & 0 deletions src/eez/gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#pragma once

#include <cmsis_os.h>

#include <eez/gui/assets.h>
#include <eez/gui/data.h>
#include <eez/gui/page.h>
Expand All @@ -41,11 +43,13 @@ bool onSystemStateChanged();

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

extern osThreadId g_guiTaskHandle;
extern bool g_isBlinkTime;

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

WidgetCursor &getFoundWidgetAtDown();
void clearFoundWidgetAtDown();
bool isActiveWidget(const WidgetCursor &widgetCursor);
uint32_t getShowPageTime();
void setShowPageTime(uint32_t time);
Expand Down
Loading

0 comments on commit afab979

Please sign in to comment.