Control library for the Sparkfun Entertainment Trackballer breakout board.

Revision:
15:a66aea99500e
Parent:
14:d566efcd787b
--- 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
     {