Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example_SLIP-OSC/bundleOUT? #14

Open
MaurinElectroTextile opened this issue Apr 30, 2018 · 4 comments
Open

example_SLIP-OSC/bundleOUT? #14

MaurinElectroTextile opened this issue Apr 30, 2018 · 4 comments

Comments

@MaurinElectroTextile
Copy link

MaurinElectroTextile commented Apr 30, 2018

Could you provide an example for SLIP/OSC bundleOUT?
Arduino to openFrameworks.

@bakercp
Copy link
Owner

bakercp commented Apr 30, 2018

Sorry, I don't understand.

@MaurinElectroTextile
Copy link
Author

MaurinElectroTextile commented Apr 30, 2018

In this example ; https://github.com/bakercp/ofxSerial/tree/master/example_SLIP-OSC
you show how to send SLIP-OSC bundle from openFrameworks to Arduino.
I'm trying to do the opposite : send SLIP-OSC bundle from Arduino to openFrameworks.
Could you provide an example for it?

@bakercp
Copy link
Owner

bakercp commented Apr 30, 2018

Can you provide a simple Arduino example demonstrating what you are trying to do?

@MaurinElectroTextile
Copy link
Author

Hear is an Arduino example of what I want to do.
The Openframeworks side will decode the incoming Bundle.


SLIPPacketSerial SLIPSerial;

void setup() {
  SLIPSerial.setPacketHandler(&onPacket);
  SLIPSerial.begin(BAUD_RATE);   // Arduino serial library ** 230400 ** extended with SLIP encoding
}

void loop() {
  serial.update();
}

void onPacket(const uint8_t* buffer, size_t size) {
  OSCBundle bundleIn;

  for (int i = 0; i < size; i++) {
    bundleIn.fill(buffer[i]);
  }
  if (!bundleIn.hasError()) {
    bundleIn.dispatch("/data", sendBundle);
  }
}

void sendBundle() {
  OSCBundle bundleOut;
  OSCMessage msg("/sensors");
  msg.add(analogRead(A0));
  msg.add(analogRead(A1));
  //...
  bundleOut.add(msg);
  SLIPSerial.beginPacket();    // Mark the OSC Packet SOF
  SLIPSerial.send(bundleOut);  // Send the bytes to the SLIP stream
  SLIPSerial.endPacket();      // Mark the OSC Packet EOF
  bundleOut.empty();           // Empty the bundle
  msg.empty();                 // Empty the message
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants