|
6 yıl önce | |
---|---|---|
.. | ||
ArduinoOSC | 6 yıl önce | |
examples | 6 yıl önce | |
.gitignore | 6 yıl önce | |
ArduinoOSC.h | 6 yıl önce | |
LICENSE | 6 yıl önce | |
README.md | 6 yıl önce | |
library.json | 6 yıl önce | |
library.properties | 6 yıl önce |
OSC library for Arduino (ESP, Teensy, AVR, etc.)
ArduinoOSC is OSC Library for Arduino. OSC packet parsing is based on the oscpkt and optimized for Arduino.
Almost all APIs has been changed in v0.2.0
and got much simpler.
Please check below if you use previous versions.
This library is tested for following platforms and interfaces.
Please see examples for detals.
#include <ArduinoOSC.h>
OscWiFi osc;
void setup()
{
WiFi.begin(ssid, pwd);
WiFi.config(ip, gateway, subnet);
osc.begin(recv_port);
// add callbacks...
osc.subscribe("/lambda", [](OscMessage& m)
{
// do something with osc message
Serial.print(m.arg<int>(0)); Serial.print(" ");
Serial.print(m.arg<float>(1)); Serial.print(" ");
Serial.print(m.arg<String>(2)); Serial.println();
});
}
void loop()
{
osc.parse(); // should be called
osc.send(host, send_port, "/send", 1, 2.2F, 3.3, "string"); // send osc packet in one line
}
#include <ArduinoOSC.h>
OscSerial osc;
void setup()
{
Ethernet.begin(mac, ip);
osc.begin(recv_port);
// add callbacks...
}
void loop()
{
osc.parse(); // should be called
osc.send(host, send_port, "/send", 1, 2.2F, 3.3, "string");
}
#include <ArduinoOSC.h>
void setup()
{
Serial.begin(115200);
osc.attach(Serial);
// add callbacks...
}
void loop()
{
osc.parse(); // should be called
osc.send("/send", 1, 2.2F, 3.3, "string");
}
// TODO: TBD
// osc.subscribe("/int32", i);
// osc.subscribe("/float", f);
// osc.subscribe("/string", s);
// osc.subscribe("/blob", b);
osc.subscribe("/callback", onOscReceived); // old style (v0.1.x)
osc.subscribe("/lambda", [](OscMessage& m)
{
Serial.print("lambda : ");
Serial.print(m.ip()); Serial.print(" ");
Serial.print(m.port()); Serial.print(" ");
Serial.print(m.size()); Serial.print(" ");
Serial.print(m.address()); Serial.print(" ");
Serial.print(m.arg<int>(0)); Serial.print(" ");
Serial.print(m.arg<float>(1)); Serial.print(" ");
Serial.print(m.arg<String>(2)); Serial.println();
});
osc.subscribe("/wildcard/*/test", [](OscMessage& m)
{
Serial.print("wildcard : ");
Serial.print(m.ip()); Serial.print(" ");
Serial.print(m.port()); Serial.print(" ");
Serial.print(m.size()); Serial.print(" ");
Serial.print(m.address()); Serial.print(" ");
Serial.print(m.arg<int>(0)); Serial.println();
});
osc.subscribe("/need/reply", [](OscMessage& m)
{
Serial.println("/need/reply");
int i = 12;
float f = 34.56F;
double d = 78.987;
String s = "hello";
bool b = true;
osc.send(host, send_port, "/send", i, f, d, s, b);
});
// TODO: TBD
// osc.publish(host, send_port, "/value", value);
// osc.publish(host, send_port, "/millis", &millis);
examples/UnoMegaAvr/*
)m.arg<type>(index)
cannot be used in AVR.
Please use old APIs.
m.getArgAsInt32(0);
m.getArgAsFloat(1);
m.getArgAsString(2);
In sending osc, one-line feature is not available in AVR.
Please create OscMessage
and send(msg)
after that.
OscMessage msg(host, send_port, "/send"); // WiFi, Ethernet
OscMessage msg("/send"); // Serial
msg.push(i).push(f).push(s);
osc.send(msg);
// directly changes variable 'i' if message with "/int32" comes
int32_t i;
osc.subscribe("/int32", i);
// send "value" automatically
float value;
osc.publish(host, send_port, "/value", value);
// send the result of "millis()" automatically
osc.publish(host, send_port, "/millis", &millis);
int32_t i = m.arg<int32_t>(0);
float f = m.arg<float>(1);
String s = m.arg<String>(2);
// becomes
int32_t i = m.arg(0);
float f = m.arg(1);
String s = m.arg(2);
MIT