Skip to content

Commit

Permalink
Improved backwards compatibility with Shuffleboard API
Browse files Browse the repository at this point in the history
* Check for elastic and shuffleboard widget names
* Check for elastic and shuffleboard widget properties
  • Loading branch information
Gold872 committed Nov 12, 2023
1 parent 4362f65 commit 8893291
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ class DraggableNT4WidgetContainer extends DraggableWidgetContainer {
jsonData: widgetProperties,
);
case 'Text Display':
case 'Text View':
return TextDisplay.fromJson(
key: UniqueKey(),
jsonData: widgetProperties,
Expand All @@ -255,16 +256,19 @@ class DraggableNT4WidgetContainer extends DraggableWidgetContainer {
jsonData: widgetProperties,
);
case 'PowerDistribution':
case 'PDP':
return PowerDistribution.fromJson(
key: UniqueKey(),
jsonData: widgetProperties,
);
case 'PIDController':
case 'PID Controller':
return PIDControllerWidget.fromJson(
key: UniqueKey(),
jsonData: widgetProperties,
);
case 'DifferentialDrive':
case 'Differential Drivebase':
return DifferentialDrive.fromJson(
key: UniqueKey(),
jsonData: widgetProperties,
Expand Down
46 changes: 39 additions & 7 deletions lib/widgets/nt4_widgets/single_topic/boolean_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class BooleanBox extends StatelessWidget with NT4Widget {
@override
String type = 'Boolean Box';

Color trueColor;
Color falseColor;
late Color trueColor;
late Color falseColor;

BooleanBox({
super.key,
Expand All @@ -26,14 +26,46 @@ class BooleanBox extends StatelessWidget with NT4Widget {
init();
}

BooleanBox.fromJson({super.key, required Map<String, dynamic> jsonData})
: trueColor =
Color(tryCast(jsonData['true_color']) ?? Colors.green.value),
falseColor =
Color(tryCast(jsonData['false_color']) ?? Colors.red.value) {
BooleanBox.fromJson({super.key, required Map<String, dynamic> jsonData}) {
topic = tryCast(jsonData['topic']) ?? '';
period = tryCast(jsonData['period']) ?? Globals.defaultPeriod;

int? trueColorValue =
tryCast(jsonData['true_color']) ?? tryCast(jsonData['colorWhenTrue']);
int? falseColorValue =
tryCast(jsonData['false_color']) ?? tryCast(jsonData['colorWhenFalse']);

if (trueColorValue == null) {
String? hexString = tryCast(jsonData['colorWhenTrue']);

if (hexString != null) {
hexString = hexString.toUpperCase().replaceAll('#', '');

if (hexString.length == 6) {
hexString = 'FF$hexString';
}

trueColorValue = int.tryParse(hexString, radix: 16);
}
}

if (falseColorValue == null) {
String? hexString = tryCast(jsonData['colorWhenFalse']);

if (hexString != null) {
hexString = hexString.toUpperCase().replaceAll('#', '');

if (hexString.length == 6) {
hexString = 'FF$hexString';
}

falseColorValue = int.tryParse(hexString, radix: 16);
}
}

trueColor = Color(trueColorValue ?? Colors.green.value);
falseColor = Color(falseColorValue ?? Colors.red.value);

init();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/nt4_widgets/single_topic/graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class GraphWidget extends StatelessWidget with NT4Widget {
GraphWidget.fromJson({super.key, required Map<String, dynamic> jsonData}) {
topic = tryCast(jsonData['topic']) ?? '';
period = tryCast(jsonData['period']) ?? Globals.defaultPeriod;
timeDisplayed = tryCast(jsonData['time_displayed']) ?? 5.0;
timeDisplayed = tryCast(jsonData['time_displayed']) ?? tryCast(jsonData['visibleTime']) ?? 5.0;
minValue = tryCast(jsonData['min_value']);
maxValue = tryCast(jsonData['max_value']);
mainColor = Color(tryCast(jsonData['color']) ?? Colors.cyan.value);
Expand Down
19 changes: 12 additions & 7 deletions lib/widgets/nt4_widgets/single_topic/number_slider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class NumberSlider extends StatelessWidget with NT4Widget {
@override
final String type = 'Number Slider';

double minValue;
double maxValue;
int divisions;
late double minValue;
late double maxValue;
late int divisions;

double _currentValue = 0.0;
double _previousValue = 0.0;
Expand All @@ -33,13 +33,18 @@ class NumberSlider extends StatelessWidget with NT4Widget {
init();
}

NumberSlider.fromJson({super.key, required Map<String, dynamic> jsonData})
: minValue = tryCast(jsonData['min_value']) ?? -1.0,
maxValue = tryCast(jsonData['max_value']) ?? 1.0,
divisions = tryCast(jsonData['divisions']) ?? 5 {
NumberSlider.fromJson({super.key, required Map<String, dynamic> jsonData}) {
topic = tryCast(jsonData['topic']) ?? '';
period = tryCast(jsonData['period']) ?? Globals.defaultPeriod;

minValue =
tryCast(jsonData['min_value']) ?? tryCast(jsonData['min']) ?? -1.0;
maxValue =
tryCast(jsonData['max_value']) ?? tryCast(jsonData['max']) ?? 1.0;
divisions = tryCast(jsonData['divisions']) ??
tryCast(jsonData['numOfTickMarks']) ??
5;

init();
}

Expand Down
8 changes: 5 additions & 3 deletions lib/widgets/nt4_widgets/single_topic/voltage_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ class VoltageView extends StatelessWidget with NT4Widget {
topic = tryCast(jsonData['topic']) ?? '';
period = tryCast(jsonData['period']) ?? Globals.defaultPeriod;

minValue = tryCast(jsonData['min_value']) ?? 4;
maxValue = tryCast(jsonData['max_value']) ?? 13.0;
divisions = tryCast(jsonData['divisions']);
minValue = tryCast(jsonData['min_value']) ?? tryCast(jsonData['min']) ?? 4;
maxValue =
tryCast(jsonData['max_value']) ?? tryCast(jsonData['max']) ?? 13.0;
divisions =
tryCast(jsonData['divisions']) ?? tryCast(jsonData['numOfTickMarks']);
inverted = tryCast(jsonData['inverted']) ?? false;
orientation = tryCast(jsonData['orientation']) ?? 'horizontal';

Expand Down

0 comments on commit 8893291

Please sign in to comment.