Laser Sensing Display for UI interfaces in the real world

Dependencies:   mbed

Fork of skinGames_forktest by Alvaro Cassinelli

Revision:
40:3ba2b0ea9f33
Parent:
35:35af5086ab4f
Child:
41:74e24a0e6e50
--- a/hardwareIO/hardwareIO.h	Wed Oct 16 15:54:39 2013 +0000
+++ b/hardwareIO/hardwareIO.h	Wed Oct 16 16:14:27 2013 +0000
@@ -5,6 +5,20 @@
 #include "mbed.h"
 #include "lockin.h"
 
+//#define USING_EXTENAL_DAC // ... or we can do both at the same time: external plus the output for the mbed DAC pins
+// ARG: MBED has only one "true" analog output (p18) - the others are pwm.. but perhaps we can set a fast PWM cycle and have enough resolution?
+// 10 bit resolution (0-1023) should be ok (a display 1024x1024...). What is the max pwm cycle then? I want to be able to write a point every 100us or so (see
+// laserSensingDisplay.h), which means 10kHz. Assuming I have a low pass filter, and I filter several cycles - at least 10 - this means I need a freq of about
+// 100kHz (presumably it will work with less than that). Possible? I found this: http://mbed.org/questions/192/what-is-the-maximum-frequency-of-the-PWM/
+// It seems that the minimum step is 1us... so, at 100kHz (period of 10us) we will only have 10 levels! (about 3 bits). More precisely, if I want 10 bits resolution, the max
+// frequency will be 2^10x1us = 1024us, or about 1kHz... too slow!! 10kHz? => about two bits less, ie, 8 bits (256 levels). Mmm... Perhaps good for testing 
+// on an osciloscope, but not good for mirror control.
+// #define mbedAnalogX p18 
+// #define mbedAnalogY
+
+
+// Serial communication speed:
+#define SERIAL_SPEED 230400//115200 //230400
 
 // potentiometer to change sensitivity by hand, or other things. 
 #define POT_ANALOG_INPUT p15 // note: analog inputs in the mbed are from 15 to 20
@@ -16,8 +30,8 @@
 #define SWITCH_ONE p10 // interrupt pin
 #define SWITCH_TWO p11 // interrupt pin
 
-
-// NOTE: the SPI library uses the following pins, but we don't have to set them and inputs or outputs (this is done when the library is initialized, which is done by pre-instantiation. 
+//SPI library (for DAC chip) uses the following pins, but we don't have to set them and inputs or outputs 
+// (this is done when the library is initialized, which is done by pre-instantiation:
 #define SCK_PIN   p7 //SPI Clock
 #define MISO_PIN  p6 //SPI input (data comming from DAC, here not connected) 
 #define MOSI_PIN  p5 //SPI output (data going to DAC)
@@ -27,7 +41,7 @@
 #define CS_DAC_MIRRORS   p8 //Chip Select of the first DAC (mirrors)
 
 //**** LASERS pins:
-#define LASER_RED_PIN   p28 // NOT YET USED!! (NOTE: this is NOT the locking sensing laser (also called red, but could be infrared...)
+#define LASER_RED_PIN   p28 // NOT YET USED (TTL control). NOTE: this is NOT the locking sensing laser!
 #define LASER_GREEN_PIN p29 // USED (TTL control)
 #define LASER_BLUE_PIN  p30 // USED (TTL control)
 
@@ -73,6 +87,10 @@
                                               // lockin.getMedianValue(); //return the median value of the buffer
 
 
+extern  DigitalOut Laser_Red, Laser_Green, Laser_Blue;
+
+// LEDS for debugging:
+extern DigitalOut myLed1, myLed2, myLed3, myLed4;
 
 // **** REFERENCE SIGNAL: 
 /*
@@ -102,11 +120,18 @@
     
     void scan_serial(unsigned short pointsPerLine = 400);
 
-    void showLimitsMirrors( int times );
+    void showLimitsMirrors( unsigned short pointsPerLine, unsigned short timeInSeconds );
+//    void showLimitsConcentric(int pointsPerSide, int times);
+//    void showCircle(int cv, int cy, float radius, int nmpoints, int times);
+//    void showGrid(float cx, float cy, int nx, int ny, float pasx, float pasy, int repeat);
+//    void gridCircles(float cx, float cy, int nx, int ny, float pasx, float pasy, float radius, int repeat, boolean sym);
+//    void showContinuousGrid(int nx, int ny, float cx, float cy, int width, int height, float pasx, float pasy, int repeat);
+
 
     // SPI control for DAC for mirrors and red laser power (low level): 
     void writeOutX(unsigned short value);
     void writeOutY(unsigned short value);
+    void writeOutXY(unsigned short valueX, unsigned short valueY) {writeOutX(valueX); writeOutY(valueY);};
     
     // mirror degree-to-AD units conversion factors: 
     //float AD_to_Deg_MIRROR_X;//=1.0*(MAX_DEG_MIRROR_X-MIN_DEG_MIRROR_X)/(MAX_AD_MIRRORS-MIN_AD_MIRRORS);
@@ -124,18 +149,19 @@
     //void setZoneDelimiters(...) // this could be here, instead on the LivingSpot class
     */
     
-    
-    //Laser Power, for the moment laser are TTL but we can use int:
-    //if powerValue > 0 ==> 'true'; else 'false'
-    void setLaserLockinPower(int powerLockingLaser);   
-    // Red laser (not used)
+    // Setting the laser power of the SENSING LASER (note: for the moment this is TTL, but could be analog): 
+    void setLaserLockinPower(int powerLockingLaser);       //if powerValue > 0 ==> 'true'; else 'false'
+    // Setting the power of the DISPLAYING  lasers: 
+    // Again: for the moment laser are TTL but these could be analog. Now, it is just: powerValue > 0 ==> 'true'; else 'false'
+    // Red laser:
     void setRedPower(int powerRed);
     // Green laser: 
     void setGreenPower(int powerGreen);
     // Blue laser: 
     void setBluePower(int powerBlue);
-
-    void setRGBPower(unsigned char color); // we will use the 3 LSB bits to set each color, note that here the "red" is the LOCKIN LASER
+    // Setting all colors at once: 
+    void setRGBPower(unsigned char color); // we will use the 3 LSB bits to set each color
+    void switchOffDisplayLasers() {setRGBPower(0x00);}
     
     //void setupPWM();
     /* IN ADVANCED HARDWARE: 
@@ -148,6 +174,7 @@
     */
 
     //float refFreq; // could be private
+    
     bool switchOneChange, switchTwoChange;
     void switchOneInterrupt();
     void switchTwoInterrupt();
@@ -162,7 +189,6 @@
     
 private:
      //DigitalOut Laser_Red, Laser_Green, Laser_Blue;
-     
 };
 
 
@@ -172,3 +198,4 @@
 
 
 #endif
+