Adjusts the great pinscape controller to work with a cheap linear potentiometer instead of the expensive CCD array

Dependencies:   USBDevice mbed

Fork of Pinscape_Controller by Mike R

Files at this revision

API Documentation at this revision

Comitter:
lemming
Date:
Tue Feb 24 05:25:41 2015 +0000
Parent:
14:df700b22ca08
Commit message:
Adjusted pinscape to work with a cheap linear potentiometer instead of a CCD array

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Sep 26 20:51:02 2014 +0000
+++ b/main.cpp	Tue Feb 24 05:25:41 2015 +0000
@@ -291,6 +291,9 @@
 DigitalIn calBtn(PTE29);
 DigitalOut calBtnLed(PTE23);
 
+//potentiometer slider
+AnalogIn potSlider(PTB0);
+
 // Joystick button input pin assignments.  You can wire up to
 // 32 GPIO ports to buttons (equipped with momentary switches).
 // Connect each switch between the desired GPIO port and ground
@@ -1259,9 +1262,6 @@
     // create the accelerometer object
     Accel accel(MMA8451_SCL_PIN, MMA8451_SDA_PIN, MMA8451_I2C_ADDRESS, MMA8451_INT_PIN);
     
-    // create the CCD array object
-    TSL1410R ccd(PTE20, PTE21, PTB0);
-    
     // last accelerometer report, in mouse coordinates
     int x = 0, y = 0, z = 0;
     
@@ -1276,9 +1276,6 @@
     // to return the plunger to rest, then we monitor the real plunger 
     // until it atcually stops.
     int firing = 0;
-
-    // start the first CCD integration cycle
-    ccd.clear();
     
     // Device status.  We report this on each update so that the host config
     // tool can detect our current settings.  This is a bit mask consisting
@@ -1286,9 +1283,7 @@
     //    0x01  -> plunger sensor enabled
     uint16_t statusFlags = (cfg.d.ccdEnabled ? 0x01 : 0x00);
     
-    // flag: send a pixel dump after the next read
-    bool reportPix = false;
-
+  
     // we're all set up - now just loop, processing sensor reports and 
     // host requests
     for (;;)
@@ -1373,7 +1368,7 @@
                     {
                         // 3 = pixel dump
                         // (No parameters)
-                        reportPix = true;
+                      
                         
                         // show purple until we finish sending the report
                         ledR = 0;
@@ -1511,82 +1506,14 @@
         }
         
         // read the plunger sensor, if it's enabled
-        uint16_t pix[npix];
         if (cfg.d.ccdEnabled)
         {
             // start with the previous reading, in case we don't have a
             // clear result on this frame
             int znew = z;
-
-            // read the array
-            ccd.read(pix, npix, ccdReadCB, 0, 3);
-    
-            // get the average brightness at each end of the sensor
-            long avg1 = (long(pix[0]) + long(pix[1]) + long(pix[2]) + long(pix[3]) + long(pix[4]))/5;
-            long avg2 = (long(pix[npix-1]) + long(pix[npix-2]) + long(pix[npix-3]) + long(pix[npix-4]) + long(pix[npix-5]))/5;
-            
-            // figure the midpoint in the brightness; multiply by 3 so that we can
-            // compare sums of three pixels at a time to smooth out noise
-            long midpt = (avg1 + avg2)/2 * 3;
-            
-            // Work from the bright end to the dark end.  VP interprets the
-            // Z axis value as the amount the plunger is pulled: zero is the
-            // rest position, and the axis maximum is fully pulled.  So we 
-            // essentially want to report how much of the sensor is lit,
-            // since this increases as the plunger is pulled back.
-            int si = 1, di = 1;
-            if (avg1 < avg2)
-                si = npix - 2, di = -1;
+            float adjustedValue = potSlider -0.2;
+            znew = int(round(float(adjustedValue) * JOYMAX));
     
-            // If the bright end and dark end don't differ by enough, skip this
-            // reading entirely - we must have an overexposed or underexposed frame.
-            // Otherwise proceed with the scan.
-            if (labs(avg1 - avg2) > 0x1000)
-            {
-                uint16_t *pixp = pix + si;           
-                for (int n = 1 ; n < npix - 1 ; ++n, pixp += di)
-                {
-                    // if we've crossed the midpoint, report this position
-                    if (long(pixp[-1]) + long(pixp[0]) + long(pixp[1]) < midpt)
-                    {
-                        // note the new position
-                        int pos = n;
-                        
-                        // Calibrate, or apply calibration, depending on the mode.
-                        // In either case, normalize to our range.  VP appears to
-                        // ignore negative Z axis values.
-                        if (calBtnState == 3)
-                        {
-                            // calibrating - note if we're expanding the calibration envelope
-                            if (pos < cfg.d.plungerMin)
-                                cfg.d.plungerMin = pos;
-                            if (pos < cfg.d.plungerZero)
-                                cfg.d.plungerZero = pos;
-                            if (pos > cfg.d.plungerMax)
-                                cfg.d.plungerMax = pos;
-                                
-                            // normalize to the full physical range while calibrating
-                            znew = int(round(float(pos)/npix * JOYMAX));
-                        }
-                        else
-                        {
-                            // Running normally - normalize to the calibration range.  Note
-                            // that values below the zero point are allowed - the zero point
-                            // represents the park position, where the plunger sits when at
-                            // rest, but a mechanical plunger has a smmall amount of travel
-                            // in the "push" direction.  We represent forward travel with
-                            // negative z values.
-                            if (pos > cfg.d.plungerMax)
-                                pos = cfg.d.plungerMax;
-                            znew = int(round(float(pos - cfg.d.plungerZero)
-                                / (cfg.d.plungerMax - cfg.d.plungerZero + 1) * JOYMAX));
-                        }
-                        
-                        // done
-                        break;
-                    }
-                }
-            }
 
             // Determine if the plunger is being fired - i.e., if the player
             // has just released the plunger from a retracted position.
@@ -1753,28 +1680,9 @@
         // arrangement of our nominal axes aligns with VP's standard
         // setting, so that we can configure VP with X Axis = X on the
         // joystick and Y Axis = Y on the joystick.
+
         js.update(y, x, z, buttons, statusFlags);
         
-        // If we're in pixel dump mode, report all pixel exposure values
-        if (reportPix)
-        {
-            // we have satisfied this request
-            reportPix = false;
-            
-            // send reports for all pixels
-            int idx = 0;
-            while (idx < npix)
-                js.updateExposure(idx, npix, pix);
-                
-            // The pixel dump requires many USB reports, since each report
-            // can only send a few pixel values.  An integration cycle has
-            // been running all this time, since each read starts a new
-            // cycle.  Our timing is longer than usual on this round, so
-            // the integration won't be comparable to a normal cycle.  Throw
-            // this one away by doing a read now, and throwing it away - that 
-            // will get the timing of the *next* cycle roughly back to normal.
-            ccd.read(pix, npix);
-        }
         
 #ifdef DEBUG_PRINTF
         if (x != 0 || y != 0)