Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed gyro widget to work with doubles #147

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions lib/widgets/nt_widgets/multi-topic/gyro.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import 'package:elastic_dashboard/widgets/nt_widgets/single_topic/graph.dart';
import 'package:elastic_dashboard/widgets/nt_widgets/single_topic/match_time.dart';
import 'package:elastic_dashboard/widgets/nt_widgets/single_topic/number_bar.dart';
import 'package:elastic_dashboard/widgets/nt_widgets/single_topic/number_slider.dart';
import 'package:elastic_dashboard/widgets/nt_widgets/single_topic/radial_gauge.dart';
import 'package:elastic_dashboard/widgets/nt_widgets/single_topic/text_display.dart';
import 'package:elastic_dashboard/widgets/nt_widgets/single_topic/voltage_view.dart';
import 'package:flutter/material.dart';

import 'package:dot_cast/dot_cast.dart';
@@ -15,9 +22,10 @@ class GyroModel extends MultiTopicNTWidgetModel {
String get valueTopic => '$topic/Value';

late NT4Subscription valueSubscription;
late NT4Subscription doubleSubscription;

@override
List<NT4Subscription> get subscriptions => [valueSubscription];
List<NT4Subscription> get subscriptions => [valueSubscription, doubleSubscription];

bool _counterClockwisePositive = false;

@@ -50,6 +58,25 @@ class GyroModel extends MultiTopicNTWidgetModel {
@override
void initializeSubscriptions() {
valueSubscription = ntConnection.subscribe(valueTopic, super.period);
doubleSubscription = ntConnection.subscribe(topic, super.period);
}

@override
List<String> getAvailableDisplayTypes() {
if (doubleSubscription.value != null) {
return [
TextDisplay.widgetType,
NumberBar.widgetType,
NumberSlider.widgetType,
VoltageView.widgetType,
RadialGauge.widgetType,
Gyro.widgetType,
GraphWidget.widgetType,
MatchTimeWidget.widgetType,
];
}

return [type];
}

@override
@@ -93,10 +120,10 @@ class Gyro extends NTWidget {
Widget build(BuildContext context) {
GyroModel model = cast(context.watch<NTWidgetModel>());

return ValueListenableBuilder(
valueListenable: model.valueSubscription,
builder: (context, data, child) {
double value = tryCast(data) ?? 0.0;
return ListenableBuilder(
listenable: Listenable.merge(model.subscriptions),
builder: (context, child) {
double value = tryCast(model.valueSubscription.value) ?? tryCast(model.doubleSubscription.value) ?? 0.0;

if (model.counterClockwisePositive) {
value *= -1;
2 changes: 2 additions & 0 deletions lib/widgets/nt_widgets/nt_widget.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:elastic_dashboard/widgets/nt_widgets/multi-topic/gyro.dart';
import 'package:flutter/material.dart';

import 'package:dot_cast/dot_cast.dart';
@@ -186,6 +187,7 @@ class SingleTopicNTWidgetModel extends NTWidgetModel {
NumberSlider.widgetType,
VoltageView.widgetType,
RadialGauge.widgetType,
Gyro.widgetType,
GraphWidget.widgetType,
MatchTimeWidget.widgetType,
];