Laser Sensing Display for UI interfaces in the real world
Fork of skinGames_forktest by
Diff: hardwareIO/hardwareIO.cpp
- Revision:
- 10:6f8e48dca1bd
- Parent:
- 0:345b3bc7a0ea
- Child:
- 14:0fc33a3a7b4b
--- a/hardwareIO/hardwareIO.cpp Wed Apr 11 13:06:23 2012 +0000 +++ b/hardwareIO/hardwareIO.cpp Wed Apr 11 14:51:08 2012 +0000 @@ -40,7 +40,7 @@ } //write on the first DAC, output A (mirror X) -void HardwareIO::writeOutX(int value){ +void HardwareIO::writeOutX(unsigned short value){ if(value > MAX_AD_MIRRORS) value = MAX_AD_MIRRORS; if(value < MIN_AD_MIRRORS) value = MIN_AD_MIRRORS; @@ -53,7 +53,7 @@ } //write on the first DAC, output B (mirror Y) -void HardwareIO::writeOutY(int value){ +void HardwareIO::writeOutY(unsigned short value){ if(value > MAX_AD_MIRRORS) value = MAX_AD_MIRRORS; if(value < MIN_AD_MIRRORS) value = MIN_AD_MIRRORS; @@ -96,7 +96,7 @@ Laser_Blue =(color&0x01); } -void HardwareIO::scan_serial(int pointsPerLine){ +void HardwareIO::scan_serial(unsigned short pointsPerLine){ //scan the total surface with a custom resolution //send the lockin value for each point as a byte on the serial port to the PC //use "scanSLP_save" to see the data on processing @@ -114,6 +114,8 @@ writeOutX(i*shiftX + MIN_AD_MIRRORS); wait_us(100);//delay between each points + + // SEND A VALUE BETWEEN 0 and 255: pc.putc(int(255.0*lockin.getMedianValue()/4095));//printf("%dL",int(valueLockin*255));//pc.putc(int(lockin*255));// } } @@ -165,9 +167,9 @@ float x, y; - //scan the surface 8 times + //scan the surface NB_SCANS times //the total value in lut[i][j] shouldn't exceed uint16 !!! - for(int loop=0; loop<8; loop++){ + for(int loop=0; loop<NB_SCANS; loop++){ for(int j=0; j<LUT_RESOLUTION; j++){ y = shiftY*j + offsetY ; writeOutY(int(y)); @@ -212,11 +214,11 @@ } -//return the lockin value corrected with the Look-UpTable -float HardwareIO::lockInCorrectedValue(int x, int y){ +//Return the lockin value "corrected with the Look-UpTable" - this means a RATIO between two reflectivities (and normally, this is <1). +float HardwareIO::lockInCorrectedValue(unsigned short x, unsigned short y){ //*******Correction using DIRECT approximation #ifdef LUT_DIRECT - return 16.0 * lockin_read() / (lut[x >> LUT_BITS_SHIFT][y >> LUT_BITS_SHIFT]); + return 2.0* NB_SCANS * lockin_read() / (lut[x >> LUT_BITS_SHIFT][y >> LUT_BITS_SHIFT]); // 2 * NB_SCANS is the number of recorded sample added to one position of the LUT (scan is performed twice: left-right and right-left) #else //*******Correction using BILINEAR approximation @@ -229,7 +231,7 @@ //Wheighted mean approximation of the Look-Up Table at the position (x,y): float wmLUT = (1-dy)*( (1-dx)*lut[X][Y] + dx*lut[X+1][Y] ) + dy*( (1-dx)*lut[X][Y+1] + dx*lut[X+1][Y+1] ); - return 16.0 * lockin_read() / wmLUT;//16.0 is the number of recorded sample added to one position of the LUT + return 2.0* NB_SCANS * lockin_read() / wmLUT;// 2 * NB_SCANS is the number of recorded sample added to one position of the LUT (scan is performed twice: left-right and right-left) #else //*******Correction using LINEAR approximation @@ -251,14 +253,13 @@ //linear approximation of the Look-Up Table at the position (x,y): linearLUT = lut[X][Y] + dzx + dzy; - return 16.0 * lockin_read() / linearLUT; //16.0 is the number of recorded sample added to one position of the LUT + return 2.0* NB_SCANS * lockin_read() / linearLUT; // 2 * NB_SCANS is the number of recorded sample added to one position of the LUT (scan is performed twice: left-right and right-left) #else -//*******No corrections, just return the normalized value - return lockin_read()/4096; +//*******No corrections, just return the value divided by 4096 (this means, we assume that the surface is everywhere perfectly reflective - we supposedly get the max value always) + return 1.0* lockin_read()/4096; #endif //LUT_LINEAR #endif //LUT_BILINEAR #endif //LUT_DIRECT } -