Laser Sensing Display for UI interfaces in the real world
Fork of skinGames_forktest by
Diff: hardwareIO/hardwareIO.cpp
- Revision:
- 22:d87317d7ca91
- Parent:
- 14:0fc33a3a7b4b
- Child:
- 23:bf666fcc61bc
diff -r bc9b9383f4b6 -r d87317d7ca91 hardwareIO/hardwareIO.cpp --- a/hardwareIO/hardwareIO.cpp Sun May 06 14:40:19 2012 +0000 +++ b/hardwareIO/hardwareIO.cpp Sat Jun 02 06:38:12 2012 +0000 @@ -97,6 +97,41 @@ Laser_Blue =(color&0x01); } +void HardwareIO::showLimitsMirrors(int times) { + unsigned short pointsPerLine=100; + + for (int repeat=0; repeat<times; repeat++) { + + int shiftX = (MAX_AD_MIRRORS - MIN_AD_MIRRORS) / pointsPerLine; + int shiftY = (MAX_AD_MIRRORS - MIN_AD_MIRRORS) / pointsPerLine; + + writeOutX(MIN_AD_MIRRORS);writeOutY(MIN_AD_MIRRORS); + for(int j=0; j<pointsPerLine; j++){ + wait_us(200);//delay between each points + writeOutY(j*shiftY + MIN_AD_MIRRORS); + } + + writeOutX(MIN_AD_MIRRORS);writeOutY(MAX_AD_MIRRORS); + for(int j=0; j<pointsPerLine; j++) { + wait_us(200);//delay between each points + writeOutX(j*shiftX + MAX_AD_MIRRORS); + } + + writeOutX(MAX_AD_MIRRORS);writeOutY(MAX_AD_MIRRORS); + for(int j=0; j<pointsPerLine; j++) { + wait_us(200);//delay between each points + writeOutY(-j*shiftX + MAX_AD_MIRRORS); + } + + writeOutX(MAX_AD_MIRRORS);writeOutY(MIN_AD_MIRRORS); + for(int j=0; j<pointsPerLine; j++) { + wait_us(200);//delay between each points + writeOutX(-j*shiftX + MAX_AD_MIRRORS); + } + + } +} + 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 @@ -201,7 +236,8 @@ #endif #ifdef LUT_H_FILENAME - //save tab in human readable file + //save tab in Human readable file (not used by the program, this is just for checking) + // NOTE: we divide the content of the lut table by NB_SCANS, for easy reading (values should be between 0-4095) fp = fopen(LUT_H_FILENAME, "w"); // Open file on the local file system for writing fprintf(fp, "scan resolution: %d x %d\r\n",LUT_RESOLUTION, LUT_RESOLUTION); for(int j=0; j<LUT_RESOLUTION; j++){ @@ -220,8 +256,8 @@ //*******Correction using DIRECT approximation #ifdef LUT_DIRECT 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 +#endif + //*******Correction using BILINEAR approximation #ifdef LUT_BILINEAR unsigned short X = x >> LUT_BITS_SHIFT; //mirror "x" is 12bits, LUT "X" needs 4bits when lut is 17x17 @@ -232,9 +268,9 @@ //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 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 + 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) +#endif + //*******Correction using LINEAR approximation #ifdef LUT_LINEAR unsigned short X = x >> LUT_BITS_SHIFT; //mirror "x" is 12bits, LUT "X" needs 4bits when lut is 17x17 @@ -256,11 +292,11 @@ linearLUT = lut[X][Y] + dzx + dzy; 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 value divided by 4096 (this means, we assume that the surface is everywhere perfectly reflective - we supposedly get the max value always) +#endif + +//*******No corrections, just return the value divided by 4096 (this means we are assuming that the surface is everywhere perfectly reflective - we supposedly get the max value always) +#ifdef NO_LUT return 1.0* lockin_read()/4096; - -#endif //LUT_LINEAR -#endif //LUT_BILINEAR -#endif //LUT_DIRECT +#endif + }