just a test

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Fri Mar 28 10:18:38 2014 +0000
Revision:
42:c4e9c1116af4
Parent:
40:ee217eff826c
Child:
44:46e25fa1669b
Added functionality for two rotary encoders to control the additional mirror delay and the fixed threshold (instead of a potentiometer), and discarded the use of interrupt based switches to change the threshold mode (instead I use a two-state switch)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedalvaro 0:345b3bc7a0ea 1 #include "mbed.h"
mbedalvaro 0:345b3bc7a0ea 2 #include "hardwareIO.h"
mbedalvaro 0:345b3bc7a0ea 3 #include "mbedOSC.h"
mbedalvaro 0:345b3bc7a0ea 4 #include "blobConfig.h"
mbedalvaro 0:345b3bc7a0ea 5 #include "simpleLaserRenderer.h"
mbedalvaro 0:345b3bc7a0ea 6
mbedalvaro 0:345b3bc7a0ea 7 extern "C" void mbed_reset();
mbedalvaro 0:345b3bc7a0ea 8
mbedalvaro 0:345b3bc7a0ea 9 blobConfig blobconf;
mbedalvaro 0:345b3bc7a0ea 10 simpleLaserSensingRenderer lsr;
mbedalvaro 0:345b3bc7a0ea 11
mbedalvaro 0:345b3bc7a0ea 12 // For tests:
mbedalvaro 0:345b3bc7a0ea 13 DigitalOut myled(LED1);
mbedalvaro 0:345b3bc7a0ea 14 DigitalOut myled2(LED2);
mbedalvaro 23:bf666fcc61bc 15 DigitalOut myled3(LED3);
mbedalvaro 0:345b3bc7a0ea 16
mbedalvaro 0:345b3bc7a0ea 17
mbedalvaro 1:a4050fee11f7 18 // To test the time it takes for executing one loop in the main program:
mbedalvaro 10:6f8e48dca1bd 19 //#define LOOPTIMECOMPUTE
mbedalvaro 1:a4050fee11f7 20
mbedalvaro 1:a4050fee11f7 21 // To get serial commands (for debug, or other things using a Terminal - for instance, a laser scan)
mbedalvaro 14:0fc33a3a7b4b 22 #define SERIAL_COMMANDS
mbedalvaro 0:345b3bc7a0ea 23
mbedalvaro 0:345b3bc7a0ea 24 //---------- ETHERNET / OSC related (in the future, put somewhere else...): -------------------------------------------
mbedalvaro 0:345b3bc7a0ea 25 // mbed IP address (server):
mbedalvaro 0:345b3bc7a0ea 26 #ifdef DHCP
mbedalvaro 0:345b3bc7a0ea 27 EthernetNetIf eth;
mbedalvaro 0:345b3bc7a0ea 28 #else
mbedalvaro 0:345b3bc7a0ea 29 EthernetNetIf eth(
mbedalvaro 36:233b12d0b1f0 30 IpAddr(10,0,0,2), //IP Address of the mbed
mbedalvaro 1:a4050fee11f7 31 IpAddr(255,255,255,0), //Network Mask
mbedalvaro 1:a4050fee11f7 32 IpAddr(10,0,0,1), //Gateway
mbedalvaro 1:a4050fee11f7 33 IpAddr(10,0,0,1) //DNS
mbedalvaro 0:345b3bc7a0ea 34 );
mbedalvaro 0:345b3bc7a0ea 35 #endif
mbedalvaro 0:345b3bc7a0ea 36
mbedalvaro 0:345b3bc7a0ea 37 //uint8_t serverMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
mbedalvaro 0:345b3bc7a0ea 38 uint8_t serverIp[] = { 10, 0, 0, 2 }; // not needed perhaps!
mbedalvaro 0:345b3bc7a0ea 39 int serverPort = 10000;
mbedalvaro 1:a4050fee11f7 40
mbedalvaro 32:52273c3291fe 41 //uint8_t destIp[] = {10, 0, 0, 3};
mbedalvaro 32:52273c3291fe 42 uint8_t destIp[] = {255, 255, 255, 255}; // broadcast, so we can use several computers for sound, etc
mbedalvaro 0:345b3bc7a0ea 43 int destPort = 12000;
mbedalvaro 1:a4050fee11f7 44
mbedalvaro 0:345b3bc7a0ea 45 char *topAddress="/mbed";
mbedalvaro 0:345b3bc7a0ea 46 char *subAddress[3]={ "/test1" , "/test2" , "/test3" };
mbedalvaro 1:a4050fee11f7 47
mbedalvaro 0:345b3bc7a0ea 48 OSCMessage recMes;
mbedalvaro 0:345b3bc7a0ea 49 OSCMessage sendMes;
mbedalvaro 1:a4050fee11f7 50
mbedalvaro 1:a4050fee11f7 51 OSCClass osc;
mbedalvaro 1:a4050fee11f7 52 //OSCClass osc(&recMes); // instantiate OSC communication object, and set the receiver container from the OSC packets
mbedalvaro 1:a4050fee11f7 53
mbedalvaro 1:a4050fee11f7 54 void processOSC(UDPSocketEvent e);
mbedalvaro 0:345b3bc7a0ea 55 // ----------------------------------------------------------------------------------------------------------------------
mbedalvaro 0:345b3bc7a0ea 56
mbedalvaro 2:34157ebbf56b 57 // Tickers:
mbedalvaro 0:345b3bc7a0ea 58 Ticker timerForRendering;
mbedalvaro 2:34157ebbf56b 59 //Ticker timerForSendingData; // better use a timer, so as not to interrupt the exact laser display ticker
mbedalvaro 2:34157ebbf56b 60
mbedalvaro 9:3321170d157c 61 // Timers:
mbedalvaro 0:345b3bc7a0ea 62 Timer measureLoopPeriod;
mbedalvaro 9:3321170d157c 63 //Timer measureUpdatePeriod;
mbedalvaro 18:d72935b13858 64
mbedalvaro 0:345b3bc7a0ea 65
mbedalvaro 1:a4050fee11f7 66 // to get serial commands (not necessary perhaps)
mbedalvaro 0:345b3bc7a0ea 67 void processSerial();
mbedalvaro 1:a4050fee11f7 68
mbedalvaro 0:345b3bc7a0ea 69 int main() {
mbedalvaro 1:a4050fee11f7 70
mbedalvaro 0:345b3bc7a0ea 71 // Initialize the hardware (laser powers, positions...):
mbedalvaro 0:345b3bc7a0ea 72 IO.init();
mbedalvaro 0:345b3bc7a0ea 73
mbedalvaro 1:a4050fee11f7 74 // -------------------------------
mbedalvaro 1:a4050fee11f7 75 // Set the Ethernet port:
mbedalvaro 1:a4050fee11f7 76 printf("Setting up...\r\n");
mbedalvaro 1:a4050fee11f7 77 EthernetErr ethErr = eth.setup();
mbedalvaro 1:a4050fee11f7 78 if (ethErr) {
mbedalvaro 1:a4050fee11f7 79 printf("Error %d in setup.\r\n", ethErr);
mbedalvaro 1:a4050fee11f7 80 return -1;
mbedalvaro 1:a4050fee11f7 81 }
mbedalvaro 1:a4050fee11f7 82 printf("Setup OK\r\n");
mbedalvaro 1:a4050fee11f7 83
mbedalvaro 1:a4050fee11f7 84 //(1) Sending message:
mbedalvaro 1:a4050fee11f7 85 // Set IP and Port:
mbedalvaro 1:a4050fee11f7 86 sendMes.setIp( destIp );
mbedalvaro 1:a4050fee11f7 87 sendMes.setPort( destPort );
mbedalvaro 1:a4050fee11f7 88 // Set data:
mbedalvaro 1:a4050fee11f7 89 // sendMes.setTopAddress(topAddress);
mbedalvaro 1:a4050fee11f7 90
mbedalvaro 1:a4050fee11f7 91 //setting osc functionnality:
mbedalvaro 1:a4050fee11f7 92 //(2) Receiving:
mbedalvaro 1:a4050fee11f7 93 // recMes.setIp( serverIp ); // not needed?
mbedalvaro 1:a4050fee11f7 94 osc.setReceiveMessage(&recMes); // this sets the receiver container for the OSC packets (we can avoid doing this if we use osc.getMessage() to get messages)
mbedalvaro 1:a4050fee11f7 95 osc.begin(serverPort, &processOSC); // binds the upd (osc) messages to an arbitrary listening port ("server" port), and callback function
mbedalvaro 1:a4050fee11f7 96 // -------------------------------
mbedalvaro 1:a4050fee11f7 97
mbedalvaro 0:345b3bc7a0ea 98 /* // sending seems not to work right after setting the osc object??
mbedalvaro 0:345b3bc7a0ea 99 wait(1);
mbedalvaro 0:345b3bc7a0ea 100 sendMes.setTopAddress("starting");
mbedalvaro 1:a4050fee11f7 101 sendMes.setSubAddress("");
mbedalvaro 0:345b3bc7a0ea 102 osc.sendOsc( &sendMes );
mbedalvaro 0:345b3bc7a0ea 103 */
mbedalvaro 1:a4050fee11f7 104
mbedalvaro 0:345b3bc7a0ea 105 // initialize with the desired blob configuration:
mbedalvaro 1:a4050fee11f7 106
mbedalvaro 0:345b3bc7a0ea 107 // Tested modes:
mbedalvaro 1:a4050fee11f7 108 blobconf.clearConfig();
mbedalvaro 10:6f8e48dca1bd 109 // blobconf.addOneElasticLoopContractCentral();
mbedalvaro 40:ee217eff826c 110 blobconf.addOneElasticContourFollowing();
mbedalvaro 1:a4050fee11f7 111
mbedalvaro 14:0fc33a3a7b4b 112 // blobconf.addOneRigidLoopBouncing();
mbedalvaro 9:3321170d157c 113 // blobconf.addOneRigidLoopBouncing();
mbedalvaro 16:2ff1cb2ae1b1 114 //blobconf.addOneRigidLoopFollowing();
mbedalvaro 29:2fc8c12822eb 115 // blobconf.addOneRigidLoopFollowing();
mbedalvaro 32:52273c3291fe 116 //blobconf.addOneElasticLoopContractCentralFast();
mbedalvaro 32:52273c3291fe 117 //blobconf.addOneRigidLoopTest();
mbedalvaro 2:34157ebbf56b 118
mbedalvaro 32:52273c3291fe 119 // START WITH TWO FOLLOWING SPOTS (exhibition Tokyo Design Week):
mbedalvaro 40:ee217eff826c 120 // blobconf.initConfig(FOLLOWING_SPOTS, 2); // value is the nb of spots instantiated
mbedalvaro 32:52273c3291fe 121 // Make them of different color:
mbedalvaro 40:ee217eff826c 122 // blobconf.blobArray[0]->setBlueColor(1);
mbedalvaro 40:ee217eff826c 123 // blobconf.blobArray[1]->setGreenColor(1);
mbedalvaro 32:52273c3291fe 124 // start in no stand by mode:
mbedalvaro 32:52273c3291fe 125 blobconf.allResume();
mbedalvaro 1:a4050fee11f7 126
mbedalvaro 0:345b3bc7a0ea 127 // Important: first, set the initial position for all the blobs, this will be useful because
mbedalvaro 0:345b3bc7a0ea 128 // when changing modes we can use the previous central position...
mbedalvaro 1:a4050fee11f7 129 // blobconf.setInitialPos(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y);
mbedalvaro 1:a4050fee11f7 130
mbedalvaro 24:4e52031a495b 131 // draw the config once before activating the laser buffer:
mbedalvaro 5:73cd58b58f95 132 blobconf.draw();
mbedalvaro 13:9f03eac02700 133 lsr.startFullDisplay();
mbedalvaro 1:a4050fee11f7 134
mbedalvaro 0:345b3bc7a0ea 135 // RENRERER (attn: setConfigToRender must be called when the blobconf is set - i.e., the number of blobs and number of points/blob is fixed)
mbedalvaro 1:a4050fee11f7 136 lsr.setConfigToRender(&blobconf);
mbedalvaro 1:a4050fee11f7 137
mbedalvaro 1:a4050fee11f7 138 // Timer on the rendering function of the oneLoop object:
mbedalvaro 9:3321170d157c 139 // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL); // the address of the object, member function, and interval (in seconds)
mbedalvaro 9:3321170d157c 140 timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL); // the address of the object, member function, and interval (in seconds)
mbedalvaro 1:a4050fee11f7 141
mbedalvaro 1:a4050fee11f7 142 // Timer for sending OSC data:
mbedalvaro 9:3321170d157c 143 // timerForSendingData.attach(&blobconf, &blobConfig::sendConfData, 0.025); // time in seconds (25ms -> 40Hz)
mbedalvaro 1:a4050fee11f7 144
mbedalvaro 1:a4050fee11f7 145 //========================================== INFINITE LOOP (in USER PROGRAM CONTEXT) ===================================================================
mbedalvaro 1:a4050fee11f7 146 #ifdef LOOPTIMECOMPUTE
mbedalvaro 1:a4050fee11f7 147 int timeCounterNum=1000;
mbedalvaro 1:a4050fee11f7 148 #endif
mbedalvaro 1:a4050fee11f7 149
mbedalvaro 9:3321170d157c 150 //measureUpdatePeriod.start();
mbedalvaro 1:a4050fee11f7 151
mbedalvaro 1:a4050fee11f7 152 while (true) {
mbedalvaro 1:a4050fee11f7 153
mbedalvaro 13:9f03eac02700 154 if (lsr.endedFullDisplay()) {
mbedalvaro 9:3321170d157c 155
mbedalvaro 9:3321170d157c 156 // measureUpdatePeriod.stop();
mbedalvaro 9:3321170d157c 157 // measureUpdatePeriod.reset();
mbedalvaro 9:3321170d157c 158
mbedalvaro 9:3321170d157c 159 // __disable_irq();
mbedalvaro 9:3321170d157c 160
mbedalvaro 1:a4050fee11f7 161 // update config dynamics (this also could be threaded?):
mbedalvaro 1:a4050fee11f7 162 blobconf.update();
mbedalvaro 1:a4050fee11f7 163
mbedalvaro 10:6f8e48dca1bd 164
mbedalvaro 1:a4050fee11f7 165 // draw the config (note: each kind of blob renders differently)
mbedalvaro 1:a4050fee11f7 166 blobconf.draw();
mbedalvaro 18:d72935b13858 167
mbedalvaro 18:d72935b13858 168
mbedalvaro 18:d72935b13858 169 // (b)Sending Data: // PUT THIS IN AN INTERRUPT OR USE A TIMER!!! it may be TOO FAST...
mbedalvaro 18:d72935b13858 170 // NOTE: better use a timer, so the only ISR "ticker" is the laser rendering (otherwise the laser rendering will be interrupted by the sending of data - the other way is ok):
mbedalvaro 18:d72935b13858 171 // NOTE: timer for sending is now not COMMON to all blobs, but depends on the blob (it could depend on the CONFIG only, but this can be simulated by using
mbedalvaro 18:d72935b13858 172 // per blob timer counter.
mbedalvaro 18:d72935b13858 173 blobconf.sendConfData();
mbedalvaro 18:d72935b13858 174
mbedalvaro 16:2ff1cb2ae1b1 175
mbedalvaro 23:bf666fcc61bc 176 lsr.startFullDisplay(); // this start the point-display counter (wherever the actual laser is). Before update and draw, the counter needs to be reset.
mbedalvaro 16:2ff1cb2ae1b1 177
mbedalvaro 9:3321170d157c 178
mbedalvaro 9:3321170d157c 179 // __enable_irq();
mbedalvaro 9:3321170d157c 180
mbedalvaro 9:3321170d157c 181 // measureUpdatePeriod.start();
mbedalvaro 10:6f8e48dca1bd 182
mbedalvaro 1:a4050fee11f7 183 }
mbedalvaro 0:345b3bc7a0ea 184
mbedalvaro 2:34157ebbf56b 185
mbedalvaro 1:a4050fee11f7 186 // COMMUNICATION:
mbedalvaro 1:a4050fee11f7 187 // (a) Reading commands:
mbedalvaro 1:a4050fee11f7 188 // Ethernet:
mbedalvaro 1:a4050fee11f7 189 Net::poll(); // this will take care of calling processOSC(UDPSocketEvent e) when a new packet arrives.
mbedalvaro 1:a4050fee11f7 190
mbedalvaro 1:a4050fee11f7 191 // Serial:
mbedalvaro 1:a4050fee11f7 192 #ifdef SERIAL_COMMANDS
mbedalvaro 1:a4050fee11f7 193 if (pc.readable()>0) processSerial();
mbedalvaro 1:a4050fee11f7 194 #endif
mbedalvaro 9:3321170d157c 195
mbedalvaro 34:1244fa3f2559 196 // Potentiometer, switches, etc:
mbedalvaro 34:1244fa3f2559 197 //(1) Check for change of threshold mode button (switch one):
mbedalvaro 42:c4e9c1116af4 198 //!!! ATTENTION: this does not work very well to say the truth: bouncing+adc settings problems... better use a TWO STATE SWITCH:
mbedalvaro 42:c4e9c1116af4 199 bool stateswitch;
mbedalvaro 42:c4e9c1116af4 200 // if (IO.switchOneCheck(stateswitch)) {
mbedalvaro 42:c4e9c1116af4 201 //if (stateswitch) pc.printf("Setting AUTO threshold mode\n"); else pc.printf("Setting FIXED threshold mode\n");
mbedalvaro 42:c4e9c1116af4 202 // for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.setThresholdMode((stateswitch? 1 : 0));
mbedalvaro 42:c4e9c1116af4 203 // }
mbedalvaro 42:c4e9c1116af4 204 if (IO.twoStateSwitchCheck(stateswitch)) { // if there is a change...
mbedalvaro 42:c4e9c1116af4 205 for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.setThresholdMode((stateswitch? 1 : 0));
mbedalvaro 42:c4e9c1116af4 206 }
mbedalvaro 42:c4e9c1116af4 207
mbedalvaro 37:fa6b1f15819f 208 //(2) in case the the second switch was pressed, check the current pot value and update the fixed threshold (regardless of the threshold mode)
mbedalvaro 42:c4e9c1116af4 209 // NOTE: using the potentiometer FAILS because I cannot properly switch back and forth between ADC modes (burst and normal)
mbedalvaro 42:c4e9c1116af4 210 //if (IO.switchTwoCheck(stateswitch)) {
mbedalvaro 42:c4e9c1116af4 211 // IO.updatePotValue();
mbedalvaro 42:c4e9c1116af4 212 // for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.setFixedThreshold(IO.potValue);
mbedalvaro 42:c4e9c1116af4 213 // pc.printf("Got :%d\n", IO.potValue);
mbedalvaro 42:c4e9c1116af4 214 // }
mbedalvaro 42:c4e9c1116af4 215 if (rotaryEncoder1.CheckNew()) for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.setFixedThreshold(rotaryEncoder1.Get());
mbedalvaro 42:c4e9c1116af4 216
mbedalvaro 42:c4e9c1116af4 217 // (3) Change additional mirror delay from rotary encoder:
mbedalvaro 42:c4e9c1116af4 218 if (rotaryEncoder2.CheckNew()) for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.setDelayMirrors(rotaryEncoder2.Get());
mbedalvaro 34:1244fa3f2559 219
mbedalvaro 9:3321170d157c 220
mbedalvaro 1:a4050fee11f7 221 // text:
mbedalvaro 1:a4050fee11f7 222 /*
mbedalvaro 1:a4050fee11f7 223 sendMes.setTopAddress("/hello");
mbedalvaro 1:a4050fee11f7 224 sendMes.setSubAddress("/daito"); // ATTENTION: the host computer needs to know in advance how many points are in the loop (I did not implement "bundle" messages yet...)
mbedalvaro 1:a4050fee11f7 225 int x=(long)10;
mbedalvaro 1:a4050fee11f7 226 sendMes.setArgs( "i", &x);
mbedalvaro 1:a4050fee11f7 227 osc.sendOsc( &sendMes );
mbedalvaro 1:a4050fee11f7 228 */
mbedalvaro 1:a4050fee11f7 229
mbedalvaro 0:345b3bc7a0ea 230 #ifdef LOOPTIMECOMPUTE
mbedalvaro 9:3321170d157c 231 if (timeCounterNum>50) myled = 0;
mbedalvaro 9:3321170d157c 232 // if (timeCounterNum%10==0) blobconf.sendConfData();
mbedalvaro 9:3321170d157c 233 if (timeCounterNum>100) {
mbedalvaro 1:a4050fee11f7 234 myled = 1;
mbedalvaro 1:a4050fee11f7 235 measureLoopPeriod.stop();
mbedalvaro 1:a4050fee11f7 236 sendMes.setTopAddress("/timeloop");
mbedalvaro 1:a4050fee11f7 237 sendMes.setSubAddress("/");
mbedalvaro 10:6f8e48dca1bd 238 // long x=(long)(int(measureLoopPeriod.read_us()/100.0));
mbedalvaro 9:3321170d157c 239 // long x=(long)(blobconf.blobArray[0]->displaySensingBuffer.lsdTrajectory.size());
mbedalvaro 9:3321170d157c 240 // long x=(long)(blobconf.blobArray[0]->normRecenteringVector);
mbedalvaro 10:6f8e48dca1bd 241 long x=(long)(1000*blobconf.blobArray[0]->displaySensingBuffer.lsdTrajectory[0].intensity);
mbedalvaro 1:a4050fee11f7 242 sendMes.setArgs( "i", &x);
mbedalvaro 1:a4050fee11f7 243 osc.sendOsc( &sendMes );
mbedalvaro 1:a4050fee11f7 244 timeCounterNum=0;
mbedalvaro 1:a4050fee11f7 245 measureLoopPeriod.reset();
mbedalvaro 1:a4050fee11f7 246 measureLoopPeriod.start();
mbedalvaro 1:a4050fee11f7 247 } else timeCounterNum++;
mbedalvaro 0:345b3bc7a0ea 248 #endif
mbedalvaro 0:345b3bc7a0ea 249
mbedalvaro 0:345b3bc7a0ea 250 }
mbedalvaro 0:345b3bc7a0ea 251 }
mbedalvaro 0:345b3bc7a0ea 252
mbedalvaro 1:a4050fee11f7 253 // ================= INTERPRET COMMAND =========================
mbedalvaro 0:345b3bc7a0ea 254 // NOTE: the following arrays are GLOBAL (used in processOSC and processSerial, as well as in interpretCommand function):
mbedalvaro 1:a4050fee11f7 255 // max of two addresses (top and sub), of a max length of 24 characters:
mbedalvaro 0:345b3bc7a0ea 256 char address[2][24];
mbedalvaro 0:345b3bc7a0ea 257 //long auxdata[2]; // to store a max of two arguments (note: we will only use LONGs)
mbedalvaro 1:a4050fee11f7 258 int data[2]; // this is to have -1 as NO DATA, to detect errors.
mbedalvaro 1:a4050fee11f7 259
mbedalvaro 1:a4050fee11f7 260 //interpretCommand(const char& address[2][], const int& data[2]) {
mbedalvaro 0:345b3bc7a0ea 261 void interpretCommand() {
mbedalvaro 0:345b3bc7a0ea 262 // (I) =========================================== SPECIAL FUNCTIONS (reset, rescan LUT, etc) ====================================================
mbedalvaro 16:2ff1cb2ae1b1 263 if ( !strcmp(address[0], "takeSnapshot" ) ) {
mbedalvaro 24:4e52031a495b 264 int value=data[0];
mbedalvaro 24:4e52031a495b 265 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 24:4e52031a495b 266
mbedalvaro 1:a4050fee11f7 267 // for test:
mbedalvaro 1:a4050fee11f7 268 for (int i=0; i<2 ; i++) {
mbedalvaro 1:a4050fee11f7 269 myled = 1;
mbedalvaro 1:a4050fee11f7 270 wait(0.1);
mbedalvaro 1:a4050fee11f7 271 myled = 0;
mbedalvaro 1:a4050fee11f7 272 wait(0.1);
mbedalvaro 1:a4050fee11f7 273 }
mbedalvaro 1:a4050fee11f7 274
mbedalvaro 1:a4050fee11f7 275 // First, we need to disable the threaded display for the loop:
mbedalvaro 1:a4050fee11f7 276 timerForRendering.detach();
mbedalvaro 1:a4050fee11f7 277
mbedalvaro 24:4e52031a495b 278 // Then, do the scan (sending values on SERIAL port):
mbedalvaro 24:4e52031a495b 279 IO.scan_serial(value);
mbedalvaro 1:a4050fee11f7 280
mbedalvaro 1:a4050fee11f7 281 // Finally, start again threaded display:
mbedalvaro 9:3321170d157c 282 timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
mbedalvaro 9:3321170d157c 283 // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
mbedalvaro 24:4e52031a495b 284
mbedalvaro 24:4e52031a495b 285 }
mbedalvaro 1:a4050fee11f7 286 }
mbedalvaro 1:a4050fee11f7 287
mbedalvaro 1:a4050fee11f7 288 else if ( !strcmp(address[0], "mbedReset" ) ) mbed_reset();
mbedalvaro 22:d87317d7ca91 289
mbedalvaro 22:d87317d7ca91 290 else if (!strcmp(address[0], "showMirrorLimits")) {
mbedalvaro 22:d87317d7ca91 291 int value=data[0];
mbedalvaro 22:d87317d7ca91 292 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 22:d87317d7ca91 293 timerForRendering.detach();
mbedalvaro 24:4e52031a495b 294 IO.showLimitsMirrors(value);
mbedalvaro 22:d87317d7ca91 295 timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
mbedalvaro 24:4e52031a495b 296 }
mbedalvaro 22:d87317d7ca91 297 }
mbedalvaro 1:a4050fee11f7 298
mbedalvaro 1:a4050fee11f7 299 else if ( !strcmp(address[0], "calibrate" ) ) {
mbedalvaro 1:a4050fee11f7 300 // First, we need to disable the threaded display for the loop:
mbedalvaro 1:a4050fee11f7 301 timerForRendering.detach();
mbedalvaro 1:a4050fee11f7 302 // RESCAN (and save LUT table):
mbedalvaro 1:a4050fee11f7 303 IO.scanLUT();
mbedalvaro 1:a4050fee11f7 304 // Finally, start again threaded display:
mbedalvaro 9:3321170d157c 305 timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
mbedalvaro 9:3321170d157c 306 // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
mbedalvaro 1:a4050fee11f7 307 }
mbedalvaro 1:a4050fee11f7 308
mbedalvaro 1:a4050fee11f7 309 // (II) ========================================= GLOBAL CONFIG and HARDWARE COMMANDS ===========================================
mbedalvaro 1:a4050fee11f7 310
mbedalvaro 32:52273c3291fe 311 else if ( !strcmp(address[0], "setAllColor" ) ) {
mbedalvaro 32:52273c3291fe 312 int value=data[0]; // this is the color (RGB bits)
mbedalvaro 32:52273c3291fe 313 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 32:52273c3291fe 314 blobconf.allSetColor(value);
mbedalvaro 32:52273c3291fe 315 }
mbedalvaro 32:52273c3291fe 316 }
mbedalvaro 33:43e8bc451ef0 317
mbedalvaro 33:43e8bc451ef0 318 else if ( !strcmp(address[0], "setAllRandomColor" ) ) {
mbedalvaro 33:43e8bc451ef0 319 blobconf.randomizeAllColors();
mbedalvaro 33:43e8bc451ef0 320 }
mbedalvaro 32:52273c3291fe 321
mbedalvaro 32:52273c3291fe 322 else if ( !strcmp(address[0], "setAllGreenColor" ) ) {
mbedalvaro 1:a4050fee11f7 323 int value=data[0];
mbedalvaro 1:a4050fee11f7 324 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 25:74cb85b85fd2 325 if (value==0)
mbedalvaro 32:52273c3291fe 326 blobconf.allSetGreen(1);
mbedalvaro 25:74cb85b85fd2 327 else
mbedalvaro 32:52273c3291fe 328 blobconf.allSetGreen(0);
mbedalvaro 1:a4050fee11f7 329 }
mbedalvaro 1:a4050fee11f7 330 }
mbedalvaro 23:bf666fcc61bc 331
mbedalvaro 32:52273c3291fe 332 else if ( !strcmp(address[0], "setAllBlueColor" ) ) {
mbedalvaro 32:52273c3291fe 333 int value=data[0];
mbedalvaro 32:52273c3291fe 334 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 32:52273c3291fe 335 if (value==0)
mbedalvaro 32:52273c3291fe 336 blobconf.allSetBlue(1);
mbedalvaro 32:52273c3291fe 337 else
mbedalvaro 32:52273c3291fe 338 blobconf.allSetBlue(0);
mbedalvaro 32:52273c3291fe 339 }
mbedalvaro 32:52273c3291fe 340 }
mbedalvaro 32:52273c3291fe 341
mbedalvaro 32:52273c3291fe 342 // NOTE: RED either afect the lock in, or some other red laser... not yet done.
mbedalvaro 32:52273c3291fe 343
mbedalvaro 23:bf666fcc61bc 344 else if ( !strcmp(address[0], "testPower" ) ) {
mbedalvaro 23:bf666fcc61bc 345 // First, we need to disable the threaded display for the loop:
mbedalvaro 23:bf666fcc61bc 346 timerForRendering.detach();
mbedalvaro 23:bf666fcc61bc 347
mbedalvaro 23:bf666fcc61bc 348 // Note: arguments is first 3 bits to set the laser powers (3 LSB bits to set each color)
mbedalvaro 23:bf666fcc61bc 349 // and then the second argument is the number of seconds to wait for the measurment
mbedalvaro 23:bf666fcc61bc 350 int value1=data[0], value2=data[1];
mbedalvaro 23:bf666fcc61bc 351 if ((value1!=-1)&&(value2!=-1)) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 23:bf666fcc61bc 352
mbedalvaro 23:bf666fcc61bc 353 // Set position of mirrors:
mbedalvaro 23:bf666fcc61bc 354 IO.writeOutX(CENTER_AD_MIRROR_X);
mbedalvaro 23:bf666fcc61bc 355 IO.writeOutY(CENTER_AD_MIRROR_Y);
mbedalvaro 23:bf666fcc61bc 356
mbedalvaro 23:bf666fcc61bc 357 for (int i=0; i<3 ; i++) {
mbedalvaro 23:bf666fcc61bc 358 myled3 = 1;
mbedalvaro 23:bf666fcc61bc 359 wait(0.2);
mbedalvaro 23:bf666fcc61bc 360 myled3 = 0;
mbedalvaro 23:bf666fcc61bc 361 wait(0.2);
mbedalvaro 23:bf666fcc61bc 362 }
mbedalvaro 23:bf666fcc61bc 363
mbedalvaro 23:bf666fcc61bc 364 // Set laser power:
mbedalvaro 23:bf666fcc61bc 365 IO.setRGBPower((unsigned char)value1);
mbedalvaro 23:bf666fcc61bc 366
mbedalvaro 23:bf666fcc61bc 367 // Wait...
mbedalvaro 23:bf666fcc61bc 368 wait(value2);// in seconds
mbedalvaro 23:bf666fcc61bc 369 //Timer t;
mbedalvaro 23:bf666fcc61bc 370 //t.start();
mbedalvaro 23:bf666fcc61bc 371 //while(t.read_ms()<value2*1000);
mbedalvaro 23:bf666fcc61bc 372 //t.stop();
mbedalvaro 23:bf666fcc61bc 373 }
mbedalvaro 23:bf666fcc61bc 374
mbedalvaro 23:bf666fcc61bc 375 // Finally, start again threaded display:
mbedalvaro 23:bf666fcc61bc 376 timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
mbedalvaro 23:bf666fcc61bc 377
mbedalvaro 23:bf666fcc61bc 378 }
mbedalvaro 23:bf666fcc61bc 379
mbedalvaro 23:bf666fcc61bc 380
mbedalvaro 1:a4050fee11f7 381
mbedalvaro 1:a4050fee11f7 382 // SIMPLE BEHAVIOUR MODES (to be read from an XML file in the future):
mbedalvaro 11:62f7183a03e7 383 else if (!strcmp(address[0], "elastic_following")) { //
mbedalvaro 1:a4050fee11f7 384 timerForRendering.detach();
mbedalvaro 30:d8af03f01cd4 385
mbedalvaro 30:d8af03f01cd4 386 blobconf.initConfig(ONE_ELASTIC_FOLLOWING);
mbedalvaro 30:d8af03f01cd4 387
mbedalvaro 1:a4050fee11f7 388 lsr.setConfigToRender(&blobconf);
mbedalvaro 9:3321170d157c 389 timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
mbedalvaro 9:3321170d157c 390 // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
mbedalvaro 16:2ff1cb2ae1b1 391
mbedalvaro 11:62f7183a03e7 392 } else if (!strcmp(address[0], "elastic_mouth")) { //
mbedalvaro 1:a4050fee11f7 393 timerForRendering.detach();
mbedalvaro 30:d8af03f01cd4 394
mbedalvaro 30:d8af03f01cd4 395 blobconf.initConfig(ONE_ELASTIC_MOUTH);
mbedalvaro 30:d8af03f01cd4 396
mbedalvaro 1:a4050fee11f7 397 lsr.setConfigToRender(&blobconf);
mbedalvaro 9:3321170d157c 398 timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
mbedalvaro 9:3321170d157c 399 // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
mbedalvaro 19:228430f1350e 400
mbedalvaro 19:228430f1350e 401 } else if (!strcmp(address[0], "elastic_mouth_small")) { //
mbedalvaro 19:228430f1350e 402 timerForRendering.detach();
mbedalvaro 30:d8af03f01cd4 403
mbedalvaro 30:d8af03f01cd4 404 blobconf.initConfig(ONE_ELASTIC_MOUTH_SMALL);
mbedalvaro 30:d8af03f01cd4 405
mbedalvaro 19:228430f1350e 406 lsr.setConfigToRender(&blobconf);
mbedalvaro 19:228430f1350e 407 timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
mbedalvaro 19:228430f1350e 408 // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
mbedalvaro 1:a4050fee11f7 409 }
mbedalvaro 11:62f7183a03e7 410 else if (!strcmp(address[0], "spot_bouncing")) {
mbedalvaro 16:2ff1cb2ae1b1 411 int value=data[0];
mbedalvaro 16:2ff1cb2ae1b1 412 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 16:2ff1cb2ae1b1 413 timerForRendering.detach();
mbedalvaro 30:d8af03f01cd4 414
mbedalvaro 30:d8af03f01cd4 415 blobconf.initConfig(BOUNCING_SPOTS, value); // value is the nb of spots instantiated
mbedalvaro 16:2ff1cb2ae1b1 416
mbedalvaro 16:2ff1cb2ae1b1 417 lsr.setConfigToRender(&blobconf);
mbedalvaro 16:2ff1cb2ae1b1 418 timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
mbedalvaro 16:2ff1cb2ae1b1 419 // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
mbedalvaro 16:2ff1cb2ae1b1 420 }
mbedalvaro 16:2ff1cb2ae1b1 421 }
mbedalvaro 16:2ff1cb2ae1b1 422
mbedalvaro 30:d8af03f01cd4 423 else if (!strcmp(address[0], "spot_lorentz")) {
mbedalvaro 27:1ce994629ffc 424 int value=data[0];
mbedalvaro 27:1ce994629ffc 425 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 27:1ce994629ffc 426 timerForRendering.detach();
mbedalvaro 30:d8af03f01cd4 427
mbedalvaro 30:d8af03f01cd4 428 blobconf.initConfig(LORENTZ_SPOTS, value); // value is the nb of spots instantiated
mbedalvaro 27:1ce994629ffc 429
mbedalvaro 27:1ce994629ffc 430 lsr.setConfigToRender(&blobconf);
mbedalvaro 27:1ce994629ffc 431 timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
mbedalvaro 27:1ce994629ffc 432 // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
mbedalvaro 27:1ce994629ffc 433 }
mbedalvaro 27:1ce994629ffc 434 }
mbedalvaro 28:44b7b6e35548 435
mbedalvaro 28:44b7b6e35548 436 else if (!strcmp(address[0], "air_hockey")) {
mbedalvaro 28:44b7b6e35548 437 int value=data[0];
mbedalvaro 28:44b7b6e35548 438 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 28:44b7b6e35548 439 timerForRendering.detach();
mbedalvaro 30:d8af03f01cd4 440
mbedalvaro 30:d8af03f01cd4 441 blobconf.initConfig(AIR_HOCKEY_GAME, value); // value is the nb of spots instantiated
mbedalvaro 28:44b7b6e35548 442
mbedalvaro 28:44b7b6e35548 443 lsr.setConfigToRender(&blobconf);
mbedalvaro 28:44b7b6e35548 444 timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
mbedalvaro 28:44b7b6e35548 445 // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
mbedalvaro 28:44b7b6e35548 446 }
mbedalvaro 28:44b7b6e35548 447 }
mbedalvaro 32:52273c3291fe 448
mbedalvaro 32:52273c3291fe 449 else if (!strcmp(address[0], "rain_mode")) {
mbedalvaro 32:52273c3291fe 450 int value=data[0];
mbedalvaro 32:52273c3291fe 451 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 32:52273c3291fe 452 timerForRendering.detach();
mbedalvaro 32:52273c3291fe 453
mbedalvaro 32:52273c3291fe 454 blobconf.initConfig(RAIN_MODE, value); // value is the nb of spots instantiated
mbedalvaro 32:52273c3291fe 455
mbedalvaro 32:52273c3291fe 456 lsr.setConfigToRender(&blobconf);
mbedalvaro 32:52273c3291fe 457 timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
mbedalvaro 32:52273c3291fe 458 // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
mbedalvaro 32:52273c3291fe 459 }
mbedalvaro 32:52273c3291fe 460 }
mbedalvaro 32:52273c3291fe 461
mbedalvaro 28:44b7b6e35548 462
mbedalvaro 28:44b7b6e35548 463 else if (!strcmp(address[0], "spot_following")) {
mbedalvaro 16:2ff1cb2ae1b1 464 int value=data[0];
mbedalvaro 16:2ff1cb2ae1b1 465 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 16:2ff1cb2ae1b1 466
mbedalvaro 16:2ff1cb2ae1b1 467 timerForRendering.detach();
mbedalvaro 22:d87317d7ca91 468
mbedalvaro 30:d8af03f01cd4 469 blobconf.initConfig(FOLLOWING_SPOTS, value); // value is the nb of spots instantiated
mbedalvaro 22:d87317d7ca91 470
mbedalvaro 16:2ff1cb2ae1b1 471 lsr.setConfigToRender(&blobconf);
mbedalvaro 16:2ff1cb2ae1b1 472 timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
mbedalvaro 16:2ff1cb2ae1b1 473 // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
mbedalvaro 16:2ff1cb2ae1b1 474 }
mbedalvaro 16:2ff1cb2ae1b1 475 }
mbedalvaro 16:2ff1cb2ae1b1 476
mbedalvaro 30:d8af03f01cd4 477 else if (!strcmp(address[0], "circular_pong")) {
mbedalvaro 30:d8af03f01cd4 478 int value=data[0];
mbedalvaro 30:d8af03f01cd4 479 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 30:d8af03f01cd4 480
mbedalvaro 30:d8af03f01cd4 481 timerForRendering.detach();
mbedalvaro 30:d8af03f01cd4 482
mbedalvaro 30:d8af03f01cd4 483 blobconf.initConfig(CIRCULAR_PONG_GAME, value); // value is the nb of spots instantiated
mbedalvaro 30:d8af03f01cd4 484
mbedalvaro 30:d8af03f01cd4 485 lsr.setConfigToRender(&blobconf);
mbedalvaro 30:d8af03f01cd4 486 timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
mbedalvaro 30:d8af03f01cd4 487 // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
mbedalvaro 30:d8af03f01cd4 488 }
mbedalvaro 30:d8af03f01cd4 489 }
mbedalvaro 31:5f039cbddee8 490
mbedalvaro 31:5f039cbddee8 491 else if (!strcmp(address[0], "fish_net")) {
mbedalvaro 30:d8af03f01cd4 492 int value=data[0];
mbedalvaro 30:d8af03f01cd4 493 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 30:d8af03f01cd4 494
mbedalvaro 30:d8af03f01cd4 495 timerForRendering.detach();
mbedalvaro 30:d8af03f01cd4 496
mbedalvaro 31:5f039cbddee8 497 blobconf.initConfig(FISH_NET_GAME, value); // value is the nb of spots instantiated
mbedalvaro 31:5f039cbddee8 498
mbedalvaro 31:5f039cbddee8 499 lsr.setConfigToRender(&blobconf);
mbedalvaro 31:5f039cbddee8 500 timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
mbedalvaro 31:5f039cbddee8 501 // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
mbedalvaro 31:5f039cbddee8 502 }
mbedalvaro 31:5f039cbddee8 503 }
mbedalvaro 31:5f039cbddee8 504
mbedalvaro 31:5f039cbddee8 505 else if (!strcmp(address[0], "vertical_pinball")) {
mbedalvaro 31:5f039cbddee8 506 int value=data[0];
mbedalvaro 31:5f039cbddee8 507 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 31:5f039cbddee8 508
mbedalvaro 31:5f039cbddee8 509 timerForRendering.detach();
mbedalvaro 31:5f039cbddee8 510
mbedalvaro 31:5f039cbddee8 511 blobconf.initConfig(VERTICAL_PINBALL_GAME, value);
mbedalvaro 31:5f039cbddee8 512
mbedalvaro 31:5f039cbddee8 513 lsr.setConfigToRender(&blobconf);
mbedalvaro 31:5f039cbddee8 514 timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
mbedalvaro 31:5f039cbddee8 515 // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
mbedalvaro 31:5f039cbddee8 516 }
mbedalvaro 31:5f039cbddee8 517 }
mbedalvaro 31:5f039cbddee8 518
mbedalvaro 31:5f039cbddee8 519 else if (!strcmp(address[0], "pac_man")) {
mbedalvaro 31:5f039cbddee8 520 timerForRendering.detach();
mbedalvaro 31:5f039cbddee8 521
mbedalvaro 30:d8af03f01cd4 522 blobconf.initConfig(PAC_MAN_GAME);
mbedalvaro 30:d8af03f01cd4 523
mbedalvaro 30:d8af03f01cd4 524 lsr.setConfigToRender(&blobconf);
mbedalvaro 30:d8af03f01cd4 525 timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
mbedalvaro 30:d8af03f01cd4 526 // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
mbedalvaro 30:d8af03f01cd4 527 }
mbedalvaro 30:d8af03f01cd4 528
mbedalvaro 31:5f039cbddee8 529 else if (!strcmp(address[0], "spot_tracking")) {
mbedalvaro 31:5f039cbddee8 530 timerForRendering.detach();
mbedalvaro 31:5f039cbddee8 531
mbedalvaro 31:5f039cbddee8 532 blobconf.initConfig(ONE_TRACKING_SPOT); // value is the nb of spots instantiated
mbedalvaro 31:5f039cbddee8 533
mbedalvaro 31:5f039cbddee8 534 lsr.setConfigToRender(&blobconf);
mbedalvaro 31:5f039cbddee8 535 timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
mbedalvaro 31:5f039cbddee8 536 // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
mbedalvaro 31:5f039cbddee8 537 }
mbedalvaro 30:d8af03f01cd4 538
mbedalvaro 16:2ff1cb2ae1b1 539 else if (!strcmp(address[0], "spot_test")) {
mbedalvaro 0:345b3bc7a0ea 540 timerForRendering.detach();
mbedalvaro 0:345b3bc7a0ea 541 // blobconf.computeBoundingBox();
mbedalvaro 1:a4050fee11f7 542 blobconf.clearConfig();
mbedalvaro 16:2ff1cb2ae1b1 543 blobconf.addOneRigidLoopTest();
mbedalvaro 1:a4050fee11f7 544 lsr.setConfigToRender(&blobconf);
mbedalvaro 9:3321170d157c 545 timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
mbedalvaro 9:3321170d157c 546 // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
mbedalvaro 1:a4050fee11f7 547 }
mbedalvaro 1:a4050fee11f7 548
mbedalvaro 1:a4050fee11f7 549 // other:
mbedalvaro 1:a4050fee11f7 550
mbedalvaro 24:4e52031a495b 551 else if ( !strcmp(address[0], "standby" ) ) { // will put ALL the blobs in stand by mode (no update function)
mbedalvaro 0:345b3bc7a0ea 552 blobconf.allStandBy(); // will avoid the update function
mbedalvaro 24:4e52031a495b 553 }
mbedalvaro 24:4e52031a495b 554 else if ( !strcmp(address[0], "resume" ) ) {
mbedalvaro 24:4e52031a495b 555 blobconf.allResume(); // Update function is called for all the blobs
mbedalvaro 1:a4050fee11f7 556 }
mbedalvaro 1:a4050fee11f7 557
mbedalvaro 1:a4050fee11f7 558 // (III) ========================================= Loop control (parameters, etc) ===========================================
mbedalvaro 19:228430f1350e 559
mbedalvaro 33:43e8bc451ef0 560 else if (!strcmp( address[0], "setSpeed" ) ) {
mbedalvaro 33:43e8bc451ef0 561 int value=data[0]; // value 1 means a speed of 0.1, value 10, a speed of 1, etc.
mbedalvaro 33:43e8bc451ef0 562 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 33:43e8bc451ef0 563 for (int i=0; i< blobconf.numBlobs; i++) {
mbedalvaro 33:43e8bc451ef0 564 //if ((!strcmp(blobconf.blobArray[i].spotName, "rigid_following"))||(!strcmp(blobconf.blobArray[i].spotName, "rigid_following"))) {
mbedalvaro 33:43e8bc451ef0 565 blobconf.blobArray[i]->setSpeed((float)(0.1*value));
mbedalvaro 33:43e8bc451ef0 566 }
mbedalvaro 33:43e8bc451ef0 567 }
mbedalvaro 33:43e8bc451ef0 568 }
mbedalvaro 24:4e52031a495b 569 else if (!strcmp( address[0], "speedFactor" ) ) {
mbedalvaro 24:4e52031a495b 570 int value=data[0]; // value 100 means no change of speed. 200 is twice as fast, 50 is half as fast.
mbedalvaro 24:4e52031a495b 571 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 24:4e52031a495b 572 for (int i=0; i< blobconf.numBlobs; i++) {
mbedalvaro 24:4e52031a495b 573 //if ((!strcmp(blobconf.blobArray[i].spotName, "rigid_following"))||(!strcmp(blobconf.blobArray[i].spotName, "rigid_following"))) {
mbedalvaro 24:4e52031a495b 574 blobconf.blobArray[i]->speedFactor((float)(1.0*value/100.0));
mbedalvaro 24:4e52031a495b 575 }
mbedalvaro 24:4e52031a495b 576 }
mbedalvaro 24:4e52031a495b 577 }
mbedalvaro 24:4e52031a495b 578
mbedalvaro 33:43e8bc451ef0 579 else if (!strcmp( address[0], "setSize" ) ) {
mbedalvaro 33:43e8bc451ef0 580 int value=data[0]; // this is the direct size of the scafold
mbedalvaro 32:52273c3291fe 581 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 33:43e8bc451ef0 582 for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->setSize((float)(1.0*value));
mbedalvaro 32:52273c3291fe 583 }
mbedalvaro 32:52273c3291fe 584 }
mbedalvaro 33:43e8bc451ef0 585 else if (!strcmp( address[0], "sizeFactor" ) ) {
mbedalvaro 33:43e8bc451ef0 586 int value=data[0]; // value 100 means no change of sice. 200 is twice as big, 50 is half as big.
mbedalvaro 33:43e8bc451ef0 587 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 33:43e8bc451ef0 588 for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->sizeFactor((float)(1.0*value/100.0));
mbedalvaro 33:43e8bc451ef0 589 }
mbedalvaro 33:43e8bc451ef0 590 }
mbedalvaro 33:43e8bc451ef0 591
mbedalvaro 32:52273c3291fe 592 // ADJUST MIRROR ANGLE CORRECTION:
mbedalvaro 32:52273c3291fe 593 else if (!strcmp( address[0], "adjustPlusAngle" ) ) {
mbedalvaro 32:52273c3291fe 594 int value=data[0]; // this is not a factor, but an additive quantity to the current delay
mbedalvaro 32:52273c3291fe 595 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 32:52273c3291fe 596 for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.addDelayMirrors(value);
mbedalvaro 32:52273c3291fe 597 }
mbedalvaro 32:52273c3291fe 598 }
mbedalvaro 32:52273c3291fe 599 else if (!strcmp( address[0], "adjustMinusAngle" ) ) {
mbedalvaro 32:52273c3291fe 600 int value=data[0]; // this is not a factor, but an substractive quantity to the current delay
mbedalvaro 32:52273c3291fe 601 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 32:52273c3291fe 602 for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.addDelayMirrors(-value);
mbedalvaro 32:52273c3291fe 603 }
mbedalvaro 32:52273c3291fe 604 }
mbedalvaro 32:52273c3291fe 605
mbedalvaro 24:4e52031a495b 606 else if (!strcmp( address[0], "adjustPlusAngle" ) ) {
mbedalvaro 24:4e52031a495b 607 int value=data[0]; // value 100 means no change of speed. 200 is twice as fast, 50 is half as fast.
mbedalvaro 24:4e52031a495b 608 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 24:4e52031a495b 609 for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.addDelayMirrors(value);
mbedalvaro 24:4e52031a495b 610 }
mbedalvaro 24:4e52031a495b 611 }
mbedalvaro 24:4e52031a495b 612
mbedalvaro 33:43e8bc451ef0 613
mbedalvaro 33:43e8bc451ef0 614 // THRESHOLD MODE, and PARAMETERS:
mbedalvaro 34:1244fa3f2559 615 //(1) Set the threshold mode:
mbedalvaro 33:43e8bc451ef0 616 else if (!strcmp( address[0], "autoThreshold" ) ) {
mbedalvaro 34:1244fa3f2559 617 int value=data[0]; // 1 (auto) or 0 (fixed)
mbedalvaro 33:43e8bc451ef0 618 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 33:43e8bc451ef0 619 for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.setThresholdMode(value);
mbedalvaro 33:43e8bc451ef0 620 }
mbedalvaro 35:35af5086ab4f 621 // set led and switch state (global value of threshold):
mbedalvaro 35:35af5086ab4f 622 IO.setSwitchOneState(value>0);
mbedalvaro 33:43e8bc451ef0 623 }
mbedalvaro 33:43e8bc451ef0 624
mbedalvaro 33:43e8bc451ef0 625 // (a) AUTO THRESHOLD:
mbedalvaro 33:43e8bc451ef0 626 // MINIMUM CONTRAST RATIO:
mbedalvaro 33:43e8bc451ef0 627 // (1) using multiplicative factor:
mbedalvaro 32:52273c3291fe 628 else if (!strcmp( address[0], "adjustMultContrast" ) ) {
mbedalvaro 32:52273c3291fe 629 int value=data[0]; // value 100 means no change of the current contrast value. 200 means a min contrast
mbedalvaro 32:52273c3291fe 630 // that is twice as large and 50 is half as large as before.
mbedalvaro 24:4e52031a495b 631 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 32:52273c3291fe 632 for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.multMinContrastRatio((float)(1.0*value/100.0));
mbedalvaro 32:52273c3291fe 633 }
mbedalvaro 32:52273c3291fe 634 }
mbedalvaro 32:52273c3291fe 635 // (2) directly:
mbedalvaro 32:52273c3291fe 636 else if (!strcmp( address[0], "adjustContrast" ) ) {
mbedalvaro 32:52273c3291fe 637 int value=data[0]; // value is in PERCENT (100=1, 50 = 0.5...)
mbedalvaro 32:52273c3291fe 638 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 32:52273c3291fe 639 for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.setMinContrastRatio((float)(1.0*value/100.0));
mbedalvaro 24:4e52031a495b 640 }
mbedalvaro 24:4e52031a495b 641 }
mbedalvaro 34:1244fa3f2559 642 // THRESHOLD FACTOR:
mbedalvaro 32:52273c3291fe 643 //(1) using multiplicative factor:
mbedalvaro 32:52273c3291fe 644 else if (!strcmp( address[0], "adjustMultThreshold" ) ) {
mbedalvaro 32:52273c3291fe 645 int value=data[0]; // value 100 means no change of the current contrast value. 200 means a min contrast
mbedalvaro 32:52273c3291fe 646 // that is twice as large and 50 is half as large as before.
mbedalvaro 32:52273c3291fe 647 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 32:52273c3291fe 648 for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.multThresholdFactor((float)(1.0*value/100.0));
mbedalvaro 32:52273c3291fe 649 }
mbedalvaro 32:52273c3291fe 650 }
mbedalvaro 32:52273c3291fe 651 //(2) directly:
mbedalvaro 32:52273c3291fe 652 else if (!strcmp( address[0], "adjustThresholdFactor" ) ) {
mbedalvaro 32:52273c3291fe 653 int value=data[0]; // value is in PERCENT (100=1, 50 = 0.5...)
mbedalvaro 32:52273c3291fe 654 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 32:52273c3291fe 655 for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.setThresholdFactor((float)(1.0*value/100.0));
mbedalvaro 32:52273c3291fe 656 }
mbedalvaro 32:52273c3291fe 657 }
mbedalvaro 33:43e8bc451ef0 658 // MINIMUM ACCEPTABLE INTENSITY:
mbedalvaro 32:52273c3291fe 659 // Adjust minimum acceptable intensity:
mbedalvaro 32:52273c3291fe 660 else if (!strcmp( address[0], "adjustMinAcceptableIntensity" ) ) {
mbedalvaro 32:52273c3291fe 661 int value=data[0]; // value is DIRECT value (0 to 255)
mbedalvaro 32:52273c3291fe 662 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 32:52273c3291fe 663 for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.setMinAcceptableIntensity(value);
mbedalvaro 32:52273c3291fe 664 }
mbedalvaro 32:52273c3291fe 665 }
mbedalvaro 32:52273c3291fe 666
mbedalvaro 33:43e8bc451ef0 667 // (b) FIXED THRESHOLD:
mbedalvaro 33:43e8bc451ef0 668 // Adjust fixedThreshold (directly):
mbedalvaro 33:43e8bc451ef0 669 else if (!strcmp( address[0], "adjustFixedThreshold" ) ) {
mbedalvaro 33:43e8bc451ef0 670 int value=data[0]; // value is DIRECT value (0 to 255)
mbedalvaro 33:43e8bc451ef0 671 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 33:43e8bc451ef0 672 for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.setFixedThreshold(value);
mbedalvaro 33:43e8bc451ef0 673 }
mbedalvaro 33:43e8bc451ef0 674 }
mbedalvaro 33:43e8bc451ef0 675
mbedalvaro 33:43e8bc451ef0 676
mbedalvaro 33:43e8bc451ef0 677
mbedalvaro 32:52273c3291fe 678 // ===================== SEND DATA MODES =======================
mbedalvaro 24:4e52031a495b 679
mbedalvaro 1:a4050fee11f7 680 else if (!strcmp( address[0], "sendOSC" ) ) {
mbedalvaro 1:a4050fee11f7 681 int value=data[0];
mbedalvaro 1:a4050fee11f7 682 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 1:a4050fee11f7 683 for (int i=0; i< blobconf.numBlobs; i++) {
mbedalvaro 1:a4050fee11f7 684 blobconf.blobArray[i]->sendOSC=(value>0);
mbedalvaro 1:a4050fee11f7 685 }
mbedalvaro 1:a4050fee11f7 686 }
mbedalvaro 1:a4050fee11f7 687 }
mbedalvaro 1:a4050fee11f7 688
mbedalvaro 1:a4050fee11f7 689 else if (!strcmp( address[0], "sendArea" ) ) {
mbedalvaro 1:a4050fee11f7 690 int value=data[0];
mbedalvaro 1:a4050fee11f7 691 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 1:a4050fee11f7 692 for (int i=0; i< blobconf.numBlobs; i++) {
mbedalvaro 1:a4050fee11f7 693 blobconf.blobArray[i]->sendingBlobArea=(value>0);
mbedalvaro 1:a4050fee11f7 694 }
mbedalvaro 1:a4050fee11f7 695 }
mbedalvaro 1:a4050fee11f7 696 }
mbedalvaro 1:a4050fee11f7 697
mbedalvaro 1:a4050fee11f7 698 else if (!strcmp( address[0], "sendPos" ) ) {
mbedalvaro 1:a4050fee11f7 699 int value=data[0];
mbedalvaro 1:a4050fee11f7 700 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 1:a4050fee11f7 701 for (int i=0; i< blobconf.numBlobs; i++) {
mbedalvaro 1:a4050fee11f7 702 blobconf.blobArray[i]->sendingLoopPositions=(value>0);
mbedalvaro 1:a4050fee11f7 703 }
mbedalvaro 1:a4050fee11f7 704 }
mbedalvaro 1:a4050fee11f7 705 }
mbedalvaro 1:a4050fee11f7 706
mbedalvaro 1:a4050fee11f7 707 else if (!strcmp( address[0], "sendRegions" ) ) {
mbedalvaro 1:a4050fee11f7 708 int value=data[0];
mbedalvaro 1:a4050fee11f7 709 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 1:a4050fee11f7 710 for (int i=0; i< blobconf.numBlobs; i++) {
mbedalvaro 1:a4050fee11f7 711 blobconf.blobArray[i]->sendingLoopRegions=(value>0);
mbedalvaro 1:a4050fee11f7 712 }
mbedalvaro 1:a4050fee11f7 713 }
mbedalvaro 1:a4050fee11f7 714 }
mbedalvaro 1:a4050fee11f7 715
mbedalvaro 1:a4050fee11f7 716 else if (!strcmp( address[0], "sendTouched" ) ) {
mbedalvaro 1:a4050fee11f7 717 int value=data[0];
mbedalvaro 1:a4050fee11f7 718 if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)
mbedalvaro 1:a4050fee11f7 719 for (int i=0; i< blobconf.numBlobs; i++) {
mbedalvaro 1:a4050fee11f7 720 blobconf.blobArray[i]->sendingTouched=(value>0);
mbedalvaro 1:a4050fee11f7 721 }
mbedalvaro 1:a4050fee11f7 722 }
mbedalvaro 1:a4050fee11f7 723 }
mbedalvaro 1:a4050fee11f7 724
mbedalvaro 1:a4050fee11f7 725
mbedalvaro 1:a4050fee11f7 726
mbedalvaro 0:345b3bc7a0ea 727 }
mbedalvaro 0:345b3bc7a0ea 728
mbedalvaro 0:345b3bc7a0ea 729 //============= RECEIVE OSC COMMANDS =========================
mbedalvaro 1:a4050fee11f7 730 // This is the callback function called when there are packets on the listening socket. It is not nice to have it
mbedalvaro 1:a4050fee11f7 731 // here, but for the time being having a "wrapping global" is the simplest solution (we cannot pass a member-function pointer
mbedalvaro 1:a4050fee11f7 732 // as handler to the upd object).
mbedalvaro 0:345b3bc7a0ea 733 void processOSC(UDPSocketEvent e) {
mbedalvaro 0:345b3bc7a0ea 734 osc.onUDPSocketEvent(e);
mbedalvaro 0:345b3bc7a0ea 735
mbedalvaro 0:345b3bc7a0ea 736 if (osc.newMessage) {
mbedalvaro 1:a4050fee11f7 737 // in fact, there is no need to check this if using the method of a global callback function - it is clear this is a new packet... however, it may be
mbedalvaro 1:a4050fee11f7 738 // interesting to use a timer, and process data (answers, etc) only after a certain amount of time, so as to avoid blocking the program in IRQ context...
mbedalvaro 1:a4050fee11f7 739
mbedalvaro 1:a4050fee11f7 740 // Acquire the addresses and arguments and put them in the GLOBAL variables:
mbedalvaro 1:a4050fee11f7 741 strcpy(address[0],"");
mbedalvaro 1:a4050fee11f7 742 strcpy(address[1],"");
mbedalvaro 1:a4050fee11f7 743 for (int i=0; i<recMes.getAddressNum(); i++) strcpy(address[i],recMes.getAddress(i)); // NOTE: up to the rest of the program to check if address[1] is really not null
mbedalvaro 1:a4050fee11f7 744 // Acquire data:
mbedalvaro 1:a4050fee11f7 745 data[0]=-1;
mbedalvaro 1:a4050fee11f7 746 data[1]=-1;
mbedalvaro 1:a4050fee11f7 747 for (int i=0; i<recMes.getArgNum(); i++) data[i]=(int)recMes.getArgInt(i);
mbedalvaro 1:a4050fee11f7 748
mbedalvaro 1:a4050fee11f7 749 // Finally, interpret the command:
mbedalvaro 1:a4050fee11f7 750 interpretCommand();//address, data);
mbedalvaro 1:a4050fee11f7 751
mbedalvaro 0:345b3bc7a0ea 752 }
mbedalvaro 1:a4050fee11f7 753 }
mbedalvaro 1:a4050fee11f7 754
mbedalvaro 0:345b3bc7a0ea 755 //============= RECEIVE SERIAL COMMANDS =========================
mbedalvaro 0:345b3bc7a0ea 756 //
mbedalvaro 1:a4050fee11f7 757 // NOTE: - NUMERIC PARAMETERS have to be send BEFORE the command word. They must be sent as ASCII DEC, without end character.
mbedalvaro 0:345b3bc7a0ea 758 // - Commands words SHOULD NOT have numbers in it. They should be C compliant STRINGS (ended with character '0')
mbedalvaro 1:a4050fee11f7 759 // - order is irrelevant: we can send 10 RADIUS or RADIUS 10.
mbedalvaro 0:345b3bc7a0ea 760
mbedalvaro 1:a4050fee11f7 761 // String to store ALPHANUMERIC DATA (i.e., integers, floating point numbers, unsigned ints, etc represented as DEC) sent wirelessly:
mbedalvaro 0:345b3bc7a0ea 762 char stringData[24]; // note: an integer is two bytes long, represented with a maximum of 5 digits, but we may send floats or unsigned int...
mbedalvaro 0:345b3bc7a0ea 763 int indexStringData=0;//position of the byte in the string
mbedalvaro 0:345b3bc7a0ea 764
mbedalvaro 0:345b3bc7a0ea 765 // String to store COMMAND WORDS:
mbedalvaro 0:345b3bc7a0ea 766 char stringCommand[24]; // note: an integer is two bytes long, represented with a maximum of 5 digits, but we may send floats or unsigned int...
mbedalvaro 0:345b3bc7a0ea 767 int indexStringCommand=0;
mbedalvaro 0:345b3bc7a0ea 768 bool commandReady=false; // will become true when receiving the byte 0 (i.e. the '/0' string terminator)
mbedalvaro 0:345b3bc7a0ea 769
mbedalvaro 0:345b3bc7a0ea 770 void processSerial() {
mbedalvaro 0:345b3bc7a0ea 771
mbedalvaro 1:a4050fee11f7 772 while (pc.readable()>0) {
mbedalvaro 1:a4050fee11f7 773
mbedalvaro 14:0fc33a3a7b4b 774
mbedalvaro 1:a4050fee11f7 775 char val =pc.getc();
mbedalvaro 0:345b3bc7a0ea 776 // pc.printf("Got :%d\n", incomingByte);
mbedalvaro 1:a4050fee11f7 777 //pc.putc(incomingByte);
mbedalvaro 1:a4050fee11f7 778
mbedalvaro 1:a4050fee11f7 779 // Save ASCII numeric characters (ASCII 0 - 9) on stringData:
mbedalvaro 1:a4050fee11f7 780 if ((val >= '0') && (val <= '9')) { // this is 45 to 57 (included)
mbedalvaro 1:a4050fee11f7 781 stringData[indexStringData] = val;
mbedalvaro 1:a4050fee11f7 782 indexStringData++;
mbedalvaro 1:a4050fee11f7 783 }
mbedalvaro 1:a4050fee11f7 784
mbedalvaro 1:a4050fee11f7 785 // Save ASCII letters in stringCommand:
mbedalvaro 1:a4050fee11f7 786 if ((val >= 'A') && (val <= 'z')) { // this is 65 to 122 (included)
mbedalvaro 1:a4050fee11f7 787 stringCommand[indexStringCommand] = val;
mbedalvaro 1:a4050fee11f7 788 indexStringCommand++;
mbedalvaro 1:a4050fee11f7 789 }
mbedalvaro 1:a4050fee11f7 790 // is command ready?
mbedalvaro 1:a4050fee11f7 791 if (val=='/') {
mbedalvaro 1:a4050fee11f7 792 commandReady=true;
mbedalvaro 1:a4050fee11f7 793 stringCommand[indexStringCommand] = 0; // string termination.
mbedalvaro 1:a4050fee11f7 794 indexStringCommand=0; // reset index string for acquiring next command
mbedalvaro 1:a4050fee11f7 795 //Serial.println(stringCommand);
mbedalvaro 1:a4050fee11f7 796 }
mbedalvaro 1:a4050fee11f7 797
mbedalvaro 1:a4050fee11f7 798 // COMMANDS (with or without numeric parameters):
mbedalvaro 1:a4050fee11f7 799 if (commandReady==true) { // it means we can interpret the command string:
mbedalvaro 1:a4050fee11f7 800 commandReady=false;
mbedalvaro 1:a4050fee11f7 801
mbedalvaro 1:a4050fee11f7 802 stringData[indexStringData] = 0 ;// string termination for numeric values;
mbedalvaro 1:a4050fee11f7 803 indexStringData=0;
mbedalvaro 1:a4050fee11f7 804
mbedalvaro 1:a4050fee11f7 805 // PARSE DATA: (TO DO!!!!!!!!!!!!!!):
mbedalvaro 0:345b3bc7a0ea 806
mbedalvaro 1:a4050fee11f7 807 // (a) Parse command (get address[0] and address[1]):
mbedalvaro 1:a4050fee11f7 808 //ex: "/1/standBy" -- > address[0]="1" and address[1]="standBy"
mbedalvaro 1:a4050fee11f7 809 // address[2]
mbedalvaro 1:a4050fee11f7 810
mbedalvaro 1:a4050fee11f7 811 // Serial.println(stringCommand);
mbedalvaro 1:a4050fee11f7 812 // Serial.println(stringData);
mbedalvaro 1:a4050fee11f7 813
mbedalvaro 1:a4050fee11f7 814 // (b) Parse data:
mbedalvaro 1:a4050fee11f7 815
mbedalvaro 1:a4050fee11f7 816 // char address[2][24];
mbedalvaro 1:a4050fee11f7 817 //long auxdata[2]; // to store a max of two arguments (note: we will only use LONGs)
mbedalvaro 1:a4050fee11f7 818 //int data[2]; // this is to have -1 as NO DATA, to detect errors.
mbedalvaro 1:a4050fee11f7 819
mbedalvaro 1:a4050fee11f7 820 // FOR THE TIME BEING there is no parsing for serial commands:
mbedalvaro 1:a4050fee11f7 821
mbedalvaro 1:a4050fee11f7 822 // SCANNING:
mbedalvaro 1:a4050fee11f7 823 if (!strcmp(stringCommand , "takeSnapshot")) {
mbedalvaro 1:a4050fee11f7 824 // First, we need to disable the threaded display for the loop:
mbedalvaro 1:a4050fee11f7 825 timerForRendering.detach();
mbedalvaro 1:a4050fee11f7 826
mbedalvaro 1:a4050fee11f7 827 // Then, do the scan (sending values on serial port):
mbedalvaro 24:4e52031a495b 828 IO.scan_serial(atoi(stringData));
mbedalvaro 1:a4050fee11f7 829
mbedalvaro 1:a4050fee11f7 830 // Finally, start again threaded display:
mbedalvaro 4:f9d364f10335 831 timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
mbedalvaro 9:3321170d157c 832 // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
mbedalvaro 16:2ff1cb2ae1b1 833 } else if (!strcmp(stringCommand , "REDON")) IO.setRedPower(1); // pc.printf("%d\n",incomingByte);
mbedalvaro 1:a4050fee11f7 834
mbedalvaro 14:0fc33a3a7b4b 835 else if (!strcmp(stringCommand , "REDOFF")) IO.setRedPower(0);
mbedalvaro 14:0fc33a3a7b4b 836
mbedalvaro 14:0fc33a3a7b4b 837 else if (!strcmp(stringCommand , "READVALUE")) pc.printf("Value read: %f", lockin.getSmoothValue());//lockin.getLastValue());/
mbedalvaro 1:a4050fee11f7 838
mbedalvaro 14:0fc33a3a7b4b 839 else if (!strcmp(stringCommand , "mbedReset")) mbed_reset();
mbedalvaro 16:2ff1cb2ae1b1 840
mbedalvaro 14:0fc33a3a7b4b 841 else if (!strcmp(stringCommand , "calibrate")) {
mbedalvaro 16:2ff1cb2ae1b1 842 // First, we need to disable the threaded display for the loop:
mbedalvaro 16:2ff1cb2ae1b1 843 timerForRendering.detach();
mbedalvaro 16:2ff1cb2ae1b1 844 // RESCAN (and save LUT table):
mbedalvaro 16:2ff1cb2ae1b1 845 IO.scanLUT();
mbedalvaro 16:2ff1cb2ae1b1 846 // Finally, start again threaded display:
mbedalvaro 16:2ff1cb2ae1b1 847 timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL);
mbedalvaro 16:2ff1cb2ae1b1 848 // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL);
mbedalvaro 16:2ff1cb2ae1b1 849 }
mbedalvaro 1:a4050fee11f7 850
mbedalvaro 1:a4050fee11f7 851 // FINALLY, interpret commands (but only after parsing):
mbedalvaro 1:a4050fee11f7 852 // interpretCommand();//address, data);
mbedalvaro 0:345b3bc7a0ea 853
mbedalvaro 0:345b3bc7a0ea 854 }
mbedalvaro 1:a4050fee11f7 855 }
mbedalvaro 1:a4050fee11f7 856 }
mbedalvaro 0:345b3bc7a0ea 857
mbedalvaro 0:345b3bc7a0ea 858
mbedalvaro 0:345b3bc7a0ea 859
mbedalvaro 0:345b3bc7a0ea 860 // ================ MISCELANEA
mbedalvaro 0:345b3bc7a0ea 861
mbedalvaro 0:345b3bc7a0ea 862 /* EXAMPLE SEND/RECEIVE on PROCESSING:
mbedalvaro 0:345b3bc7a0ea 863
mbedalvaro 0:345b3bc7a0ea 864 // oscP5sendreceive by andreas schlegel
mbedalvaro 0:345b3bc7a0ea 865 // example shows how to send and receive osc messages.
mbedalvaro 0:345b3bc7a0ea 866 // oscP5 website at http://www.sojamo.de/oscP5
mbedalvaro 0:345b3bc7a0ea 867
mbedalvaro 0:345b3bc7a0ea 868 import oscP5.*;
mbedalvaro 0:345b3bc7a0ea 869 import netP5.*;
mbedalvaro 1:a4050fee11f7 870
mbedalvaro 0:345b3bc7a0ea 871 OscP5 oscP5;
mbedalvaro 0:345b3bc7a0ea 872 NetAddress myRemoteLocation;
mbedalvaro 0:345b3bc7a0ea 873
mbedalvaro 0:345b3bc7a0ea 874 void setup() {
mbedalvaro 0:345b3bc7a0ea 875 size(400,400);
mbedalvaro 0:345b3bc7a0ea 876 frameRate(25);
mbedalvaro 1:a4050fee11f7 877 // start oscP5, listening for incoming messages at port 12000
mbedalvaro 0:345b3bc7a0ea 878 oscP5 = new OscP5(this,12000);
mbedalvaro 1:a4050fee11f7 879
mbedalvaro 0:345b3bc7a0ea 880 // myRemoteLocation is a NetAddress. a NetAddress takes 2 parameters,
mbedalvaro 0:345b3bc7a0ea 881 // an ip address and a port number. myRemoteLocation is used as parameter in
mbedalvaro 1:a4050fee11f7 882 // oscP5.send() when sending osc packets to another computer, device,
mbedalvaro 0:345b3bc7a0ea 883 // application. usage see below. for testing purposes the listening port
mbedalvaro 0:345b3bc7a0ea 884 // and the port of the remote location address are the same, hence you will
mbedalvaro 0:345b3bc7a0ea 885 // send messages back to this sketch.
mbedalvaro 0:345b3bc7a0ea 886 myRemoteLocation = new NetAddress("10.0.0.2",10000);
mbedalvaro 0:345b3bc7a0ea 887 }
mbedalvaro 0:345b3bc7a0ea 888
mbedalvaro 0:345b3bc7a0ea 889
mbedalvaro 0:345b3bc7a0ea 890 void draw() {
mbedalvaro 1:a4050fee11f7 891 background(0);
mbedalvaro 0:345b3bc7a0ea 892 }
mbedalvaro 0:345b3bc7a0ea 893
mbedalvaro 0:345b3bc7a0ea 894 void mousePressed() {
mbedalvaro 1:a4050fee11f7 895 // in the following different ways of creating osc messages are shown by example
mbedalvaro 0:345b3bc7a0ea 896 OscMessage myMessage = new OscMessage("/mbed/test1");
mbedalvaro 1:a4050fee11f7 897
mbedalvaro 1:a4050fee11f7 898 myMessage.add(123); // add an int to the osc message
mbedalvaro 0:345b3bc7a0ea 899
mbedalvaro 1:a4050fee11f7 900 // send the message
mbedalvaro 1:a4050fee11f7 901 oscP5.send(myMessage, myRemoteLocation);
mbedalvaro 0:345b3bc7a0ea 902 }
mbedalvaro 0:345b3bc7a0ea 903
mbedalvaro 0:345b3bc7a0ea 904
mbedalvaro 1:a4050fee11f7 905 // incoming osc message are forwarded to the oscEvent method.
mbedalvaro 0:345b3bc7a0ea 906 void oscEvent(OscMessage theOscMessage) {
mbedalvaro 1:a4050fee11f7 907 // print the address pattern and the typetag of the received OscMessage
mbedalvaro 0:345b3bc7a0ea 908 print("### received an osc message.");
mbedalvaro 0:345b3bc7a0ea 909 print(" addrpattern: "+theOscMessage.addrPattern());
mbedalvaro 0:345b3bc7a0ea 910 println(" typetag: "+theOscMessage.typetag());
mbedalvaro 0:345b3bc7a0ea 911 }
mbedalvaro 0:345b3bc7a0ea 912
mbedalvaro 0:345b3bc7a0ea 913 */