Interface to access to Avago ADNS-9500 laser mouse sensors.

Fork of ADNS9500 by Chris Majoros

Revision:
17:af2fb65ee807
Parent:
16:de76a70defb3
--- a/adns9500.cpp	Wed Dec 12 03:16:18 2012 +0000
+++ b/adns9500.cpp	Thu Mar 14 13:14:51 2013 +0000
@@ -283,7 +283,7 @@
         ncs_.write(1);
     }
     
-    bool ADNS9500::getMotionDelta(int& dx, int& dy)
+    bool ADNS9500::getMotionDelta(int16_t& dx, int16_t& dy)
     {
         if (! enabled_)
             error("ADNS9500::getMotionDelta : the sensor is not enabled\n");
@@ -315,7 +315,7 @@
     
     bool ADNS9500::getMotionDeltaMM(float& dx, float& dy)
     {
-        int rawDx, rawDy;
+        int16_t rawDx, rawDy;
         bool motion = getMotionDelta(rawDx, rawDy);
         dx = (float)rawDx / xCpi_ * 25.4;
         dy = (float)rawDy / yCpi_ * 25.4;
@@ -375,19 +375,13 @@
         return ADNS9500_IF_MOTION(data.motion);
     }
     
-    void ADNS9500::setResolution( int xy_cpi )
+    void ADNS9500::setResolution( uint16_t cpi_xy )
     {
         
         if (! enabled_)
             error("ADNS9500::setResolution : the sensor is not enabled\n");
-        //FIXME
-        int xy_res = xy_cpi / 90;
-        if( xy_res < 0x01 ){
-            xy_res = 0x01;
-        }
-        if( xy_res > 0x38 ){
-            xy_res = 0x38;
-        }
+
+        int res_xy = cpi_to_res(cpi_xy);
         
         ncs_.write(0);
         WAIT_TNCSSCLK();
@@ -400,20 +394,23 @@
 
         // set resolution for X-axis and Y-axis
         WAIT_TSWW();
-        spiSend(CONFIGURATION_I, xy_res);
+        spiSend(CONFIGURATION_I, res_xy);
 
         WAIT_TSCLKNCS();
         ncs_.write(1);
         
-        xCpi_ = xy_res * CPI_CHANGE_UNIT;
-        yCpi_ = xy_res * CPI_CHANGE_UNIT;
+        xCpi_ = res_xy * CPI_CHANGE_UNIT;
+        yCpi_ = res_xy * CPI_CHANGE_UNIT;
     }
     
-    void ADNS9500::setResolution(Resolution x_resolution, Resolution y_resolution)
+    void ADNS9500::setResolution(uint16_t cpi_x, uint16_t cpi_y)
     {
         if (! enabled_)
             error("ADNS9500::setResolution : the sensor is not enabled\n");
-            
+        
+        int res_x = cpi_to_res(cpi_x);
+        int res_y = cpi_to_res(cpi_y);
+           
         ncs_.write(0);
         WAIT_TNCSSCLK();
 
@@ -425,17 +422,17 @@
         
         // set resolution for X-axis
         WAIT_TSWW();
-        spiSend(CONFIGURATION_I, x_resolution);
+        spiSend(CONFIGURATION_I, res_x);
                 
         // set resolution for Y-axis
         WAIT_TSWW();
-        spiSend(CONFIGURATION_V, y_resolution);
+        spiSend(CONFIGURATION_V, res_y);
 
         WAIT_TSCLKNCS();
         ncs_.write(1);
 
-        xCpi_ = x_resolution * CPI_CHANGE_UNIT;
-        yCpi_ = y_resolution * CPI_CHANGE_UNIT;
+        xCpi_ = res_x * CPI_CHANGE_UNIT;
+        yCpi_ = res_y * CPI_CHANGE_UNIT;
     }
     
     void ADNS9500::captureFrame(uint8_t* pixels)