Skip to content

Commit

Permalink
only encoder down will close popup with action
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Jan 17, 2020
1 parent 672ac28 commit 414e317
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 78 deletions.
22 changes: 12 additions & 10 deletions src/eez/gui/page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ void Page::pageFree() {
void Page::pageWillAppear() {
}

bool Page::onEncoder(int counter) {
return false;
void Page::onEncoder(int counter) {
}

bool Page::onEncoderClicked() {
return false;
void Page::onEncoderClicked() {
}

Unit Page::getEncoderUnit() {
Expand Down Expand Up @@ -188,14 +186,18 @@ ToastMessagePage *ToastMessagePage::create(ToastType type, const char *message,
return page;
}

bool ToastMessagePage::onEncoder(int counter) {
popPage();
return false;
void ToastMessagePage::onEncoder(int counter) {
if (counter < 0) {
popPage();
}
}

bool ToastMessagePage::onEncoderClicked() {
popPage();
return false;
void ToastMessagePage::onEncoderClicked() {
if (hasAction()) {
eez::gui::executeAction((int)(int16_t)actionWidget.action);
} else {
popPage();
}
}

void ToastMessagePage::refresh(const WidgetCursor& widgetCursor) {
Expand Down
8 changes: 4 additions & 4 deletions src/eez/gui/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class Page {

virtual void pageWillAppear();

virtual bool onEncoder(int counter);
virtual bool onEncoderClicked();
virtual void onEncoder(int counter);
virtual void onEncoderClicked();
virtual Unit getEncoderUnit();

virtual int getDirty();
Expand Down Expand Up @@ -89,8 +89,8 @@ class ToastMessagePage : public InternalPage {

void pageFree();

bool onEncoder(int counter);
bool onEncoderClicked();
void onEncoder(int counter);
void onEncoderClicked();

void refresh(const WidgetCursor& widgetCursor);
void updatePage(const WidgetCursor& widgetCursor);
Expand Down
13 changes: 4 additions & 9 deletions src/eez/modules/psu/gui/numeric_keypad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,26 +579,24 @@ void NumericKeypad::cancel() {

#if OPTION_ENCODER

bool NumericKeypad::onEncoderClicked() {
void NumericKeypad::onEncoderClicked() {
if (m_state == START) {
if (getActivePageId() == PAGE_ID_EDIT_MODE_KEYPAD) {
return false;
return;
}
}
ok();
return true;
}

bool NumericKeypad::onEncoder(int counter) {
void NumericKeypad::onEncoder(int counter) {
if (m_state == START) {
if (getActivePageId() == PAGE_ID_EDIT_MODE_KEYPAD) {
return false;
return;
}

if (m_startValue.getType() == VALUE_TYPE_FLOAT) {
float newValue = mcu::encoder::increment(m_startValue, counter, m_options.min, m_options.max, m_options.channelIndex, 0.01f);
m_startValue = MakeValue(newValue, m_startValue.getUnit());
return true;
} else if (m_startValue.getType() == VALUE_TYPE_INT) {
int newValue = m_startValue.getInt() + counter;

Expand All @@ -611,13 +609,10 @@ bool NumericKeypad::onEncoder(int counter) {
}

m_startValue = data::Value(newValue);

return true;
}
}

sound::playBeep();
return true;
}

#endif
Expand Down
4 changes: 2 additions & 2 deletions src/eez/modules/psu/gui/numeric_keypad.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ class NumericKeypad : public Keypad {
void cancel();

#if OPTION_ENCODER
bool onEncoderClicked();
bool onEncoder(int counter);
void onEncoderClicked();
void onEncoder(int counter);
#endif

Unit getSwitchToUnit();
Expand Down
15 changes: 5 additions & 10 deletions src/eez/modules/psu/gui/page_ch_settings_trigger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ void ChSettingsListsPage::set() {
}
}

bool ChSettingsListsPage::onEncoder(int counter) {
void ChSettingsListsPage::onEncoder(int counter) {
#if OPTION_ENCODER
data::Cursor cursor(getCursorIndexWithinPage());
uint16_t dataId = getDataIdAtCursor();
Expand All @@ -497,32 +497,29 @@ bool ChSettingsListsPage::onEncoder(int counter) {
float newValue = mcu::encoder::increment(value, counter, min.getFloat(), max.getFloat(), g_channel->channelIndex, 0);

setFocusedValue(newValue);

return true;
#endif
return false;
}

bool ChSettingsListsPage::onEncoderClicked() {
void ChSettingsListsPage::onEncoderClicked() {
uint16_t dataId = getDataIdAtCursor();
int iRow = getRowIndex();

if (dataId == DATA_ID_CHANNEL_LIST_DWELL) {
if (iRow <= m_voltageListLength) {
m_iCursor += 1;
return true;
return;
}

if (iRow <= m_currentListLength) {
m_iCursor += 2;
return true;
return;
}

m_iCursor += 3;
} else if (dataId == DATA_ID_CHANNEL_LIST_VOLTAGE) {
if (iRow <= m_currentListLength) {
m_iCursor += 1;
return true;
return;
}

m_iCursor += 2;
Expand All @@ -531,8 +528,6 @@ bool ChSettingsListsPage::onEncoderClicked() {
}

moveCursorToFirstAvailableCell();

return true;
}

Unit ChSettingsListsPage::getEncoderUnit() {
Expand Down
4 changes: 2 additions & 2 deletions src/eez/modules/psu/gui/page_ch_settings_trigger.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ class ChSettingsListsPage : public SetPage {
int getDirty();
void set();

bool onEncoder(int counter);
bool onEncoderClicked();
void onEncoder(int counter);
void onEncoderClicked();
Unit getEncoderUnit();

void showInsertMenu();
Expand Down
57 changes: 16 additions & 41 deletions src/eez/modules/psu/gui/psu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1210,38 +1210,21 @@ void onEncoder(int counter, bool clicked) {
int activePageId = getActivePageId();

if (activePageId == PAGE_ID_EDIT_MODE_KEYPAD || activePageId == PAGE_ID_NUMERIC_KEYPAD) {
if (((NumericKeypad *)getActiveKeypad())->onEncoder(counter)) {
return;
}
((NumericKeypad *)getActiveKeypad())->onEncoder(counter);
}

#if defined(EEZ_PLATFORM_SIMULATOR)
if (activePageId == PAGE_ID_FRONT_PANEL_NUMERIC_KEYPAD) {
if (((NumericKeypad *)getActiveKeypad())->onEncoder(counter)) {
return;
}
else if (activePageId == PAGE_ID_FRONT_PANEL_NUMERIC_KEYPAD) {
((NumericKeypad *)getActiveKeypad())->onEncoder(counter);
}
#endif

if (activePageId == PAGE_ID_EDIT_MODE_STEP) {
else if (activePageId == PAGE_ID_EDIT_MODE_STEP) {
edit_mode_step::onEncoder(counter);
return;
}

if (activePageId == PAGE_ID_FILE_MANAGER) {
} else if (activePageId == PAGE_ID_FILE_MANAGER) {
file_manager::onEncoder(counter);
return;
}

if (activePageId == PAGE_ID_DEBUG_TRACE_LOG) {
} else if (activePageId == PAGE_ID_DEBUG_TRACE_LOG) {
eez::debug::onEncoder(counter);
return;
}

if (activePage) {
if (activePage->onEncoder(counter)) {
return;
}
} else if (activePage) {
activePage->onEncoder(counter);
}
}

Expand All @@ -1260,26 +1243,18 @@ void onEncoder(int counter, bool clicked) {
}

sound::playClick();
}

int activePageId = getActivePageId();
if (activePageId == PAGE_ID_EDIT_MODE_KEYPAD || activePageId == PAGE_ID_NUMERIC_KEYPAD) {
if (((NumericKeypad *)getActiveKeypad())->onEncoderClicked()) {
return;
} else {
int activePageId = getActivePageId();
if (activePageId == PAGE_ID_EDIT_MODE_KEYPAD || activePageId == PAGE_ID_NUMERIC_KEYPAD) {
((NumericKeypad *)getActiveKeypad())->onEncoderClicked();
}
}

#if defined(EEZ_PLATFORM_SIMULATOR)
if (activePageId == PAGE_ID_FRONT_PANEL_NUMERIC_KEYPAD) {
if (((NumericKeypad *)getActiveKeypad())->onEncoderClicked()) {
return;
else if (activePageId == PAGE_ID_FRONT_PANEL_NUMERIC_KEYPAD) {
((NumericKeypad *)getActiveKeypad())->onEncoderClicked();
}
}
#endif

if (activePage) {
if (activePage->onEncoderClicked()) {
return;
else if (activePage) {
activePage->onEncoderClicked();
}
}
}
Expand Down

0 comments on commit 414e317

Please sign in to comment.