Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 15:a66aea99500e, committed 2011-02-20
- Comitter:
- Nakor
- Date:
- Sun Feb 20 18:05:08 2011 +0000
- Parent:
- 14:d566efcd787b
- Commit message:
Changed in this revision
trackballer.cpp | Show annotated file Show diff for this revision Revisions of this file |
trackballer.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/trackballer.cpp Sun Feb 20 17:33:59 2011 +0000 +++ b/trackballer.cpp Sun Feb 20 18:05:08 2011 +0000 @@ -62,6 +62,9 @@ void trackballer::getState(float &xPosition, float &yPosition, char &button) { + char heldState = 0x00; + char isHeld = 0x00; + char exitWhile = 0x00; _buttonState = _buttonPin->read(); @@ -74,6 +77,8 @@ // if the state has changed, increment the counter if (_buttonState == 1) { + + /* while(_buttonPin->read() == _buttonState) { @@ -92,6 +97,40 @@ button = 0x01; //printf("Number of button pushes: %i\n", _buttonPushCounter); } + else if(_buttonState == 0) + { + _holdTimer.start(); + while(_holdTimer.read() < 2.0 && !exitWhile) + { + heldState = !_buttonPin->read(); + + if(heldState == 0) + { + isHeld = 0x00; + exitWhile = 0x01; + } + else + { + if(_holdTimer.read() > 1.0) + { + isHeld = 0x01; + exitWhile = 0x01; + } + } + + + } + + _holdTimer.stop(); + _holdTimer.reset(); + + if(isHeld) + { + printf("HELD\n"); + button = 0x03; + return; + } + } } else {
--- a/trackballer.h Sun Feb 20 17:33:59 2011 +0000 +++ b/trackballer.h Sun Feb 20 18:05:08 2011 +0000 @@ -38,6 +38,7 @@ protected: Timer _outputTimer; + Timer _holdTimer; DigitalIn * _buttonPin; DigitalIn * _rightPin;