Laser Sensing Display for UI interfaces in the real world

Dependencies:   mbed

Fork of skinGames_forktest by Alvaro Cassinelli

Revision:
9:3321170d157c
Parent:
8:5816bb17536b
Child:
10:6f8e48dca1bd
--- a/main.cpp	Tue Apr 10 10:45:16 2012 +0000
+++ b/main.cpp	Wed Apr 11 13:06:23 2012 +0000
@@ -16,7 +16,7 @@
 
 
 // To test the time it takes for executing one loop in the main program:
-//#define LOOPTIMECOMPUTE
+#define LOOPTIMECOMPUTE
 
 // To get serial commands (for debug, or other things using a Terminal - for instance, a laser scan)
 //#define SERIAL_COMMANDS
@@ -57,9 +57,9 @@
 Ticker timerForRendering;
 //Ticker timerForSendingData; // better use a timer, so as not to interrupt the exact laser display ticker
 
-// Timers: 
+// Timers:
 Timer measureLoopPeriod;
-Timer measureUpdatePeriod;
+//Timer measureUpdatePeriod;
 Timer measureSendPeriod;
 
 // to get serial commands (not necessary perhaps)
@@ -105,12 +105,12 @@
 
     // Tested modes:
     blobconf.clearConfig();
-//  blobconf.addOneElasticLoopContractCentral();
+  blobconf.addOneElasticLoopContractCentral();
 //  blobconf.addOneElasticContourFollowing();
 
-blobconf.addOneRigidLoopBouncing();
-blobconf.addOneRigidLoopBouncing();
-// blobconf.addOneRigidLoopFollowing();
+//    blobconf.addOneRigidLoopBouncing();
+//  blobconf.addOneRigidLoopBouncing();
+ //blobconf.addOneRigidLoopFollowing();
 
 
 //blobconf.addOneRigidLoopTest();
@@ -126,40 +126,44 @@
     lsr.setConfigToRender(&blobconf);
 
     // Timer on the rendering function of the oneLoop object:
-   // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL); // the address of the object, member function, and interval (in seconds)
-   timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL); // the address of the object, member function, and interval (in seconds)
+    // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL); // the address of the object, member function, and interval (in seconds)
+    timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL); // the address of the object, member function, and interval (in seconds)
 
     // Timer for sending OSC data:
-   // timerForSendingData.attach(&blobconf, &blobConfig::sendConfData, 0.025); // time in seconds (25ms -> 40Hz)
+    // timerForSendingData.attach(&blobconf, &blobConfig::sendConfData, 0.025); // time in seconds (25ms -> 40Hz)
 
     //==========================================   INFINITE LOOP (in USER PROGRAM CONTEXT) ===================================================================
 #ifdef LOOPTIMECOMPUTE
     int timeCounterNum=1000;
 #endif
 
