Skip to content

Commit 5368372

Browse files
committed
Fixed example in README
1 parent 8416466 commit 5368372

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

README.md

+21-6
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,29 @@ Main features:
5050
Tiny SLIP Library is very easy to use:
5151
```.cpp
5252
SLIP::SLIP proto;
53-
SLIP::Packet<256> packet;
53+
54+
void onReceive(SLIP::IPacket &pkt)
55+
{
56+
// Process incoming packets here
57+
58+
/* Send message back */
59+
proto.write( pkt );
60+
}
61+
62+
...
63+
...
64+
proto.setReceiveCallback( onReceive );
65+
proto.begin();
66+
...
5467
...
5568
if (Serial.available()) {
56-
int len = proto.read( packet );
57-
if (len > 0) {
58-
/* Send message back */
59-
proto.write( packet );
60-
}
69+
uint8_t byte = Serial.read();
70+
proto.run_rx(&byte, 1);
71+
}
72+
uint8_t byte;
73+
if ( proto.run_tx(&byte, 1) == 1)
74+
{
75+
Serial.write( byte );
6176
}
6277
```
6378

0 commit comments

Comments
 (0)