RobotCore 1.0
WPILib port to raspberry Pi
Loading...
Searching...
No Matches
TunableDouble.java
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5package org.wpilib.tunable;
6
7import java.util.function.DoubleConsumer;
8import java.util.function.DoubleSupplier;
9
11public abstract class TunableDouble extends TunableBase implements DoubleSupplier, DoubleConsumer {
17 public static TunableDouble create() {
18 return create(0.0);
19 }
20
27 public static TunableDouble create(double initialValue) {
28 return createConfig(initialValue, null);
29 }
30
40 public static TunableDouble create(DoubleSupplier getter, DoubleConsumer setter) {
41 return createConfig(getter, setter, null);
42 }
43
51 return createConfig(0.0, config);
52 }
53
61 public static TunableDouble createConfig(double initialValue, TunableConfig config) {
62 return new TunableDouble(config, true) {
63 @Override
64 public void set(double value) {
65 if (Double.compare(m_value, value) == 0) {
66 return;
67 }
68 m_value = value;
70 }
71
72 @Override
73 public double get() {
74 return m_value;
75 }
76
77 private double m_value = initialValue;
78 };
79 }
80
92 DoubleSupplier getter, DoubleConsumer setter, TunableConfig config) {
93 if (config == null) {
95 } else if (config.getPolling() == TunableConfig.Polling.DEFAULT) {
97 }
98 return new TunableDouble(config, true) {
99 @Override
100 public void set(double value) {
101 boolean changed = Double.compare(getter.getAsDouble(), value) != 0;
102 if (setter != null) {
103 setter.accept(value);
104 }
105 if (changed) {
106 markChanged();
107 }
108 }
109
110 @Override
111 public double get() {
112 return getter.getAsDouble();
113 }
114 };
115 }
116
122 protected TunableDouble(TunableConfig config) {
123 super(config);
124 }
125
133 super(config, supportsChangeNotification);
134 }
135
143 public abstract void set(double value);
144
152 public abstract double get();
153
154 @Override
155 public double getAsDouble() {
156 return get();
157 }
158
159 @Override
160 public void accept(double value) {
161 set(value);
162 }
163}
TunableBase(TunableConfig config)
TunableConfig withPolling(Polling polling)
static TunableConfig of(TunableOption... options)
static TunableDouble create(DoubleSupplier getter, DoubleConsumer setter)
static TunableDouble createConfig(DoubleSupplier getter, DoubleConsumer setter, TunableConfig config)
TunableDouble(TunableConfig config)
static TunableDouble create(double initialValue)
static TunableDouble create()
TunableDouble(TunableConfig config, boolean supportsChangeNotification)
static TunableDouble createConfig(TunableConfig config)
static TunableDouble createConfig(double initialValue, TunableConfig config)