mirror of
https://github.com/PhotonVision/photonvision
synced 2026-07-05 03:21:40 +00:00
Remove pipeline index/driver mode/led mode caching in PhotonCamera
This commit is contained in:
@@ -37,10 +37,6 @@ public class PhotonCamera {
|
||||
final NetworkTable mainTable = NetworkTableInstance.getDefault().getTable("photonvision");
|
||||
private final String path;
|
||||
|
||||
boolean driverMode;
|
||||
int pipelineIndex;
|
||||
VisionLEDMode mode;
|
||||
|
||||
Packet packet = new Packet(1);
|
||||
|
||||
/**
|
||||
@@ -57,10 +53,6 @@ public class PhotonCamera {
|
||||
pipelineIndexEntry = rootTable.getEntry("pipelineIndex");
|
||||
ledModeEntry = mainTable.getEntry("ledMode");
|
||||
versionEntry = mainTable.getEntry("version");
|
||||
|
||||
driverMode = driverModeEntry.getBoolean(false);
|
||||
pipelineIndex = pipelineIndexEntry.getNumber(0).intValue();
|
||||
getLEDMode();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,7 +93,7 @@ public class PhotonCamera {
|
||||
* @return Whether the camera is in driver mode.
|
||||
*/
|
||||
public boolean getDriverMode() {
|
||||
return driverMode;
|
||||
return driverModeEntry.getBoolean(false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,10 +102,7 @@ public class PhotonCamera {
|
||||
* @param driverMode Whether to set driver mode.
|
||||
*/
|
||||
public void setDriverMode(boolean driverMode) {
|
||||
if (this.driverMode != driverMode) {
|
||||
this.driverMode = driverMode;
|
||||
driverModeEntry.setBoolean(this.driverMode);
|
||||
}
|
||||
driverModeEntry.setBoolean(driverMode);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,7 +131,7 @@ public class PhotonCamera {
|
||||
* @return The active pipeline index.
|
||||
*/
|
||||
public int getPipelineIndex() {
|
||||
return pipelineIndex;
|
||||
return pipelineIndexEntry.getNumber(0).intValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,10 +140,7 @@ public class PhotonCamera {
|
||||
* @param index The active pipeline index.
|
||||
*/
|
||||
public void setPipelineIndex(int index) {
|
||||
if (pipelineIndex != index) {
|
||||
pipelineIndex = index;
|
||||
pipelineIndexEntry.setNumber(pipelineIndex);
|
||||
}
|
||||
pipelineIndexEntry.setNumber(index);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,20 +152,15 @@ public class PhotonCamera {
|
||||
int value = ledModeEntry.getNumber(-1).intValue();
|
||||
switch (value) {
|
||||
case 0:
|
||||
mode = VisionLEDMode.kOff;
|
||||
break;
|
||||
return VisionLEDMode.kOff;
|
||||
case 1:
|
||||
mode = VisionLEDMode.kOn;
|
||||
break;
|
||||
return VisionLEDMode.kOn;
|
||||
case 2:
|
||||
mode = VisionLEDMode.kBlink;
|
||||
break;
|
||||
return VisionLEDMode.kBlink;
|
||||
case -1:
|
||||
default:
|
||||
mode = VisionLEDMode.kDefault;
|
||||
break;
|
||||
return VisionLEDMode.kDefault;
|
||||
}
|
||||
return mode;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,9 +169,7 @@ public class PhotonCamera {
|
||||
* @param led The mode to set to.
|
||||
*/
|
||||
public void setLED(VisionLEDMode led) {
|
||||
if (led != mode) {
|
||||
ledModeEntry.setNumber(led.value);
|
||||
}
|
||||
ledModeEntry.setNumber(led.value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,11 +26,7 @@ PhotonCamera::PhotonCamera(std::shared_ptr<nt::NetworkTable> rootTable)
|
||||
inputSaveImgEntry(rootTable->GetEntry("inputSaveImgCmd")),
|
||||
outputSaveImgEntry(rootTable->GetEntry("outputSaveImgCmd")),
|
||||
pipelineIndexEntry(rootTable->GetEntry("pipelineIndex")),
|
||||
ledModeEntry(mainTable->GetEntry("ledMode")) {
|
||||
driverMode = driverModeEntry.GetBoolean(false);
|
||||
pipelineIndex = static_cast<int>(pipelineIndexEntry.GetDouble(0.0));
|
||||
mode = GetLEDMode();
|
||||
}
|
||||
ledModeEntry(mainTable->GetEntry("ledMode")) {}
|
||||
|
||||
PhotonCamera::PhotonCamera(const std::string& cameraName)
|
||||
: PhotonCamera(nt::NetworkTableInstance::GetDefault()
|
||||
@@ -58,36 +54,30 @@ PhotonPipelineResult PhotonCamera::GetLatestResult() const {
|
||||
}
|
||||
|
||||
void PhotonCamera::SetDriverMode(bool driverMode) {
|
||||
if (this->driverMode != driverMode) {
|
||||
this->driverMode = driverMode;
|
||||
driverModeEntry.SetBoolean(this->driverMode);
|
||||
}
|
||||
driverModeEntry.SetBoolean(driverMode);
|
||||
}
|
||||
|
||||
void PhotonCamera::TakeInputSnapshot() { inputSaveImgEntry.SetBoolean(true); }
|
||||
|
||||
void PhotonCamera::TakeOutputSnapshot() { outputSaveImgEntry.SetBoolean(true); }
|
||||
|
||||
bool PhotonCamera::GetDriverMode() const { return driverMode; }
|
||||
bool PhotonCamera::GetDriverMode() const {
|
||||
return driverModeEntry.GetBoolean(false);
|
||||
}
|
||||
|
||||
void PhotonCamera::SetPipelineIndex(int index) {
|
||||
if (index != pipelineIndex) {
|
||||
pipelineIndex = index;
|
||||
pipelineIndexEntry.SetDouble(static_cast<double>(pipelineIndex));
|
||||
}
|
||||
pipelineIndexEntry.SetDouble(static_cast<double>(index));
|
||||
}
|
||||
|
||||
int PhotonCamera::GetPipelineIndex() const { return pipelineIndex; }
|
||||
int PhotonCamera::GetPipelineIndex() const {
|
||||
return static_cast<int>(pipelineIndexEntry.GetDouble(0));
|
||||
}
|
||||
|
||||
LEDMode PhotonCamera::GetLEDMode() const {
|
||||
mode = static_cast<LEDMode>(static_cast<int>(ledModeEntry.GetDouble(-1.0)));
|
||||
return mode;
|
||||
return static_cast<LEDMode>(static_cast<int>(ledModeEntry.GetDouble(-1.0)));
|
||||
}
|
||||
|
||||
void PhotonCamera::SetLEDMode(LEDMode led) {
|
||||
if (led != mode) {
|
||||
mode = led;
|
||||
ledModeEntry.SetDouble(static_cast<double>(static_cast<int>(mode)));
|
||||
}
|
||||
void PhotonCamera::SetLEDMode(LEDMode mode) {
|
||||
ledModeEntry.SetDouble(static_cast<double>(static_cast<int>(mode)));
|
||||
}
|
||||
} // namespace photonlib
|
||||
|
||||
@@ -139,10 +139,6 @@ class PhotonCamera {
|
||||
nt::NetworkTableEntry ledModeEntry;
|
||||
|
||||
mutable Packet packet;
|
||||
|
||||
bool driverMode;
|
||||
double pipelineIndex;
|
||||
mutable LEDMode mode;
|
||||
};
|
||||
|
||||
} // namespace photonlib
|
||||
|
||||
Reference in New Issue
Block a user