-  measureUpdatePeriod.start();
-  measureSendPeriod.start();
+    //measureUpdatePeriod.start();
+    measureSendPeriod.start();
 
     while (true) {
 
         //NOTE: the updating period needs to be calculated as a function of the number of diplays points and the "refresh" rate of the laser.
         // THIS IS THE EQUICALENT OF "VERTICAL SYNCH"...
-        if (measureUpdatePeriod.read_ms()>4) { // 4 or 5 ms seems to be the minimum time required for performing one main loop (for a blob of 40 points)
-                                               // with laser rendering ISR every 110us (total loop time 4300us, 3100us of effective loop time, and each laser interrupt about 30us)
-            measureUpdatePeriod.stop();
-            measureUpdatePeriod.reset();
-            
-          //  __disable_irq();
-            
+        // if (measureUpdatePeriod.read_ms()>4) { // 4 or 5 ms seems to be the minimum time required for performing one main loop (for a blob of 40 points)
+        // with laser rendering ISR every 110us (total loop time 4300us, 3100us of effective loop time, and each laser interrupt about 30us)
+        if (lsr.endedDisplay) {
+
+            lsr.endedDisplay=false;
+
+            //  measureUpdatePeriod.stop();
+            //  measureUpdatePeriod.reset();
+
+            //  __disable_irq();
+
             // update config dynamics (this also could be threaded?):
             blobconf.update();
 
             // draw the config (note: each kind of blob renders differently)
             blobconf.draw();
-            
-           // __enable_irq();
-            
-            measureUpdatePeriod.start();
+
+            // __enable_irq();
+
+            //     measureUpdatePeriod.start();
         }
 
 
@@ -172,16 +176,16 @@
 #ifdef SERIAL_COMMANDS
         if (pc.readable()>0) processSerial();
 #endif
-        
+
         // (b)Sending Data: // PUT THIS IN AN INTERRUPT OR USE A TIMER!!! it may be TOO FAST...
         // NOTE: better use a timer, so the only ISR "ticker" is the laser rendering (otherwise the laser rendering will be interrupted by the sending of data - the other way is ok):
         if (measureSendPeriod.read_ms()>25) {
             measureSendPeriod.stop();
             measureSendPeriod.reset();
-            
+
             blobconf.sendConfData();
-            
-             measureSendPeriod.start();
+
+            measureSendPeriod.start();
         }
 
         // text:
@@ -194,16 +198,17 @@
          */
 
 #ifdef LOOPTIMECOMPUTE
-        if (timeCounterNum>500)  myled = 0;
-       // if (timeCounterNum%10==0) blobconf.sendConfData();
-        if (timeCounterNum>1000) {
+        if (timeCounterNum>50)  myled = 0;
+        // if (timeCounterNum%10==0) blobconf.sendConfData();
+        if (timeCounterNum>100) {
             myled = 1;
             measureLoopPeriod.stop();
             sendMes.setTopAddress("/timeloop");
             sendMes.setSubAddress("/");
-            long x=(long)(int(measureLoopPeriod.read_us()/1000.0));
-           // long x=(long)(blobconf.blobArray[0]->displaySensingBuffer.lsdTrajectory.size());
-           // long x=(long)(blobconf.blobArray[0]->normRecenteringVector);
+          //  long x=(long)(int(measureLoopPeriod.read_us()/100.0));
+            // long x=(long)(blobconf.blobArray[0]->displaySensingBuffer.lsdTrajectory.size());
+            // long x=(long)(blobconf.blobArray[0]->normRecenteringVector);
+             long x=(long)(1000*blobconf.blobArray[0]->displaySensingBuffer.lsdTrajectory[0].intensity);
             sendMes.setArgs( "i", &x);
             osc.sendOsc( &sendMes );
             timeCounterNum=0;
@@ -242,8 +247,8 @@
         IO.scan_serial();
 
         // Finally, start again threaded display:
-         timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
-       // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
+        timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
+        // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
     }
 
     else if ( !strcmp(address[0], "mbedReset" ) ) mbed_reset();
@@ -254,8 +259,8 @@
         // RESCAN (and save LUT table):
         IO.scanLUT();
         // Finally, start again threaded display:
-         timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
-       // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
+        timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
+        // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
     }
 
     // (II) ========================================= GLOBAL CONFIG and HARDWARE COMMANDS ===========================================
@@ -275,16 +280,16 @@
         blobconf.clearConfig();
         blobconf.addOneElasticContourFollowing();
         lsr.setConfigToRender(&blobconf);
-          timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
-       // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
+        timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
+        // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
     } else if (!strcmp(address[0], "loop")) { //
         timerForRendering.detach();
         // blobconf.computeBoundingBox();
         blobconf.clearConfig();
         blobconf.addOneElasticLoopContractCentral();
         lsr.setConfigToRender(&blobconf);
-          timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
-       // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
+        timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
+        // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
     }
 
     else if (!strcmp(address[0], "bouncing")) {
@@ -293,8 +298,8 @@
         blobconf.clearConfig();
         blobconf.addOneElasticBouncing();
         lsr.setConfigToRender(&blobconf);
-          timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
-       // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
+        timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
+        // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
     }
 
     // other:
@@ -459,7 +464,7 @@
 
                 // Finally, start again threaded display:
                 timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
-                 // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
+                // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
             }
 
             if (!strcmp(stringCommand , "REDON"))   IO.setRedPower(1); // pc.printf("%d\n",incomingByte);