Skip to content

Commit

Permalink
allow logging/config from rootcontainer
Browse files Browse the repository at this point in the history
  • Loading branch information
Oblarg committed Feb 26, 2019
1 parent 3e9e2df commit 91ec500
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.github.oblarg.logexample;

import edu.wpi.first.wpilibj.Victor;
import edu.wpi.first.wpilibj.command.Subsystem;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import io.github.oblarg.oblog.Loggable;
import io.github.oblarg.oblog.annotations.Config;
import io.github.oblarg.oblog.annotations.Log;
Expand Down
6 changes: 6 additions & 0 deletions examples/src/main/java/io/github/oblarg/logexample/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
/*----------------------------------------------------------------------------*/

import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.Victor;
import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import io.github.oblarg.oblog.Logger;
Expand All @@ -27,6 +29,10 @@ public class Robot extends TimedRobot {
private LoggedCommand command5Seconds = new LoggedCommand(5);
private LoggedCommand command10Seconds = new LoggedCommand(10);


@Log.DifferentialDrive
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.
@Log.Exclude
private LoggedCommand commandExcluded = new LoggedCommand(10);
Expand Down
38 changes: 36 additions & 2 deletions lib/src/main/java/io/github/oblarg/oblog/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.wpilibj.AnalogInput;
import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardContainer;
import io.github.oblarg.oblog.annotations.*;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.wpilibj.shuffleboard.BuiltInWidgets;
Expand Down Expand Up @@ -102,6 +103,39 @@ private static void configureLogging(LogType logType,
ShuffleboardWrapper shuffleboard,
NetworkTableInstance nt) {

ShuffleboardContainerWrapper bin = shuffleboard.getTab(rootContainer.getClass().getSimpleName());

switch(logType) {
case LOG:
logFieldsAndMethods(rootContainer,
rootContainer.getClass(),
bin,
new HashSet<>(),
new HashSet<>());
break;
case CONFIG:
configFieldsAndMethods(rootContainer,
rootContainer.getClass(),
bin,
nt,
new HashSet<>(),
new HashSet<>());
break;
case BOTH:
logFieldsAndMethods(rootContainer,
rootContainer.getClass(),
bin,
new HashSet<>(),
new HashSet<>());
configFieldsAndMethods(rootContainer,
rootContainer.getClass(),
bin,
nt,
new HashSet<>(),
new HashSet<>());
break;
}

Consumer<Loggable> log = (toLog) -> logLoggable(logType,
toLog,
toLog.getClass(),
Expand Down Expand Up @@ -477,7 +511,7 @@ private interface SetterProcessor {

);

private static void configFieldsAndMethods(Loggable loggable,
private static void configFieldsAndMethods(Object loggable,
Class loggableClass,
ShuffleboardContainerWrapper bin,
NetworkTableInstance nt,
Expand Down Expand Up @@ -540,7 +574,7 @@ private static void configFieldsAndMethods(Loggable loggable,
}


private static void logFieldsAndMethods(Loggable loggable,
private static void logFieldsAndMethods(Object loggable,
Class loggableClass,
ShuffleboardContainerWrapper bin,
Set<Field> registeredFields,
Expand Down

0 comments on commit 91ec500

Please sign in to comment.