Library to handle SpaceBall, SpaceMouse and SpaceOrb on serial port. Gets access to 3D rotation and translation vector as well as button status. (USB is not supported)

Dependents:   SpaceBall_Example

Library to handle SpaceBall, SpaceMouse and SpaceOrb on serial port. Gets access to 3D rotation and translation vector as well as button status. (USB is not supported)

All handling and decoding is done in the RX interrupt and the vector values can be read out asynchronously with different coordinate mappings.

Example:

#include "mbed.h"
#include "SpaceBall.h"
 
PwmOut led[] = {(LED1), (LED2), (LED3), (LED4) };
SpaceBall SBall(p9, p10);   // tx, rx, bSOrb
 
int main() {
    SBall.Init();
    
    while(1) {
 
        led[0] = abs( SBall[TX] ) + abs( SBall[TY] ) + abs( SBall[TZ] );
        led[1] = abs( SBall[RX] );
        led[2] = abs( SBall[RY] );
        led[3] = abs( SBall[RZ] );
        
        wait_us(500);
    }
}

In this exaple the 4 LEDs are powered dependent on force at the Spaceball. LED1 shows the sum of all translation forces. LED2 to LED4 shows the rotation forces.

For more information about SpaceBall devices see manufactorers page http://www.3dconnexion.com

For connecting a SpaceBall (or SpaceMouse or SpaceOrb) to mbed see page wiki/Serial-Connection

Example: SpaceBall 4000

/media/uploads/jocis/spaceball1.jpg

Files at this revision

API Documentation at this revision

Comitter:
jocis
Date:
Tue Sep 02 09:34:06 2014 +0000
Parent:
2:a7c0fcd157f7
Child:
4:f953792e45cb
Commit message:
Initial commit

Changed in this revision

SpaceBall.cpp Show annotated file Show diff for this revision Revisions of this file
SpaceBall.h Show annotated file Show diff for this revision Revisions of this file
--- a/SpaceBall.cpp	Sat Dec 01 21:38:49 2012 +0000
+++ b/SpaceBall.cpp	Tue Sep 02 09:34:06 2014 +0000
@@ -1,7 +1,7 @@
 #include "SpaceBall.h"
 
 #define Sleep(x) wait_ms(x*10)
-extern Serial pc;
+//extern Serial pc;
 
 ///////////////////////////////////////////////////////////////////////////////
 
@@ -26,7 +26,7 @@
     m_spaceball4000 = 0; /* if set, its a Spaceball 4000 */
     m_leftymode4000 = 0; /* if set, Spaceball 4000 in "lefty" orientation */
 
-
+    _mapping = 1;
     _escape = false;
     _idx = 0;
     
--- a/SpaceBall.h	Sat Dec 01 21:38:49 2012 +0000
+++ b/SpaceBall.h	Tue Sep 02 09:34:06 2014 +0000
@@ -1,3 +1,25 @@
+/* mbed SpaceBall, SpaceMouse and SpaceOrb Library
+ * Copyright (c) 2012 Jochen Krapf
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+ 
 #include "mbed.h"
 
 /* Spaceball Button bit-masks */
@@ -45,13 +67,26 @@
 enum eSpaceBallMapping { 
     RAW=0, CNC, CNCvert };
 
-
+/** SpaceBall class, based on serial connection
+ *
+ * Example:
+ * @code
+ * @endcode
+ */
 class SpaceBall {
 public:
     
+    /** Create a input object connected to the specified serial pin
+     *
+     * @param pin PwmOut pin to connect to 
+     */
     SpaceBall ( PinName tx, PinName rx, bool bSpaceOrb=false );
     ~SpaceBall() {};
 
+    /** ...
+     *
+     * @param xxx ...
+     */
     void Init();
     
     void SetMapping ( int mapping )