RobotCore 1.0
WPILib port to raspberry Pi
Loading...
Searching...
No Matches
TunableFloat.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 org.wpilib.util.function.FloatConsumer;
8import org.wpilib.util.function.FloatSupplier;
9
11public abstract class TunableFloat extends TunableBase implements FloatSupplier, FloatConsumer {
17 public static TunableFloat create() {
18 return create(0.0f);
19 }
20
27 public static TunableFloat create(float initialValue) {
28 return createConfig(initialValue, null);
29 }
30
40 public static TunableFloat create(FloatSupplier getter, FloatConsumer setter) {
41 return createConfig(getter, setter, null);
42 }
43
50 public static TunableFloat createConfig(TunableConfig config) {
51 return createConfig(0.0f, config);
52 }
53
61 public static TunableFloat createConfig(float initialValue, TunableConfig config) {
62 return new TunableFloat(config, true) {
63 @Override
64 public void set(float value) {
65 if (Float.compare(m_value, value) == 0) {
66 return;
67 }
68 m_value = value;
70 }
71
72 @Override
73 public float get() {
74 return m_value;
75 }
76
77 private float m_value = initialValue;
78 };
79 }
80
92 FloatSupplier getter, FloatConsumer setter, TunableConfig config) {
93 if (config == null) {
95 } else if (config.getPolling() == TunableConfig.Polling.DEFAULT) {
97 }
98 return new TunableFloat(config, true) {
99 @Override
100 public void set(float value) {
101 boolean changed = Float.compare(getter.getAsFloat(), value) != 0;
102 if (setter != null) {
103 setter.accept(value);
104 }
105 if (changed) {
106 markChanged();
107 }
108 }
109
110 @Override
111 public float get() {
112 return getter.getAsFloat();
113 }
114 };
115 }
116
122 protected TunableFloat(TunableConfig config) {
123 super(config);
124 }
125
133 super(config, supportsChangeNotification);
134 }
135
143 public abstract void set(float value);
144
152 public abstract float get();
153
154 @Override
155 public float getAsFloat() {
156 return get();
157 }
158
159 @Override
160 public void accept(float value) {
161 set(value);
162 }
163}
TunableBase(TunableConfig config)
TunableConfig withPolling(Polling polling)
static TunableConfig of(TunableOption... options)
static TunableFloat create(float initialValue)
TunableFloat(TunableConfig config)
static TunableFloat createConfig(float initialValue, TunableConfig config)
static TunableFloat createConfig(TunableConfig config)
static TunableFloat create()
static TunableFloat create(FloatSupplier getter, FloatConsumer setter)
static TunableFloat createConfig(FloatSupplier getter, FloatConsumer setter, TunableConfig config)
TunableFloat(TunableConfig config, boolean supportsChangeNotification)