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