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