123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- #include <OSCMessage.h>
- #include <Ethernet.h>
- #include <EthernetUdp.h>
- #include <SPI.h>
- #include <OSCBoards.h>
- #ifdef BOARD_HAS_USB_SERIAL
- #include <SLIPEncodedUSBSerial.h>
- SLIPEncodedUSBSerial SLIPSerial( thisBoardsSerialUSB );
- #else
- #include <SLIPEncodedSerial.h>
- SLIPEncodedSerial SLIPSerial(Serial);
- #endif
- template <typename TYPE> void sendOSC(const char * adress, TYPE parameter) {
- OSCMessage OSCmsg(adress);
- OSCmsg.add(parameter);
- SLIPSerial.beginPacket();
-
- OSCmsg.send(SLIPSerial);
- SLIPSerial.endPacket();
-
- OSCmsg.empty();
- }
- void printTest(OSCMessage &msg) {
- sendOSC("/still", "up and running");
- }
- void moveTo_Stepper_OSC (OSCMessage &msg){
- long int distance = moveTo_Stepper(msg.getInt(0), msg.getInt(1));
- sendOSC("/stepper/distanceToGo",distance );
- }
- void move_Stepper_OSC (OSCMessage &msg){
- long int distance = move_Stepper(msg.getInt(0), msg.getInt(1));
- sendOSC("/stepper/distanceToGo",distance );
- }
- void maxSpeed_Stepper (OSCMessage &msg){
- long int max_speed = maxSpeed_Stepper(msg.getInt(0), msg.getInt(1));
- sendOSC("/stepper/maxSpeed",max_speed );
- }
- void acceleration_Stepper (OSCMessage &msg){
- long int acceleration = acceleration_Stepper(msg.getInt(0), msg.getInt(1));
- sendOSC("/stepper/acceleration",acceleration );
- }
- void currentPos_Stepper_OSC(OSCMessage &msg) {
- sendOSC("/stepper/currentPos", steppers[msg.getInt(0)].currentPosition());
- }
- void setup_OSC(){
-
- SLIPSerial.begin(115200);
- sendOSC("/ready", "to go");
-
- }
- void handleOSCIn() {
-
- OSCMessage OSCin;
- int size;
- if (SLIPSerial.available()) {
- while (!SLIPSerial.endofPacket())
- if ( (size = SLIPSerial.available()) > 0)
- {
- while (size--)
- OSCin.fill(SLIPSerial.read());
- }
- }
-
-
- if (!OSCin.hasError()) {
- OSCin.dispatch("/test", printTest);
- OSCin.dispatch("/stepper/currentPos", currentPos_Stepper_OSC);
- OSCin.dispatch("/stepper/moveTo", moveTo_Stepper_OSC);
- OSCin.dispatch("/stepper/move", move_Stepper_OSC);
- OSCin.dispatch("/stepper/maxSpeed", maxSpeed_Stepper);
- OSCin.dispatch("/stepper/acceleration", acceleration_Stepper);
- }
- }
|