Control library for the Sparkfun Entertainment Trackballer breakout board.

Files at this revision

API Documentation at this revision

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
diff -r d566efcd787b -r a66aea99500e trackballer.cpp
--- 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
     {
diff -r d566efcd787b -r a66aea99500e trackballer.h
--- 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;