UsbCamera: Allow silencing of Connecting message (#1231)

This commit is contained in:
Peter Johnson
2018-07-28 14:57:41 -07:00
committed by GitHub
parent 0614913f1a
commit 6b37ca9f9a
7 changed files with 49 additions and 5 deletions

View File

@@ -50,6 +50,8 @@ static constexpr char const* kPropWbValue = "white_balance_temperature";
static constexpr char const* kPropExAuto = "exposure_auto";
static constexpr char const* kPropExValue = "exposure_absolute";
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)
static inline int FractToFPS(const struct v4l2_fract& timeperframe) {
@@ -221,6 +223,11 @@ UsbCameraImpl::UsbCameraImpl(wpi::StringRef name, wpi::StringRef path)
m_active{true} {
SetDescription(GetDescriptionImpl(m_path.c_str()));
SetQuirks();
CreateProperty(kPropConnectVerbose, [] {
return std::make_unique<UsbCameraProperty>(kPropConnectVerbose,
kPropConnectVerboseId,
CS_PROP_INTEGER, 0, 1, 1, 1, 1);
});
}
UsbCameraImpl::~UsbCameraImpl() {
@@ -453,7 +460,7 @@ void UsbCameraImpl::DeviceDisconnect() {
void UsbCameraImpl::DeviceConnect() {
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
SDEBUG3("opening device");
@@ -489,7 +496,8 @@ void UsbCameraImpl::DeviceConnect() {
for (size_t i = 0; i < m_propertyData.size(); ++i) {
const auto prop =
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))
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)
if (!prop->DeviceSet(lock, m_fd, value, valueStr))
return CS_PROPERTY_WRITE_FAILED;
if (!prop->device) {
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
UpdatePropertyValue(property, setString, value, valueStr);

View File

@@ -143,6 +143,7 @@ class UsbCameraImpl : public SourceImpl {
bool m_modeSetPixelFormat{false};
bool m_modeSetResolution{false};
bool m_modeSetFPS{false};
int m_connectVerbose{1};
#ifdef __linux__
unsigned m_capabilities = 0;
#endif

View File

@@ -289,7 +289,7 @@ bool UsbCameraProperty::DeviceSet(std::unique_lock<wpi::mutex>& lock,
bool UsbCameraProperty::DeviceSet(std::unique_lock<wpi::mutex>& lock, int fd,
int newValue,
wpi::StringRef newValueStr) const {
if (fd < 0) return true;
if (!device || fd < 0) return true;
unsigned idCopy = id;
int rv = 0;

View File

@@ -26,6 +26,15 @@ class UsbCameraProperty : public PropertyImpl {
UsbCameraProperty() = default;
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
UsbCameraProperty(wpi::StringRef name_, int rawIndex_,
const UsbCameraProperty& rawProp, int defaultValue_,
@@ -55,6 +64,9 @@ class UsbCameraProperty : public PropertyImpl {
wpi::StringRef newValueStr) const;
#endif
// If this is a device (rather than software) property
bool device{true};
// If this is a percentage (rather than raw) property
bool percentage{false};