Laser Sensing Display for UI interfaces in the real world

Dependencies:   mbed

Fork of skinGames_forktest by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Wed Apr 04 10:05:25 2012 +0000
Revision:
4:f9d364f10335
Parent:
3:b44ff6de81bd
Child:
5:73cd58b58f95
- the new optimized laser output buffer has not been tested, but it compiles; - I am commiting here, because I am planning to change the structure of the classes: soundSpot will not contain an object of type classLaserSensingTrajectory, but be a CHILD o...

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 0:345b3bc7a0ea 18 minI=4096;
mbedalvaro 4:f9d364f10335 19 int auxSize=lsdTrajectory.size();
mbedalvaro 4:f9d364f10335 20
mbedalvaro 0:345b3bc7a0ea 21 for (int i = 0; i < lsdTrajectory.size(); i++) {
mbedalvaro 4:f9d364f10335 22 float mesI=lsdTrajectory[(i+auxSize-delayMirrorSamples)%auxSize].intensity; // I need to do "auxSize-delay" instead of "-delay" only, because otherwise I will get negative values
mbedalvaro 0:345b3bc7a0ea 23 if (maxI<mesI) maxI=mesI;
mbedalvaro 0:345b3bc7a0ea 24 if (minI>mesI) minI=mesI;
mbedalvaro 0:345b3bc7a0ea 25 }
mbedalvaro 0:345b3bc7a0ea 26
mbedalvaro 0:345b3bc7a0ea 27 // Compute autoThreshold:
mbedalvaro 0:345b3bc7a0ea 28 if (1.0*maxI/(minI+0.1) > MIN_CONTRAST_RATIO ) {
mbedalvaro 0:345b3bc7a0ea 29 autoThreshold = 1.0 * (maxI-minI) * THRESHOLD_FACTOR + minI; // THRESHOLD_FACTOR = 2/3 or 1/2 is a good value.
mbedalvaro 0:345b3bc7a0ea 30 } else {// ... otherwise, we consider that the saccade is FULL on something white
mbedalvaro 0:345b3bc7a0ea 31 autoThreshold=-1;
mbedalvaro 0:345b3bc7a0ea 32 }
mbedalvaro 0:345b3bc7a0ea 33
mbedalvaro 0:345b3bc7a0ea 34 // 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 35 // 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 36 // 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 37 // idea of the blob "constant" internal pressure...
mbedalvaro 0:345b3bc7a0ea 38 lightTouched=false;
mbedalvaro 0:345b3bc7a0ea 39 for (int i = 0; i < lsdTrajectory.size(); i++) {
mbedalvaro 4:f9d364f10335 40 int delayedpoint=(i+auxSize-delayMirrorSamples)%auxSize;
mbedalvaro 4:f9d364f10335 41 if (lsdTrajectory[delayedpoint].intensity>autoThreshold) { // this means a WHITE zone:
mbedalvaro 4:f9d364f10335 42 lsdTrajectory[delayedpoint].lightZone= -1;//1;
mbedalvaro 0:345b3bc7a0ea 43 } else { // something touched: DARK ZONE
mbedalvaro 4:f9d364f10335 44 lsdTrajectory[delayedpoint].lightZone= 2;//0;
mbedalvaro 0:345b3bc7a0ea 45 lightTouched=true; // (for the whole loop)
mbedalvaro 0:345b3bc7a0ea 46 }
mbedalvaro 0:345b3bc7a0ea 47 }
mbedalvaro 0:345b3bc7a0ea 48 }