Skip to content

Commit

Permalink
add method to subscribe with options
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansen4857 committed Nov 15, 2023
1 parent 01cd8a5 commit a908b30
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion example/nt4_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ void main() async {
client.addSample(examplePub, 123456);

// Subscribe to a topic
NT4Subscription exampleSub = client.subscribe('/SmartDashboard/Example');
NT4Subscription exampleSub =
client.subscribePeriodic('/SmartDashboard/Example');

// Recieve data from subscription with a callback or stream
exampleSub.listen((data) => print('Recieved data from callback: $data'));
Expand Down
15 changes: 13 additions & 2 deletions lib/src/nt4_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,22 @@ class NT4Client {
///
/// [period] represents how often the server should send updated data
/// for this topic, in seconds
NT4Subscription subscribe(String topic, [double period = 0.1]) {
NT4Subscription subscribePeriodic(String topic, [double period = 0.1]) {
return subscribe(
topic, NT4SubscriptionOptions(periodicRateSeconds: period));
}

/// Subscribe to a topic with the name [topic] and a period of [period]
///
/// [topic] should be the full path to the topic you wish to subscribe to
/// Example: '/SmartDashboard/SomeTopic'
///
/// [options] The subscription options
NT4Subscription subscribe(String topic, NT4SubscriptionOptions options) {
NT4Subscription newSub = NT4Subscription(
topic: topic,
uid: getNewSubUID(),
options: NT4SubscriptionOptions(periodicRateSeconds: period),
options: options,
);

_subscriptions[newSub.uid] = newSub;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: nt4
description: Dart implementation of the WPILib NT4 protocol
version: 1.1.1
version: 1.2.0
repository: https://github.com/mjansen4857/nt4

environment:
Expand Down

0 comments on commit a908b30

Please sign in to comment.