Added ButtonTracker class for synchronous detection of rising and trailing edges in button states #89

Open
wants to merge 1 commit into
from

Projects

None yet

3 participants

@calcmogul
Member
calcmogul commented May 29, 2016 edited

This change is Reviewable

@PeterJohnson PeterJohnson commented on an outdated diff Jun 21, 2016
wpilibc/athena/src/ButtonTracker.cpp
+ GetButtonState(m_newStates, button) == true;
+}
+
+/**
+ * @param buttonStates button statuses received from Driver Station.
+ * @param button The button number to be checked (starting at 1).
+ * @return true if button is currently pressed.
+ */
+bool ButtonTracker::GetButtonState(uint32_t buttonStates, uint32_t button) {
+ return ((1 << (button - 1)) & buttonStates) != 0;
+}
+
+/**
+ * Gets new button statuses for joystick from Driver Station.
+ *
+ * This should be called once per loop iteration in operatorControl().
@PeterJohnson
PeterJohnson Jun 21, 2016 Member

operatorControl in C++ should be OperatorControl, and vice-versa in Java (currently this is backwards).

+ */
+ public boolean pressedButton(int button) {
+ return getButtonState(m_oldStates, button) == false
+ && getButtonState(m_newStates, button) == true;
@AustinShalit
AustinShalit Nov 22, 2016 Member

Could be:

return !getButtonState(m_oldStates, button)
    && getButtonState(m_newStates, button);
+ */
+ public boolean releasedButton(int button) {
+ return getButtonState(m_oldStates, button) == true
+ && getButtonState(m_newStates, button) == false;
@AustinShalit
AustinShalit Nov 22, 2016 Member

Could be:

return getButtonState(m_oldStates, button)
    && !getButtonState(m_newStates, button);
+ */
+ public boolean heldButton(int button) {
+ return getButtonState(m_oldStates, button) == true
+ && getButtonState(m_newStates, button) == true;
@AustinShalit
AustinShalit Nov 22, 2016 Member

Could be:

return getButtonState(m_oldStates, button)
    && getButtonState(m_newStates, button);
@calcmogul calcmogul Added ButtonTracker class for synchronous detection of rising and tra…
…iling edges in button states
71abe69
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment