Laser Sensing Display for UI interfaces in the real world

Dependencies:   mbed

Fork of skinGames_forktest by Alvaro Cassinelli

Revision:
10:6f8e48dca1bd
Parent:
0:345b3bc7a0ea
Child:
14:0fc33a3a7b4b
--- a/hardwareIO/lockin.cpp	Wed Apr 11 13:06:23 2012 +0000
+++ b/hardwareIO/lockin.cpp	Wed Apr 11 14:51:08 2012 +0000
@@ -2,9 +2,11 @@
 
 Lockin lockin=Lockin();//pre-instanciation of object lockin with inter-file scope (declared extern in .h file)
 
+
+// NOTE: the ADC interrupt catching function is not a method of the Lockin class, hence the use of the pre-instantiated object "lockin":
 void catchInterupt(uint32_t value){ 
     lockin.buffer_pos=(lockin.buffer_pos+1)%BUFFER_SIZE;
-    lockin.buffer[lockin.buffer_pos] = (value>>4)&0xFFF; // this is 12 bit precision ADC (0 to 4095)
+    lockin.buffer[lockin.buffer_pos] = (value>>4)&0xFFF; // this is 12 bit precision ADC (0 to 4095), can be stored in an "unsigned short" (two bytes)
 }
 
 // PWM generation is configure as double edge 
@@ -134,26 +136,26 @@
 */
 
 //****** aquisition method *****//
-float Lockin::getLastValue(){
+unsigned short Lockin::getLastValue(){
     return buffer[buffer_pos];
 }
 
-float Lockin::getSmoothValue(){
-    float smoothValue = buffer[0];
+unsigned short Lockin::getSmoothValue(){
+    unsigned short smoothValue = buffer[0];
     for(int i=1; i<BUFFER_SIZE; i++){
         smoothValue += buffer[i];
     }
-    smoothValue /= BUFFER_SIZE;
+    smoothValue = (unsigned short)(smoothValue/BUFFER_SIZE); // note: we could have more precision (sub-12 bit), but it's not required and would imply using a float as output
     
     return smoothValue;
 }
 
-float Lockin::getMedianValue(){
+unsigned short Lockin::getMedianValue(){
     //this method applies a median filter to the buffer
     //It reduces the salt-and-pepper noise
     //It seems that this noise is very strong on certain mBed board, but not all...
 
-    float orderedBuffer[BUFFER_SIZE_MEDIAN];
+    unsigned short orderedBuffer[BUFFER_SIZE_MEDIAN];
     
     //sort half of the buffer: