Laser Sensing Display for UI interfaces in the real world

Dependencies:   mbed

Fork of skinGames_forktest by Alvaro Cassinelli

Revision:
43:1dd4cfc30788
Parent:
42:5f21a710ebc5
Child:
44:2432c218f191
--- a/WrapperFunctions.cpp	Fri Oct 18 07:25:03 2013 +0000
+++ b/WrapperFunctions.cpp	Mon Oct 21 11:26:48 2013 +0000
@@ -9,6 +9,39 @@
 
 bool previousLsdState; //local scope - only used in this file.
 
+// =============== SOME IMPORTANT LOW LEVEL FUNCTIONS CONTROLLING THE DISPLAYING ENGINE =========================================
+
+// This is a special function that needs to be called at least once to set the displaying engine ON, thus setting the current state of the engine:
+void startDisplay() {
+ previousLsdState=lsd.isRunning();
+ IO.setLaserLockinPower(1);
+ lsd.run(); // note: current state of the Lsd renderer is lsd.isRunning()
+}
+
+void stopDisplay() // save previous displaying status, stops the displaying engine, and switch off lasers
+{
+    previousLsdState=lsd.isRunning();
+    lsd.stop();
+    // also, switch off lasers:
+    IO.setLaserLockinPower(0);
+    IO.switchOffDisplayLasers();
+}
+
+void toggleDisplay() {
+    if (lsd.isRunning()) stopDisplay(); else startDisplay();
+}
+
+void resumeDisplay() // resume display engine if it was displaying, otherwise does not do anything
+// and set the sensing laser ON (no need to explicitly switch the DISPLAYING lasers ON - this is done in the displaying engine ISR). 
+{
+    if (previousLsdState) {
+    //switch on sensing lasers:
+    IO.setLaserLockinPower(1);
+    lsd.run();
+    // rem: no need to set the displaying lasers: this is done per-object basis
+    }
+}
+
 // =================================   BASIC "OPENGL-like" object/scene builders and query functions ("sense") ==========================================
 
 void clearScene()   // THIS SHOULD BE CALLED WHENEVER we want to create a new scene from scratch.
@@ -23,13 +56,17 @@
     } else { //do nothing, the display engine is not working (we don't need to wait for the display to end!)
     }
     scene.clear();
-    //updateScene();
 }
 
 void updateScene()   // THIS SHOULD BE CALLED WHENEVER we ended CREATING or MODIFYING a scene
 {
-    // In fact, the only thing this routine does is to indicate to the (dormant!) displaying engine that the scene STRUCTURE has changed.
-    // NOTE: 
+    //We need to stop the display, and then indicate to the lsd that the scene has changed. NOTE: we don't resume displaying until we haven't drawn the scene again. 
+    // Of course, it could 
+     if (lsd.isRunning()) {
+        lsd.startDisplayCheck();
+        while(!lsd.isDisplayingOver());
+        stopDisplay();
+    }
     lsd.setSceneToDisplay(&scene); // this will compute the number of objects, points, etc, to prepare the displaying engine
     resumeDisplay();// this will resume display IF it was displaying before. 
 }
@@ -446,31 +483,7 @@
     resumeDisplay();
 }
 
-// This is a special function that needs to be called at least once to set the displaying engine ON, thus setting the current state of the engine:
-void startDisplay() {
- IO.setLaserLockinPower(1);
- lsd.run();
-}
 
-void stopDisplay() // save previous displaying status, stops the displaying engine, and switch off lasers
-{
-    previousLsdState=lsd.isRunning();
-    lsd.stop();
-    // also, switch off lasers:
-    IO.setLaserLockinPower(0);
-    IO.switchOffDisplayLasers();
-}
-
-void resumeDisplay() // go back to previous state of displaying engine 
-// and set the sensing laser ON (no need to explicitly switch the DISPLAYING lasers ON - this is done in the displaying engine ISR). 
-{
-    if (previousLsdState) {
-    //switch on sensing lasers:
-    IO.setLaserLockinPower(1);
-    lsd.run();
-    // rem: no need to set the displaying lasers: this is done per-object basis
-    }
-}
 
 // =============================== HARDWARE KNOBS: switches, potentiometers... =================================================
 void hardwareKnobs()