mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
Allow video sources to be added to Shuffleboard (#1453)
Add a Sendable wrapper for VideoSource objects. Add convenience methods for adding video sources directly to containers so users won't have to manually wrap video sources.
This commit is contained in:
committed by
Peter Johnson
parent
a2368a6199
commit
80f87ff8ad
@@ -0,0 +1,46 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "frc/shuffleboard/SendableCameraWrapper.h"
|
||||
|
||||
#include <cscore_oo.h>
|
||||
#include <wpi/DenseMap.h>
|
||||
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
namespace {
|
||||
constexpr const char* kProtocol = "camera_server://";
|
||||
wpi::DenseMap<int, std::unique_ptr<SendableCameraWrapper>> wrappers;
|
||||
} // namespace
|
||||
|
||||
SendableCameraWrapper& SendableCameraWrapper::Wrap(
|
||||
const cs::VideoSource& source) {
|
||||
return Wrap(source.GetHandle());
|
||||
}
|
||||
|
||||
SendableCameraWrapper& SendableCameraWrapper::Wrap(CS_Source source) {
|
||||
auto& wrapper = wrappers[static_cast<int>(source)];
|
||||
if (!wrapper)
|
||||
wrapper = std::make_unique<SendableCameraWrapper>(source, private_init{});
|
||||
return *wrapper;
|
||||
}
|
||||
|
||||
SendableCameraWrapper::SendableCameraWrapper(CS_Source source,
|
||||
const private_init&)
|
||||
: SendableBase(false), m_uri(kProtocol) {
|
||||
CS_Status status = 0;
|
||||
auto name = cs::GetSourceName(source, &status);
|
||||
SetName(name);
|
||||
m_uri += name;
|
||||
}
|
||||
|
||||
void SendableCameraWrapper::InitSendable(SendableBuilder& builder) {
|
||||
builder.AddStringProperty(".ShuffleboardURI", [this] { return m_uri; },
|
||||
nullptr);
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
#include "frc/shuffleboard/ComplexWidget.h"
|
||||
#include "frc/shuffleboard/SendableCameraWrapper.h"
|
||||
#include "frc/shuffleboard/ShuffleboardComponent.h"
|
||||
#include "frc/shuffleboard/ShuffleboardLayout.h"
|
||||
#include "frc/shuffleboard/SimpleWidget.h"
|
||||
@@ -62,6 +63,11 @@ ComplexWidget& ShuffleboardContainer::Add(const wpi::Twine& title,
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
ComplexWidget& ShuffleboardContainer::Add(const wpi::Twine& title,
|
||||
const cs::VideoSource& video) {
|
||||
return Add(title, SendableCameraWrapper::Wrap(video));
|
||||
}
|
||||
|
||||
ComplexWidget& ShuffleboardContainer::Add(Sendable& sendable) {
|
||||
if (sendable.GetName().empty()) {
|
||||
wpi::outs() << "Sendable must have a name\n";
|
||||
@@ -69,6 +75,10 @@ ComplexWidget& ShuffleboardContainer::Add(Sendable& sendable) {
|
||||
return Add(sendable.GetName(), sendable);
|
||||
}
|
||||
|
||||
ComplexWidget& ShuffleboardContainer::Add(const cs::VideoSource& video) {
|
||||
return Add(SendableCameraWrapper::Wrap(video));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::Add(
|
||||
const wpi::Twine& title, std::shared_ptr<nt::Value> defaultValue) {
|
||||
CheckTitle(title);
|
||||
|
||||
Reference in New Issue
Block a user