Open pixelpusher opened 5 years ago
I'm stumped on this, so I'm calling it an issue for now - I can't figure out why this is the case, though. I'm trying to read SLIPSerial from across different loops so I can multitask and do other things (like send responses) but altering the simple receive example (which works fine) doesn't work. this produces decoding errors in the OSC bundle and I'm unsure why, since the logic is the same:
/*
* Set the LED according to incoming OSC control
*/
#include <OSCBundle.h>
#include <OSCBoards.h>
#ifdef BOARD_HAS_USB_SERIAL
#include <SLIPEncodedUSBSerial.h>
SLIPEncodedUSBSerial SLIPSerial(thisBoardsSerialUSB);
#else
#include <SLIPEncodedSerial.h>
SLIPEncodedSerial SLIPSerial(Serial1);
#endif
void LEDcontrol(OSCMessage &msg)
{
if (msg.isInt(0))
{
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, (msg.getInt(0) > 0) ? HIGH : LOW);
}
else if (msg.isString(0))
{
int length = msg.getDataLength(0);
if (length < 5)
{
char str[length];
msg.getString(0, str, length);
if ((strcmp("on", str) == 0) || (strcmp("On", str) == 0))
{
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
}
else if ((strcmp("Of", str) == 0) || (strcmp("off", str) == 0))
{
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
}
}
}
}
void setup()
{
SLIPSerial.begin(38400); // set this as high as you can reliably run on your platform
}
OSCBundle bundleIN;
//reads and dispatches the incoming message
void loop()
{
int size;
if (!SLIPSerial.endofPacket())
{
if ((size = SLIPSerial.available()) > 0)
{
while (size--)
bundleIN.fill(SLIPSerial.read());
}
}
else
{
if (!bundleIN.hasError())
{
bundleIN.dispatch("/m", LEDcontrol);
}
bundleIN.empty();
}
}
Hi, I'm trying to do something simple. I'd like to constantly send OSC messages over serial, and also sometimes receive them. I've found that I can send messages constantly (as fast as possible) as long as I don't also receive them. The Ardruino code below illustrates this problem. It will only send back a response via serial when a response is received via serial, when it should be constantly sending messages: