Add delay to version check (#466)

Rate limits version check spam print

Co-authored-by: Chris Gerth <gerth2@users.noreply.github.com>
This commit is contained in:
Matt
2022-10-21 20:53:28 -04:00
committed by GitHub
parent aff163fc6a
commit def40484e3
3 changed files with 22 additions and 5 deletions

View File

@@ -25,11 +25,15 @@
#include "photonlib/PhotonCamera.h"
#include <frc/Errors.h>
#include <frc/Timer.h>
#include "PhotonVersion.h"
#include "photonlib/Packet.h"
namespace photonlib {
constexpr const units::second_t VERSION_CHECK_INTERVAL = 5_s;
PhotonCamera::PhotonCamera(std::shared_ptr<nt::NetworkTableInstance> instance,
const std::string& cameraName)
: mainTable(instance->GetTable("photonvision")),
@@ -48,7 +52,7 @@ PhotonCamera::PhotonCamera(const std::string& cameraName)
nt::NetworkTableInstance::GetDefault()),
cameraName) {}
PhotonPipelineResult PhotonCamera::GetLatestResult() const {
PhotonPipelineResult PhotonCamera::GetLatestResult() {
// Prints warning if not connected
VerifyVersion();
@@ -99,9 +103,14 @@ void PhotonCamera::SetLEDMode(LEDMode mode) {
ledModeEntry.SetDouble(static_cast<double>(static_cast<int>(mode)));
}
void PhotonCamera::VerifyVersion() const {
void PhotonCamera::VerifyVersion() {
if (!PhotonCamera::VERSION_CHECK_ENABLED) return;
if ((frc::Timer::GetFPGATimestamp() - lastVersionCheckTime) <
VERSION_CHECK_INTERVAL)
return;
this->lastVersionCheckTime = frc::Timer::GetFPGATimestamp();
const std::string& versionString = versionEntry.GetString("");
if (versionString.empty()) {
std::string path_ = path;