Skip to content

Commit

Permalink
Use enum for butten mode change
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeg-sfy committed Oct 14, 2021
1 parent 2162a3e commit d4ea94a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
10 changes: 9 additions & 1 deletion examples/window-app/common/include/WindowApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ class WindowApp
BLEConnectionsChanged,
};

enum ButtonCtrlMode
{
Tilt = 0,
Lift,
};

struct Event
{
Event(EventId id) : mId(id), mEndpoint(0) {}
Expand Down Expand Up @@ -154,8 +160,10 @@ class WindowApp
Timer * mLongPressTimer = nullptr;
Button * mButtonUp = nullptr;
Button * mButtonDown = nullptr;
ButtonCtrlMode mButtonCtrlMode;

StateFlags mState;
bool mTiltMode = false;

bool mUpPressed = false;
bool mDownPressed = false;
bool mUpSuppressed = false;
Expand Down
12 changes: 10 additions & 2 deletions examples/window-app/common/src/WindowApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ void WindowApp::DispatchEvent(const WindowApp::Event & event)
}
else if (mDownPressed)
{
mTiltMode = !mTiltMode;
if (ButtonCtrlMode::Tilt == mButtonCtrlMode)
mButtonCtrlMode = ButtonCtrlMode::Lift;
else
mButtonCtrlMode = ButtonCtrlMode::Tilt;

mUpSuppressed = mDownSuppressed = true;
PostEvent(EventId::TiltModeChange);
}
Expand Down Expand Up @@ -227,7 +231,11 @@ void WindowApp::DispatchEvent(const WindowApp::Event & event)
}
else if (mUpPressed)
{
mTiltMode = !mTiltMode;
if (ButtonCtrlMode::Tilt == mButtonCtrlMode)
mButtonCtrlMode = ButtonCtrlMode::Lift;
else
mButtonCtrlMode = ButtonCtrlMode::Tilt;

mUpSuppressed = mDownSuppressed = true;
PostEvent(EventId::TiltModeChange);
}
Expand Down
8 changes: 7 additions & 1 deletion examples/window-app/efr32/src/WindowAppImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,13 @@ void WindowAppImpl::DispatchEvent(const WindowApp::Event & event)
break;
case EventId::TiltModeChange:
mIconTimer.Start();
mIcon = mTiltMode ? LcdIcon::Tilt : LcdIcon::Lift;
switch (mButtonCtrlMode)
{
case ButtonCtrlMode::Tilt: mIcon = LcdIcon::Tilt; break;
case ButtonCtrlMode::Lift: mIcon = LcdIcon::Lift; break;
default:
break;
}
UpdateLCD();
break;
default:
Expand Down

0 comments on commit d4ea94a

Please sign in to comment.