just a test

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Tue Dec 02 04:28:42 2014 +0000
Revision:
48:7633d8e7b0d3
Parent:
47:2312a8dc9658
this is the working version of the skin games sowtware (aka, scorelight but with pre-determined "games")

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