mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-03 03:01:44 +00:00
UsbCamera: Allow silencing of Connecting message (#1231)
This commit is contained in:
@@ -43,4 +43,13 @@ public class UsbCamera extends VideoCamera {
|
|||||||
public String getPath() {
|
public String getPath() {
|
||||||
return CameraServerJNI.getUsbCameraPath(m_handle);
|
return CameraServerJNI.getUsbCameraPath(m_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set how verbose the camera connection messages are.
|
||||||
|
* @param level 0=don't display Connecting message, 1=do display message
|
||||||
|
*/
|
||||||
|
void setConnectVerbose(int level) {
|
||||||
|
CameraServerJNI.setProperty(CameraServerJNI.getSourceProperty(m_handle, "connect_verbose"),
|
||||||
|
level);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ static constexpr char const* kPropWbValue = "white_balance_temperature";
|
|||||||
static constexpr char const* kPropExAuto = "exposure_auto";
|
static constexpr char const* kPropExAuto = "exposure_auto";
|
||||||
static constexpr char const* kPropExValue = "exposure_absolute";
|
static constexpr char const* kPropExValue = "exposure_absolute";
|
||||||
static constexpr char const* kPropBrValue = "brightness";
|
static constexpr char const* kPropBrValue = "brightness";
|
||||||
|
static constexpr char const* kPropConnectVerbose = "connect_verbose";
|
||||||
|
static constexpr unsigned kPropConnectVerboseId = 0;
|
||||||
|
|
||||||
// Conversions v4l2_fract time per frame from/to frames per second (fps)
|
// Conversions v4l2_fract time per frame from/to frames per second (fps)
|
||||||
static inline int FractToFPS(const struct v4l2_fract& timeperframe) {
|
static inline int FractToFPS(const struct v4l2_fract& timeperframe) {
|
||||||
@@ -221,6 +223,11 @@ UsbCameraImpl::UsbCameraImpl(wpi::StringRef name, wpi::StringRef path)
|
|||||||
m_active{true} {
|
m_active{true} {
|
||||||
SetDescription(GetDescriptionImpl(m_path.c_str()));
|
SetDescription(GetDescriptionImpl(m_path.c_str()));
|
||||||
SetQuirks();
|
SetQuirks();
|
||||||
|
CreateProperty(kPropConnectVerbose, [] {
|
||||||
|
return std::make_unique<UsbCameraProperty>(kPropConnectVerbose,
|
||||||
|
kPropConnectVerboseId,
|
||||||
|
CS_PROP_INTEGER, 0, 1, 1, 1, 1);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
UsbCameraImpl::~UsbCameraImpl() {
|
UsbCameraImpl::~UsbCameraImpl() {
|
||||||
@@ -453,7 +460,7 @@ void UsbCameraImpl::DeviceDisconnect() {
|
|||||||
void UsbCameraImpl::DeviceConnect() {
|
void UsbCameraImpl::DeviceConnect() {
|
||||||
if (m_fd >= 0) return;
|
if (m_fd >= 0) return;
|
||||||
|
|
||||||
SINFO("Connecting to USB camera on " << m_path);
|
if (m_connectVerbose) SINFO("Connecting to USB camera on " << m_path);
|
||||||
|
|
||||||
// Try to open the device
|
// Try to open the device
|
||||||
SDEBUG3("opening device");
|
SDEBUG3("opening device");
|
||||||
@@ -489,7 +496,8 @@ void UsbCameraImpl::DeviceConnect() {
|
|||||||
for (size_t i = 0; i < m_propertyData.size(); ++i) {
|
for (size_t i = 0; i < m_propertyData.size(); ++i) {
|
||||||
const auto prop =
|
const auto prop =
|
||||||
static_cast<const UsbCameraProperty*>(m_propertyData[i].get());
|
static_cast<const UsbCameraProperty*>(m_propertyData[i].get());
|
||||||
if (!prop || !prop->valueSet || prop->percentage) continue;
|
if (!prop || !prop->valueSet || !prop->device || prop->percentage)
|
||||||
|
continue;
|
||||||
if (!prop->DeviceSet(lock2, m_fd))
|
if (!prop->DeviceSet(lock2, m_fd))
|
||||||
SWARNING("failed to set property " << prop->name);
|
SWARNING("failed to set property " << prop->name);
|
||||||
}
|
}
|
||||||
@@ -694,8 +702,12 @@ CS_StatusValue UsbCameraImpl::DeviceCmdSetProperty(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actually set the new value on the device (if possible)
|
// Actually set the new value on the device (if possible)
|
||||||
if (!prop->DeviceSet(lock, m_fd, value, valueStr))
|
if (!prop->device) {
|
||||||
return CS_PROPERTY_WRITE_FAILED;
|
if (prop->id == kPropConnectVerboseId) m_connectVerbose = value;
|
||||||
|
} else {
|
||||||
|
if (!prop->DeviceSet(lock, m_fd, value, valueStr))
|
||||||
|
return CS_PROPERTY_WRITE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
// Cache the set values
|
// Cache the set values
|
||||||
UpdatePropertyValue(property, setString, value, valueStr);
|
UpdatePropertyValue(property, setString, value, valueStr);
|
||||||
|
|||||||
@@ -143,6 +143,7 @@ class UsbCameraImpl : public SourceImpl {
|
|||||||
bool m_modeSetPixelFormat{false};
|
bool m_modeSetPixelFormat{false};
|
||||||
bool m_modeSetResolution{false};
|
bool m_modeSetResolution{false};
|
||||||
bool m_modeSetFPS{false};
|
bool m_modeSetFPS{false};
|
||||||
|
int m_connectVerbose{1};
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
unsigned m_capabilities = 0;
|
unsigned m_capabilities = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -289,7 +289,7 @@ bool UsbCameraProperty::DeviceSet(std::unique_lock<wpi::mutex>& lock,
|
|||||||
bool UsbCameraProperty::DeviceSet(std::unique_lock<wpi::mutex>& lock, int fd,
|
bool UsbCameraProperty::DeviceSet(std::unique_lock<wpi::mutex>& lock, int fd,
|
||||||
int newValue,
|
int newValue,
|
||||||
wpi::StringRef newValueStr) const {
|
wpi::StringRef newValueStr) const {
|
||||||
if (fd < 0) return true;
|
if (!device || fd < 0) return true;
|
||||||
unsigned idCopy = id;
|
unsigned idCopy = id;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,15 @@ class UsbCameraProperty : public PropertyImpl {
|
|||||||
UsbCameraProperty() = default;
|
UsbCameraProperty() = default;
|
||||||
explicit UsbCameraProperty(wpi::StringRef name_) : PropertyImpl{name_} {}
|
explicit UsbCameraProperty(wpi::StringRef name_) : PropertyImpl{name_} {}
|
||||||
|
|
||||||
|
// Software property constructor
|
||||||
|
UsbCameraProperty(wpi::StringRef name_, unsigned id_, CS_PropertyKind kind_,
|
||||||
|
int minimum_, int maximum_, int step_, int defaultValue_,
|
||||||
|
int value_)
|
||||||
|
: PropertyImpl(name_, kind_, minimum_, maximum_, step_, defaultValue_,
|
||||||
|
value_),
|
||||||
|
device{false},
|
||||||
|
id{id_} {}
|
||||||
|
|
||||||
// Normalized property constructor
|
// Normalized property constructor
|
||||||
UsbCameraProperty(wpi::StringRef name_, int rawIndex_,
|
UsbCameraProperty(wpi::StringRef name_, int rawIndex_,
|
||||||
const UsbCameraProperty& rawProp, int defaultValue_,
|
const UsbCameraProperty& rawProp, int defaultValue_,
|
||||||
@@ -55,6 +64,9 @@ class UsbCameraProperty : public PropertyImpl {
|
|||||||
wpi::StringRef newValueStr) const;
|
wpi::StringRef newValueStr) const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// If this is a device (rather than software) property
|
||||||
|
bool device{true};
|
||||||
|
|
||||||
// If this is a percentage (rather than raw) property
|
// If this is a percentage (rather than raw) property
|
||||||
bool percentage{false};
|
bool percentage{false};
|
||||||
|
|
||||||
|
|||||||
@@ -268,6 +268,10 @@ class UsbCamera : public VideoCamera {
|
|||||||
|
|
||||||
/// Get the path to the device.
|
/// Get the path to the device.
|
||||||
std::string GetPath() const;
|
std::string GetPath() const;
|
||||||
|
|
||||||
|
/// Set how verbose the camera connection messages are.
|
||||||
|
/// @param level 0=don't display Connecting message, 1=do display message
|
||||||
|
void SetConnectVerbose(int level);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A source that represents a MJPEG-over-HTTP (IP) camera.
|
/// A source that represents a MJPEG-over-HTTP (IP) camera.
|
||||||
|
|||||||
@@ -233,6 +233,12 @@ inline std::string UsbCamera::GetPath() const {
|
|||||||
return ::cs::GetUsbCameraPath(m_handle, &m_status);
|
return ::cs::GetUsbCameraPath(m_handle, &m_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void UsbCamera::SetConnectVerbose(int level) {
|
||||||
|
m_status = 0;
|
||||||
|
SetProperty(GetSourceProperty(m_handle, "connect_verbose", &m_status), level,
|
||||||
|
&m_status);
|
||||||
|
}
|
||||||
|
|
||||||
inline HttpCamera::HttpCamera(wpi::StringRef name, wpi::StringRef url,
|
inline HttpCamera::HttpCamera(wpi::StringRef name, wpi::StringRef url,
|
||||||
HttpCameraKind kind) {
|
HttpCameraKind kind) {
|
||||||
m_handle = CreateHttpCamera(
|
m_handle = CreateHttpCamera(
|
||||||
|
|||||||
Reference in New Issue
Block a user