2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2017-08-25 17:48:06 -07:00
|
|
|
|
2016-12-22 20:51:04 -08:00
|
|
|
#include <chrono>
|
2021-06-06 16:13:58 -07:00
|
|
|
#include <cstdio>
|
2016-12-22 20:51:04 -08:00
|
|
|
#include <thread>
|
|
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
#include <wpi/StringExtras.h>
|
2024-05-12 06:25:42 -07:00
|
|
|
#include <wpi/print.h>
|
2016-12-22 20:51:04 -08:00
|
|
|
|
2017-08-25 17:48:06 -07:00
|
|
|
#include "cscore.h"
|
2016-12-22 20:51:04 -08:00
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
|
if (argc < 2) {
|
2021-06-06 16:13:58 -07:00
|
|
|
std::fputs("Usage: settings camera [prop val] ... -- [prop val]...\n",
|
|
|
|
|
stderr);
|
|
|
|
|
std::fputs(" Example: settings 1 brightness 30 raw_contrast 10\n", stderr);
|
2016-12-22 20:51:04 -08:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int id;
|
2021-06-06 16:13:58 -07:00
|
|
|
if (auto v = wpi::parse_integer<int>(argv[1], 10)) {
|
|
|
|
|
id = v.value();
|
|
|
|
|
} else {
|
|
|
|
|
std::fputs("Expected number for camera\n", stderr);
|
2016-12-22 20:51:04 -08:00
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cs::UsbCamera camera{"usbcam", id};
|
|
|
|
|
|
|
|
|
|
// Set prior to connect
|
|
|
|
|
int arg = 2;
|
2021-06-06 16:13:58 -07:00
|
|
|
std::string_view propName;
|
|
|
|
|
for (; arg < argc && std::string_view{argv[arg]} != "--"; ++arg) {
|
2017-08-25 17:48:06 -07:00
|
|
|
if (propName.empty()) {
|
2016-12-22 20:51:04 -08:00
|
|
|
propName = argv[arg];
|
2017-08-25 17:48:06 -07:00
|
|
|
} else {
|
2021-06-06 16:13:58 -07:00
|
|
|
std::string_view propVal{argv[arg]};
|
|
|
|
|
if (auto v = wpi::parse_integer<int>(propVal, 10)) {
|
|
|
|
|
camera.GetProperty(propName).Set(v.value());
|
2020-12-28 12:58:06 -08:00
|
|
|
} else {
|
2021-06-06 16:13:58 -07:00
|
|
|
camera.GetProperty(propName).SetString(propVal);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2021-06-06 16:13:58 -07:00
|
|
|
propName = {};
|
2016-12-22 20:51:04 -08:00
|
|
|
}
|
|
|
|
|
}
|
2021-06-06 16:13:58 -07:00
|
|
|
if (arg < argc && std::string_view{argv[arg]} == "--") {
|
2020-12-28 12:58:06 -08:00
|
|
|
++arg;
|
|
|
|
|
}
|
2016-12-22 20:51:04 -08:00
|
|
|
|
|
|
|
|
// Wait to connect
|
2020-12-28 12:58:06 -08:00
|
|
|
while (!camera.IsConnected()) {
|
2016-12-22 20:51:04 -08:00
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2016-12-22 20:51:04 -08:00
|
|
|
|
|
|
|
|
// Set rest
|
2021-06-06 16:13:58 -07:00
|
|
|
propName = {};
|
2016-12-22 20:51:04 -08:00
|
|
|
for (; arg < argc; ++arg) {
|
2017-08-25 17:48:06 -07:00
|
|
|
if (propName.empty()) {
|
2016-12-22 20:51:04 -08:00
|
|
|
propName = argv[arg];
|
2017-08-25 17:48:06 -07:00
|
|
|
} else {
|
2021-06-06 16:13:58 -07:00
|
|
|
std::string_view propVal{argv[arg]};
|
|
|
|
|
if (auto v = wpi::parse_integer<int>(propVal, 10)) {
|
|
|
|
|
camera.GetProperty(propName).Set(v.value());
|
2020-12-28 12:58:06 -08:00
|
|
|
} else {
|
2021-06-06 16:13:58 -07:00
|
|
|
camera.GetProperty(propName).SetString(propVal);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2021-06-06 16:13:58 -07:00
|
|
|
propName = {};
|
2016-12-22 20:51:04 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Print settings
|
2021-06-06 16:13:58 -07:00
|
|
|
std::puts("Properties:");
|
2016-12-22 20:51:04 -08:00
|
|
|
for (const auto& prop : camera.EnumerateProperties()) {
|
2024-05-12 06:25:42 -07:00
|
|
|
wpi::print(" {}", prop.GetName());
|
2016-12-22 20:51:04 -08:00
|
|
|
switch (prop.GetKind()) {
|
|
|
|
|
case cs::VideoProperty::kBoolean:
|
2024-05-12 06:25:42 -07:00
|
|
|
wpi::print(" (bool): value={} default={}", prop.Get(),
|
2021-06-06 16:13:58 -07:00
|
|
|
prop.GetDefault());
|
2016-12-22 20:51:04 -08:00
|
|
|
break;
|
|
|
|
|
case cs::VideoProperty::kInteger:
|
2024-05-12 06:25:42 -07:00
|
|
|
wpi::print(" (int): value={} min={} max={} step={} default={}",
|
2021-06-06 16:13:58 -07:00
|
|
|
prop.Get(), prop.GetMin(), prop.GetMax(), prop.GetStep(),
|
|
|
|
|
prop.GetDefault());
|
2016-12-22 20:51:04 -08:00
|
|
|
break;
|
|
|
|
|
case cs::VideoProperty::kString:
|
2024-05-12 06:25:42 -07:00
|
|
|
wpi::print(" (string): {}", prop.GetString());
|
2016-12-22 20:51:04 -08:00
|
|
|
break;
|
|
|
|
|
case cs::VideoProperty::kEnum: {
|
2024-05-12 06:25:42 -07:00
|
|
|
wpi::print(" (enum): value={}", prop.Get());
|
2016-12-22 20:51:04 -08:00
|
|
|
auto choices = prop.GetChoices();
|
|
|
|
|
for (size_t i = 0; i < choices.size(); ++i) {
|
2021-06-06 16:13:58 -07:00
|
|
|
if (!choices[i].empty()) {
|
2024-05-12 06:25:42 -07:00
|
|
|
wpi::print("\n {}: {}", i, choices[i]);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2016-12-22 20:51:04 -08:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-06-06 16:13:58 -07:00
|
|
|
std::fputc('\n', stdout);
|
2016-12-22 20:51:04 -08:00
|
|
|
}
|
|
|
|
|
}
|