diff --git a/photon-lib/src/main/java/org/photonvision/PhotonCamera.java b/photon-lib/src/main/java/org/photonvision/PhotonCamera.java index c276655d4..aa0951f06 100644 --- a/photon-lib/src/main/java/org/photonvision/PhotonCamera.java +++ b/photon-lib/src/main/java/org/photonvision/PhotonCamera.java @@ -80,6 +80,7 @@ public class PhotonCamera { } private final String path; + private final String name; private static boolean VERSION_CHECK_ENABLED = true; private static long VERSION_CHECK_INTERVAL = 5; @@ -104,6 +105,7 @@ public class PhotonCamera { * @param cameraName The name of the camera, as seen in the UI. */ public PhotonCamera(NetworkTableInstance instance, String cameraName) { + name = cameraName; var mainTable = instance.getTable("photonvision"); this.rootTable = mainTable.getSubTable(cameraName); path = rootTable.getPath(); @@ -252,6 +254,16 @@ public class PhotonCamera { return getLatestResult().hasTargets(); } + /** + * Returns the name of the camera. This will return the same value that was given to the + * constructor as cameraName. + * + * @return The name of the camera. + */ + public String getName() { + return name; + } + /** * Returns whether the camera is connected and actively returning new data. Connection status is * debounced. diff --git a/photon-lib/src/main/native/cpp/photonlib/PhotonCamera.cpp b/photon-lib/src/main/native/cpp/photonlib/PhotonCamera.cpp index 5223a64fc..02186c91c 100644 --- a/photon-lib/src/main/native/cpp/photonlib/PhotonCamera.cpp +++ b/photon-lib/src/main/native/cpp/photonlib/PhotonCamera.cpp @@ -35,7 +35,7 @@ namespace photonlib { constexpr const units::second_t VERSION_CHECK_INTERVAL = 5_s; PhotonCamera::PhotonCamera(std::shared_ptr instance, - const std::string& cameraName) + const std::string_view cameraName) : mainTable(instance->GetTable("photonvision")), rootTable(mainTable->GetSubTable(cameraName)), rawBytesEntry(rootTable->GetRawTopic("rawBytes").Subscribe("raw", {})), @@ -52,9 +52,10 @@ PhotonCamera::PhotonCamera(std::shared_ptr instance, pipelineIndexSubscriber( rootTable->GetIntegerTopic("pipelineIndex").Subscribe(-1)), ledModeSubscriber(mainTable->GetIntegerTopic("ledMode").Subscribe(0)), - path(rootTable->GetPath()) {} + path(rootTable->GetPath()), + m_cameraName(cameraName) {} -PhotonCamera::PhotonCamera(const std::string& cameraName) +PhotonCamera::PhotonCamera(const std::string_view cameraName) : PhotonCamera(std::make_shared( nt::NetworkTableInstance::GetDefault()), cameraName) {} @@ -109,6 +110,10 @@ void PhotonCamera::SetLEDMode(LEDMode mode) { ledModeEntry.Set(static_cast(static_cast(mode))); } +const std::string_view PhotonCamera::GetCameraName() const { + return m_cameraName; +} + void PhotonCamera::VerifyVersion() { if (!PhotonCamera::VERSION_CHECK_ENABLED) return; diff --git a/photon-lib/src/main/native/include/photonlib/PhotonCamera.h b/photon-lib/src/main/native/include/photonlib/PhotonCamera.h index fa2640b76..ada9c52de 100644 --- a/photon-lib/src/main/native/include/photonlib/PhotonCamera.h +++ b/photon-lib/src/main/native/include/photonlib/PhotonCamera.h @@ -58,14 +58,14 @@ class PhotonCamera { * over. */ explicit PhotonCamera(std::shared_ptr instance, - const std::string& cameraName); + const std::string_view cameraName); /** * Constructs a PhotonCamera from the name of the camera. * @param cameraName The nickname of the camera (found in the PhotonVision * UI). */ - explicit PhotonCamera(const std::string& cameraName); + explicit PhotonCamera(const std::string_view cameraName); /** * Returns the latest pipeline result. @@ -131,6 +131,14 @@ class PhotonCamera { */ void SetLEDMode(LEDMode led); + /** + * Returns the name of the camera. + * This will return the same value that was given to the constructor as + * cameraName. + * @return The name of the camera. + */ + const std::string_view GetCameraName() const; + /** * Returns whether the latest target result has targets. * This method is deprecated; {@link PhotonPipelineResult#hasTargets()} should @@ -163,6 +171,7 @@ class PhotonCamera { nt::IntegerSubscriber ledModeSubscriber; std::string path; + std::string m_cameraName; mutable Packet packet;