Skip to content

Commit 4ce8361

Browse files
author
globi
committed
Adding clean example code
1 parent eed6a69 commit 4ce8361

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

README.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,19 @@ TinyFrame is a simple library for building and parsing data frames to be sent ov
1212
import 'dart:typed_data';
1313
import 'package:tiny_frame/tiny_frame.dart';
1414
15-
void write(Uint8List data) => print('write: $data');
1615
void main() {
17-
const mainID = 1;
18-
// create a TinyFrame instance as master (peer id set)
19-
// the write method has to be implemented, tinyframe will call it
20-
// to send the data after building the frame
21-
final tf = TinyFrame(write);
16+
const typeID = 1;
17+
// create a TinyFrame instance with a write function
18+
// TF_WriteImpl in C Library
19+
final tf = TinyFrame((Uint8List data) => print('write: $data'));
2220
// some optional settings
2321
tf.cksumType = 'xor';
2422
// generate a listener for the id 1
25-
tf.addIdListener(mainID, (Uint8List frame) => print('main: $frame'));
23+
tf.addTypeListener(typeID, (_, TF_Msg msg) => print('main: $msg'));
2624
// if no listener is found for the id, this listener will be called
27-
tf.addFallbackListener((Uint8List frame) => print('fallback: $frame'));
25+
tf.addFallbackListener((_, TF_Msg msg) => print('fallback: $msg'));
2826
// send to slave on id 1
29-
tf.send(mainID, Uint8List.fromList('abcde'.codeUnits));
27+
tf.send(typeID, Uint8List.fromList('abcde'.codeUnits));
3028
}
3129
```
3230

example/example.dart

+7-10
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@ import 'dart:typed_data';
22

33
import 'package:tiny_frame/tiny_frame.dart';
44

5-
void write(Uint8List data) => print('write: $data');
65
void main() {
7-
const mainID = 1;
8-
// create a TinyFrame instance as master (peer id set)
9-
// the write method has to be implemented, tinyframe will call it
10-
// to send the data after building the frame
11-
final tf = TinyFrame(write);
6+
const typeID = 1;
7+
// create a TinyFrame instance with a write function
8+
// TF_WriteImpl in C Library
9+
final tf = TinyFrame((Uint8List data) => print('write: $data'));
1210
// some optional settings
1311
tf.cksumType = 'xor';
1412
// generate a listener for the id 1
15-
tf.addIdListener(mainID, (Uint8List frame) => print('main: $frame'));
13+
tf.addTypeListener(typeID, (_, TF_Msg msg) => print('main: $msg'));
1614
// if no listener is found for the id, this listener will be called
17-
tf.addFallbackListener((Uint8List frame) => print('fallback: $frame'));
18-
15+
tf.addFallbackListener((_, TF_Msg msg) => print('fallback: $msg'));
1916
// send to slave on id 1
20-
tf.send(mainID, Uint8List.fromList('abcde'.codeUnits));
17+
tf.send(typeID, Uint8List.fromList('abcde'.codeUnits));
2118
}

pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: tiny_frame
2-
description: TinyFrame port
3-
version: 1.0.0
2+
description: TinyFrame library port
3+
version: 1.0.1
44
repository: https://github.com/marcel-cd/tiny_frame
55

66
environment:

0 commit comments

Comments
 (0)