Skip to content

Commit

Permalink
feat(misc): Added tuning utility
Browse files Browse the repository at this point in the history
  • Loading branch information
Gitter499 committed Jan 19, 2024
1 parent 96eedb9 commit 1849ccf
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
## WIP
## WIP
63 changes: 63 additions & 0 deletions src/main/java/org/robolancers321/util/TunableSet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* (C) Robolancers 2024 */
package org.robolancers321.util;

import static edu.wpi.first.wpilibj.smartdashboard.SmartDashboard.*;

public class TunableSet {
public static class Tunable {
public static int tune(String key, int defaultValue) {
var entry = getEntry(key);
if (!entry.exists()) putNumber(key, defaultValue);
return (int) entry.getInteger(defaultValue);
}

public static double tune(String key, double defaultValue) {
var entry = getEntry(key);
if (!entry.exists()) putNumber(key, defaultValue);
return entry.getDouble(defaultValue);
}

public static String tune(String key, String defaultValue) {
var entry = getEntry(key);
if (!entry.exists()) putString(key, defaultValue);
return entry.getString(defaultValue);
}

public static boolean tune(String key, boolean defaultValue) {
var entry = getEntry(key);
if (!entry.exists()) putBoolean(key, defaultValue);
return entry.getBoolean(defaultValue);
}
}

private String prefix;

public TunableSet(String prefix) {
this.prefix = prefix;
}

// !TODO Add prefixes
public int tune(String key, int defaultValue) {
var entry = getEntry(prefix + " " + key);
if (!entry.exists()) putNumber(key, defaultValue);
return (int) entry.getInteger(defaultValue);
}

public double tune(String key, double defaultValue) {
var entry = getEntry(prefix + " " + key);
if (!entry.exists()) putNumber(key, defaultValue);
return entry.getDouble(defaultValue);
}

public String tune(String key, String defaultValue) {
var entry = getEntry(prefix + " " + key);
if (!entry.exists()) putString(key, defaultValue);
return entry.getString(defaultValue);
}

public boolean tune(String key, boolean defaultValue) {
var entry = getEntry(prefix + " " + key);
if (!entry.exists()) putBoolean(key, defaultValue);
return entry.getBoolean(defaultValue);
}
}

0 comments on commit 1849ccf

Please sign in to comment.