Laser Sensing Display for UI interfaces in the real world

Dependencies:   mbed

Fork of skinGames_forktest by Alvaro Cassinelli

Revision:
2:34157ebbf56b
Parent:
1:a4050fee11f7
Child:
3:b44ff6de81bd
--- a/main.cpp	Sat Mar 31 08:19:31 2012 +0000
+++ b/main.cpp	Sat Mar 31 12:50:32 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
@@ -53,10 +53,14 @@
 void processOSC(UDPSocketEvent e);
 // ----------------------------------------------------------------------------------------------------------------------
 
+// Tickers:
 Ticker timerForRendering;
-Ticker timerForSendingData;
+//Ticker timerForSendingData; // better use a timer, so as not to interrupt the exact laser display ticker
+
+// Timers: 
 Timer measureLoopPeriod;
 Timer measureUpdatePeriod;
+Timer measureSendPeriod;
 
 // to get serial commands (not necessary perhaps)
 void  processSerial();
@@ -102,10 +106,15 @@
     // Tested modes:
     blobconf.clearConfig();
 //   blobconf.addOneElasticLoopContractCentral();
-//     blobconf.addOneElasticContourFollowing();
+//   blobconf.addOneElasticContourFollowing();
 
-    blobconf.addOneRigidLoopBouncing();
-   //    blobconf.addOneRigidLoopBouncing();
+//  blobconf.addOneRigidLoopBouncing();
+//  blobconf.addOneRigidLoopBouncing();
+//  blobconf.addOneRigidLoopBouncing();
+//  blobconf.addOneRigidLoopBouncing();
+// blobconf.addOneRigidLoopBouncing();
+
+ blobconf.addOneRigidLoopFollowing();
 
     // 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...
@@ -120,7 +129,7 @@
     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
@@ -128,23 +137,30 @@
 #endif
 
   measureUpdatePeriod.start();
+  measureSendPeriod.start();
 
     while (true) {
 
-        if (measureUpdatePeriod.read_ms()>4) { // 4 or 5 ms seems to be the minimum time required for performing one
-                                               // loop with laser rendering every 110us (total loop time 4300us, 3100us of effective loop time, and each laser interrupt about 30us)
+
+        if (measureUpdatePeriod.read_ms()>2) { // 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();
+            
             // 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();
         }
 
+
         // COMMUNICATION:
         // (a) Reading commands:
         // Ethernet:
@@ -154,8 +170,17 @@
 #ifdef SERIAL_COMMANDS
         if (pc.readable()>0) processSerial();
 #endif
-        // (b)Sending Data: // PUT THIS IN AN INTERRUPT OR A TIMER!!! it may be TOO FAST...
-        //blobconf.sendConfData();
+        
+        // (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();
+        }
 
         // text:
         /*