Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset displayed spindle angle with SET long press #4

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions els-f280049c/UserInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ MESSAGE BEGIN =
.displayTime = UI_REFRESH_RATE_HZ * 0.2
};


const Uint16 SET_HOLD_SECONDS = 1;

const Uint16 VALUE_BLANK[4] = { BLANK, BLANK, BLANK, BLANK };

Expand All @@ -142,6 +142,9 @@ UserInterface :: UserInterface(ControlPanel *controlPanel, Core *core, FeedTable

this->isInMenu = false;

this->setHoldTime = 0.0;
this->setHeld = false;

// initialize the core so we start up correctly
core->setReverse(this->reverse);
core->setFeed(loadFeedTable());
Expand Down Expand Up @@ -218,7 +221,7 @@ void UserInterface :: loop( void )
Uint16 currentRpm = core->getRPM();

// read the current spindle position to keep this up to date
Uint16 currentSpindleAngle = encoder->getSpindleAngle();
Uint16 currentSpindleAngle = encoder->getSpindleAngle() + spindleAngleOffset % 3600;

// display an override message, if there is one
overrideMessage();
Expand Down Expand Up @@ -281,7 +284,43 @@ void UserInterface :: mainLoop( Uint16 currentRpm )
}
if( keys.bit.SET )
{
beginMenu();
if (showAngle) // or, later, showPosition for carriage position
{
if (setHoldTime == 0)
{
// start counting for short or long press
setHoldTime = UI_REFRESH_RATE_HZ * SET_HOLD_SECONDS;
setHeld = false;
}
else
{
setHoldTime--;
}
else
{
// !showAngle
beginMenu();
}
}
else
{
// !keys.bit.SET
if ( setHeld )
{
if ( setHoldTime <= 0 )
{
// set held for long press
spindleAngleOffset = encoder->getSpindleAngle();
setHeld = false;
}
else
{
// set released before timeout
setHoldTime = 0;
setHeld = false;
beginMenu();
}
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions els-f280049c/UserInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class UserInterface
bool isInMenu;
Uint16 menuState, menuSubState;

Uint16 setHoldTime;
bool setHeld;

int numStarts, currentStart;

FeedTable *feedTable;
Expand All @@ -63,6 +66,8 @@ class UserInterface
const MESSAGE *message;
Uint16 messageTime;

Uint16 spindleAngleOffset;

const FEED_THREAD *loadFeedTable();
LED_REG calculateLEDs();
void setMessage(const MESSAGE *message);
Expand Down