Laser Sensing Display for UI interfaces in the real world

Dependencies:   mbed

Fork of skinGames_forktest by Alvaro Cassinelli

Revision:
41:74e24a0e6e50
Parent:
40:3ba2b0ea9f33
Child:
42:5f21a710ebc5
diff -r 3ba2b0ea9f33 -r 74e24a0e6e50 main.cpp
--- a/main.cpp	Wed Oct 16 16:14:27 2013 +0000
+++ b/main.cpp	Wed Oct 16 17:26:13 2013 +0000
@@ -8,33 +8,34 @@
 #include "mbed.h"
 #include "mbedOSC.h"
 
-// Ethernet can be created with *either* an address assigned by DHCP or a static IP address. Uncomment the define line for DHCP
-//#define DHCP
+// mbed IP address (server):
 #ifdef DHCP
 EthernetNetIf eth;
 #else
 EthernetNetIf eth(
-    IpAddr(10,0,0,2), //IP Address
+    IpAddr(10,0,0,2), //IP Address of the mbed
     IpAddr(255,255,255,0), //Network Mask
     IpAddr(10,0,0,1), //Gateway
     IpAddr(10,0,0,1)  //DNS
 );
 #endif
 
-//// OSC
-// The message objects to send and receive with
+//uint8_t serverMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
+uint8_t serverIp[]  = { 10, 0, 0, 2 }; 
+int  serverPort  = 10000;
+
+//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";
+char *subAddress[3]={ "/test1" , "/test2" , "/test3" };
+
 OSCMessage recMes;
 OSCMessage sendMes;
 
-// Setting - The port we're listening to on the mbed for OSC messages
-unsigned short  serverPort  = 10000;
-
-// Setting - The address and port we're going to send to, from the mbed
-uint8_t destIp[]  = { 10, 0, 0, 1};
-int  destPort = 12000;
-
-// The object to do the work of sending and receiving
 OSCClass osc;
+//OSCClass osc(&recMes);  // instantiate OSC communication object, and set the receiver container from the OSC packets
 void processOSC(UDPSocketEvent e);
 
 
@@ -102,6 +103,7 @@
 extern "C" void mbed_reset();
 
 void createSceneTest();
+void setOrthographicView();
 
 void interpretData();
 void processOSC();
@@ -125,29 +127,28 @@
     IO.init();
     
     // OSC initialization:
-    // =====================================================
-    //// TASK: Set up the Ethernet port
-    printf("Setting up ethernet...\r\n");
+    // Set the Ethernet port:
+    printf("Setting up...\r\n");
     EthernetErr ethErr = eth.setup();
     if (ethErr) {
-        printf("Ethernet Failed to setup. Error: %d\r\n", ethErr);
+        printf("Error %d in setup.\r\n", ethErr);
         return -1;
     }
-    printf("Ethernet OK\r\n");
+    printf("Setup OK\r\n");
 
- // SET OSC ===================================================================
- //(1) Sending message:
+    //(1) Sending message:
     // Set IP and Port:
     sendMes.setIp( destIp );
     sendMes.setPort( destPort );
     // Set data:
-    // sendMes.setTopAddress(topAddress);
+    sendMes.setTopAddress(topAddress);
 
     //setting osc functionnality:
     //(2) Receiving:
     // recMes.setIp( serverIp ); // not needed?
     osc.setReceiveMessage(&recMes); // this sets the receiver container for the OSC packets (we can avoid doing this if we use osc.getMessage() to get messages)
     osc.begin(serverPort, &processOSC); // binds the upd (osc) messages to an arbitrary listening port ("server" port), and callback function
+    
     //===================================================================
 
     /*
@@ -241,7 +242,8 @@
     lsr.loadExtrinsicsMatrix(E1);
 
     // (2) Create the scene in "local" coordinates:
-    createTextScene(); // Create a default scene (for tests)
+    //createTextScene(); // Create a default scene (for tests)
+    setOrthographicView();
 
     // (3) Set a default PERSPECTIVE and GLOBAL POSE for start displaying:
     lsr.loadProjMatrix(K1, scaleFactorProjector1);
@@ -341,6 +343,16 @@
     // =================================
 }
 
+void setOrthographicView() {
+            clearScene();
+            // set color:
+            lsr.setColor(0x02); // green
+            //IO.setLaserLockinPower(0); // DISABLING SENSING LASER! (here the red). This is FOR CALIBRATION laser-camera
+            
+             lsr.setOrthoProjection();
+            lsr.setIdentityPose(); // we could have done the translation here instead of in "local coordinates", but it's the same.
+}
+
 void createSceneTest()
 {
     lsr.pushPoseMatrix();
@@ -468,6 +480,9 @@
     osc.onUDPSocketEvent(e);
 
     if (osc.newMessage) {
+    
+          pc.putc('A');
+          
         // Acquire the addresses and arguments and put them in the GLOBAL variables to be processed by the interpretData function (common to serial and OSC):
         strcpy(address[0],"");
         strcpy(address[1],"");
@@ -479,7 +494,8 @@
         for (int i=0; i<numArgs; i++) data[i]=(int)recMes.getArgInt(i);
 
         // Finally, interpret the command or data:
-      interpretData();
+         interpretData();
+     
       }
 }
 
@@ -501,6 +517,10 @@
     
     else if ( !strcmp(address[0], "mbedReset" ) ) mbed_reset();
     
+     else if ( !strcmp(address[0], "testPower" ) ) {
+        // TO DO
+    }
+    
      // Enable/disable projection:
      else if ( !strcmp(address[0], "stopDisplay" )) stopDisplay();
      else if (!strcmp(address[0], "resumeDisplay"))  resumeDisplay();