-
Notifications
You must be signed in to change notification settings - Fork 613
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
156 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/proto/Mechanism2dProto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
package edu.wpi.first.wpilibj.smartdashboard.proto; | ||
|
||
import edu.wpi.first.util.protobuf.Protobuf; | ||
import edu.wpi.first.wpilibj.proto.Mechanism2D.ProtobufMechanism2d; | ||
import edu.wpi.first.wpilibj.proto.Mechanism2D.ProtobufMechanismLigament2d; | ||
import edu.wpi.first.wpilibj.proto.Mechanism2D.ProtobufMechanismRoot2d; | ||
import edu.wpi.first.wpilibj.smartdashboard.Mechanism2d; | ||
import edu.wpi.first.wpilibj.smartdashboard.MechanismLigament2d; | ||
import edu.wpi.first.wpilibj.smartdashboard.MechanismObject2d; | ||
import edu.wpi.first.wpilibj.smartdashboard.MechanismRoot2d; | ||
import edu.wpi.first.wpilibj.util.Color8Bit; | ||
import us.hebi.quickbuf.Descriptors.Descriptor; | ||
|
||
public class Mechanism2dProto implements Protobuf<Mechanism2d, ProtobufMechanism2d> { | ||
@Override | ||
public Class<Mechanism2d> getTypeClass() { | ||
return MechanismRoot2d.class; | ||
} | ||
|
||
@Override | ||
public Descriptor getDescriptor() { | ||
return ProtobufMechanism2d.getDescriptor(); | ||
} | ||
|
||
@Override | ||
public ProtobufMechanism2d createMessage() { | ||
return ProtobufMechanism2d.newInstance(); | ||
} | ||
|
||
@Override | ||
public Mechanism2d unpack(ProtobufMechanism2d msg) { | ||
var mechanism = new Mechanism2d(msg.getX(), msg.getY(), new Color8Bit(msg.getColor())); | ||
// Unpack each root into the mechanism | ||
for (ProtobufMechanismRoot2d root : msg.getRoots()) { | ||
var mechanismRoot = mechanism.getRoot(root.getName(), root.getX(), root.getY()); | ||
// Unpack the ligaments for each root | ||
for (ProtobufMechanismLigament2d ligament : root.getLigaments()) { | ||
mechanismRoot.append(MechanismLigament2d.proto.unpack(ligament)); | ||
} | ||
} | ||
return mechanism; | ||
} | ||
|
||
@Override | ||
public void pack(ProtobufMechanism2d msg, Mechanism2d value) { | ||
msg.setHeight(value.getHeight()); | ||
msg.setWidth(value.getWidth()); | ||
for (MechanismRoot2d root : value.getAllRoots().values()) { | ||
var nestedRoot = MechanismRoot2d.proto.createMessage(); | ||
MechanismRoot2d.proto.pack(nestedRoot, root); | ||
msg.addRoots(nestedRoot); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/proto/MechanismRoot2dProto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
package edu.wpi.first.wpilibj.smartdashboard.proto; | ||
|
||
import edu.wpi.first.util.protobuf.Protobuf; | ||
import edu.wpi.first.wpilibj.proto.Mechanism2D.ProtobufMechanismLigament2d; | ||
import edu.wpi.first.wpilibj.proto.Mechanism2D.ProtobufMechanismRoot2d; | ||
import edu.wpi.first.wpilibj.smartdashboard.MechanismLigament2d; | ||
import edu.wpi.first.wpilibj.smartdashboard.MechanismObject2d; | ||
import edu.wpi.first.wpilibj.smartdashboard.MechanismRoot2d; | ||
import us.hebi.quickbuf.Descriptors.Descriptor; | ||
|
||
public class MechanismRoot2dProto implements Protobuf<MechanismRoot2d, ProtobufMechanismRoot2d> { | ||
@Override | ||
public Class<MechanismRoot2d> getTypeClass() { | ||
return MechanismRoot2d.class; | ||
} | ||
|
||
@Override | ||
public Descriptor getDescriptor() { | ||
return ProtobufMechanismRoot2d.getDescriptor(); | ||
} | ||
|
||
@Override | ||
public ProtobufMechanismRoot2d createMessage() { | ||
return ProtobufMechanismRoot2d.newInstance(); | ||
} | ||
|
||
@Override | ||
public MechanismRoot2d unpack(ProtobufMechanismRoot2d msg) { | ||
var root = new MechanismRoot2d(msg.getName(), msg.getX(), msg.getY()); | ||
for (ProtobufMechanismLigament2d ligament : msg.getLigaments()) { | ||
root.append(MechanismLigament2d.proto.unpack(ligament)); | ||
} | ||
return root; | ||
} | ||
|
||
@Override | ||
public void pack(ProtobufMechanismRoot2d msg, MechanismRoot2d value) { | ||
msg.setX(value.getX()); | ||
msg.setY(value.getY()); | ||
for (MechanismObject2d ligament : value.getObjects().values()) { | ||
var nestedLigament = MechanismLigament2d.proto.createMessage(); | ||
MechanismLigament2d.proto.pack(nestedLigament, (MechanismLigament2d)ligament); | ||
msg.addLigaments(nestedLigament); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters