Laser Sensing Display for UI interfaces in the real world

Dependencies:   mbed

Fork of skinGames_forktest by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Thu Apr 17 08:04:14 2014 +0000
Revision:
47:199042980678
Parent:
44:2432c218f191
publishing for sharing with Ken Iwasaki

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedalvaro 40:3ba2b0ea9f33 1 #include "WrapperFunctions.h"
mbedalvaro 40:3ba2b0ea9f33 2 #include "textData.h" // this just contains a special switch/case function to load an array of data, so as to store data in FLASH.
mbedalvaro 40:3ba2b0ea9f33 3
mbedalvaro 40:3ba2b0ea9f33 4 using namespace std;
mbedalvaro 40:3ba2b0ea9f33 5
mbedalvaro 40:3ba2b0ea9f33 6 extern LaserRenderer lsr;
mbedalvaro 40:3ba2b0ea9f33 7 extern Scene scene;
mbedalvaro 40:3ba2b0ea9f33 8 extern laserSensingDisplay lsd;
mbedalvaro 40:3ba2b0ea9f33 9
mbedalvaro 40:3ba2b0ea9f33 10 bool previousLsdState; //local scope - only used in this file.
mbedalvaro 40:3ba2b0ea9f33 11
mbedalvaro 43:1dd4cfc30788 12 // =============== SOME IMPORTANT LOW LEVEL FUNCTIONS CONTROLLING THE DISPLAYING ENGINE =========================================
mbedalvaro 43:1dd4cfc30788 13
mbedalvaro 43:1dd4cfc30788 14 // This is a special function that needs to be called at least once to set the displaying engine ON, thus setting the current state of the engine:
mbedalvaro 43:1dd4cfc30788 15 void startDisplay() {
mbedalvaro 43:1dd4cfc30788 16 previousLsdState=lsd.isRunning();
mbedalvaro 43:1dd4cfc30788 17 IO.setLaserLockinPower(1);
mbedalvaro 43:1dd4cfc30788 18 lsd.run(); // note: current state of the Lsd renderer is lsd.isRunning()
mbedalvaro 43:1dd4cfc30788 19 }
mbedalvaro 43:1dd4cfc30788 20
mbedalvaro 43:1dd4cfc30788 21 void stopDisplay() // save previous displaying status, stops the displaying engine, and switch off lasers
mbedalvaro 43:1dd4cfc30788 22 {
mbedalvaro 43:1dd4cfc30788 23 previousLsdState=lsd.isRunning();
mbedalvaro 43:1dd4cfc30788 24 lsd.stop();
mbedalvaro 43:1dd4cfc30788 25 // also, switch off lasers:
mbedalvaro 43:1dd4cfc30788 26 IO.setLaserLockinPower(0);
mbedalvaro 43:1dd4cfc30788 27 IO.switchOffDisplayLasers();
mbedalvaro 43:1dd4cfc30788 28 }
mbedalvaro 43:1dd4cfc30788 29
mbedalvaro 43:1dd4cfc30788 30 void toggleDisplay() {
mbedalvaro 43:1dd4cfc30788 31 if (lsd.isRunning()) stopDisplay(); else startDisplay();
mbedalvaro 43:1dd4cfc30788 32 }
mbedalvaro 43:1dd4cfc30788 33
mbedalvaro 43:1dd4cfc30788 34 void resumeDisplay() // resume display engine if it was displaying, otherwise does not do anything
mbedalvaro 43:1dd4cfc30788 35 // and set the sensing laser ON (no need to explicitly switch the DISPLAYING lasers ON - this is done in the displaying engine ISR).
mbedalvaro 43:1dd4cfc30788 36 {
mbedalvaro 43:1dd4cfc30788 37 if (previousLsdState) {
mbedalvaro 43:1dd4cfc30788 38 //switch on sensing lasers:
mbedalvaro 43:1dd4cfc30788 39 IO.setLaserLockinPower(1);
mbedalvaro 43:1dd4cfc30788 40 lsd.run();
mbedalvaro 43:1dd4cfc30788 41 // rem: no need to set the displaying lasers: this is done per-object basis
mbedalvaro 43:1dd4cfc30788 42 }
mbedalvaro 43:1dd4cfc30788 43 }
mbedalvaro 43:1dd4cfc30788 44
mbedalvaro 40:3ba2b0ea9f33 45 // ================================= BASIC "OPENGL-like" object/scene builders and query functions ("sense") ==========================================
mbedalvaro 40:3ba2b0ea9f33 46
mbedalvaro 40:3ba2b0ea9f33 47 void clearScene() // THIS SHOULD BE CALLED WHENEVER we want to create a new scene from scratch.
mbedalvaro 40:3ba2b0ea9f33 48 {
mbedalvaro 40:3ba2b0ea9f33 49 // This is delicate: first, we have to STOP the displaying engine, then we clear the scene and we are ready to add objects (begin/end, or primitive builders)
mbedalvaro 40:3ba2b0ea9f33 50 // BUT WE NEED TO LET THE DISPLAYING ENGINE FINISH THE WORK IT'S DOING on the current buffer. TWO WAYS: DOUBLE BUFFERING, or wait:
mbedalvaro 40:3ba2b0ea9f33 51 // Check in which point of the drawing we are:
mbedalvaro 40:3ba2b0ea9f33 52 if (lsd.isRunning()) {
mbedalvaro 40:3ba2b0ea9f33 53 lsd.startDisplayCheck();
mbedalvaro 40:3ba2b0ea9f33 54 while(!lsd.isDisplayingOver());
mbedalvaro 40:3ba2b0ea9f33 55 stopDisplay();
mbedalvaro 40:3ba2b0ea9f33 56 } else { //do nothing, the display engine is not working (we don't need to wait for the display to end!)
mbedalvaro 40:3ba2b0ea9f33 57 }
mbedalvaro 40:3ba2b0ea9f33 58 scene.clear();
mbedalvaro 40:3ba2b0ea9f33 59 }
mbedalvaro 40:3ba2b0ea9f33 60
mbedalvaro 42:5f21a710ebc5 61 void updateScene() // THIS SHOULD BE CALLED WHENEVER we ended CREATING or MODIFYING a scene
mbedalvaro 42:5f21a710ebc5 62 {
mbedalvaro 43:1dd4cfc30788 63 //We need to stop the display, and then indicate to the lsd that the scene has changed. NOTE: we don't resume displaying until we haven't drawn the scene again.
mbedalvaro 43:1dd4cfc30788 64 // Of course, it could
mbedalvaro 43:1dd4cfc30788 65 if (lsd.isRunning()) {
mbedalvaro 43:1dd4cfc30788 66 lsd.startDisplayCheck();
mbedalvaro 43:1dd4cfc30788 67 while(!lsd.isDisplayingOver());
mbedalvaro 43:1dd4cfc30788 68 stopDisplay();
mbedalvaro 43:1dd4cfc30788 69 }
mbedalvaro 42:5f21a710ebc5 70 lsd.setSceneToDisplay(&scene); // this will compute the number of objects, points, etc, to prepare the displaying engine
mbedalvaro 42:5f21a710ebc5 71 resumeDisplay();// this will resume display IF it was displaying before.
mbedalvaro 42:5f21a710ebc5 72 }
mbedalvaro 42:5f21a710ebc5 73
mbedalvaro 42:5f21a710ebc5 74
mbedalvaro 40:3ba2b0ea9f33 75 void deleteObject(int _id) {
mbedalvaro 40:3ba2b0ea9f33 76 if (lsd.isRunning()) {
mbedalvaro 40:3ba2b0ea9f33 77 lsd.startDisplayCheck();
mbedalvaro 40:3ba2b0ea9f33 78 while(!lsd.isDisplayingOver());
mbedalvaro 40:3ba2b0ea9f33 79 stopDisplay();
mbedalvaro 40:3ba2b0ea9f33 80 } else { //do nothing, the display engine is not working (we don't need to wait for the display to end!)
mbedalvaro 40:3ba2b0ea9f33 81 }
mbedalvaro 40:3ba2b0ea9f33 82 // DELETE THE OBJECT and update the scene:
mbedalvaro 40:3ba2b0ea9f33 83 scene.deleteObject(_id);
mbedalvaro 40:3ba2b0ea9f33 84 updateScene();
mbedalvaro 40:3ba2b0ea9f33 85 }
mbedalvaro 40:3ba2b0ea9f33 86
mbedalvaro 40:3ba2b0ea9f33 87 // Object creation ("openGL-style").
mbedalvaro 40:3ba2b0ea9f33 88 // NOTE: returning the pointer will make it possible to create COLLECTIONS of objects (by creating a vector<BaseObject*> firstCollection, which is a SUBSET of the
mbedalvaro 40:3ba2b0ea9f33 89 // scene collection. In the future, I will make a "collection" class with specific sensing methods, but for the time being this can be done by hand.
mbedalvaro 40:3ba2b0ea9f33 90 BaseObject* begin(unsigned char _id=0)
mbedalvaro 40:3ba2b0ea9f33 91 {
mbedalvaro 40:3ba2b0ea9f33 92 // This will add a new object. In the future, we can have modes - lines, bezier, and points - as well as specification of the type of object (enum)
mbedalvaro 40:3ba2b0ea9f33 93 // TO DO interesting feature: MERGING OF OBJECTS if they have the same ID? Note that if we DON'T specify an ID, the index will grow automatically starting from 0.
mbedalvaro 40:3ba2b0ea9f33 94 // for (int i=0; i<scene.totalObjects(); i++) if ((scene.objectArray[i]->ID())==_id) ptr_object=scene.objectArray[i];
mbedalvaro 40:3ba2b0ea9f33 95
mbedalvaro 40:3ba2b0ea9f33 96 BaseObject* ptr_newObject=new BaseObject(_id); // note: I cannot simply do: BaseObject newObject(_id) because this would be a LOCAL object, deallocated at the exit of this function.
mbedalvaro 40:3ba2b0ea9f33 97 // NOTE: by allocating the memory for the object pointed by ptr_newObject using new BaseObject, we lost the possibility of intantiating CHILD objects.
mbedalvaro 40:3ba2b0ea9f33 98 // One possibility is to have a parameter in the begin() method to indicate the type of object (for instance: GENERIC_OBJECT, LETTER, etc...). This way,
mbedalvaro 40:3ba2b0ea9f33 99 // we can properly instantiate the object. Another possiblity is to
mbedalvaro 40:3ba2b0ea9f33 100
mbedalvaro 40:3ba2b0ea9f33 101 if (ptr_newObject) { // check to see if we could allocate memory
mbedalvaro 40:3ba2b0ea9f33 102 scene.ptr_currentObject=ptr_newObject; // type casting "slices" the child object (but in principle, "scene" WON'T use derived methods)
mbedalvaro 40:3ba2b0ea9f33 103 ptr_newObject->setColor(lsr.color); // use current color in state machine
mbedalvaro 40:3ba2b0ea9f33 104 //pc.printf("Could allocate object: %d", _id);
mbedalvaro 40:3ba2b0ea9f33 105 } else {
mbedalvaro 40:3ba2b0ea9f33 106 //pc.printf("Could not allocate object: %d", _id);
mbedalvaro 40:3ba2b0ea9f33 107 }
mbedalvaro 40:3ba2b0ea9f33 108 return(ptr_newObject);
mbedalvaro 40:3ba2b0ea9f33 109 }
mbedalvaro 40:3ba2b0ea9f33 110
mbedalvaro 40:3ba2b0ea9f33 111 void vertex(V3& _v3)
mbedalvaro 40:3ba2b0ea9f33 112 {
mbedalvaro 40:3ba2b0ea9f33 113 // Add a 3d point to the "current" object (ie, the latest added object in principle!), but do not RENDER it yet (no final projection computed).
mbedalvaro 40:3ba2b0ea9f33 114 // NOTE: the point WILL however be added by transforming it with the current MODELVIEW matrix. This way, we can create a whole 3d "scene" before rendering,
mbedalvaro 40:3ba2b0ea9f33 115 // that can be rotated again without the need to rebuilt it.
mbedalvaro 40:3ba2b0ea9f33 116
mbedalvaro 40:3ba2b0ea9f33 117 scene.ptr_currentObject->addVertex(_v3, lsr.RT);
mbedalvaro 40:3ba2b0ea9f33 118 // Or, to avoid using ptr_currentObject: scene.objectArray.back()->addVertex(_v3, lsr.RT);
mbedalvaro 40:3ba2b0ea9f33 119
mbedalvaro 40:3ba2b0ea9f33 120 // Another way: ptr_currentObject->vertexArray.push_back(lsr.RT*_v3);
mbedalvaro 40:3ba2b0ea9f33 121 // yet another way: use a method of lsr that "transform" a 3d point. Too heavy...
mbedalvaro 40:3ba2b0ea9f33 122 }
mbedalvaro 40:3ba2b0ea9f33 123
mbedalvaro 40:3ba2b0ea9f33 124 void vertex(float x, float y, float z)
mbedalvaro 40:3ba2b0ea9f33 125 {
mbedalvaro 40:3ba2b0ea9f33 126 V3 v(x, y, z);
mbedalvaro 40:3ba2b0ea9f33 127 vertex(v); // why I cannot do: vertex(V3(x, y, z)) ? because vertex(V3& _v3) needs a REFERENCE to an object that has larger scope that this method itself!
mbedalvaro 40:3ba2b0ea9f33 128 }
mbedalvaro 44:2432c218f191 129
mbedalvaro 40:3ba2b0ea9f33 130 void vertexArray(vector<V3>& _vertexArray) {
mbedalvaro 40:3ba2b0ea9f33 131 for (int i=0; i<_vertexArray.size(); i++) {
mbedalvaro 40:3ba2b0ea9f33 132 vertex(_vertexArray[i]);
mbedalvaro 40:3ba2b0ea9f33 133 }
mbedalvaro 40:3ba2b0ea9f33 134 }
mbedalvaro 40:3ba2b0ea9f33 135
mbedalvaro 40:3ba2b0ea9f33 136 void end() // add the object to the current scene (we could add to a specific scene in the future...)
mbedalvaro 40:3ba2b0ea9f33 137 {
mbedalvaro 44:2432c218f191 138 // note: the current object pointed by ptr_newObject can be BaseObject or any child class. This is not a problem as long as the methods applied to the
mbedalvaro 40:3ba2b0ea9f33 139 // scene vector array don't use child methods (then we can do a dynamic cast before including in the array: pb = dynamic_cast<CBase*>(&d); ). IF we want
mbedalvaro 40:3ba2b0ea9f33 140 // the scene class to be able to use child methods, then we need to make BaseObject polymorphic, by declaring all usable methods VIRTUAL.
mbedalvaro 40:3ba2b0ea9f33 141 scene.addCurrentObject(); // add the currently tracked object to the vector array
mbedalvaro 40:3ba2b0ea9f33 142 //scene.addObject(scene.ptr_newObject); // use Scene method to add object to the scene (global).
mbedalvaro 40:3ba2b0ea9f33 143 // NOTE: scene structure changed, BUT we don't need to inform the displaying engine if we don't want (the new object won't be displayed though)
mbedalvaro 40:3ba2b0ea9f33 144 }
mbedalvaro 40:3ba2b0ea9f33 145
mbedalvaro 40:3ba2b0ea9f33 146 // Sensing methods (query and process sensed data for all objects):
mbedalvaro 40:3ba2b0ea9f33 147 // Objects: we can query the object by their ID or by just giving the object pointer. Now, since we are using begin/end to create objects (at least for now), it will
mbedalvaro 40:3ba2b0ea9f33 148 // be better to query by ID (and assume also that their IDs are different). Now, note that matching the ID may be costly (well, I assume they are not more than ten or so objects).
mbedalvaro 40:3ba2b0ea9f33 149 bool senseObject(int _id)
mbedalvaro 40:3ba2b0ea9f33 150 {
mbedalvaro 40:3ba2b0ea9f33 151 BaseObject* ptr_object=NULL;
mbedalvaro 40:3ba2b0ea9f33 152 for (int i=0; i<scene.totalObjects(); i++) if ((scene.objectArray[i]->ID())==_id) ptr_object=scene.objectArray[i];
mbedalvaro 40:3ba2b0ea9f33 153 if (ptr_object!=NULL) return(ptr_object->sense());
mbedalvaro 40:3ba2b0ea9f33 154 else return(false); // if there is no object with this ID, return false (convention)
mbedalvaro 40:3ba2b0ea9f33 155 }
mbedalvaro 40:3ba2b0ea9f33 156
mbedalvaro 40:3ba2b0ea9f33 157 bool senseScene()
mbedalvaro 40:3ba2b0ea9f33 158 {
mbedalvaro 40:3ba2b0ea9f33 159 return(scene.sense());
mbedalvaro 40:3ba2b0ea9f33 160 }
mbedalvaro 40:3ba2b0ea9f33 161
mbedalvaro 40:3ba2b0ea9f33 162 // ================================= "GLOBAL" TRANSFORMATIONS (i.e. "viewing transforms") ON OBJECTS and SCENE without rebuilding them ============================================================
mbedalvaro 40:3ba2b0ea9f33 163 // NOTE: There are two ways of doing this: (1) one is to apply the required transformation on the object/scene 3d points themselves; (2) the other is to mantain the 3d points values, but apply
mbedalvaro 40:3ba2b0ea9f33 164 // the transformation FOR rendering only. The advantage of this last technique is that there will not be any drifting of the values because
mbedalvaro 40:3ba2b0ea9f33 165 // of approximations after a while; the disadvantage is that we cannot easily track an "incremental" interactive transformation (say, scrolling a sphere). But this can be solved by using
mbedalvaro 40:3ba2b0ea9f33 166 // an "accumulator" tranformation matrix (or a quaternion). Also, the second methodology closely matches the OpenGL philosophy: defining the "modelview transformation" and the "viewing transformation",
mbedalvaro 40:3ba2b0ea9f33 167 // even though these transformations apply to the same modelview matrix.
mbedalvaro 40:3ba2b0ea9f33 168 // I will implement both, because even the first option can be useful (to create more complex scenes by rotating already created objects for instance - but it will be trickier to understand though)
mbedalvaro 40:3ba2b0ea9f33 169
mbedalvaro 40:3ba2b0ea9f33 170 // (1) applying a transformation on the 3d points (NOTE: we could also apply transformations on the projected points! this is however a work for the "viewport").
mbedalvaro 47:199042980678 171 // NOTE: I may later create specific transform methods (rotation and translations), but in general we can use the lsr stack. So, I assume the user has set RT to what she wants. Then, we will
mbedalvaro 40:3ba2b0ea9f33 172 // just apply RT to the object or whole scene. This method can be used to RESIZE the object (in particular when it is centered).
mbedalvaro 40:3ba2b0ea9f33 173 //(a) Objects:
mbedalvaro 47:199042980678 174 void transformObject(int _id) // use maps in the future!!!
mbedalvaro 40:3ba2b0ea9f33 175 {
mbedalvaro 40:3ba2b0ea9f33 176 BaseObject* ptr_object=NULL;
mbedalvaro 40:3ba2b0ea9f33 177 for (int i=0; i<scene.totalObjects(); i++) if ((scene.objectArray[i]->ID())==_id) ptr_object=scene.objectArray[i];
mbedalvaro 40:3ba2b0ea9f33 178 if (ptr_object!=NULL) {
mbedalvaro 40:3ba2b0ea9f33 179 // Apply the current RT transformation:
mbedalvaro 40:3ba2b0ea9f33 180 ptr_object->transform(lsr.RT);
mbedalvaro 40:3ba2b0ea9f33 181 // Them RENDER the object? no, this will be done only when drawing: the reason is that ON TOP of this transform, we may have the GLOBAL MODELVIEW matrix to apply
mbedalvaro 40:3ba2b0ea9f33 182 //lsr.renderObject(ptr_object);
mbedalvaro 40:3ba2b0ea9f33 183 }
mbedalvaro 40:3ba2b0ea9f33 184 }
mbedalvaro 40:3ba2b0ea9f33 185 // If we know the object already (this is the output of "begin" method for instance), we can apply the transformation without having to match the ID:
mbedalvaro 40:3ba2b0ea9f33 186 void transformObject(BaseObject* ptr_object)
mbedalvaro 40:3ba2b0ea9f33 187 {
mbedalvaro 40:3ba2b0ea9f33 188 ptr_object->transform(lsr.RT);
mbedalvaro 40:3ba2b0ea9f33 189 // lsr.renderObject(ptr_object);
mbedalvaro 40:3ba2b0ea9f33 190 }
mbedalvaro 40:3ba2b0ea9f33 191 // (b) Whole scene:
mbedalvaro 40:3ba2b0ea9f33 192 void transformScene()
mbedalvaro 40:3ba2b0ea9f33 193 {
mbedalvaro 40:3ba2b0ea9f33 194 scene.transform(lsr.RT); // or equialently: for (int i=0; i<scene.totalObjects(); i++) scene.objectArray[i]->transform(lsr.RT);
mbedalvaro 40:3ba2b0ea9f33 195 // lsr.renderScene(&scene);
mbedalvaro 40:3ba2b0ea9f33 196 }
mbedalvaro 40:3ba2b0ea9f33 197
mbedalvaro 47:199042980678 198 // Some elementary transformations (again, note that this if applied too much will make the object eventually deform - it would be much better to do the
mbedalvaro 47:199042980678 199 // rotation/translation actions as part of a program IN the mbed, instead of sending commands:
mbedalvaro 47:199042980678 200 void translateObject(int _id, int xx, int yy, int zz) {
mbedalvaro 47:199042980678 201 lsr.pushPoseMatrix();
mbedalvaro 47:199042980678 202 lsr.setIdentityPose(); // we could use a wrapper, but I won't for the time being.
mbedalvaro 47:199042980678 203 lsr.flipY(); // there is a pb here...
mbedalvaro 47:199042980678 204 //lsr.flipX();
mbedalvaro 47:199042980678 205 lsr.translate(xx,yy,zz);
mbedalvaro 47:199042980678 206 transformObject(_id);
mbedalvaro 47:199042980678 207 lsr.popPoseMatrix();
mbedalvaro 47:199042980678 208 }
mbedalvaro 47:199042980678 209
mbedalvaro 47:199042980678 210 void rotateObjectX(int _id, float alpha) {
mbedalvaro 47:199042980678 211 lsr.pushPoseMatrix();
mbedalvaro 47:199042980678 212 lsr.setIdentityPose(); // we could use a wrapper, but I won't for the time being.
mbedalvaro 47:199042980678 213 lsr.flipY();
mbedalvaro 47:199042980678 214 //lsr.flipX();
mbedalvaro 47:199042980678 215 lsr.rotateX(alpha);
mbedalvaro 47:199042980678 216 transformObject(_id);
mbedalvaro 47:199042980678 217 lsr.popPoseMatrix();
mbedalvaro 47:199042980678 218 }
mbedalvaro 47:199042980678 219
mbedalvaro 47:199042980678 220 void rotateObjectY(int _id, float alpha){
mbedalvaro 47:199042980678 221 lsr.pushPoseMatrix();
mbedalvaro 47:199042980678 222 lsr.setIdentityPose(); // we could use a wrapper, but I won't for the time being.
mbedalvaro 47:199042980678 223 lsr.flipY();
mbedalvaro 47:199042980678 224 //lsr.flipX();
mbedalvaro 47:199042980678 225 lsr.rotateY(alpha);
mbedalvaro 47:199042980678 226 transformObject(_id);
mbedalvaro 47:199042980678 227 lsr.popPoseMatrix();
mbedalvaro 47:199042980678 228 }
mbedalvaro 47:199042980678 229
mbedalvaro 47:199042980678 230 void rotateObjectZ(int _id, float alpha) { lsr.pushPoseMatrix();
mbedalvaro 47:199042980678 231 lsr.setIdentityPose(); // we could use a wrapper, but I won't for the time being.
mbedalvaro 47:199042980678 232 lsr.flipY();
mbedalvaro 47:199042980678 233 //lsr.flipX();
mbedalvaro 47:199042980678 234 lsr.rotateZ(alpha);
mbedalvaro 47:199042980678 235 transformObject(_id);
mbedalvaro 47:199042980678 236 lsr.popPoseMatrix();
mbedalvaro 47:199042980678 237 }
mbedalvaro 47:199042980678 238
mbedalvaro 47:199042980678 239 // =======================================================================================================
mbedalvaro 47:199042980678 240
mbedalvaro 40:3ba2b0ea9f33 241 //(2) Apply current RT transformation and render but KEEPING the original values of the 3d points:
mbedalvaro 40:3ba2b0ea9f33 242 //(a) Objects:
mbedalvaro 40:3ba2b0ea9f33 243 void drawObject(int _id) // use maps in the future!!!
mbedalvaro 40:3ba2b0ea9f33 244 {
mbedalvaro 40:3ba2b0ea9f33 245 BaseObject* ptr_object=NULL;
mbedalvaro 40:3ba2b0ea9f33 246 for (int i=0; i<scene.totalObjects(); i++) if ((scene.objectArray[i]->ID())==_id) ptr_object=scene.objectArray[i];
mbedalvaro 40:3ba2b0ea9f33 247 if (ptr_object!=NULL) {
mbedalvaro 40:3ba2b0ea9f33 248 // We don't apply the current RT transformation (ptr_object->transform(lsr.RT)), but instead we directly RENDER it with a pre-transformation:
mbedalvaro 40:3ba2b0ea9f33 249 lsr.renderObject(ptr_object, lsr.RT);
mbedalvaro 40:3ba2b0ea9f33 250 }
mbedalvaro 40:3ba2b0ea9f33 251 }
mbedalvaro 40:3ba2b0ea9f33 252 // If we know the object already (this is the output of "begin" method for instance), we can apply the transformation without having to match the ID:
mbedalvaro 40:3ba2b0ea9f33 253 void drawObject(BaseObject* ptr_object)
mbedalvaro 40:3ba2b0ea9f33 254 {
mbedalvaro 40:3ba2b0ea9f33 255 //ptr_object->transform(lsr.RT);
mbedalvaro 40:3ba2b0ea9f33 256 lsr.renderObject(ptr_object, lsr.RT);
mbedalvaro 40:3ba2b0ea9f33 257 }
mbedalvaro 40:3ba2b0ea9f33 258 // (b) Whole scene:
mbedalvaro 40:3ba2b0ea9f33 259 // ATTENTION: we may need START the display engine the FIRST time or nothing will be seeing (this is done by calling startDisplay()).
mbedalvaro 40:3ba2b0ea9f33 260 void drawScene()
mbedalvaro 40:3ba2b0ea9f33 261 {
mbedalvaro 40:3ba2b0ea9f33 262 //NOTE: there is no need, AND IT IS better NOT to stop/resume the display engine (detaching and reattaching the ISR).
mbedalvaro 40:3ba2b0ea9f33 263 // There is no need in principle, because we only call drawScene AFTER the scene to draw has been passed to the laserSensingDisplay object. This means
mbedalvaro 40:3ba2b0ea9f33 264 // that the number of objects and points per object did NOT change.
mbedalvaro 40:3ba2b0ea9f33 265 //scene.transform(lsr.RT); // or equialently: for (int i=0; i<scene.totalObjects(); i++) scene.objectArray[i]->transform(lsr.RT);
mbedalvaro 40:3ba2b0ea9f33 266 lsr.renderScene(&scene, lsr.RT);
mbedalvaro 40:3ba2b0ea9f33 267 }
mbedalvaro 40:3ba2b0ea9f33 268
mbedalvaro 40:3ba2b0ea9f33 269 // Color attribute transformation (for the time being, only to the whole scene):
mbedalvaro 40:3ba2b0ea9f33 270 void changeColorScene(unsigned char _color) {
mbedalvaro 40:3ba2b0ea9f33 271 for (int i=0; i<scene.totalObjects(); i++) scene.objectArray[i]->setColor(_color);
mbedalvaro 40:3ba2b0ea9f33 272 }
mbedalvaro 40:3ba2b0ea9f33 273
mbedalvaro 40:3ba2b0ea9f33 274 // ================================= OBJECT PRIMITIVES (this could be in a different file) ============================================================
mbedalvaro 40:3ba2b0ea9f33 275 // NOTE: these methods will not create new objects, unless we explicitly say so (by preceding them with "begin" and ending by "end".
mbedalvaro 40:3ba2b0ea9f33 276 // Instead, they will add the vertices to the "current object" being created.
mbedalvaro 40:3ba2b0ea9f33 277
mbedalvaro 40:3ba2b0ea9f33 278 // A line:
mbedalvaro 40:3ba2b0ea9f33 279 void line(V3& v0, V3& v1, int npoints)
mbedalvaro 40:3ba2b0ea9f33 280 {
mbedalvaro 40:3ba2b0ea9f33 281 V3 stepVector=(v1-v0)/(npoints-1);
mbedalvaro 40:3ba2b0ea9f33 282 for (int i=0; i<npoints; i++) {
mbedalvaro 40:3ba2b0ea9f33 283 V3 v(v0+stepVector*i); // vertex added to the current object
mbedalvaro 40:3ba2b0ea9f33 284 vertex(v);
mbedalvaro 40:3ba2b0ea9f33 285 }
mbedalvaro 40:3ba2b0ea9f33 286 }
mbedalvaro 40:3ba2b0ea9f33 287 void line(float x0, float y0, float z0, float x1, float y1, float z1, int npoints)
mbedalvaro 40:3ba2b0ea9f33 288 {
mbedalvaro 40:3ba2b0ea9f33 289 // NOTE: we don't clear the current modelview, but use it's current value.
mbedalvaro 40:3ba2b0ea9f33 290 V3 A(x0, y0, z0), B(x1, y1, z1);
mbedalvaro 40:3ba2b0ea9f33 291 line(A, B, npoints);
mbedalvaro 40:3ba2b0ea9f33 292 }
mbedalvaro 40:3ba2b0ea9f33 293 // A line in the z=0 plane:
mbedalvaro 40:3ba2b0ea9f33 294 void line(float x0, float y0, float x1, float y1, int npoints)
mbedalvaro 40:3ba2b0ea9f33 295 {
mbedalvaro 40:3ba2b0ea9f33 296 // NOTE: we don't clear the current modelview, but use it's current value.
mbedalvaro 40:3ba2b0ea9f33 297 V3 A(x0, y0, 0), B(x1, y1, 0);
mbedalvaro 40:3ba2b0ea9f33 298 line(A, B, npoints);
mbedalvaro 40:3ba2b0ea9f33 299 }
mbedalvaro 40:3ba2b0ea9f33 300
mbedalvaro 40:3ba2b0ea9f33 301 // A square in the z=0 plane
mbedalvaro 40:3ba2b0ea9f33 302 void square(float sideSize, int npointsSide)
mbedalvaro 40:3ba2b0ea9f33 303 {
mbedalvaro 40:3ba2b0ea9f33 304 V3 A(0,0, 0), B(sideSize, 0, 0);
mbedalvaro 40:3ba2b0ea9f33 305 line(A, B, npointsSide);
mbedalvaro 40:3ba2b0ea9f33 306 A.x = sideSize;
mbedalvaro 40:3ba2b0ea9f33 307 A.y = sideSize;
mbedalvaro 40:3ba2b0ea9f33 308 line(B, A, npointsSide);
mbedalvaro 40:3ba2b0ea9f33 309 B.x = 0;
mbedalvaro 40:3ba2b0ea9f33 310 B.y = sideSize;
mbedalvaro 40:3ba2b0ea9f33 311 line(A, B, npointsSide);
mbedalvaro 40:3ba2b0ea9f33 312 A.x = 0;
mbedalvaro 40:3ba2b0ea9f33 313 A.y = 0;
mbedalvaro 40:3ba2b0ea9f33 314 line(B, A, npointsSide);
mbedalvaro 40:3ba2b0ea9f33 315 }
mbedalvaro 40:3ba2b0ea9f33 316
mbedalvaro 40:3ba2b0ea9f33 317 // A rectangle in the z=0 plane
mbedalvaro 40:3ba2b0ea9f33 318 void rectangle(float sideSizeX, float sideSizeY, int interPointDistance)
mbedalvaro 40:3ba2b0ea9f33 319 // note: interPointDistance (degrees per point) would be the equivalent of "pixels" separation for the laser projector
mbedalvaro 40:3ba2b0ea9f33 320 {
mbedalvaro 40:3ba2b0ea9f33 321 V3 A(0,0, 0), B(sideSizeX, 0, 0);
mbedalvaro 40:3ba2b0ea9f33 322 line(A, B, sideSizeX/interPointDistance);
mbedalvaro 40:3ba2b0ea9f33 323 A.x = sideSizeX;
mbedalvaro 40:3ba2b0ea9f33 324 A.y = sideSizeY;
mbedalvaro 40:3ba2b0ea9f33 325 line(B, A, sideSizeY/interPointDistance);
mbedalvaro 40:3ba2b0ea9f33 326 B.x = 0;
mbedalvaro 40:3ba2b0ea9f33 327 B.y = sideSizeY;
mbedalvaro 40:3ba2b0ea9f33 328 line(A, B, sideSizeX/interPointDistance);
mbedalvaro 40:3ba2b0ea9f33 329 A.x = 0;
mbedalvaro 40:3ba2b0ea9f33 330 A.y = 0;
mbedalvaro 40:3ba2b0ea9f33 331 line(B, A, sideSizeY/interPointDistance);
mbedalvaro 40:3ba2b0ea9f33 332 }
mbedalvaro 40:3ba2b0ea9f33 333
mbedalvaro 40:3ba2b0ea9f33 334
mbedalvaro 40:3ba2b0ea9f33 335
mbedalvaro 40:3ba2b0ea9f33 336 void circle(float radius, int numpoints)
mbedalvaro 40:3ba2b0ea9f33 337 {
mbedalvaro 40:3ba2b0ea9f33 338 float angleStep=360.0/numpoints;
mbedalvaro 40:3ba2b0ea9f33 339 lsr.pushPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 340 for (int i=0; i<numpoints; i++) {
mbedalvaro 40:3ba2b0ea9f33 341 vertex(radius, 0, 0);
mbedalvaro 40:3ba2b0ea9f33 342 lsr.rotateZ(angleStep);
mbedalvaro 40:3ba2b0ea9f33 343 }
mbedalvaro 40:3ba2b0ea9f33 344 // Redo the first point to close the cirlce:
mbedalvaro 40:3ba2b0ea9f33 345 vertex(radius, 0, 0);
mbedalvaro 40:3ba2b0ea9f33 346 lsr.popPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 347 }
mbedalvaro 40:3ba2b0ea9f33 348
mbedalvaro 40:3ba2b0ea9f33 349 // A "cube" (with one corner at the origin):
mbedalvaro 40:3ba2b0ea9f33 350 void cube(float sideSize, int nbpointsSide)
mbedalvaro 40:3ba2b0ea9f33 351 {
mbedalvaro 40:3ba2b0ea9f33 352 lsr.pushPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 353 square(sideSize, nbpointsSide);
mbedalvaro 40:3ba2b0ea9f33 354 line(0,0,0,0,0,sideSize, nbpointsSide);
mbedalvaro 40:3ba2b0ea9f33 355 lsr.translate(0,0,sideSize);
mbedalvaro 40:3ba2b0ea9f33 356 square(sideSize, nbpointsSide);
mbedalvaro 40:3ba2b0ea9f33 357 lsr.popPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 358 }
mbedalvaro 40:3ba2b0ea9f33 359
mbedalvaro 40:3ba2b0ea9f33 360 // LETTERS and STRINGS:
mbedalvaro 40:3ba2b0ea9f33 361 // NOTE: for the time being, these letters are not special object. I will just add the vertex of the letter to a normal BaseObject.
mbedalvaro 40:3ba2b0ea9f33 362 void letter3d(char _letter, float width, float height)
mbedalvaro 40:3ba2b0ea9f33 363 {
mbedalvaro 40:3ba2b0ea9f33 364 unsigned char numpoints=fillAuxBuffer(_letter);
mbedalvaro 40:3ba2b0ea9f33 365 lsr.pushPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 366 lsr.resize(0.1*width, 1.0/15.0*height, 1); // note: letter size as defined in textData.h is: width = 10, height = 15
mbedalvaro 40:3ba2b0ea9f33 367 for (int i=0; i<numpoints; i++ ) vertex(auxbuffer[2*i], auxbuffer[2*i+1], 0);
mbedalvaro 40:3ba2b0ea9f33 368 lsr.popPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 369 }
mbedalvaro 40:3ba2b0ea9f33 370
mbedalvaro 40:3ba2b0ea9f33 371 // To create a string: either as a single object, or separate objects. In the later case, we should NOT call to "begin/end", because this will be done
mbedalvaro 40:3ba2b0ea9f33 372 // in THIS wrapping function... how to indicate this? and which index? So, for the time being, I will consider the FIRST case only. If we want to have
mbedalvaro 40:3ba2b0ea9f33 373 // separate objects, we will need to do this explicitly, basically copying this code and interspeeding it with "begin/end" and numbering the objects (cool
mbedalvaro 40:3ba2b0ea9f33 374 // for detecting individual touched letters).
mbedalvaro 40:3ba2b0ea9f33 375 void string3d(string _text, float totalWidth, float height)
mbedalvaro 40:3ba2b0ea9f33 376 {
mbedalvaro 40:3ba2b0ea9f33 377 float stepX=1.0*totalWidth/_text.length(); // this is just fontWidth, or some percentage of it
mbedalvaro 40:3ba2b0ea9f33 378 lsr.pushPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 379 for (unsigned short i=0; i<_text.length(); i++) {
mbedalvaro 40:3ba2b0ea9f33 380 char ch=_text.at(i);
mbedalvaro 40:3ba2b0ea9f33 381 lsr.translate(1.3*stepX,0,0); // slightly larger than the fontWidth...
mbedalvaro 40:3ba2b0ea9f33 382 if (ch!=' ') letter3d(ch, stepX, height);
mbedalvaro 40:3ba2b0ea9f33 383 }
mbedalvaro 40:3ba2b0ea9f33 384 lsr.popPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 385 }
mbedalvaro 40:3ba2b0ea9f33 386
mbedalvaro 40:3ba2b0ea9f33 387
mbedalvaro 40:3ba2b0ea9f33 388
mbedalvaro 40:3ba2b0ea9f33 389 // ========= MULTI OBJECTS ==================================================================================
mbedalvaro 40:3ba2b0ea9f33 390
mbedalvaro 40:3ba2b0ea9f33 391 // A simple "normalized" grid on the z=0 plane (with points, repeated to get them more "clear").
mbedalvaro 40:3ba2b0ea9f33 392 // Also, it may be interesting to make each group of points a separate object (for switching off laser, but also querying touch)
mbedalvaro 40:3ba2b0ea9f33 393 // Corner of the grid at the origin.
mbedalvaro 40:3ba2b0ea9f33 394 // NOTE: this is an example of a "multi-object" that does NOT need "begin/end" in the main
mbedalvaro 40:3ba2b0ea9f33 395 void grid(int nx, int ny, int repeatpoint)
mbedalvaro 40:3ba2b0ea9f33 396 {
mbedalvaro 40:3ba2b0ea9f33 397 float px=1.0/(nx-1), py=1.0/(ny-1);
mbedalvaro 40:3ba2b0ea9f33 398 //lsr.pushPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 399 for (int i=0; i<ny; i++) {
mbedalvaro 40:3ba2b0ea9f33 400 // pc.printf("\n");
mbedalvaro 40:3ba2b0ea9f33 401 if (i%2==0) { // to do zig-zag...
mbedalvaro 40:3ba2b0ea9f33 402 for (int j=0; j<nx; j++) {
mbedalvaro 40:3ba2b0ea9f33 403 begin(ny*i+j);
mbedalvaro 40:3ba2b0ea9f33 404 for (int k=0; k<repeatpoint; k++)
mbedalvaro 40:3ba2b0ea9f33 405 //vertex(1.0*j*px,1.0*i*py,0); // faster than using translations...
mbedalvaro 40:3ba2b0ea9f33 406 vertex(1.0*i*py,1.0*j*px,0);
mbedalvaro 40:3ba2b0ea9f33 407 end();
mbedalvaro 40:3ba2b0ea9f33 408 //pc.printf("%4.2f ", 1.0*j*px);
mbedalvaro 40:3ba2b0ea9f33 409 }
mbedalvaro 40:3ba2b0ea9f33 410 } else { // odd line:
mbedalvaro 40:3ba2b0ea9f33 411 for (int j=nx-1; j>=0; j--) {
mbedalvaro 40:3ba2b0ea9f33 412 begin(ny*i+j);
mbedalvaro 40:3ba2b0ea9f33 413 for (int k=0; k<repeatpoint; k++)
mbedalvaro 40:3ba2b0ea9f33 414 // vertex(1.0*j*px,1.0*i*py,0); // faster than using translations...
mbedalvaro 40:3ba2b0ea9f33 415 vertex(1.0*i*py,1.0*j*px,0);
mbedalvaro 40:3ba2b0ea9f33 416 end();
mbedalvaro 40:3ba2b0ea9f33 417 //pc.printf("%4.2f ", 1.0*j*px);
mbedalvaro 40:3ba2b0ea9f33 418 }
mbedalvaro 40:3ba2b0ea9f33 419 }
mbedalvaro 40:3ba2b0ea9f33 420 }
mbedalvaro 40:3ba2b0ea9f33 421 //lsr.popPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 422 }
mbedalvaro 40:3ba2b0ea9f33 423
mbedalvaro 40:3ba2b0ea9f33 424 // A simple "muti-object" grid, not normalized (this is just for convenience):
mbedalvaro 40:3ba2b0ea9f33 425 void grid(float sizeX, float sizeY, int nx, int ny, int repeatpoint)
mbedalvaro 40:3ba2b0ea9f33 426 {
mbedalvaro 40:3ba2b0ea9f33 427 lsr.pushPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 428 lsr.resize(sizeX, sizeY, 1);
mbedalvaro 40:3ba2b0ea9f33 429 grid(nx, ny, repeatpoint);
mbedalvaro 40:3ba2b0ea9f33 430 lsr.popPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 431 }
mbedalvaro 40:3ba2b0ea9f33 432
mbedalvaro 40:3ba2b0ea9f33 433 //Normalized grid of circles:
mbedalvaro 40:3ba2b0ea9f33 434 void gridCircles(int nx, int ny, float radius, int nbpointsCircle)
mbedalvaro 40:3ba2b0ea9f33 435 {
mbedalvaro 40:3ba2b0ea9f33 436 float px=1.0/(nx-1), py=1.0/(ny-1);
mbedalvaro 40:3ba2b0ea9f33 437 lsr.pushPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 438 for (int i=0; i<ny; i++) {
mbedalvaro 40:3ba2b0ea9f33 439 if (i%2==0) { // to do zig-zag...
mbedalvaro 40:3ba2b0ea9f33 440 for (int j=0; j<nx; j++) {
mbedalvaro 40:3ba2b0ea9f33 441 begin(ny*i+j);
mbedalvaro 40:3ba2b0ea9f33 442 circle(radius, nbpointsCircle);
mbedalvaro 40:3ba2b0ea9f33 443 end();
mbedalvaro 40:3ba2b0ea9f33 444 lsr.translate(px, 0, 0);
mbedalvaro 40:3ba2b0ea9f33 445 }
mbedalvaro 40:3ba2b0ea9f33 446 } else { // odd line:
mbedalvaro 40:3ba2b0ea9f33 447 for (int j=nx-1; j>=0; j--) {
mbedalvaro 40:3ba2b0ea9f33 448 begin(ny*i+j);
mbedalvaro 40:3ba2b0ea9f33 449 circle(radius, nbpointsCircle);
mbedalvaro 40:3ba2b0ea9f33 450 end();
mbedalvaro 40:3ba2b0ea9f33 451 lsr.translate(-px, 0, 0);
mbedalvaro 40:3ba2b0ea9f33 452 }
mbedalvaro 40:3ba2b0ea9f33 453 }
mbedalvaro 40:3ba2b0ea9f33 454 lsr.translate(0, py, 0);
mbedalvaro 40:3ba2b0ea9f33 455 }
mbedalvaro 40:3ba2b0ea9f33 456 lsr.popPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 457 }
mbedalvaro 40:3ba2b0ea9f33 458
mbedalvaro 40:3ba2b0ea9f33 459 // Not normalized grid of circles:
mbedalvaro 40:3ba2b0ea9f33 460 void gridCircles(float sizeX, float sizeY, int nx, int ny, float radius, int nbpointsCircle)
mbedalvaro 40:3ba2b0ea9f33 461 {
mbedalvaro 40:3ba2b0ea9f33 462 float px=sizeX/(nx-1), py=sizeY/(ny-1);
mbedalvaro 40:3ba2b0ea9f33 463 lsr.pushPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 464 for (int i=0; i<ny; i++) {
mbedalvaro 40:3ba2b0ea9f33 465 if (i%2==0) { // to do zig-zag...
mbedalvaro 40:3ba2b0ea9f33 466 for (int j=0; j<nx; j++) {
mbedalvaro 40:3ba2b0ea9f33 467 begin(ny*i+j);
mbedalvaro 40:3ba2b0ea9f33 468 circle(radius, nbpointsCircle);
mbedalvaro 40:3ba2b0ea9f33 469 end();
mbedalvaro 40:3ba2b0ea9f33 470 lsr.translate(px, 0, 0);
mbedalvaro 40:3ba2b0ea9f33 471 }
mbedalvaro 40:3ba2b0ea9f33 472 } else { // odd line:
mbedalvaro 40:3ba2b0ea9f33 473 for (int j=nx-1; j>=0; j--) {
mbedalvaro 40:3ba2b0ea9f33 474 lsr.translate(-px, 0, 0);
mbedalvaro 40:3ba2b0ea9f33 475 begin(ny*i+j);
mbedalvaro 40:3ba2b0ea9f33 476 circle(radius, nbpointsCircle);
mbedalvaro 40:3ba2b0ea9f33 477 end();
mbedalvaro 40:3ba2b0ea9f33 478 }
mbedalvaro 40:3ba2b0ea9f33 479 }
mbedalvaro 40:3ba2b0ea9f33 480 lsr.translate(0, py, 0);
mbedalvaro 40:3ba2b0ea9f33 481 }
mbedalvaro 40:3ba2b0ea9f33 482 lsr.popPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 483 }
mbedalvaro 40:3ba2b0ea9f33 484
mbedalvaro 40:3ba2b0ea9f33 485 // WRAPPERS TO CREATE ARBITRARY OBJECTS FROM SENT DATA POINTS (V3 array) =============================================
mbedalvaro 40:3ba2b0ea9f33 486 void createShapeObject(int idobject, vector<V3> &arrayVertices) {
mbedalvaro 40:3ba2b0ea9f33 487 begin(idobject);
mbedalvaro 40:3ba2b0ea9f33 488 vertexArray(arrayVertices);
mbedalvaro 40:3ba2b0ea9f33 489 end();
mbedalvaro 40:3ba2b0ea9f33 490 }
mbedalvaro 40:3ba2b0ea9f33 491
mbedalvaro 40:3ba2b0ea9f33 492 // WRAPPERS TO LOAD OBJECTS FROM SYSTEM FILE =========================================================================
mbedalvaro 40:3ba2b0ea9f33 493 // ... to do
mbedalvaro 40:3ba2b0ea9f33 494
mbedalvaro 40:3ba2b0ea9f33 495 // WRAPPERS TO LOAD MATRICES FROM SYSTEM FILE ==========================================================================
mbedalvaro 40:3ba2b0ea9f33 496 // ...to do
mbedalvaro 40:3ba2b0ea9f33 497
mbedalvaro 40:3ba2b0ea9f33 498 // ================================= WRAPPERS FOR MORE BASIC IO FUNCTIONS =================================
mbedalvaro 40:3ba2b0ea9f33 499 void showLimitsMirrors(unsigned short pointsPerLine, unsigned short durationSecs)
mbedalvaro 40:3ba2b0ea9f33 500 {
mbedalvaro 40:3ba2b0ea9f33 501 // Stop the display engine and lasers:
mbedalvaro 40:3ba2b0ea9f33 502 stopDisplay();
mbedalvaro 40:3ba2b0ea9f33 503 // but we need to ensure that the DISPLAYING lasers are ON:
mbedalvaro 40:3ba2b0ea9f33 504 IO.setRGBPower(0x07);
mbedalvaro 40:3ba2b0ea9f33 505 IO.showLimitsMirrors(pointsPerLine, durationSecs);
mbedalvaro 40:3ba2b0ea9f33 506 resumeDisplay();
mbedalvaro 40:3ba2b0ea9f33 507 }
mbedalvaro 40:3ba2b0ea9f33 508
mbedalvaro 40:3ba2b0ea9f33 509 void scanSerial(unsigned short pointsPerLine)
mbedalvaro 40:3ba2b0ea9f33 510 {
mbedalvaro 40:3ba2b0ea9f33 511 // Stop the display engine and lasers:
mbedalvaro 40:3ba2b0ea9f33 512 stopDisplay();
mbedalvaro 40:3ba2b0ea9f33 513 // ...but we need to ensure that the sensing laser is ON:
mbedalvaro 40:3ba2b0ea9f33 514 IO.setLaserLockinPower(1);
mbedalvaro 40:3ba2b0ea9f33 515 IO.scan_serial(pointsPerLine);
mbedalvaro 40:3ba2b0ea9f33 516 resumeDisplay();
mbedalvaro 40:3ba2b0ea9f33 517 }
mbedalvaro 40:3ba2b0ea9f33 518
mbedalvaro 40:3ba2b0ea9f33 519 void recomputeLookUpTable()
mbedalvaro 40:3ba2b0ea9f33 520 {
mbedalvaro 40:3ba2b0ea9f33 521 // Stop the display engine and lasers:
mbedalvaro 40:3ba2b0ea9f33 522 stopDisplay();
mbedalvaro 40:3ba2b0ea9f33 523 // but we need to ensure that the sensing laser is ON:
mbedalvaro 40:3ba2b0ea9f33 524 IO.setLaserLockinPower(1);
mbedalvaro 40:3ba2b0ea9f33 525 IO.scanLUT(); // this recreates and SAVES the LUT table
mbedalvaro 40:3ba2b0ea9f33 526 resumeDisplay();
mbedalvaro 40:3ba2b0ea9f33 527 }
mbedalvaro 40:3ba2b0ea9f33 528
mbedalvaro 40:3ba2b0ea9f33 529
mbedalvaro 40:3ba2b0ea9f33 530
mbedalvaro 40:3ba2b0ea9f33 531 // =============================== HARDWARE KNOBS: switches, potentiometers... =================================================
mbedalvaro 40:3ba2b0ea9f33 532 void hardwareKnobs()
mbedalvaro 40:3ba2b0ea9f33 533 {
mbedalvaro 40:3ba2b0ea9f33 534 // Potentiometer, switches, etc:
mbedalvaro 40:3ba2b0ea9f33 535 //(1) Check for change of threshold mode button (switch one):
mbedalvaro 40:3ba2b0ea9f33 536 //!!! ATTENTION: this does not work very well to say the truth: bouncing+adc settings problems...
mbedalvaro 40:3ba2b0ea9f33 537 bool stateswitch;
mbedalvaro 40:3ba2b0ea9f33 538 if (IO.switchOneCheck(stateswitch)) {
mbedalvaro 40:3ba2b0ea9f33 539 if (stateswitch) pc.printf("Set: AUTO threshold mode\n");
mbedalvaro 40:3ba2b0ea9f33 540 else pc.printf("Set: FIXED threshold mode\n");
mbedalvaro 40:3ba2b0ea9f33 541 for (int i=0; i< scene.totalObjects(); i++) scene.objectArray[i]->displaySensingBuffer.setThresholdMode((stateswitch? 1 : 0));
mbedalvaro 40:3ba2b0ea9f33 542 }
mbedalvaro 40:3ba2b0ea9f33 543 //(2) Check the current pot value and update the "fixed threshold" when pressing second switch (I don't care if the threshold mode
mbedalvaro 40:3ba2b0ea9f33 544 // is fixed or not - this will set the VALUE of the fixed threshold)
mbedalvaro 40:3ba2b0ea9f33 545 // NOTE: as thresholding mode CAN be object dependent though, but this is a simple hardware command that set the fixed threshold for all the objects.
mbedalvaro 40:3ba2b0ea9f33 546 if (IO.switchTwoCheck(stateswitch)) {
mbedalvaro 40:3ba2b0ea9f33 547 IO.updatePotValue();
mbedalvaro 40:3ba2b0ea9f33 548 for (int i=0; i< scene.totalObjects(); i++) scene.objectArray[i]->displaySensingBuffer.setFixedThreshold(IO.potValue);
mbedalvaro 40:3ba2b0ea9f33 549 pc.printf("Fixed Threshold :%d\n", IO.potValue);
mbedalvaro 40:3ba2b0ea9f33 550 }
mbedalvaro 40:3ba2b0ea9f33 551 }
mbedalvaro 40:3ba2b0ea9f33 552