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 05:16:48 2012 +0000
Revision:
11:62f7183a03e7
Parent:
10:6f8e48dca1bd
Child:
24:4e52031a495b
It seems to work (but not tested on real hardware). ; NEEDS TO DO: ; 1) DOUBLE BUFFERING; 2) template class for vector2D, so as to use unsigned short for the rigid scafold instead of float...;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedalvaro 0:345b3bc7a0ea 1 #include "classLaserSensingTrajectory.h"
mbedalvaro 0:345b3bc7a0ea 2
mbedalvaro 0:345b3bc7a0ea 3 LaserSensingTrajectory::LaserSensingTrajectory(): lightTouched(false) {
mbedalvaro 0:345b3bc7a0ea 4 }
mbedalvaro 0:345b3bc7a0ea 5
mbedalvaro 0:345b3bc7a0ea 6 LaserSensingTrajectory::~LaserSensingTrajectory() {
mbedalvaro 0:345b3bc7a0ea 7 // lsdTrajectory.clear(); // there is no need to clear the vector, the destructor of this vector is called by default (and it's NOT a vector of pointers)
mbedalvaro 0:345b3bc7a0ea 8 }
mbedalvaro 0:345b3bc7a0ea 9
mbedalvaro 4:f9d364f10335 10
mbedalvaro 4:f9d364f10335 11 void LaserSensingTrajectory::setDelayMirrors(int delay) {
mbedalvaro 4:f9d364f10335 12 delayMirrorSamples=delay;
mbedalvaro 4:f9d364f10335 13 }
mbedalvaro 4:f9d364f10335 14
mbedalvaro 0:345b3bc7a0ea 15 void LaserSensingTrajectory::processSensedData() {
mbedalvaro 0:345b3bc7a0ea 16 // Compute max and min intensity on the loop
mbedalvaro 0:345b3bc7a0ea 17 maxI=0;
mbedalvaro 10:6f8e48dca1bd 18 minI=255; // ratio has been normalized between 0 and 255
mbedalvaro 4:f9d364f10335 19 int auxSize=lsdTrajectory.size();
mbedalvaro 4:f9d364f10335 20
mbedalvaro 5:73cd58b58f95 21 // Compute minimum and maximum intensities:
mbedalvaro 0:345b3bc7a0ea 22 for (int i = 0; i < lsdTrajectory.size(); i++) {
mbedalvaro 10:6f8e48dca1bd 23 unsigned char mesI=lsdTrajectory[i].intensity;
mbedalvaro 0:345b3bc7a0ea 24 if (maxI<mesI) maxI=mesI;
mbedalvaro 0:345b3bc7a0ea 25 if (minI>mesI) minI=mesI;
mbedalvaro 0:345b3bc7a0ea 26 }
mbedalvaro 0:345b3bc7a0ea 27
mbedalvaro 0:345b3bc7a0ea 28 // Compute autoThreshold:
mbedalvaro 10:6f8e48dca1bd 29 if (minI==0) autoThreshold=0; // (we consider that the saccade is FULL on something white)
mbedalvaro 10:6f8e48dca1bd 30 else if (1.0*maxI/minI > MIN_CONTRAST_RATIO ) {
mbedalvaro 10:6f8e48dca1bd 31 autoThreshold = (unsigned char) (1.0 * (maxI-minI) * THRESHOLD_FACTOR + minI); // THRESHOLD_FACTOR = 2/3 or 1/2 is a good value.
mbedalvaro 0:345b3bc7a0ea 32 } else {// ... otherwise, we consider that the saccade is FULL on something white
mbedalvaro 10:6f8e48dca1bd 33 autoThreshold=0;
mbedalvaro 0:345b3bc7a0ea 34 }
mbedalvaro 0:345b3bc7a0ea 35
mbedalvaro 0:345b3bc7a0ea 36 // Segment the trajectory (only two levels for the time being, but we can have more - meaning different forces, real or even complex values to have different angle forces...):
mbedalvaro 0:345b3bc7a0ea 37 // NOTE: if using 1 and -1 instead of 1 and 0, we can avoid having to add a "blob internal pressure"! -1 means a force towards the interior, and +1 outwards...
mbedalvaro 0:345b3bc7a0ea 38 // This means that the loop will naturally become inside-out depending on the color of the main surface! (but will mantain its normal size). Much better and elegant solution than the
mbedalvaro 0:345b3bc7a0ea 39 // idea of the blob "constant" internal pressure...
mbedalvaro 0:345b3bc7a0ea 40 lightTouched=false;
mbedalvaro 5:73cd58b58f95 41 // int counterLight=0;
mbedalvaro 0:345b3bc7a0ea 42 for (int i = 0; i < lsdTrajectory.size(); i++) {
mbedalvaro 7:0df17f3078bc 43 int delayedpoint=(i+auxSize+delayMirrorSamples)%auxSize; // this way we can have negative delayMirrorSamples if required (would be absurd though)
mbedalvaro 10:6f8e48dca1bd 44 if (lsdTrajectory[delayedpoint].intensity>=autoThreshold) { // this means a WHITE zone:
mbedalvaro 11:62f7183a03e7 45 lsdTrajectory[i].lightZone= -1;
mbedalvaro 5:73cd58b58f95 46 // counterLight++;
mbedalvaro 0:345b3bc7a0ea 47 } else { // something touched: DARK ZONE
mbedalvaro 11:62f7183a03e7 48 lsdTrajectory[i].lightZone= 2;
mbedalvaro 0:345b3bc7a0ea 49 lightTouched=true; // (for the whole loop)
mbedalvaro 0:345b3bc7a0ea 50 }
mbedalvaro 0:345b3bc7a0ea 51 }
mbedalvaro 5:73cd58b58f95 52 //coko=counterLight;
mbedalvaro 5:73cd58b58f95 53 // lightRatio=1.0*counterLight/lsdTrajectory.size();
mbedalvaro 0:345b3bc7a0ea 54 }