Laser Sensing Display for UI interfaces in the real world

Dependencies:   mbed

Fork of skinGames_forktest by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Thu Apr 12 13:02:59 2012 +0000
Revision:
14:0fc33a3a7b4b
Parent:
10:6f8e48dca1bd
Child:
22:d87317d7ca91
checking old version, need to branch

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedalvaro 0:345b3bc7a0ea 1
mbedalvaro 0:345b3bc7a0ea 2 #ifndef hardwareIO_h
mbedalvaro 0:345b3bc7a0ea 3 #define hardwareIO_h
mbedalvaro 0:345b3bc7a0ea 4
mbedalvaro 0:345b3bc7a0ea 5 #include "mbed.h"
mbedalvaro 0:345b3bc7a0ea 6 #include "lockin.h"
mbedalvaro 0:345b3bc7a0ea 7
mbedalvaro 0:345b3bc7a0ea 8
mbedalvaro 0:345b3bc7a0ea 9 // 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.
mbedalvaro 0:345b3bc7a0ea 10 #define SCK_PIN p7 //SPI Clock
mbedalvaro 0:345b3bc7a0ea 11 #define MISO_PIN p6 //SPI input (data comming from DAC, here not connected)
mbedalvaro 0:345b3bc7a0ea 12 #define MOSI_PIN p5 //SPI output (data going to DAC)
mbedalvaro 0:345b3bc7a0ea 13
mbedalvaro 0:345b3bc7a0ea 14 //**** CHIP SELECT pins for MP4922 DAC (mirrors and red laser)
mbedalvaro 0:345b3bc7a0ea 15 // VERY IMPORTANT: the chip select for the DACs should be different from the default SPI "SS" pin (Slave Select), which is 53 by default (and will be used by the Ethernet Shield).
mbedalvaro 0:345b3bc7a0ea 16 #define CS_DAC_MIRRORS p8 //Chip Select of the first DAC (mirrors)
mbedalvaro 0:345b3bc7a0ea 17
mbedalvaro 0:345b3bc7a0ea 18 //**** LASERS pins:
mbedalvaro 0:345b3bc7a0ea 19 #define LASER_RED_PIN p28
mbedalvaro 0:345b3bc7a0ea 20 #define LASER_GREEN_PIN p29
mbedalvaro 0:345b3bc7a0ea 21 #define LASER_BLUE_PIN p30
mbedalvaro 0:345b3bc7a0ea 22
mbedalvaro 0:345b3bc7a0ea 23 //**** MIRRORS:
mbedalvaro 0:345b3bc7a0ea 24 //The DAC is 12 bytes capable (Max=4096), but we will limit this a little.
mbedalvaro 0:345b3bc7a0ea 25 #define MAX_AD_MIRRORS 4095 // Absolute maximum for the SPI voltage (5V). This is for checking hardware compliance, but max and min angles can be defined for X and Y in each LivingSpot instance.
mbedalvaro 0:345b3bc7a0ea 26 #define MIN_AD_MIRRORS 0
mbedalvaro 0:345b3bc7a0ea 27 // We assume that the center of the mirror is at MAX_AD_MIRRORS/2 = 2000:
mbedalvaro 0:345b3bc7a0ea 28 #define CENTER_AD_MIRROR_X 2047 // This MUST BE the direction of the photodetector.
mbedalvaro 0:345b3bc7a0ea 29 #define CENTER_AD_MIRROR_Y 2047 // This MUST BE the direction of the photodetector.
mbedalvaro 0:345b3bc7a0ea 30
mbedalvaro 0:345b3bc7a0ea 31
mbedalvaro 0:345b3bc7a0ea 32 //**** Look-Up Table:
mbedalvaro 0:345b3bc7a0ea 33 #define uint16 unsigned short
mbedalvaro 0:345b3bc7a0ea 34 #define LUT_RESOLUTION 33 // resolution of the Look-Up Table (power of 2 +1)
mbedalvaro 0:345b3bc7a0ea 35 #define LUT_BITS_SHIFT 7 // bits shift from mirror DAC (12 bits) to LUT ( root_square(LUT_RESOLUTION - 1) )
mbedalvaro 0:345b3bc7a0ea 36 #define LUT_BITS_MASK 127 // bits mask to obtain the position remainder ( 2^LUT_BITS_SHIFT - 1 )
mbedalvaro 0:345b3bc7a0ea 37 // possible configurations:
mbedalvaro 0:345b3bc7a0ea 38 // LUT_RESOLUTION LUT_BITS_SHIFT LUT_BITS_MASK
mbedalvaro 0:345b3bc7a0ea 39 // 9 9 511
mbedalvaro 0:345b3bc7a0ea 40 // 17 8 255
mbedalvaro 0:345b3bc7a0ea 41 // 33 7 127
mbedalvaro 0:345b3bc7a0ea 42 // 65 6 63
mbedalvaro 0:345b3bc7a0ea 43 // ...
mbedalvaro 10:6f8e48dca1bd 44 #define NB_SCANS 8 // number of scans performed to generate the LUT table (actually, each site CUMULATES NB_SCANS values)
mbedalvaro 10:6f8e48dca1bd 45
mbedalvaro 0:345b3bc7a0ea 46 #define LUT_FILENAME "/local/LUT.txt"
mbedalvaro 14:0fc33a3a7b4b 47
mbedalvaro 14:0fc33a3a7b4b 48 // For checking (define if human readable file is required - note: it is not used by the program, just as output for human reading)
mbedalvaro 14:0fc33a3a7b4b 49 //#define LUT_H_FILENAME "/local/LUT_pos.txt"
mbedalvaro 0:345b3bc7a0ea 50
mbedalvaro 14:0fc33a3a7b4b 51 // Current Look-up table approximation (only one at a time!):
mbedalvaro 14:0fc33a3a7b4b 52 //#define LUT_BILINEAR
mbedalvaro 14:0fc33a3a7b4b 53 //#define LUT_DIRECT
mbedalvaro 14:0fc33a3a7b4b 54 //#define LUT_LINEAR
mbedalvaro 14:0fc33a3a7b4b 55 #define NO_LUT
mbedalvaro 0:345b3bc7a0ea 56
mbedalvaro 10:6f8e48dca1bd 57 //Current method for lockin data acquisition and correction
mbedalvaro 10:6f8e48dca1bd 58 #define lockin_read() lockin.getMedianValue() // lockin.getSmoothValue(); //return the average of the value stored on the buffer
mbedalvaro 10:6f8e48dca1bd 59 // lockin.getLastValue(); //return the last conversion of the ADC
mbedalvaro 10:6f8e48dca1bd 60 // lockin.getMedianValue(); //return the median value of the buffer
mbedalvaro 10:6f8e48dca1bd 61
mbedalvaro 0:345b3bc7a0ea 62
mbedalvaro 0:345b3bc7a0ea 63 // **** REFERENCE SIGNAL:
mbedalvaro 0:345b3bc7a0ea 64 /*
mbedalvaro 0:345b3bc7a0ea 65 #define testPin_OC1A 11 // this is, output compare pin OC1A //connected to CK2 = lockIn clock
mbedalvaro 0:345b3bc7a0ea 66 #define testPin_OC1B 12 // this is, output compare pin OC1B //connected to CK1 = laser clock
mbedalvaro 0:345b3bc7a0ea 67 #define testPin_OC1C 13
mbedalvaro 0:345b3bc7a0ea 68 */
mbedalvaro 0:345b3bc7a0ea 69
mbedalvaro 0:345b3bc7a0ea 70 // ==================================================================================================================================================================
mbedalvaro 0:345b3bc7a0ea 71
mbedalvaro 0:345b3bc7a0ea 72 class HardwareIO {
mbedalvaro 0:345b3bc7a0ea 73 public:
mbedalvaro 0:345b3bc7a0ea 74
mbedalvaro 0:345b3bc7a0ea 75
mbedalvaro 0:345b3bc7a0ea 76 void init(void);
mbedalvaro 0:345b3bc7a0ea 77
mbedalvaro 0:345b3bc7a0ea 78 //Lock-in acquisition methods:
mbedalvaro 10:6f8e48dca1bd 79 // float LockInRead_Volts();
mbedalvaro 10:6f8e48dca1bd 80 // int LockInRead_AD();
mbedalvaro 10:6f8e48dca1bd 81 // float LockInAD_to_Volts(int);
mbedalvaro 0:345b3bc7a0ea 82
mbedalvaro 0:345b3bc7a0ea 83 //Look-Up Table:
mbedalvaro 14:0fc33a3a7b4b 84 unsigned short lut[LUT_RESOLUTION][LUT_RESOLUTION]; //Look-Up Table (uint16 is "unsigned short")
mbedalvaro 0:345b3bc7a0ea 85 void scanLUT(); //create and save the Look-Up Table
mbedalvaro 0:345b3bc7a0ea 86 void setLUT(); //set the Look-Up Table: either from scanning, or from the file LUT.TXT (if it is present)
mbedalvaro 10:6f8e48dca1bd 87 float lockInCorrectedValue(unsigned short x, unsigned short y); //return the lockin value corrected with the Look-UpTable (this is, a RATIO of reflectivities, and <1)
mbedalvaro 0:345b3bc7a0ea 88
mbedalvaro 10:6f8e48dca1bd 89 void scan_serial(unsigned short pointsPerLine = 400);
mbedalvaro 0:345b3bc7a0ea 90
mbedalvaro 0:345b3bc7a0ea 91 // SPI control for DAC for mirrors and red laser power (low level):
mbedalvaro 10:6f8e48dca1bd 92 void writeOutX(unsigned short value);
mbedalvaro 10:6f8e48dca1bd 93 void writeOutY(unsigned short value);
mbedalvaro 0:345b3bc7a0ea 94
mbedalvaro 0:345b3bc7a0ea 95 // mirror degree-to-AD units conversion factors:
mbedalvaro 0:345b3bc7a0ea 96 //float AD_to_Deg_MIRROR_X;//=1.0*(MAX_DEG_MIRROR_X-MIN_DEG_MIRROR_X)/(MAX_AD_MIRRORS-MIN_AD_MIRRORS);
mbedalvaro 0:345b3bc7a0ea 97 //float AD_to_Deg_MIRROR_Y;//=1.0*(MAX_DEG_MIRROR_Y-MIN_DEG_MIRROR_Y)/(MAX_AD_MIRRORS-MIN_AD_MIRRORS);
mbedalvaro 0:345b3bc7a0ea 98
mbedalvaro 0:345b3bc7a0ea 99 /*
mbedalvaro 0:345b3bc7a0ea 100 // Mirror position:
mbedalvaro 0:345b3bc7a0ea 101 void setMirrorX_Deg(float _Az);
mbedalvaro 0:345b3bc7a0ea 102 void setMirrorY_Deg(float _El);
mbedalvaro 0:345b3bc7a0ea 103 void setMirrorX_AD(int _AzAD);
mbedalvaro 0:345b3bc7a0ea 104 void setMirrorY_AD(int _ElAD);
mbedalvaro 0:345b3bc7a0ea 105 void setMirrorsXY_AD(int _xAD, int _yAD);
mbedalvaro 0:345b3bc7a0ea 106 void setMirrorsCenter();
mbedalvaro 0:345b3bc7a0ea 107 void getAnglesFromAD(float &Az, float &El, int _xAD, int _yAD);
mbedalvaro 0:345b3bc7a0ea 108 //void setZoneDelimiters(...) // this could be here, instead on the LivingSpot class
mbedalvaro 0:345b3bc7a0ea 109 */
mbedalvaro 0:345b3bc7a0ea 110
mbedalvaro 0:345b3bc7a0ea 111
mbedalvaro 0:345b3bc7a0ea 112 //Laser Power, for the moment laser are TTL but we can use int:
mbedalvaro 0:345b3bc7a0ea 113 //if powerValue > 0 ==> 'true'; else 'false'
mbedalvaro 0:345b3bc7a0ea 114 // Red laser:
mbedalvaro 0:345b3bc7a0ea 115 void setRedPower(int powerRed);
mbedalvaro 0:345b3bc7a0ea 116 // Green laser:
mbedalvaro 0:345b3bc7a0ea 117 void setGreenPower(int powerGreen);
mbedalvaro 0:345b3bc7a0ea 118 // Blue laser:
mbedalvaro 0:345b3bc7a0ea 119 void setBluePower(int powerBlue);
mbedalvaro 0:345b3bc7a0ea 120
mbedalvaro 0:345b3bc7a0ea 121 void setRGBPower(char color); // we will use the 3 LSB bits to set each color
mbedalvaro 0:345b3bc7a0ea 122
mbedalvaro 0:345b3bc7a0ea 123 //void setupPWM();
mbedalvaro 0:345b3bc7a0ea 124 /* IN ADVANCED HARDWARE:
mbedalvaro 0:345b3bc7a0ea 125 // init PWM for reference generation:
mbedalvaro 0:345b3bc7a0ea 126 void initPWM();
mbedalvaro 0:345b3bc7a0ea 127 // reference signal:
mbedalvaro 0:345b3bc7a0ea 128 void setRefFreq(int);
mbedalvaro 0:345b3bc7a0ea 129 void incRefFreq(int inc=1);
mbedalvaro 0:345b3bc7a0ea 130 void decRefFreq(int dec=1);
mbedalvaro 0:345b3bc7a0ea 131 */
mbedalvaro 0:345b3bc7a0ea 132
mbedalvaro 0:345b3bc7a0ea 133 //float refFreq; // could be private
mbedalvaro 0:345b3bc7a0ea 134
mbedalvaro 0:345b3bc7a0ea 135
mbedalvaro 0:345b3bc7a0ea 136 private:
mbedalvaro 0:345b3bc7a0ea 137
mbedalvaro 0:345b3bc7a0ea 138 };
mbedalvaro 0:345b3bc7a0ea 139
mbedalvaro 0:345b3bc7a0ea 140
mbedalvaro 0:345b3bc7a0ea 141 extern HardwareIO IO; // allows the object IO to be used in other .cpp files (IO is pre-instantiated in hardwareIO.cpp)
mbedalvaro 0:345b3bc7a0ea 142 // NOTE: IO encapsulates many IO functions, but perhaps it is better not to have an IO object - just use each IO function separatedly (as with pc object for instance)
mbedalvaro 0:345b3bc7a0ea 143 extern Serial pc; // allows pc to be manipulated by other .cpp files, even if pc is defined in the hardwareIO.cpp
mbedalvaro 0:345b3bc7a0ea 144
mbedalvaro 0:345b3bc7a0ea 145
mbedalvaro 0:345b3bc7a0ea 146 #endif