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