Laser Sensing Display for UI interfaces in the real world

Dependencies:   mbed

Fork of skinGames_forktest by Alvaro Cassinelli

Revision:
24:4e52031a495b
Parent:
23:bf666fcc61bc
Child:
25:74cb85b85fd2
--- a/main.cpp	Wed Jun 13 10:09:41 2012 +0000
+++ b/main.cpp	Mon Jun 18 08:00:57 2012 +0000
@@ -120,7 +120,7 @@
     // when changing modes we can use the previous central position...
     // blobconf.setInitialPos(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y);
 
-// draw the config once befor activating the laser buffer:
+// draw the config once before activating the laser buffer:
     blobconf.draw();
     lsr.startFullDisplay();
 
@@ -229,7 +229,9 @@
 void interpretCommand() {
     // (I) =========================================== SPECIAL FUNCTIONS (reset, rescan LUT, etc) ====================================================
     if ( !strcmp(address[0], "takeSnapshot" ) ) {
-
+     int value=data[0];
+        if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
+       
         // for test:
         for (int i=0; i<2 ; i++) {
             myled = 1;
@@ -241,12 +243,14 @@
         // First, we need to disable the threaded display for the loop:
         timerForRendering.detach();
 
-        // Then, do the scan (sending values on serial port):
-        IO.scan_serial();
+        // Then, do the scan (sending values on SERIAL port):
+        IO.scan_serial(value);
 
         // Finally, start again threaded display:
         timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
         // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
+        
+        }
     }
 
     else if ( !strcmp(address[0], "mbedReset" ) ) mbed_reset();
@@ -255,9 +259,9 @@
         int value=data[0];
         if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
           timerForRendering.detach();
-               IO.showLimitsMirrors(value);
+          IO.showLimitsMirrors(value);
           timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);     
-             }
+        }
        }
 
     else if ( !strcmp(address[0], "calibrate" ) ) {
@@ -355,10 +359,12 @@
             blobconf.clearConfig();
 
             // HACK for the time being: 
+            /*
             int aux=rand()%100;
            if (aux<70) value=1; 
            else if (aux<80) value=2; 
            else value=3;
+           */
 
             for (int i=0; i<value ; i++) blobconf.addOneRigidLoopBouncing();
 
@@ -377,10 +383,12 @@
             blobconf.clearConfig();
             
            // HACK for the time being: 
+           /*
            int aux=rand()%100;
            if (aux<70) value=1; 
            else if (aux<80) value=2; 
            else value=6;
+           */
             
             for (int i=0; i<value ; i++) blobconf.addOneRigidLoopFollowing();
             
@@ -403,14 +411,39 @@
 
     // other:
 
-    else if ( !strcmp(address[0], "standby" ) ) { // will put ALL the spots in stand by mode
+    else if ( !strcmp(address[0], "standby" ) ) { // will put ALL the blobs in stand by mode (no update function)
         blobconf.allStandBy(); // will avoid the update function
-    } else if ( !strcmp(address[0], "resume" ) ) { // will put ALL the spots in stand by mode
-        blobconf.allResume(); // will avoid the update function
+    } 
+    else if ( !strcmp(address[0], "resume" ) ) { 
+        blobconf.allResume(); // Update function is called for all the blobs
     }
 
     // (III) ========================================= Loop control (parameters, etc) ===========================================
  
+    else if (!strcmp( address[0], "speedFactor" ) ) {
+      int value=data[0]; // value 100 means no change of speed. 200 is twice as fast, 50 is half as fast. 
+      if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
+            for (int i=0; i< blobconf.numBlobs; i++) {
+                //if ((!strcmp(blobconf.blobArray[i].spotName, "rigid_following"))||(!strcmp(blobconf.blobArray[i].spotName, "rigid_following"))) {
+                blobconf.blobArray[i]->speedFactor((float)(1.0*value/100.0));
+            }
+      }
+    }
+    
+    else if (!strcmp( address[0], "adjustPlusAngle" ) ) {
+      int value=data[0]; // value 100 means no change of speed. 200 is twice as fast, 50 is half as fast. 
+      if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)     
+          for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.addDelayMirrors(value);
+      }
+    }
+
+    else if (!strcmp( address[0], "adjustMinusAngle" ) ) {
+      int value=data[0]; // value 100 means no change of speed. 200 is twice as fast, 50 is half as fast. 
+      if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)     
+        for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.addDelayMirrors(-value);
+      }
+    }
+ 
     else if (!strcmp( address[0], "sendOSC" ) ) {
         int value=data[0];
         if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
@@ -559,7 +592,7 @@
                 timerForRendering.detach();
 
                 // Then, do the scan (sending values on serial port):
-                IO.scan_serial();
+                IO.scan_serial(atoi(stringData));
 
                 // Finally, start again threaded display:
                 timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);