Laser Sensing Display for UI interfaces in the real world
Fork of skinGames_forktest by
laserSensingDisplay.h@40:3ba2b0ea9f33, 2013-10-16 (annotated)
- Committer:
- mbedalvaro
- Date:
- Wed Oct 16 16:14:27 2013 +0000
- Revision:
- 40:3ba2b0ea9f33
- Child:
- 45:5ef809480c12
ca compile
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedalvaro | 40:3ba2b0ea9f33 | 1 | #ifndef LASER_SENSING_DISPLAY_h |
mbedalvaro | 40:3ba2b0ea9f33 | 2 | #define LASER_SENSING_DISPLAY_h |
mbedalvaro | 40:3ba2b0ea9f33 | 3 | |
mbedalvaro | 40:3ba2b0ea9f33 | 4 | #include "mbed.h" // we will use in particular the Ticker object |
mbedalvaro | 40:3ba2b0ea9f33 | 5 | #include "hardwareIO.h" // Include hardware interface for display and sensing |
mbedalvaro | 40:3ba2b0ea9f33 | 6 | #include "Scene.h" |
mbedalvaro | 40:3ba2b0ea9f33 | 7 | |
mbedalvaro | 40:3ba2b0ea9f33 | 8 | //extern laserSensingDisplay lsd; // pre-instantiated in the implementation file. |
mbedalvaro | 40:3ba2b0ea9f33 | 9 | |
mbedalvaro | 40:3ba2b0ea9f33 | 10 | // ===================================================================================================================== |
mbedalvaro | 40:3ba2b0ea9f33 | 11 | // NOTE: it would be much better to be able to wait in between points depending on the distance from these; but this is too computationally expensive here (perhaps!), |
mbedalvaro | 40:3ba2b0ea9f33 | 12 | // so for the time being, it would be better to compute "optimal trajectories" with repetitive points if necessary on the pc side... |
mbedalvaro | 40:3ba2b0ea9f33 | 13 | |
mbedalvaro | 40:3ba2b0ea9f33 | 14 | // ===================================================================================================================== |
mbedalvaro | 40:3ba2b0ea9f33 | 15 | |
mbedalvaro | 40:3ba2b0ea9f33 | 16 | //#define debugDelayMirrors // this is to check visually the mirror delay (but it is also beautiful) |
mbedalvaro | 40:3ba2b0ea9f33 | 17 | |
mbedalvaro | 40:3ba2b0ea9f33 | 18 | #define SENSING_LASER_BLANKING // note: this blanking introduces problems because the Lock-in looses signal, but we can add more points to compensate when there |
mbedalvaro | 40:3ba2b0ea9f33 | 19 | // are many blobs, see "DEFAULT_OVERLAP_POINTS" (but will slow down...) |
mbedalvaro | 40:3ba2b0ea9f33 | 20 | |
mbedalvaro | 40:3ba2b0ea9f33 | 21 | #define RENDER_INTERVAL 0.000056 //0.0001 is good for CALIBRATION grid, 0.000054 good for normal display // in seconds (Ticker) |
mbedalvaro | 40:3ba2b0ea9f33 | 22 | |
mbedalvaro | 40:3ba2b0ea9f33 | 23 | #define WAIT_NORMAL 1 // good :0 // (minimum is 0) waiting time for setting mirror position MINUS waiting laser time (note that this total waiting time may be |
mbedalvaro | 40:3ba2b0ea9f33 | 24 | //equal to 0 if we set a good sampling freq for the renderer, but and if the shape is regular so that this time does not change significatively - this is not |
mbedalvaro | 40:3ba2b0ea9f33 | 25 | // the case for multiple blobs or highly deformed blobs). |
mbedalvaro | 40:3ba2b0ea9f33 | 26 | #define WAIT_LASER 2 // Good 5 for grid. (minimum is 0) waiting time for properly powering the laser (if there are color changes IN BETWEEN points). Maybe needed for the green laser |
mbedalvaro | 40:3ba2b0ea9f33 | 27 | // WHEN THERE IS MORE THAN ONE SPOT: |
mbedalvaro | 40:3ba2b0ea9f33 | 28 | #define WAIT_FIRST 8// Good 7 for grid. 12 // special waiting time for mirror positioning to first point on next |
mbedalvaro | 40:3ba2b0ea9f33 | 29 | // blob BEFORE re-activating laser |
mbedalvaro | 40:3ba2b0ea9f33 | 30 | |
mbedalvaro | 40:3ba2b0ea9f33 | 31 | // ****IMPORTANT: IN FACT WAITING TIMES SHOULD DEPEND ON THE DISTANCE BETWEEN THE POINTS. AND THAT'S ALL***** |
mbedalvaro | 40:3ba2b0ea9f33 | 32 | |
mbedalvaro | 40:3ba2b0ea9f33 | 33 | #define WAIT_FIRST_LASER 0 // IMPORTANT waiting time for the activation of the RED laser and LOCK-IN (also waiting time for the mirrors) |
mbedalvaro | 40:3ba2b0ea9f33 | 34 | #define WAIT_LAST 2 // special waiting time for last point |
mbedalvaro | 40:3ba2b0ea9f33 | 35 | |
mbedalvaro | 40:3ba2b0ea9f33 | 36 | // Redundant drawing for avoiding deformed saccade (note: this could be active when there is more than one blob, instead of using a #define...) |
mbedalvaro | 40:3ba2b0ea9f33 | 37 | // NOTE: THIS IS ONLY MEANINFUL IF THE OBJECT IS A LOOP!!! |
mbedalvaro | 40:3ba2b0ea9f33 | 38 | #define DEFAULT_OVERLAP_POINTS 0 // 10 |
mbedalvaro | 40:3ba2b0ea9f33 | 39 | |
mbedalvaro | 40:3ba2b0ea9f33 | 40 | enum lsdStateType {START_FIRST_OBJECT, NORMAL_POINT, LAST_POINT, MOVE_NEXT_OBJECT, START_POINT}; |
mbedalvaro | 40:3ba2b0ea9f33 | 41 | |
mbedalvaro | 40:3ba2b0ea9f33 | 42 | typedef struct { |
mbedalvaro | 40:3ba2b0ea9f33 | 43 | // to do! |
mbedalvaro | 40:3ba2b0ea9f33 | 44 | } lsdParams; |
mbedalvaro | 40:3ba2b0ea9f33 | 45 | |
mbedalvaro | 40:3ba2b0ea9f33 | 46 | class laserSensingDisplay { |
mbedalvaro | 40:3ba2b0ea9f33 | 47 | public: |
mbedalvaro | 40:3ba2b0ea9f33 | 48 | |
mbedalvaro | 40:3ba2b0ea9f33 | 49 | // constructor: |
mbedalvaro | 40:3ba2b0ea9f33 | 50 | laserSensingDisplay(); |
mbedalvaro | 40:3ba2b0ea9f33 | 51 | |
mbedalvaro | 40:3ba2b0ea9f33 | 52 | // We can "attach" any scene to display (if laserSensingDisplay object is an ivar of LaserRenderer lsr, then all this will be set at the LaserRenderer init): |
mbedalvaro | 40:3ba2b0ea9f33 | 53 | void setSceneToDisplay(Scene* ); |
mbedalvaro | 40:3ba2b0ea9f33 | 54 | // NOTE: as this does display AND sensing, I cannot separate the 3d SCENE points from the 2d FRAME points. I call |
mbedalvaro | 40:3ba2b0ea9f33 | 55 | // therefore the "frame and scene" as just the "scene" for the time being. |
mbedalvaro | 40:3ba2b0ea9f33 | 56 | Scene* ptSceneToDisplay; |
mbedalvaro | 40:3ba2b0ea9f33 | 57 | |
mbedalvaro | 40:3ba2b0ea9f33 | 58 | //void startRenderer(); // pb: I cannot use the ticker function inside the class! |
mbedalvaro | 40:3ba2b0ea9f33 | 59 | void laserDisplayThread(); |
mbedalvaro | 40:3ba2b0ea9f33 | 60 | void run(); // start the ticker on laserDisplayThread |
mbedalvaro | 40:3ba2b0ea9f33 | 61 | void stop(); // stop the ticker on laserDisplayThread |
mbedalvaro | 40:3ba2b0ea9f33 | 62 | bool isRunning(); |
mbedalvaro | 40:3ba2b0ea9f33 | 63 | |
mbedalvaro | 40:3ba2b0ea9f33 | 64 | lsdStateType stateLsd; |
mbedalvaro | 40:3ba2b0ea9f33 | 65 | unsigned char totalObjects; // I assume no more than 255 objects! |
mbedalvaro | 40:3ba2b0ea9f33 | 66 | unsigned char currentObject; |
mbedalvaro | 40:3ba2b0ea9f33 | 67 | unsigned short currentPoint; |
mbedalvaro | 40:3ba2b0ea9f33 | 68 | unsigned char currentMirrorDelay; |
mbedalvaro | 40:3ba2b0ea9f33 | 69 | unsigned short currentTotalPoints; |
mbedalvaro | 40:3ba2b0ea9f33 | 70 | unsigned char currentColor; |
mbedalvaro | 40:3ba2b0ea9f33 | 71 | |
mbedalvaro | 40:3ba2b0ea9f33 | 72 | unsigned short x,y; // auxiliary variables storing mirror position(0-4096) |
mbedalvaro | 40:3ba2b0ea9f33 | 73 | |
mbedalvaro | 40:3ba2b0ea9f33 | 74 | // New method to check complete display of one loop: |
mbedalvaro | 40:3ba2b0ea9f33 | 75 | unsigned short configTotalPoints; |
mbedalvaro | 40:3ba2b0ea9f33 | 76 | unsigned short pointDisplayCounter; |
mbedalvaro | 40:3ba2b0ea9f33 | 77 | unsigned char numOverlapPoints; // I assume no more than 255 points of overlap! |
mbedalvaro | 40:3ba2b0ea9f33 | 78 | bool isDisplayingOver(); |
mbedalvaro | 40:3ba2b0ea9f33 | 79 | void startDisplayCheck(); |
mbedalvaro | 40:3ba2b0ea9f33 | 80 | |
mbedalvaro | 40:3ba2b0ea9f33 | 81 | unsigned char waitNormal, waitLaser, waitFirst, waitFirstLaser, waitLast; |
mbedalvaro | 40:3ba2b0ea9f33 | 82 | |
mbedalvaro | 40:3ba2b0ea9f33 | 83 | private: |
mbedalvaro | 40:3ba2b0ea9f33 | 84 | |
mbedalvaro | 40:3ba2b0ea9f33 | 85 | // Ticker to run/stop the ISR "laserDisplayThread()" |
mbedalvaro | 40:3ba2b0ea9f33 | 86 | Ticker timerForRendering; // note: this is the only file that uses this object (attach and detach). |
mbedalvaro | 40:3ba2b0ea9f33 | 87 | bool runningState; |
mbedalvaro | 40:3ba2b0ea9f33 | 88 | bool displayingFinished; |
mbedalvaro | 40:3ba2b0ea9f33 | 89 | }; |
mbedalvaro | 40:3ba2b0ea9f33 | 90 | |
mbedalvaro | 40:3ba2b0ea9f33 | 91 | #endif |
mbedalvaro | 40:3ba2b0ea9f33 | 92 | |
mbedalvaro | 40:3ba2b0ea9f33 | 93 | |
mbedalvaro | 40:3ba2b0ea9f33 | 94 | |
mbedalvaro | 40:3ba2b0ea9f33 | 95 |