Alvaro Cassinelli / Mbed 2 deprecated skinGames_forktest

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Revision:
3:b44ff6de81bd
Parent:
1:a4050fee11f7
Child:
4:f9d364f10335
--- a/simpleLaserRenderer.cpp	Sat Mar 31 12:50:32 2012 +0000
+++ b/simpleLaserRenderer.cpp	Mon Apr 02 05:33:44 2012 +0000
@@ -13,11 +13,11 @@
     currentColor=ptBlobCfToRender->blobArray[currentBlob]->blobColor;
 
     // Blanking:
-    IO.setRGBPower(0);
+    //IO.setRGBPower(0);
     // or start with the correct color (case of unique blob)
     // IO.setRGBPower(currentColor|0x04); // Note: RED always on better? (to avoid loosing LockIn signal)
     // OR RED ONLY:
-    //IO.setRGBPower(0x04);
+    IO.setRGBPower(0x04);
 
     // Set mirrors to the start of FIRST blob:
     x= ptBlobCfToRender->blobArray[currentBlob]->displaySensingBuffer.lsdTrajectory[0].x;
@@ -29,7 +29,9 @@
     // Reset current point to special "start value":
     currentPoint=-1;
     // or start on first point (case of unique blob rendering function):
-    // currentPoint=0;
+//     currentPoint=0;
+
+    pauseCounter=20; 
 
 }
 
@@ -40,13 +42,28 @@
         IO.setRGBPower(currentColor|0x04); // Note: RED always on...
 
         // First of all, read the light at currentPoint=0
+       currentPoint=0;
+    int delayedPoint=currentMirrorDelay%currentTotalPoints;//just equal to (currentPoint+currentMirrorDelay)%currentTotalPoints;
+
+#ifdef debugDelayMirrors
+        if ( ptBlobCfToRender->blobArray[currentBlob]->displaySensingBuffer.lsdTrajectory[delayedPoint].lightZone<0) {
+            IO.setBluePower(0);
+            // myled3=0;
+        } else {
+            IO.setBluePower(1);
+            // myled3=1;
+        }
+        //IO.setRGBPower(0x04); else  IO.setRGBPower(0x07);
+#endif
+
+
         // Use direct reading:
         // ptBlobCfToRender->blobArray[currentBlob].displaySensingBuffer.lsdTrajectory[currentMirrorDelay%currentTotalPoints]=lockin.getMedianValue();//lockin.getSmoothValue(); //lockin.getLastValue();//
         // Or corrected by lookup table (NOTE: x and y are supposed to be positioned at the currenPoint=0 already)
-        ptBlobCfToRender->blobArray[currentBlob]->displaySensingBuffer.lsdTrajectory[currentMirrorDelay%currentTotalPoints].intensity=IO.lockInCorrectedValue(x,y);
+        ptBlobCfToRender->blobArray[currentBlob]->displaySensingBuffer.lsdTrajectory[delayedPoint].intensity=IO.lockInCorrectedValue(x,y);
 
         // Then, set current point to the SECOND saccade point and position the mirrors (the first was already drawn and measured...):
-        currentPoint=1;
+        // currentPoint=1; // already done
         x= ptBlobCfToRender->blobArray[currentBlob]->displaySensingBuffer.lsdTrajectory[currentPoint].x;
         y= ptBlobCfToRender->blobArray[currentBlob]->displaySensingBuffer.lsdTrajectory[currentPoint].y;
         IO.writeOutX(x);
@@ -54,7 +71,7 @@
 
         // Re-schedule interruption:
         // Timeout
-    } else if (currentPoint>=currentTotalPoints) { // this means that we ended rendering the current blob
+    } else if (currentPoint==currentTotalPoints-1) { // this means that we ended rendering the current blob
         // Start processing next blob:
         currentBlob=(currentBlob+1)%totalBlobs;
 
@@ -63,11 +80,11 @@
         currentColor=ptBlobCfToRender->blobArray[currentBlob]->blobColor;
 
         // Blanking:
-        IO.setRGBPower(0);
+        // IO.setRGBPower(0);
         // or start with the correct color (case of unique blob)
         // IO.setRGBPower(currentColor|0x04); // Note: RED always on better? (to avoid loosing LockIn signal)
         // OR RED ONLY:
-        //IO.setRGBPower(0x04);
+        IO.setRGBPower(0x04);
 
         // Set mirrors to the start of next blob:
         x= ptBlobCfToRender->blobArray[currentBlob]->displaySensingBuffer.lsdTrajectory[0].x;
@@ -78,16 +95,29 @@
         // Reset current point to special "start value":
         currentPoint=-1;
 
-        // Re-schedule interruption:
-        //Timeout
-
     } else { // proceed with the laser rendering/sensing (note: the mirrors are positioned already on the next point to be measured)
 
         // (1) SENSING (on the current blob and particle index):
         // Either using direct value:
         // ptBlobCfToRender->blobArray[currentBlob].sensingBuffer[(currentPoint+currentMirrorDelay)%currentTotalPoints]=lockin.getMedianValue(); //lockin.getLastValue();//
         // Or corrected by lookup table (NOTE: x and y are supposed to be positioned at the currenPoint already)
-        ptBlobCfToRender->blobArray[currentBlob]->displaySensingBuffer.lsdTrajectory[(currentPoint+currentMirrorDelay)%currentTotalPoints].intensity=IO.lockInCorrectedValue(x,y);
+
+        int delayedPoint=(currentPoint+currentMirrorDelay)%currentTotalPoints;
+
+
+#ifdef debugDelayMirrors
+        if ( ptBlobCfToRender->blobArray[currentBlob]->displaySensingBuffer.lsdTrajectory[delayedPoint].lightZone<0) {
+            IO.setBluePower(0);
+            // myled3=0;
+        } else {
+            IO.setBluePower(1);
+            // myled3=1;
+        }
+        //IO.setRGBPower(0x04); else  IO.setRGBPower(0x07);
+#endif
+
+        // Make the current measurement:
+        ptBlobCfToRender->blobArray[currentBlob]->displaySensingBuffer.lsdTrajectory[delayedPoint].intensity=IO.lockInCorrectedValue(x,y);
 
 
         // (2) increment the current point index and position the mirrors:
@@ -104,8 +134,8 @@
     // When we arrive here, we ASSUME the mirrors are well positioned at the currentPoint-1, so we need to process the currentPoint:
 
     // Current mirror position:
-    int x= ptBlobCfToRender->blobArray[currentBlob]->displaySensingBuffer.lsdTrajectory[currentPoint].x;
-    int y= ptBlobCfToRender->blobArray[currentBlob]->displaySensingBuffer.lsdTrajectory[currentPoint].y;
+    x= ptBlobCfToRender->blobArray[currentBlob]->displaySensingBuffer.lsdTrajectory[currentPoint].x;
+    y= ptBlobCfToRender->blobArray[currentBlob]->displaySensingBuffer.lsdTrajectory[currentPoint].y;
 
     // (2) Send command to position the mirrors to the next position:
     IO.writeOutX(x);
@@ -116,10 +146,10 @@
 #ifdef debugDelayMirrors
     if ( ptBlobCfToRender->blobArray[currentBlob]->displaySensingBuffer.lsdTrajectory[delayedPoint].lightZone<0) {
         IO.setBluePower(0);
-       // myled3=0;
+        // myled3=0;
     } else {
         IO.setBluePower(1);
-       // myled3=1;
+        // myled3=1;
     }
     //IO.setRGBPower(0x04); else  IO.setRGBPower(0x07);
 #endif