![](/media/cache/profiles/68a15b5278e4f7c4c056df9d5f1d3b1f.jpg.50x50_q85.jpg)
save loops
mbedOSC.h@0:df6fdd9b99f0, 2014-12-02 (annotated)
- Committer:
- mbedalvaro
- Date:
- Tue Dec 02 04:39:15 2014 +0000
- Revision:
- 0:df6fdd9b99f0
this new version of skinGames will have a function that stops scanning as the laser reaches the same position (i.e., loops) with a certain precision. It is for extracting contours for Takashita project. It can then save on a file or send on osc
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedalvaro | 0:df6fdd9b99f0 | 1 | /* mbedOSC.h |
mbedalvaro | 0:df6fdd9b99f0 | 2 | This is an OSC library for the mbed, created to be compatible with Recotana's OSCClass library (http://recotana.com) for the |
mbedalvaro | 0:df6fdd9b99f0 | 3 | Arduino with Ethernet shield. I have also used parts of the OSC Transceiver(Sender/Receiver) code by xshige |
mbedalvaro | 0:df6fdd9b99f0 | 4 | written by: Alvaro Cassinelli, 7.10.2011 |
mbedalvaro | 0:df6fdd9b99f0 | 5 | |
mbedalvaro | 0:df6fdd9b99f0 | 6 | This library is free software; you can redistribute it and/or |
mbedalvaro | 0:df6fdd9b99f0 | 7 | modify it under the terms of the GNU Lesser General Public |
mbedalvaro | 0:df6fdd9b99f0 | 8 | License version 2.1 as published by the Free Software Foundation. |
mbedalvaro | 0:df6fdd9b99f0 | 9 | Open Sound Control http://opensoundcontrol.org/ |
mbedalvaro | 0:df6fdd9b99f0 | 10 | |
mbedalvaro | 0:df6fdd9b99f0 | 11 | mbedOSC version 0.1 Specification (similar to Recotana's OSCClass library) |
mbedalvaro | 0:df6fdd9b99f0 | 12 | |
mbedalvaro | 0:df6fdd9b99f0 | 13 | ******** |
mbedalvaro | 0:df6fdd9b99f0 | 14 | Address : max 2 |
mbedalvaro | 0:df6fdd9b99f0 | 15 | "/ard" |
mbedalvaro | 0:df6fdd9b99f0 | 16 | "/ard/output" --address[0]="/ard" :max 15character |
mbedalvaro | 0:df6fdd9b99f0 | 17 | --address[1]="/output" :max 15character |
mbedalvaro | 0:df6fdd9b99f0 | 18 | |
mbedalvaro | 0:df6fdd9b99f0 | 19 | ******* |
mbedalvaro | 0:df6fdd9b99f0 | 20 | TypeTag : max 2 |
mbedalvaro | 0:df6fdd9b99f0 | 21 | |
mbedalvaro | 0:df6fdd9b99f0 | 22 | "i" - long or unsigned long |
mbedalvaro | 0:df6fdd9b99f0 | 23 | "f" - double |
mbedalvaro | 0:df6fdd9b99f0 | 24 | |
mbedalvaro | 0:df6fdd9b99f0 | 25 | ******* |
mbedalvaro | 0:df6fdd9b99f0 | 26 | arg : max 2 |
mbedalvaro | 0:df6fdd9b99f0 | 27 | |
mbedalvaro | 0:df6fdd9b99f0 | 28 | ******* |
mbedalvaro | 0:df6fdd9b99f0 | 29 | Example of an OSC message: "/mbed/test1, if 50 32.4" (Note: this is not the byte string |
mbedalvaro | 0:df6fdd9b99f0 | 30 | sent as UDP packet - there are no spaces, and arguments are in binary, BIG ENDIAN) |
mbedalvaro | 0:df6fdd9b99f0 | 31 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 32 | |
mbedalvaro | 0:df6fdd9b99f0 | 33 | #ifndef mbedOSC_h |
mbedalvaro | 0:df6fdd9b99f0 | 34 | #define mbedOSC_h |
mbedalvaro | 0:df6fdd9b99f0 | 35 | |
mbedalvaro | 0:df6fdd9b99f0 | 36 | #include "mbed.h" |
mbedalvaro | 0:df6fdd9b99f0 | 37 | #include "EthernetNetIf.h" |
mbedalvaro | 0:df6fdd9b99f0 | 38 | #include "UDPSocket.h" |
mbedalvaro | 0:df6fdd9b99f0 | 39 | |
mbedalvaro | 0:df6fdd9b99f0 | 40 | // setup IP of destination (computer): |
mbedalvaro | 0:df6fdd9b99f0 | 41 | #define DEFAULT_SEND_PORT 12000 |
mbedalvaro | 0:df6fdd9b99f0 | 42 | //Host sendHost(IpAddr(10, 0, 0, 1), DEFAULT_SEND_PORT, NULL); // Send Port |
mbedalvaro | 0:df6fdd9b99f0 | 43 | // set IP of origin of UDP packets - the mbed acts as a SERVER here, and needs to bind the socket to the "client" (the computer) |
mbedalvaro | 0:df6fdd9b99f0 | 44 | #define DEFAULT_RECEIVE_PORT 57130 |
mbedalvaro | 0:df6fdd9b99f0 | 45 | //Host recHost(IpAddr(10, 0, 0, 1), DEFAULT_RECEIVE_PORT, NULL); // Receive Port |
mbedalvaro | 0:df6fdd9b99f0 | 46 | //UDPSocket udpRec,udpSend; |
mbedalvaro | 0:df6fdd9b99f0 | 47 | |
mbedalvaro | 0:df6fdd9b99f0 | 48 | |
mbedalvaro | 0:df6fdd9b99f0 | 49 | #define MAX_ADDRESS 2 |
mbedalvaro | 0:df6fdd9b99f0 | 50 | #define MAX_ARG 2 |
mbedalvaro | 0:df6fdd9b99f0 | 51 | |
mbedalvaro | 0:df6fdd9b99f0 | 52 | #define TYPE_INT 1 |
mbedalvaro | 0:df6fdd9b99f0 | 53 | #define TYPE_FLOAT 2 |
mbedalvaro | 0:df6fdd9b99f0 | 54 | #define TYPE_BLOB 3 |
mbedalvaro | 0:df6fdd9b99f0 | 55 | |
mbedalvaro | 0:df6fdd9b99f0 | 56 | |
mbedalvaro | 0:df6fdd9b99f0 | 57 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 58 | Container class for OSC messages (receiving or sending) |
mbedalvaro | 0:df6fdd9b99f0 | 59 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 60 | class OSCMessage{ |
mbedalvaro | 0:df6fdd9b99f0 | 61 | |
mbedalvaro | 0:df6fdd9b99f0 | 62 | private: |
mbedalvaro | 0:df6fdd9b99f0 | 63 | |
mbedalvaro | 0:df6fdd9b99f0 | 64 | char *address[MAX_ADDRESS]; // these are strings (as char*) |
mbedalvaro | 0:df6fdd9b99f0 | 65 | uint8_t addressNum; // current number of addresses in the message (ex: "/ard/test" --> the number of the addresses is 2) |
mbedalvaro | 0:df6fdd9b99f0 | 66 | |
mbedalvaro | 0:df6fdd9b99f0 | 67 | char typeTag[MAX_ARG]; |
mbedalvaro | 0:df6fdd9b99f0 | 68 | |
mbedalvaro | 0:df6fdd9b99f0 | 69 | void *arg[MAX_ARG]; |
mbedalvaro | 0:df6fdd9b99f0 | 70 | uint8_t argNum; |
mbedalvaro | 0:df6fdd9b99f0 | 71 | |
mbedalvaro | 0:df6fdd9b99f0 | 72 | // Information about the connection: |
mbedalvaro | 0:df6fdd9b99f0 | 73 | //uint8_t ip[4]; |
mbedalvaro | 0:df6fdd9b99f0 | 74 | //uint16_t port; |
mbedalvaro | 0:df6fdd9b99f0 | 75 | Host host; |
mbedalvaro | 0:df6fdd9b99f0 | 76 | |
mbedalvaro | 0:df6fdd9b99f0 | 77 | public: |
mbedalvaro | 0:df6fdd9b99f0 | 78 | |
mbedalvaro | 0:df6fdd9b99f0 | 79 | OSCMessage(); |
mbedalvaro | 0:df6fdd9b99f0 | 80 | |
mbedalvaro | 0:df6fdd9b99f0 | 81 | const IpAddr& getIp(); // return IpAddr object |
mbedalvaro | 0:df6fdd9b99f0 | 82 | const int& getPort(); // return port |
mbedalvaro | 0:df6fdd9b99f0 | 83 | |
mbedalvaro | 0:df6fdd9b99f0 | 84 | //ex. address patern "/adr/test" |
mbedalvaro | 0:df6fdd9b99f0 | 85 | // address[2]={"/ard" , "/test"} |
mbedalvaro | 0:df6fdd9b99f0 | 86 | char *getAddress(uint8_t _index); //retturn address |
mbedalvaro | 0:df6fdd9b99f0 | 87 | char *getTopAddress(); //return address[0] :"/ard" |
mbedalvaro | 0:df6fdd9b99f0 | 88 | char *getSubAddress(); //return address[1] :"/test" |
mbedalvaro | 0:df6fdd9b99f0 | 89 | uint8_t getAddressNum(); //return 2 |
mbedalvaro | 0:df6fdd9b99f0 | 90 | |
mbedalvaro | 0:df6fdd9b99f0 | 91 | // 'i': long(int32_t) |
mbedalvaro | 0:df6fdd9b99f0 | 92 | // 'f': double |
mbedalvaro | 0:df6fdd9b99f0 | 93 | //ex 'if' 123 54.21 |
mbedalvaro | 0:df6fdd9b99f0 | 94 | char getTypeTag(uint8_t _index); //_index=0 ->'i' |
mbedalvaro | 0:df6fdd9b99f0 | 95 | //_index=1 ->'f' |
mbedalvaro | 0:df6fdd9b99f0 | 96 | |
mbedalvaro | 0:df6fdd9b99f0 | 97 | uint8_t getArgNum(); //return 2 |
mbedalvaro | 0:df6fdd9b99f0 | 98 | |
mbedalvaro | 0:df6fdd9b99f0 | 99 | int32_t getArgInt(uint8_t _index); //_index=0 -> 123 |
mbedalvaro | 0:df6fdd9b99f0 | 100 | double getArgFloat(uint8_t _index); //_index=1 -> 54.21 |
mbedalvaro | 0:df6fdd9b99f0 | 101 | |
mbedalvaro | 0:df6fdd9b99f0 | 102 | |
mbedalvaro | 0:df6fdd9b99f0 | 103 | void setTopAddress(char *_address); //set address[0] |
mbedalvaro | 0:df6fdd9b99f0 | 104 | void setSubAddress(char *_address); //set address[1] |
mbedalvaro | 0:df6fdd9b99f0 | 105 | void setAddress(char *_topAddress, |
mbedalvaro | 0:df6fdd9b99f0 | 106 | char *_subAddress); |
mbedalvaro | 0:df6fdd9b99f0 | 107 | void setAddress(uint8_t _index, //set 0,address[0] |
mbedalvaro | 0:df6fdd9b99f0 | 108 | char *_address); |
mbedalvaro | 0:df6fdd9b99f0 | 109 | //set 1,address[1] |
mbedalvaro | 0:df6fdd9b99f0 | 110 | |
mbedalvaro | 0:df6fdd9b99f0 | 111 | void setIp( uint8_t *_ip ); //set ip |
mbedalvaro | 0:df6fdd9b99f0 | 112 | |
mbedalvaro | 0:df6fdd9b99f0 | 113 | void setIp(uint8_t _ip1, //set(192, |
mbedalvaro | 0:df6fdd9b99f0 | 114 | uint8_t _ip2, // 168, |
mbedalvaro | 0:df6fdd9b99f0 | 115 | uint8_t _ip3, // 0, |
mbedalvaro | 0:df6fdd9b99f0 | 116 | uint8_t _ip4); // 100) |
mbedalvaro | 0:df6fdd9b99f0 | 117 | |
mbedalvaro | 0:df6fdd9b99f0 | 118 | void setPort( uint16_t _port ); |
mbedalvaro | 0:df6fdd9b99f0 | 119 | |
mbedalvaro | 0:df6fdd9b99f0 | 120 | //ex. long v1=100 |
mbedalvaro | 0:df6fdd9b99f0 | 121 | // double v2=123.21 |
mbedalvaro | 0:df6fdd9b99f0 | 122 | void setArgs( char *types , ... ); //set ("if",&v1,&v2) |
mbedalvaro | 0:df6fdd9b99f0 | 123 | void clearArgs(); // clear arguments |
mbedalvaro | 0:df6fdd9b99f0 | 124 | |
mbedalvaro | 0:df6fdd9b99f0 | 125 | friend class OSCClass; |
mbedalvaro | 0:df6fdd9b99f0 | 126 | |
mbedalvaro | 0:df6fdd9b99f0 | 127 | }; |
mbedalvaro | 0:df6fdd9b99f0 | 128 | |
mbedalvaro | 0:df6fdd9b99f0 | 129 | |
mbedalvaro | 0:df6fdd9b99f0 | 130 | |
mbedalvaro | 0:df6fdd9b99f0 | 131 | /* ==================================== OSCClass for sending and receiving OSC messages using UDP protocol ===================================== */ |
mbedalvaro | 0:df6fdd9b99f0 | 132 | |
mbedalvaro | 0:df6fdd9b99f0 | 133 | #include "UDPSocket.h" |
mbedalvaro | 0:df6fdd9b99f0 | 134 | |
mbedalvaro | 0:df6fdd9b99f0 | 135 | class OSCClass { |
mbedalvaro | 0:df6fdd9b99f0 | 136 | |
mbedalvaro | 0:df6fdd9b99f0 | 137 | private: |
mbedalvaro | 0:df6fdd9b99f0 | 138 | |
mbedalvaro | 0:df6fdd9b99f0 | 139 | UDPSocket udpRec,udpSend; |
mbedalvaro | 0:df6fdd9b99f0 | 140 | char rcvBuff[256]; // raw buffer for UDP packets (udpRec.recvfrom( buf, 256, &host ) )) |
mbedalvaro | 0:df6fdd9b99f0 | 141 | int buflength; |
mbedalvaro | 0:df6fdd9b99f0 | 142 | |
mbedalvaro | 0:df6fdd9b99f0 | 143 | OSCMessage *receiverMessage; |
mbedalvaro | 0:df6fdd9b99f0 | 144 | OSCMessage *sendContainer; |
mbedalvaro | 0:df6fdd9b99f0 | 145 | |
mbedalvaro | 0:df6fdd9b99f0 | 146 | char tempAddress[MAX_ADDRESS][16]; |
mbedalvaro | 0:df6fdd9b99f0 | 147 | uint8_t tempArg[MAX_ARG][4]; |
mbedalvaro | 0:df6fdd9b99f0 | 148 | |
mbedalvaro | 0:df6fdd9b99f0 | 149 | void decodePacket( OSCMessage *_mes); // makes OSC message from packet |
mbedalvaro | 0:df6fdd9b99f0 | 150 | |
mbedalvaro | 0:df6fdd9b99f0 | 151 | public: |
mbedalvaro | 0:df6fdd9b99f0 | 152 | |
mbedalvaro | 0:df6fdd9b99f0 | 153 | OSCClass(); |
mbedalvaro | 0:df6fdd9b99f0 | 154 | OSCClass(OSCMessage *_mes); // set the receiver message container |
mbedalvaro | 0:df6fdd9b99f0 | 155 | void onUDPSocketEvent(UDPSocketEvent e); |
mbedalvaro | 0:df6fdd9b99f0 | 156 | |
mbedalvaro | 0:df6fdd9b99f0 | 157 | //init osc |
mbedalvaro | 0:df6fdd9b99f0 | 158 | void begin(void (*fp)(UDPSocketEvent)); |
mbedalvaro | 0:df6fdd9b99f0 | 159 | void begin(uint16_t _recievePort, void (*fp)(UDPSocketEvent)); |
mbedalvaro | 0:df6fdd9b99f0 | 160 | void stop(); |
mbedalvaro | 0:df6fdd9b99f0 | 161 | |
mbedalvaro | 0:df6fdd9b99f0 | 162 | //new OSC data in the receiver message container: |
mbedalvaro | 0:df6fdd9b99f0 | 163 | bool newMessage; |
mbedalvaro | 0:df6fdd9b99f0 | 164 | |
mbedalvaro | 0:df6fdd9b99f0 | 165 | void setReceiveMessage( OSCMessage *_mes ); //set receive OSCmessage container (note: the message has a "host" object from which we get the upd packets) |
mbedalvaro | 0:df6fdd9b99f0 | 166 | OSCMessage *getMessage(); //return received OSCmessage |
mbedalvaro | 0:df6fdd9b99f0 | 167 | |
mbedalvaro | 0:df6fdd9b99f0 | 168 | //buffer clear |
mbedalvaro | 0:df6fdd9b99f0 | 169 | //void flush(); |
mbedalvaro | 0:df6fdd9b99f0 | 170 | |
mbedalvaro | 0:df6fdd9b99f0 | 171 | //OSC send |
mbedalvaro | 0:df6fdd9b99f0 | 172 | void sendOsc( OSCMessage *_mes ); //set&send OSCmessage (note: it will be sent to the host defined in the message container) |
mbedalvaro | 0:df6fdd9b99f0 | 173 | |
mbedalvaro | 0:df6fdd9b99f0 | 174 | // AND THIS IS BAD, need a better function: |
mbedalvaro | 0:df6fdd9b99f0 | 175 | void sendOscBlob( uint8_t * myblob, int sizeblob, OSCMessage *_mes ); |
mbedalvaro | 0:df6fdd9b99f0 | 176 | void sendOscString( uint8_t * myblob, int sizeblo, OSCMessage *_mesb ); |
mbedalvaro | 0:df6fdd9b99f0 | 177 | }; |
mbedalvaro | 0:df6fdd9b99f0 | 178 | |
mbedalvaro | 0:df6fdd9b99f0 | 179 | #endif |