Laser Sensing Display for UI interfaces in the real world

Dependencies:   mbed

Fork of skinGames_forktest by Alvaro Cassinelli

Revision:
32:52273c3291fe
Parent:
31:5f039cbddee8
Child:
33:43e8bc451ef0
--- a/main.cpp	Sun Sep 23 10:11:43 2012 +0000
+++ b/main.cpp	Mon Oct 29 14:28:47 2012 +0000
@@ -38,7 +38,8 @@
 uint8_t serverIp[]  = { 10, 0, 0, 2 }; // not needed perhaps!
 int  serverPort  = 10000;
 
-uint8_t destIp[]  = {10, 0, 0, 3};
+//uint8_t destIp[]  = {10, 0, 0, 3}; 
+uint8_t destIp[]  = {255, 255, 255, 255};  // broadcast, so we can use several computers for sound, etc
 int  destPort = 12000;
 
 char *topAddress="/mbed";
@@ -112,11 +113,16 @@
 //  blobconf.addOneRigidLoopBouncing();
 //blobconf.addOneRigidLoopFollowing();
    // blobconf.addOneRigidLoopFollowing();
-    
-        blobconf.addOneElasticLoopContractCentralFast();
+  //blobconf.addOneElasticLoopContractCentralFast();
+ //blobconf.addOneRigidLoopTest();
 
-
-//blobconf.addOneRigidLoopTest();
+// START WITH TWO FOLLOWING SPOTS (exhibition Tokyo Design Week):
+  blobconf.initConfig(FOLLOWING_SPOTS, 2); // value is the nb of spots instantiated
+// Make them of different color:
+ blobconf.blobArray[0]->setBlueColor(1);
+ blobconf.blobArray[1]->setGreenColor(1);
+ // start in no stand by mode:
+ blobconf.allResume();
 
     // Important: first, set the initial position for all the blobs, this will be useful because
     // when changing modes we can use the previous central position...
@@ -278,16 +284,35 @@
 
     // (II) ========================================= GLOBAL CONFIG and HARDWARE COMMANDS ===========================================
 
-    else if ( !strcmp(address[0], "setGreenLaser" ) ) {
+    else if ( !strcmp(address[0], "setAllColor" ) ) {
+        int value=data[0]; // this is the color (RGB bits)
+        if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
+                blobconf.allSetColor(value);
+    }
+    }
+
+    else if ( !strcmp(address[0], "setAllGreenColor" ) ) {
         int value=data[0];
         if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
             if (value==0) 
-                blobconf.allSetColor(0x04);// only red (note that we are in blue for "test" mode... so the blue will appear when touching something anyway
+                blobconf.allSetGreen(1);
             else 
-                blobconf.allSetColor(0x06); // RED and GREEN (note: in the future, make a method to set colors properly! one by one...)
+                blobconf.allSetGreen(0);
         }
     }
     
+    else if ( !strcmp(address[0], "setAllBlueColor" ) ) {
+        int value=data[0];
+        if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
+            if (value==0) 
+                blobconf.allSetBlue(1);
+            else 
+                blobconf.allSetBlue(0);
+        }
+    }
+    
+    // NOTE: RED either afect the lock in, or some other red laser... not yet done. 
+    
     else if ( !strcmp(address[0], "testPower" ) ) {
     // First, we need to disable the threaded display for the loop:
         timerForRendering.detach();
@@ -392,6 +417,20 @@
             // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
         }
     }
+      
+   else if (!strcmp(address[0], "rain_mode")) {
+        int value=data[0];
+        if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
+            timerForRendering.detach();
+            
+            blobconf.initConfig(RAIN_MODE, value); // value is the nb of spots instantiated
+
+            lsr.setConfigToRender(&blobconf);
+            timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
+            // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
+        }
+    }
+    
    
    else if (!strcmp(address[0], "spot_following")) {
         int value=data[0];
@@ -501,6 +540,27 @@
       }
     }
     
+  else if (!strcmp( address[0], "sizeFactor" ) ) {
+      int value=data[0]; // value 100 means no change of sice. 200 is twice as big, 50 is half as big. 
+      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]->sizeFactor((float)(1.0*value/100.0));
+      }
+    }
+    
+    // ADJUST MIRROR ANGLE CORRECTION:
+    else if (!strcmp( address[0], "adjustPlusAngle" ) ) {
+      int value=data[0]; // this is not a factor, but an additive quantity to the current delay
+      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]; // this is not a factor, but an substractive quantity to the current delay 
+      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], "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)     
@@ -508,12 +568,49 @@
       }
     }
 
-    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. 
+// ADJUST MIN CONTRAST RATIO 
+// (1) using multiplicative factor:
+    else if (!strcmp( address[0], "adjustMultContrast" ) ) {
+      int value=data[0]; // value 100 means no change of the current contrast value. 200 means a min contrast 
+      // that is twice as large and 50 is half as large as before. 
       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);
+        for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.multMinContrastRatio((float)(1.0*value/100.0));
+      }
+    } 
+// (2) directly:
+ else if (!strcmp( address[0], "adjustContrast" ) ) {
+      int value=data[0];  // value is in PERCENT (100=1, 50 = 0.5...)
+      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.setMinContrastRatio((float)(1.0*value/100.0));
       }
     }
+    
+ // ADJUST THRESHOLD RATIO:
+    //(1) using multiplicative factor:
+    else if (!strcmp( address[0], "adjustMultThreshold" ) ) {
+      int value=data[0]; // value 100 means no change of the current contrast value. 200 means a min contrast 
+      // that is twice as large and 50 is half as large as before. 
+      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.multThresholdFactor((float)(1.0*value/100.0));
+      }
+    } 
+     //(2) directly:
+    else if (!strcmp( address[0], "adjustThresholdFactor" ) ) {
+      int value=data[0]; // value is in PERCENT (100=1, 50 = 0.5...)
+      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.setThresholdFactor((float)(1.0*value/100.0));
+      }
+    } 
+    
+    // Adjust minimum acceptable intensity:
+     else if (!strcmp( address[0], "adjustMinAcceptableIntensity" ) ) {
+      int value=data[0]; // value is DIRECT value (0 to 255)
+      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.setMinAcceptableIntensity(value);
+      }
+    } 
+    
+ // ===================== SEND DATA MODES =======================
  
     else if (!strcmp( address[0], "sendOSC" ) ) {
         int value=data[0];