Skip to content

Commit

Permalink
improve default annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Oblarg committed Feb 28, 2019
1 parent ab5491e commit 597b17d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class Robot extends TimedRobot {
private LoggedCommand command10Seconds = new LoggedCommand(10);


@Log.DifferentialDrive
@Log
private static DifferentialDrive drive = new DifferentialDrive(new Victor(1), new Victor(2));

//This is loggable, but will not be logged due to the exclude annotation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class LoggedCommand extends Command implements Loggable {

private double timeout;

@Config.Command
@Config
private Command thisCommand = this;

//logs a graph of time since initialized
Expand All @@ -28,12 +28,13 @@ public String configureLogName() {
public LoggedCommand(double timeout){
super(timeout);
this.timeout = timeout;

setRunWhenDisabled(true);
}

@Override
public void execute(){
time = timeSinceInitialized();
System.out.println("Executing!");
}

@Override
Expand Down
4 changes: 4 additions & 0 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ dependencies {
compile wpi.deps.vendor.java()
nativeZip wpi.deps.vendor.jni(wpi.platforms.roborio)
nativeDesktopZip wpi.deps.vendor.jni(wpi.platforms.desktop)

simulation rootProject.files('libs/halsim_ds_socketd.dll')
simulation "edu.wpi.first.halsim:halsim_ds_socket:${wpi.wpilibVersion}:${wpi.platforms.desktop}@zip"
simulation "edu.wpi.first.halsim:halsim_ds_socket:${wpi.wpilibVersion}:${wpi.platforms.desktop}debug@zip"
}

/* Utils */
Expand Down
28 changes: 22 additions & 6 deletions lib/src/main/java/io/github/oblarg/oblog/Logger.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package io.github.oblarg.oblog;

import edu.wpi.cscore.VideoSource;
import edu.wpi.first.networktables.EntryListenerFlags;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.wpilibj.AnalogInput;
import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.wpilibj.*;
import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.command.CommandGroup;
import edu.wpi.first.wpilibj.command.PIDCommand;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.drive.MecanumDrive;
import edu.wpi.first.wpilibj.interfaces.Accelerometer;
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardContainer;
import edu.wpi.first.wpilibj.shuffleboard.WidgetType;
import io.github.oblarg.oblog.annotations.*;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.wpilibj.shuffleboard.BuiltInWidgets;
Expand Down Expand Up @@ -280,6 +287,11 @@ private interface SetterProcessor {


private static final Map<Class<? extends Annotation>, FieldProcessor> configFieldHandler = Map.ofEntries(
entry(Config.class,
(supplier, rawParams, bin, name) -> {
Config params = (Config) rawParams;
bin.add((params.name().equals("NO_NAME")) ? name : params.name(), (Sendable) supplier.get());
}),
entry(Config.Command.class,
(supplier, rawParams, bin, name) -> {
Config.Command params = (Config.Command) rawParams;
Expand Down Expand Up @@ -310,9 +322,13 @@ private interface SetterProcessor {
entry(Log.class,
(supplier, rawParams, bin, name) -> {
Log params = (Log) rawParams;
Logger.registerEntry(
bin.add((params.name().equals("NO_NAME")) ? name : params.name(), supplier.get()).getEntry(),
supplier);
if (supplier.get() instanceof Sendable) {
bin.add((params.name().equals("NO_NAME")) ? name : params.name(), (Sendable) supplier.get());
} else {
Logger.registerEntry(
bin.add((params.name().equals("NO_NAME")) ? name : params.name(), supplier.get()).getEntry(),
supplier);
}
}),
entry(Log.NumberBar.class,
(supplier, rawParams, bin, name) -> {
Expand Down Expand Up @@ -484,7 +500,7 @@ private interface SetterProcessor {
})
);

private static Map<Class, Function<Object, Object>> setterCaster = Map.ofEntries(
private static final Map<Class, Function<Object, Object>> setterCaster = Map.ofEntries(
entry(Integer.TYPE, (value) -> ((Number) value).intValue()),
entry(Integer.class, (value) -> ((Number) value).intValue()),
entry(Double.TYPE, (value) -> ((Number) value).doubleValue()),
Expand Down

0 comments on commit 597b17d

Please sign in to comment.