Control library for the Sparkfun Entertainment Trackballer breakout board.
Revision 6:c0ebd0f8f873, committed 2011-02-19
- Comitter:
- Nakor
- Date:
- Sat Feb 19 20:31:43 2011 +0000
- Parent:
- 5:0abcaea1fb07
- Child:
- 7:229fc175e05e
- 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 Sat Feb 19 19:57:07 2011 +0000 +++ b/trackballer.cpp Sat Feb 19 20:31:43 2011 +0000 @@ -4,9 +4,11 @@ -trackballer::trackballer(PinName button, PinName right, PinName down, PinName left, PinName up, PinName red, PinName green, PinName blue, PinName white) +trackballer::trackballer(PinName button, PinName right, PinName down, PinName left, PinName up, PinName red, PinName green, PinName blue, PinName white, char limits) { + _limits = limits; + _buttonPin = new DigitalIn(button); _rightPin = new DigitalIn(right); _downPin = new DigitalIn(down); @@ -99,9 +101,12 @@ // if the current state is 1 then the button // went from off to on: _yPosition-=TRACK_INC; - if (_yPosition < 0.0) + if(_limits) { - _yPosition = 0.0; + if (_yPosition < 0.0) + { + _yPosition = 0.0; + } } } } @@ -119,9 +124,12 @@ // if the current state is 1 then the button // went from off to on: _yPosition+=TRACK_INC; - if (_yPosition > 1.0) + if(_limits) { - _yPosition = 1.0; + if (_yPosition > 1.0) + { + _yPosition = 1.0; + } } } } @@ -139,9 +147,12 @@ // if the current state is 1 then the button // went from off to on: _xPosition-=TRACK_INC; - if (_xPosition < 0.0) + if(_limits) { - _xPosition = 0.0; + if (_xPosition < 0.0) + { + _xPosition = 0.0; + } } } } @@ -158,9 +169,12 @@ // if the current state is 1 then the button // went from off to on: _xPosition+=TRACK_INC; - if (_xPosition > 1.0) + if(_limits) { - _xPosition = 1.0; + if (_xPosition > 1.0) + { + _xPosition = 1.0; + } } } } @@ -173,9 +187,13 @@ yPosition = _yPosition; + + #if DEBUG_POSITION int ixPosition = _xPosition * 95; int iyPosition = _yPosition * 63; + + if (_outputTimer.read_ms() > 1000) { printf("Position: (x%i, y%i)\n", ixPosition, iyPosition); @@ -183,5 +201,6 @@ _outputTimer.reset(); } + #endif } \ No newline at end of file
--- a/trackballer.h Sat Feb 19 19:57:07 2011 +0000 +++ b/trackballer.h Sat Feb 19 20:31:43 2011 +0000 @@ -17,6 +17,8 @@ #define TRACK_INC 0.01 +#define DEBUG_POSITION 0 + class trackballer { @@ -26,7 +28,7 @@ - trackballer(PinName button, PinName right, PinName down, PinName left, PinName up, PinName red, PinName green, PinName blue, PinName white); + trackballer(PinName button, PinName right, PinName down, PinName left, PinName up, PinName red, PinName green, PinName blue, PinName white, char limits = 0x00); void getState(float &xPosition, float &yPosition, char &button); @@ -66,6 +68,7 @@ char _direction; + char _limits; };