Skip to content

Commit 6b5d644

Browse files
committed
docs: add APIs section to README
1 parent 6df5aab commit 6b5d644

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed

README.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,131 @@ You can see the debug log when you insert following line before include `Arduino
249249
#include <ArduinoOSC.h>
250250
```
251251

252+
## APIs
253+
254+
### Main Class (`OscWiFi` / `OscEther`)
255+
256+
#### Subscribing to OSC Messages
257+
258+
```cpp
259+
// Subscribe a value to an OSC message
260+
OscWiFi.subscribe(const uint16_t port, const String& addr, T& value);
261+
// Subscribe multiple values to an OSC message
262+
OscWiFi.subscribe(const uint16_t port, const String& addr, T1& v1, T2& v2, ...);
263+
// Subscribe a lambda to an OSC message with arguments
264+
OscWiFi.subscribe(const uint16_t port, const String& addr, [](T1 arg1, T2 arg2, ...) { ... });
265+
// Subscribe a lambda to an OSC message with OscMessage argument
266+
OscWiFi.subscribe(const uint16_t port, const String& addr, [](const OscMessage& msg) { ... });
267+
// Subscribe a function to an OSC message
268+
OscWiFi.subscribe(const uint16_t port, const String& addr, onOscReceived);
269+
```
270+
271+
#### Unsubscribing from OSC Messages
272+
273+
```cpp
274+
// Unsubscribe from a specific address on a port
275+
OscWiFi.unsubscribe(const uint16_t port, const String& addr);
276+
// Unsubscribe from all addresses on a port
277+
OscWiFi.unsubscribe(const uint16_t port);
278+
// Unsubscribe from all addresses on all ports
279+
OscWiFi.unsubscribe();
280+
```
281+
282+
#### Sending OSC Messages
283+
284+
```cpp
285+
// Send an OSC message with arguments
286+
OscWiFi.send(const String& ip, const uint16_t port, const String& addr, T1 arg1, T2 arg2, ...);
287+
```
288+
289+
#### Publishing OSC Messages
290+
291+
```cpp
292+
// Publish a value periodically
293+
OscWiFi.publish(const String& ip, const uint16_t port, const String& addr, T& value)
294+
->setFrameRate(float fps);
295+
// Publish multiple values periodically
296+
OscWiFi.publish(const String& ip, const uint16_t port, const String& addr, T1& v1, T2& v2, ...)
297+
->setIntervalMsec(float ms);
298+
// Publish function results periodically
299+
OscWiFi.publish(const String& ip, const uint16_t port, const String& addr, &func1, &func2)
300+
->setIntervalSec(float sec);
301+
```
302+
303+
#### OSC Bundle Support
304+
305+
```cpp
306+
// Create and send OSC bundles
307+
OscWiFi.begin_bundle(const TimeTag& tt = TimeTag::immediate());
308+
OscWiFi.add_bundle(const String& addr, T1 arg1, T2 arg2, ...);
309+
OscWiFi.end_bundle();
310+
OscWiFi.send_bundle(const String& ip, const uint16_t port);
311+
```
312+
313+
#### Update Functions
314+
315+
```cpp
316+
// Parse incoming OSC messages (server)
317+
OscWiFi.parse();
318+
// Parse incoming OSC messages and publish outgoing messages (server + client)
319+
OscWiFi.update();
320+
// Send published OSC messages (client)
321+
OscWiFi.post();
322+
```
323+
324+
### OscMessage
325+
326+
#### Argument Getters
327+
328+
```cpp
329+
msg.arg<T>(const uint8_t index); // Get argument as type T
330+
msg.getArgAsInt32(const size_t i);
331+
msg.getArgAsInt64(const size_t i);
332+
msg.getArgAsFloat(const size_t i);
333+
msg.getArgAsDouble(const size_t i);
334+
msg.getArgAsString(const size_t i);
335+
msg.getArgAsBlob(const size_t i);
336+
msg.getArgAsBool(const size_t i);
337+
```
338+
339+
#### Type Checkers
340+
341+
```cpp
342+
msg.isBool(const size_t i);
343+
msg.isInt32(const size_t i);
344+
msg.isInt64(const size_t i);
345+
msg.isFloat(const size_t i);
346+
msg.isDouble(const size_t i);
347+
msg.isStr(const size_t i);
348+
msg.isBlob(const size_t i);
349+
```
350+
351+
#### Message Information
352+
353+
```cpp
354+
msg.address(); // Get OSC address
355+
msg.size(); // Get number of arguments
356+
msg.typeTags(); // Get type tag string
357+
msg.remoteIP(); // Get sender's IP address
358+
msg.remotePort(); // Get sender's port
359+
msg.match(const String& pattern); // Check if address matches pattern
360+
```
361+
362+
### Manual Packet Handling (for boards with limited memory)
363+
364+
```cpp
365+
// Server for receiving
366+
OscEtherServer server(recv_port);
367+
if (server.parse()) {
368+
const OscMessage* msg = server.message();
369+
// Process message...
370+
}
371+
372+
// Client for sending
373+
OscEtherClient client;
374+
client.send(host, send_port, "/addr", arg1, arg2);
375+
```
376+
252377
## Dependent Libraries
253378
254379
- [ArxTypeTraits](https://github.com/hideakitai/ArxTypeTraits)

0 commit comments

Comments
 (0)