Laser Sensing Display for UI interfaces in the real world

Dependencies:   mbed

Fork of skinGames_forktest by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Wed Oct 30 02:50:58 2013 +0000
Revision:
44:2432c218f191
Parent:
43:1dd4cfc30788
Child:
47:199042980678
This is a security commit, I will start creating UIobject class with behaviours (a child of BaseObject)

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 40:3ba2b0ea9f33 171 // NOTE: I am not going to create new transform methods (rotation and translations), but instead 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 40:3ba2b0ea9f33 174 void trasformObject(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 40:3ba2b0ea9f33 198 //(2) Apply current RT transformation and render but KEEPING the original values of the 3d points:
mbedalvaro 40:3ba2b0ea9f33 199 //(a) Objects:
mbedalvaro 40:3ba2b0ea9f33 200 void drawObject(int _id) // use maps in the future!!!
mbedalvaro 40:3ba2b0ea9f33 201 {
mbedalvaro 40:3ba2b0ea9f33 202 BaseObject* ptr_object=NULL;
mbedalvaro 40:3ba2b0ea9f33 203 for (int i=0; i<scene.totalObjects(); i++) if ((scene.objectArray[i]->ID())==_id) ptr_object=scene.objectArray[i];
mbedalvaro 40:3ba2b0ea9f33 204 if (ptr_object!=NULL) {
mbedalvaro 40:3ba2b0ea9f33 205 // 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 206 lsr.renderObject(ptr_object, lsr.RT);
mbedalvaro 40:3ba2b0ea9f33 207 }
mbedalvaro 40:3ba2b0ea9f33 208 }
mbedalvaro 40:3ba2b0ea9f33 209 // 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 210 void drawObject(BaseObject* ptr_object)
mbedalvaro 40:3ba2b0ea9f33 211 {
mbedalvaro 40:3ba2b0ea9f33 212 //ptr_object->transform(lsr.RT);
mbedalvaro 40:3ba2b0ea9f33 213 lsr.renderObject(ptr_object, lsr.RT);
mbedalvaro 40:3ba2b0ea9f33 214 }
mbedalvaro 40:3ba2b0ea9f33 215 // (b) Whole scene:
mbedalvaro 40:3ba2b0ea9f33 216 // 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 217 void drawScene()
mbedalvaro 40:3ba2b0ea9f33 218 {
mbedalvaro 40:3ba2b0ea9f33 219 //NOTE: there is no need, AND IT IS better NOT to stop/resume the display engine (detaching and reattaching the ISR).
mbedalvaro 40:3ba2b0ea9f33 220 // 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 221 // that the number of objects and points per object did NOT change.
mbedalvaro 40:3ba2b0ea9f33 222 //scene.transform(lsr.RT); // or equialently: for (int i=0; i<scene.totalObjects(); i++) scene.objectArray[i]->transform(lsr.RT);
mbedalvaro 40:3ba2b0ea9f33 223 lsr.renderScene(&scene, lsr.RT);
mbedalvaro 40:3ba2b0ea9f33 224 }
mbedalvaro 40:3ba2b0ea9f33 225
mbedalvaro 40:3ba2b0ea9f33 226 // Color attribute transformation (for the time being, only to the whole scene):
mbedalvaro 40:3ba2b0ea9f33 227 void changeColorScene(unsigned char _color) {
mbedalvaro 40:3ba2b0ea9f33 228 for (int i=0; i<scene.totalObjects(); i++) scene.objectArray[i]->setColor(_color);
mbedalvaro 40:3ba2b0ea9f33 229 }
mbedalvaro 40:3ba2b0ea9f33 230
mbedalvaro 40:3ba2b0ea9f33 231 // ================================= OBJECT PRIMITIVES (this could be in a different file) ============================================================
mbedalvaro 40:3ba2b0ea9f33 232 // 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 233 // Instead, they will add the vertices to the "current object" being created.
mbedalvaro 40:3ba2b0ea9f33 234
mbedalvaro 40:3ba2b0ea9f33 235 // A line:
mbedalvaro 40:3ba2b0ea9f33 236 void line(V3& v0, V3& v1, int npoints)
mbedalvaro 40:3ba2b0ea9f33 237 {
mbedalvaro 40:3ba2b0ea9f33 238 V3 stepVector=(v1-v0)/(npoints-1);
mbedalvaro 40:3ba2b0ea9f33 239 for (int i=0; i<npoints; i++) {
mbedalvaro 40:3ba2b0ea9f33 240 V3 v(v0+stepVector*i); // vertex added to the current object
mbedalvaro 40:3ba2b0ea9f33 241 vertex(v);
mbedalvaro 40:3ba2b0ea9f33 242 }
mbedalvaro 40:3ba2b0ea9f33 243 }
mbedalvaro 40:3ba2b0ea9f33 244 void line(float x0, float y0, float z0, float x1, float y1, float z1, int npoints)
mbedalvaro 40:3ba2b0ea9f33 245 {
mbedalvaro 40:3ba2b0ea9f33 246 // NOTE: we don't clear the current modelview, but use it's current value.
mbedalvaro 40:3ba2b0ea9f33 247 V3 A(x0, y0, z0), B(x1, y1, z1);
mbedalvaro 40:3ba2b0ea9f33 248 line(A, B, npoints);
mbedalvaro 40:3ba2b0ea9f33 249 }
mbedalvaro 40:3ba2b0ea9f33 250 // A line in the z=0 plane:
mbedalvaro 40:3ba2b0ea9f33 251 void line(float x0, float y0, float x1, float y1, int npoints)
mbedalvaro 40:3ba2b0ea9f33 252 {
mbedalvaro 40:3ba2b0ea9f33 253 // NOTE: we don't clear the current modelview, but use it's current value.
mbedalvaro 40:3ba2b0ea9f33 254 V3 A(x0, y0, 0), B(x1, y1, 0);
mbedalvaro 40:3ba2b0ea9f33 255 line(A, B, npoints);
mbedalvaro 40:3ba2b0ea9f33 256 }
mbedalvaro 40:3ba2b0ea9f33 257
mbedalvaro 40:3ba2b0ea9f33 258 // A square in the z=0 plane
mbedalvaro 40:3ba2b0ea9f33 259 void square(float sideSize, int npointsSide)
mbedalvaro 40:3ba2b0ea9f33 260 {
mbedalvaro 40:3ba2b0ea9f33 261 V3 A(0,0, 0), B(sideSize, 0, 0);
mbedalvaro 40:3ba2b0ea9f33 262 line(A, B, npointsSide);
mbedalvaro 40:3ba2b0ea9f33 263 A.x = sideSize;
mbedalvaro 40:3ba2b0ea9f33 264 A.y = sideSize;
mbedalvaro 40:3ba2b0ea9f33 265 line(B, A, npointsSide);
mbedalvaro 40:3ba2b0ea9f33 266 B.x = 0;
mbedalvaro 40:3ba2b0ea9f33 267 B.y = sideSize;
mbedalvaro 40:3ba2b0ea9f33 268 line(A, B, npointsSide);
mbedalvaro 40:3ba2b0ea9f33 269 A.x = 0;
mbedalvaro 40:3ba2b0ea9f33 270 A.y = 0;
mbedalvaro 40:3ba2b0ea9f33 271 line(B, A, npointsSide);
mbedalvaro 40:3ba2b0ea9f33 272 }
mbedalvaro 40:3ba2b0ea9f33 273
mbedalvaro 40:3ba2b0ea9f33 274 // A rectangle in the z=0 plane
mbedalvaro 40:3ba2b0ea9f33 275 void rectangle(float sideSizeX, float sideSizeY, int interPointDistance)
mbedalvaro 40:3ba2b0ea9f33 276 // note: interPointDistance (degrees per point) would be the equivalent of "pixels" separation for the laser projector
mbedalvaro 40:3ba2b0ea9f33 277 {
mbedalvaro 40:3ba2b0ea9f33 278 V3 A(0,0, 0), B(sideSizeX, 0, 0);
mbedalvaro 40:3ba2b0ea9f33 279 line(A, B, sideSizeX/interPointDistance);
mbedalvaro 40:3ba2b0ea9f33 280 A.x = sideSizeX;
mbedalvaro 40:3ba2b0ea9f33 281 A.y = sideSizeY;
mbedalvaro 40:3ba2b0ea9f33 282 line(B, A, sideSizeY/interPointDistance);
mbedalvaro 40:3ba2b0ea9f33 283 B.x = 0;
mbedalvaro 40:3ba2b0ea9f33 284 B.y = sideSizeY;
mbedalvaro 40:3ba2b0ea9f33 285 line(A, B, sideSizeX/interPointDistance);
mbedalvaro 40:3ba2b0ea9f33 286 A.x = 0;
mbedalvaro 40:3ba2b0ea9f33 287 A.y = 0;
mbedalvaro 40:3ba2b0ea9f33 288 line(B, A, sideSizeY/interPointDistance);
mbedalvaro 40:3ba2b0ea9f33 289 }
mbedalvaro 40:3ba2b0ea9f33 290
mbedalvaro 40:3ba2b0ea9f33 291
mbedalvaro 40:3ba2b0ea9f33 292
mbedalvaro 40:3ba2b0ea9f33 293 void circle(float radius, int numpoints)
mbedalvaro 40:3ba2b0ea9f33 294 {
mbedalvaro 40:3ba2b0ea9f33 295 float angleStep=360.0/numpoints;
mbedalvaro 40:3ba2b0ea9f33 296 lsr.pushPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 297 for (int i=0; i<numpoints; i++) {
mbedalvaro 40:3ba2b0ea9f33 298 vertex(radius, 0, 0);
mbedalvaro 40:3ba2b0ea9f33 299 lsr.rotateZ(angleStep);
mbedalvaro 40:3ba2b0ea9f33 300 }
mbedalvaro 40:3ba2b0ea9f33 301 // Redo the first point to close the cirlce:
mbedalvaro 40:3ba2b0ea9f33 302 vertex(radius, 0, 0);
mbedalvaro 40:3ba2b0ea9f33 303 lsr.popPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 304 }
mbedalvaro 40:3ba2b0ea9f33 305
mbedalvaro 40:3ba2b0ea9f33 306 // A "cube" (with one corner at the origin):
mbedalvaro 40:3ba2b0ea9f33 307 void cube(float sideSize, int nbpointsSide)
mbedalvaro 40:3ba2b0ea9f33 308 {
mbedalvaro 40:3ba2b0ea9f33 309 lsr.pushPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 310 square(sideSize, nbpointsSide);
mbedalvaro 40:3ba2b0ea9f33 311 line(0,0,0,0,0,sideSize, nbpointsSide);
mbedalvaro 40:3ba2b0ea9f33 312 lsr.translate(0,0,sideSize);
mbedalvaro 40:3ba2b0ea9f33 313 square(sideSize, nbpointsSide);
mbedalvaro 40:3ba2b0ea9f33 314 lsr.popPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 315 }
mbedalvaro 40:3ba2b0ea9f33 316
mbedalvaro 40:3ba2b0ea9f33 317 // LETTERS and STRINGS:
mbedalvaro 40:3ba2b0ea9f33 318 // 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 319 void letter3d(char _letter, float width, float height)
mbedalvaro 40:3ba2b0ea9f33 320 {
mbedalvaro 40:3ba2b0ea9f33 321 unsigned char numpoints=fillAuxBuffer(_letter);
mbedalvaro 40:3ba2b0ea9f33 322 lsr.pushPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 323 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 324 for (int i=0; i<numpoints; i++ ) vertex(auxbuffer[2*i], auxbuffer[2*i+1], 0);
mbedalvaro 40:3ba2b0ea9f33 325 lsr.popPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 326 }
mbedalvaro 40:3ba2b0ea9f33 327
mbedalvaro 40:3ba2b0ea9f33 328 // 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 329 // 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 330 // 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 331 // for detecting individual touched letters).
mbedalvaro 40:3ba2b0ea9f33 332 void string3d(string _text, float totalWidth, float height)
mbedalvaro 40:3ba2b0ea9f33 333 {
mbedalvaro 40:3ba2b0ea9f33 334 float stepX=1.0*totalWidth/_text.length(); // this is just fontWidth, or some percentage of it
mbedalvaro 40:3ba2b0ea9f33 335 lsr.pushPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 336 for (unsigned short i=0; i<_text.length(); i++) {
mbedalvaro 40:3ba2b0ea9f33 337 char ch=_text.at(i);
mbedalvaro 40:3ba2b0ea9f33 338 lsr.translate(1.3*stepX,0,0); // slightly larger than the fontWidth...
mbedalvaro 40:3ba2b0ea9f33 339 if (ch!=' ') letter3d(ch, stepX, height);
mbedalvaro 40:3ba2b0ea9f33 340 }
mbedalvaro 40:3ba2b0ea9f33 341 lsr.popPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 342 }
mbedalvaro 40:3ba2b0ea9f33 343
mbedalvaro 40:3ba2b0ea9f33 344
mbedalvaro 40:3ba2b0ea9f33 345
mbedalvaro 40:3ba2b0ea9f33 346 // ========= MULTI OBJECTS ==================================================================================
mbedalvaro 40:3ba2b0ea9f33 347
mbedalvaro 40:3ba2b0ea9f33 348 // A simple "normalized" grid on the z=0 plane (with points, repeated to get them more "clear").
mbedalvaro 40:3ba2b0ea9f33 349 // 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 350 // Corner of the grid at the origin.
mbedalvaro 40:3ba2b0ea9f33 351 // NOTE: this is an example of a "multi-object" that does NOT need "begin/end" in the main
mbedalvaro 40:3ba2b0ea9f33 352 void grid(int nx, int ny, int repeatpoint)
mbedalvaro 40:3ba2b0ea9f33 353 {
mbedalvaro 40:3ba2b0ea9f33 354 float px=1.0/(nx-1), py=1.0/(ny-1);
mbedalvaro 40:3ba2b0ea9f33 355 //lsr.pushPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 356 for (int i=0; i<ny; i++) {
mbedalvaro 40:3ba2b0ea9f33 357 // pc.printf("\n");
mbedalvaro 40:3ba2b0ea9f33 358 if (i%2==0) { // to do zig-zag...
mbedalvaro 40:3ba2b0ea9f33 359 for (int j=0; j<nx; j++) {
mbedalvaro 40:3ba2b0ea9f33 360 begin(ny*i+j);
mbedalvaro 40:3ba2b0ea9f33 361 for (int k=0; k<repeatpoint; k++)
mbedalvaro 40:3ba2b0ea9f33 362 //vertex(1.0*j*px,1.0*i*py,0); // faster than using translations...
mbedalvaro 40:3ba2b0ea9f33 363 vertex(1.0*i*py,1.0*j*px,0);
mbedalvaro 40:3ba2b0ea9f33 364 end();
mbedalvaro 40:3ba2b0ea9f33 365 //pc.printf("%4.2f ", 1.0*j*px);
mbedalvaro 40:3ba2b0ea9f33 366 }
mbedalvaro 40:3ba2b0ea9f33 367 } else { // odd line:
mbedalvaro 40:3ba2b0ea9f33 368 for (int j=nx-1; j>=0; j--) {
mbedalvaro 40:3ba2b0ea9f33 369 begin(ny*i+j);
mbedalvaro 40:3ba2b0ea9f33 370 for (int k=0; k<repeatpoint; k++)
mbedalvaro 40:3ba2b0ea9f33 371 // vertex(1.0*j*px,1.0*i*py,0); // faster than using translations...
mbedalvaro 40:3ba2b0ea9f33 372 vertex(1.0*i*py,1.0*j*px,0);
mbedalvaro 40:3ba2b0ea9f33 373 end();
mbedalvaro 40:3ba2b0ea9f33 374 //pc.printf("%4.2f ", 1.0*j*px);
mbedalvaro 40:3ba2b0ea9f33 375 }
mbedalvaro 40:3ba2b0ea9f33 376 }
mbedalvaro 40:3ba2b0ea9f33 377 }
mbedalvaro 40:3ba2b0ea9f33 378 //lsr.popPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 379 }
mbedalvaro 40:3ba2b0ea9f33 380
mbedalvaro 40:3ba2b0ea9f33 381 // A simple "muti-object" grid, not normalized (this is just for convenience):
mbedalvaro 40:3ba2b0ea9f33 382 void grid(float sizeX, float sizeY, int nx, int ny, int repeatpoint)
mbedalvaro 40:3ba2b0ea9f33 383 {
mbedalvaro 40:3ba2b0ea9f33 384 lsr.pushPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 385 lsr.resize(sizeX, sizeY, 1);
mbedalvaro 40:3ba2b0ea9f33 386 grid(nx, ny, repeatpoint);
mbedalvaro 40:3ba2b0ea9f33 387 lsr.popPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 388 }
mbedalvaro 40:3ba2b0ea9f33 389
mbedalvaro 40:3ba2b0ea9f33 390 //Normalized grid of circles:
mbedalvaro 40:3ba2b0ea9f33 391 void gridCircles(int nx, int ny, float radius, int nbpointsCircle)
mbedalvaro 40:3ba2b0ea9f33 392 {
mbedalvaro 40:3ba2b0ea9f33 393 float px=1.0/(nx-1), py=1.0/(ny-1);
mbedalvaro 40:3ba2b0ea9f33 394 lsr.pushPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 395 for (int i=0; i<ny; i++) {
mbedalvaro 40:3ba2b0ea9f33 396 if (i%2==0) { // to do zig-zag...
mbedalvaro 40:3ba2b0ea9f33 397 for (int j=0; j<nx; j++) {
mbedalvaro 40:3ba2b0ea9f33 398 begin(ny*i+j);
mbedalvaro 40:3ba2b0ea9f33 399 circle(radius, nbpointsCircle);
mbedalvaro 40:3ba2b0ea9f33 400 end();
mbedalvaro 40:3ba2b0ea9f33 401 lsr.translate(px, 0, 0);
mbedalvaro 40:3ba2b0ea9f33 402 }
mbedalvaro 40:3ba2b0ea9f33 403 } else { // odd line:
mbedalvaro 40:3ba2b0ea9f33 404 for (int j=nx-1; j>=0; j--) {
mbedalvaro 40:3ba2b0ea9f33 405 begin(ny*i+j);
mbedalvaro 40:3ba2b0ea9f33 406 circle(radius, nbpointsCircle);
mbedalvaro 40:3ba2b0ea9f33 407 end();
mbedalvaro 40:3ba2b0ea9f33 408 lsr.translate(-px, 0, 0);
mbedalvaro 40:3ba2b0ea9f33 409 }
mbedalvaro 40:3ba2b0ea9f33 410 }
mbedalvaro 40:3ba2b0ea9f33 411 lsr.translate(0, py, 0);
mbedalvaro 40:3ba2b0ea9f33 412 }
mbedalvaro 40:3ba2b0ea9f33 413 lsr.popPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 414 }
mbedalvaro 40:3ba2b0ea9f33 415
mbedalvaro 40:3ba2b0ea9f33 416 // Not normalized grid of circles:
mbedalvaro 40:3ba2b0ea9f33 417 void gridCircles(float sizeX, float sizeY, int nx, int ny, float radius, int nbpointsCircle)
mbedalvaro 40:3ba2b0ea9f33 418 {
mbedalvaro 40:3ba2b0ea9f33 419 float px=sizeX/(nx-1), py=sizeY/(ny-1);
mbedalvaro 40:3ba2b0ea9f33 420 lsr.pushPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 421 for (int i=0; i<ny; i++) {
mbedalvaro 40:3ba2b0ea9f33 422 if (i%2==0) { // to do zig-zag...
mbedalvaro 40:3ba2b0ea9f33 423 for (int j=0; j<nx; j++) {
mbedalvaro 40:3ba2b0ea9f33 424 begin(ny*i+j);
mbedalvaro 40:3ba2b0ea9f33 425 circle(radius, nbpointsCircle);
mbedalvaro 40:3ba2b0ea9f33 426 end();
mbedalvaro 40:3ba2b0ea9f33 427 lsr.translate(px, 0, 0);
mbedalvaro 40:3ba2b0ea9f33 428 }
mbedalvaro 40:3ba2b0ea9f33 429 } else { // odd line:
mbedalvaro 40:3ba2b0ea9f33 430 for (int j=nx-1; j>=0; j--) {
mbedalvaro 40:3ba2b0ea9f33 431 lsr.translate(-px, 0, 0);
mbedalvaro 40:3ba2b0ea9f33 432 begin(ny*i+j);
mbedalvaro 40:3ba2b0ea9f33 433 circle(radius, nbpointsCircle);
mbedalvaro 40:3ba2b0ea9f33 434 end();
mbedalvaro 40:3ba2b0ea9f33 435 }
mbedalvaro 40:3ba2b0ea9f33 436 }
mbedalvaro 40:3ba2b0ea9f33 437 lsr.translate(0, py, 0);
mbedalvaro 40:3ba2b0ea9f33 438 }
mbedalvaro 40:3ba2b0ea9f33 439 lsr.popPoseMatrix();
mbedalvaro 40:3ba2b0ea9f33 440 }
mbedalvaro 40:3ba2b0ea9f33 441
mbedalvaro 40:3ba2b0ea9f33 442 // WRAPPERS TO CREATE ARBITRARY OBJECTS FROM SENT DATA POINTS (V3 array) =============================================
mbedalvaro 40:3ba2b0ea9f33 443 void createShapeObject(int idobject, vector<V3> &arrayVertices) {
mbedalvaro 40:3ba2b0ea9f33 444 begin(idobject);
mbedalvaro 40:3ba2b0ea9f33 445 vertexArray(arrayVertices);
mbedalvaro 40:3ba2b0ea9f33 446 end();
mbedalvaro 40:3ba2b0ea9f33 447 }
mbedalvaro 40:3ba2b0ea9f33 448
mbedalvaro 40:3ba2b0ea9f33 449 // WRAPPERS TO LOAD OBJECTS FROM SYSTEM FILE =========================================================================
mbedalvaro 40:3ba2b0ea9f33 450 // ... to do
mbedalvaro 40:3ba2b0ea9f33 451
mbedalvaro 40:3ba2b0ea9f33 452 // WRAPPERS TO LOAD MATRICES FROM SYSTEM FILE ==========================================================================
mbedalvaro 40:3ba2b0ea9f33 453 // ...to do
mbedalvaro 40:3ba2b0ea9f33 454
mbedalvaro 40:3ba2b0ea9f33 455 // ================================= WRAPPERS FOR MORE BASIC IO FUNCTIONS =================================
mbedalvaro 40:3ba2b0ea9f33 456 void showLimitsMirrors(unsigned short pointsPerLine, unsigned short durationSecs)
mbedalvaro 40:3ba2b0ea9f33 457 {
mbedalvaro 40:3ba2b0ea9f33 458 // Stop the display engine and lasers:
mbedalvaro 40:3ba2b0ea9f33 459 stopDisplay();
mbedalvaro 40:3ba2b0ea9f33 460 // but we need to ensure that the DISPLAYING lasers are ON:
mbedalvaro 40:3ba2b0ea9f33 461 IO.setRGBPower(0x07);
mbedalvaro 40:3ba2b0ea9f33 462 IO.showLimitsMirrors(pointsPerLine, durationSecs);
mbedalvaro 40:3ba2b0ea9f33 463 resumeDisplay();
mbedalvaro 40:3ba2b0ea9f33 464 }
mbedalvaro 40:3ba2b0ea9f33 465
mbedalvaro 40:3ba2b0ea9f33 466 void scanSerial(unsigned short pointsPerLine)
mbedalvaro 40:3ba2b0ea9f33 467 {
mbedalvaro 40:3ba2b0ea9f33 468 // Stop the display engine and lasers:
mbedalvaro 40:3ba2b0ea9f33 469 stopDisplay();
mbedalvaro 40:3ba2b0ea9f33 470 // ...but we need to ensure that the sensing laser is ON:
mbedalvaro 40:3ba2b0ea9f33 471 IO.setLaserLockinPower(1);
mbedalvaro 40:3ba2b0ea9f33 472 IO.scan_serial(pointsPerLine);
mbedalvaro 40:3ba2b0ea9f33 473 resumeDisplay();
mbedalvaro 40:3ba2b0ea9f33 474 }
mbedalvaro 40:3ba2b0ea9f33 475
mbedalvaro 40:3ba2b0ea9f33 476 void recomputeLookUpTable()
mbedalvaro 40:3ba2b0ea9f33 477 {
mbedalvaro 40:3ba2b0ea9f33 478 // Stop the display engine and lasers:
mbedalvaro 40:3ba2b0ea9f33 479 stopDisplay();
mbedalvaro 40:3ba2b0ea9f33 480 // but we need to ensure that the sensing laser is ON:
mbedalvaro 40:3ba2b0ea9f33 481 IO.setLaserLockinPower(1);
mbedalvaro 40:3ba2b0ea9f33 482 IO.scanLUT(); // this recreates and SAVES the LUT table
mbedalvaro 40:3ba2b0ea9f33 483 resumeDisplay();
mbedalvaro 40:3ba2b0ea9f33 484 }
mbedalvaro 40:3ba2b0ea9f33 485
mbedalvaro 40:3ba2b0ea9f33 486
mbedalvaro 40:3ba2b0ea9f33 487
mbedalvaro 40:3ba2b0ea9f33 488 // =============================== HARDWARE KNOBS: switches, potentiometers... =================================================
mbedalvaro 40:3ba2b0ea9f33 489 void hardwareKnobs()
mbedalvaro 40:3ba2b0ea9f33 490 {
mbedalvaro 40:3ba2b0ea9f33 491 // Potentiometer, switches, etc:
mbedalvaro 40:3ba2b0ea9f33 492 //(1) Check for change of threshold mode button (switch one):
mbedalvaro 40:3ba2b0ea9f33 493 //!!! ATTENTION: this does not work very well to say the truth: bouncing+adc settings problems...
mbedalvaro 40:3ba2b0ea9f33 494 bool stateswitch;
mbedalvaro 40:3ba2b0ea9f33 495 if (IO.switchOneCheck(stateswitch)) {
mbedalvaro 40:3ba2b0ea9f33 496 if (stateswitch) pc.printf("Set: AUTO threshold mode\n");
mbedalvaro 40:3ba2b0ea9f33 497 else pc.printf("Set: FIXED threshold mode\n");
mbedalvaro 40:3ba2b0ea9f33 498 for (int i=0; i< scene.totalObjects(); i++) scene.objectArray[i]->displaySensingBuffer.setThresholdMode((stateswitch? 1 : 0));
mbedalvaro 40:3ba2b0ea9f33 499 }
mbedalvaro 40:3ba2b0ea9f33 500 //(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 501 // is fixed or not - this will set the VALUE of the fixed threshold)
mbedalvaro 40:3ba2b0ea9f33 502 // 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 503 if (IO.switchTwoCheck(stateswitch)) {
mbedalvaro 40:3ba2b0ea9f33 504 IO.updatePotValue();
mbedalvaro 40:3ba2b0ea9f33 505 for (int i=0; i< scene.totalObjects(); i++) scene.objectArray[i]->displaySensingBuffer.setFixedThreshold(IO.potValue);
mbedalvaro 40:3ba2b0ea9f33 506 pc.printf("Fixed Threshold :%d\n", IO.potValue);
mbedalvaro 40:3ba2b0ea9f33 507 }
mbedalvaro 40:3ba2b0ea9f33 508 }
mbedalvaro 40:3ba2b0ea9f33 509