RobotCore 1.0
WPILib port to raspberry Pi
Loading...
Searching...
No Matches
TunableBoolean.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.BooleanSupplier;
8import org.wpilib.util.function.BooleanConsumer;
9
11public abstract class TunableBoolean extends TunableBase
12 implements BooleanSupplier, BooleanConsumer {
18 public static TunableBoolean create() {
19 return create(false);
20 }
21
28 public static TunableBoolean create(boolean initialValue) {
29 return createConfig(initialValue, null);
30 }
31
41 public static TunableBoolean create(BooleanSupplier getter, BooleanConsumer setter) {
42 return createConfig(getter, setter, null);
43 }
44
52 return createConfig(false, config);
53 }
54
62 public static TunableBoolean createConfig(boolean initialValue, TunableConfig config) {
63 return new TunableBoolean(config, true) {
64 @Override
65 public void set(boolean value) {
66 if (m_value == value) {
67 return;
68 }
69 m_value = value;
71 }
72
73 @Override
74 public boolean get() {
75 return m_value;
76 }
77
78 private boolean m_value = initialValue;
79 };
80 }
81
93 BooleanSupplier getter, BooleanConsumer setter, TunableConfig config) {
94 if (config == null) {
96 } else if (config.getPolling() == TunableConfig.Polling.DEFAULT) {
98 }
99 return new TunableBoolean(config, true) {
100 @Override
101 public void set(boolean value) {
102 boolean changed = getter.getAsBoolean() != value;
103 if (setter != null) {
104 setter.accept(value);
105 }
106 if (changed) {
107 markChanged();
108 }
109 }
110
111 @Override
112 public boolean get() {
113 return getter.getAsBoolean();
114 }
115 };
116 }
117
123 protected TunableBoolean(TunableConfig config) {
124 super(config);
125 }
126
134 super(config, supportsChangeNotification);
135 }
136
144 public abstract void set(boolean value);
145
153 public abstract boolean get();
154
155 @Override
156 public boolean getAsBoolean() {
157 return get();
158 }
159
160 @Override
161 public void accept(boolean value) {
162 set(value);
163 }
164}
TunableBase(TunableConfig config)
TunableBoolean(TunableConfig config, boolean supportsChangeNotification)
static TunableBoolean createConfig(boolean initialValue, TunableConfig config)
static TunableBoolean create(BooleanSupplier getter, BooleanConsumer setter)
static TunableBoolean createConfig(TunableConfig config)
static TunableBoolean create(boolean initialValue)
static TunableBoolean createConfig(BooleanSupplier getter, BooleanConsumer setter, TunableConfig config)
TunableConfig withPolling(Polling polling)
static TunableConfig of(TunableOption... options)