mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
SCRIPT namespace replacements
This commit is contained in:
committed by
Peter Johnson
parent
ae6c043632
commit
9aca8e0fd6
@@ -18,11 +18,11 @@
|
||||
#include "wpi/util/json.hpp"
|
||||
#include "wpi/util/timestamp.h"
|
||||
|
||||
using namespace cs;
|
||||
using namespace wpi::cs;
|
||||
|
||||
static constexpr size_t kMaxImagesAvail = 32;
|
||||
|
||||
SourceImpl::SourceImpl(std::string_view name, wpi::Logger& logger,
|
||||
SourceImpl::SourceImpl(std::string_view name, wpi::util::Logger& logger,
|
||||
Notifier& notifier, Telemetry& telemetry)
|
||||
: m_logger(logger),
|
||||
m_notifier(notifier),
|
||||
@@ -50,7 +50,7 @@ void SourceImpl::SetDescription(std::string_view description) {
|
||||
}
|
||||
|
||||
std::string_view SourceImpl::GetDescription(
|
||||
wpi::SmallVectorImpl<char>& buf) const {
|
||||
wpi::util::SmallVectorImpl<char>& buf) const {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
buf.append(m_description.begin(), m_description.end());
|
||||
return {buf.data(), buf.size()};
|
||||
@@ -94,7 +94,7 @@ Frame SourceImpl::GetNextFrame(double timeout, Frame::Time lastFrameTime) {
|
||||
if (!m_frameCv.wait_for(
|
||||
lock, std::chrono::milliseconds(static_cast<int>(timeout * 1000)),
|
||||
[=, this] { return m_frame.GetTime() != lastFrameTime; })) {
|
||||
m_frame = Frame{*this, "timed out getting frame", wpi::Now(),
|
||||
m_frame = Frame{*this, "timed out getting frame", wpi::util::Now(),
|
||||
WPI_TIMESRC_UNKNOWN};
|
||||
}
|
||||
return m_frame;
|
||||
@@ -179,10 +179,10 @@ bool SourceImpl::SetFPS(int fps, CS_Status* status) {
|
||||
}
|
||||
|
||||
bool SourceImpl::SetConfigJson(std::string_view config, CS_Status* status) {
|
||||
wpi::json j;
|
||||
wpi::util::json j;
|
||||
try {
|
||||
j = wpi::json::parse(config);
|
||||
} catch (const wpi::json::parse_error& e) {
|
||||
j = wpi::util::json::parse(config);
|
||||
} catch (const wpi::util::json::parse_error& e) {
|
||||
SWARNING("SetConfigJson: parse error at byte {}: {}", e.byte, e.what());
|
||||
*status = CS_PROPERTY_WRITE_FAILED;
|
||||
return false;
|
||||
@@ -190,34 +190,34 @@ bool SourceImpl::SetConfigJson(std::string_view config, CS_Status* status) {
|
||||
return SetConfigJson(j, status);
|
||||
}
|
||||
|
||||
bool SourceImpl::SetConfigJson(const wpi::json& config, CS_Status* status) {
|
||||
bool SourceImpl::SetConfigJson(const wpi::util::json& config, CS_Status* status) {
|
||||
VideoMode mode;
|
||||
|
||||
// pixel format
|
||||
if (config.count("pixel format") != 0) {
|
||||
try {
|
||||
auto str = config.at("pixel format").get<std::string>();
|
||||
if (wpi::equals_lower(str, "mjpeg")) {
|
||||
mode.pixelFormat = cs::VideoMode::kMJPEG;
|
||||
} else if (wpi::equals_lower(str, "yuyv")) {
|
||||
mode.pixelFormat = cs::VideoMode::kYUYV;
|
||||
} else if (wpi::equals_lower(str, "rgb565")) {
|
||||
mode.pixelFormat = cs::VideoMode::kRGB565;
|
||||
} else if (wpi::equals_lower(str, "bgr")) {
|
||||
mode.pixelFormat = cs::VideoMode::kBGR;
|
||||
} else if (wpi::equals_lower(str, "bgra")) {
|
||||
mode.pixelFormat = cs::VideoMode::kBGRA;
|
||||
} else if (wpi::equals_lower(str, "gray")) {
|
||||
mode.pixelFormat = cs::VideoMode::kGray;
|
||||
} else if (wpi::equals_lower(str, "y16")) {
|
||||
mode.pixelFormat = cs::VideoMode::kY16;
|
||||
} else if (wpi::equals_lower(str, "uyvy")) {
|
||||
mode.pixelFormat = cs::VideoMode::kUYVY;
|
||||
if (wpi::util::equals_lower(str, "mjpeg")) {
|
||||
mode.pixelFormat = wpi::cs::VideoMode::kMJPEG;
|
||||
} else if (wpi::util::equals_lower(str, "yuyv")) {
|
||||
mode.pixelFormat = wpi::cs::VideoMode::kYUYV;
|
||||
} else if (wpi::util::equals_lower(str, "rgb565")) {
|
||||
mode.pixelFormat = wpi::cs::VideoMode::kRGB565;
|
||||
} else if (wpi::util::equals_lower(str, "bgr")) {
|
||||
mode.pixelFormat = wpi::cs::VideoMode::kBGR;
|
||||
} else if (wpi::util::equals_lower(str, "bgra")) {
|
||||
mode.pixelFormat = wpi::cs::VideoMode::kBGRA;
|
||||
} else if (wpi::util::equals_lower(str, "gray")) {
|
||||
mode.pixelFormat = wpi::cs::VideoMode::kGray;
|
||||
} else if (wpi::util::equals_lower(str, "y16")) {
|
||||
mode.pixelFormat = wpi::cs::VideoMode::kY16;
|
||||
} else if (wpi::util::equals_lower(str, "uyvy")) {
|
||||
mode.pixelFormat = wpi::cs::VideoMode::kUYVY;
|
||||
} else {
|
||||
SWARNING("SetConfigJson: could not understand pixel format value '{}'",
|
||||
str);
|
||||
}
|
||||
} catch (const wpi::json::exception& e) {
|
||||
} catch (const wpi::util::json::exception& e) {
|
||||
SWARNING("SetConfigJson: could not read pixel format: {}", e.what());
|
||||
}
|
||||
}
|
||||
@@ -226,7 +226,7 @@ bool SourceImpl::SetConfigJson(const wpi::json& config, CS_Status* status) {
|
||||
if (config.count("width") != 0) {
|
||||
try {
|
||||
mode.width = config.at("width").get<unsigned int>();
|
||||
} catch (const wpi::json::exception& e) {
|
||||
} catch (const wpi::util::json::exception& e) {
|
||||
SWARNING("SetConfigJson: could not read width: {}", e.what());
|
||||
}
|
||||
}
|
||||
@@ -235,7 +235,7 @@ bool SourceImpl::SetConfigJson(const wpi::json& config, CS_Status* status) {
|
||||
if (config.count("height") != 0) {
|
||||
try {
|
||||
mode.height = config.at("height").get<unsigned int>();
|
||||
} catch (const wpi::json::exception& e) {
|
||||
} catch (const wpi::util::json::exception& e) {
|
||||
SWARNING("SetConfigJson: could not read height: {}", e.what());
|
||||
}
|
||||
}
|
||||
@@ -244,7 +244,7 @@ bool SourceImpl::SetConfigJson(const wpi::json& config, CS_Status* status) {
|
||||
if (config.count("fps") != 0) {
|
||||
try {
|
||||
mode.fps = config.at("fps").get<unsigned int>();
|
||||
} catch (const wpi::json::exception& e) {
|
||||
} catch (const wpi::util::json::exception& e) {
|
||||
SWARNING("SetConfigJson: could not read fps: {}", e.what());
|
||||
}
|
||||
}
|
||||
@@ -258,9 +258,9 @@ bool SourceImpl::SetConfigJson(const wpi::json& config, CS_Status* status) {
|
||||
mode.pixelFormat, mode.width, mode.height, mode.fps);
|
||||
SetVideoMode(mode, status);
|
||||
} else {
|
||||
if (mode.pixelFormat != cs::VideoMode::kUnknown) {
|
||||
if (mode.pixelFormat != wpi::cs::VideoMode::kUnknown) {
|
||||
SINFO("SetConfigJson: setting pixelFormat {}", mode.pixelFormat);
|
||||
SetPixelFormat(static_cast<cs::VideoMode::PixelFormat>(mode.pixelFormat),
|
||||
SetPixelFormat(static_cast<wpi::cs::VideoMode::PixelFormat>(mode.pixelFormat),
|
||||
status);
|
||||
}
|
||||
if (mode.width != 0 && mode.height != 0) {
|
||||
@@ -280,7 +280,7 @@ bool SourceImpl::SetConfigJson(const wpi::json& config, CS_Status* status) {
|
||||
int val = config.at("brightness").get<int>();
|
||||
SINFO("SetConfigJson: setting brightness to {}", val);
|
||||
SetBrightness(val, status);
|
||||
} catch (const wpi::json::exception& e) {
|
||||
} catch (const wpi::util::json::exception& e) {
|
||||
SWARNING("SetConfigJson: could not read brightness: {}", e.what());
|
||||
}
|
||||
}
|
||||
@@ -291,10 +291,10 @@ bool SourceImpl::SetConfigJson(const wpi::json& config, CS_Status* status) {
|
||||
auto& setting = config.at("white balance");
|
||||
if (setting.is_string()) {
|
||||
auto str = setting.get<std::string>();
|
||||
if (wpi::equals_lower(str, "auto")) {
|
||||
if (wpi::util::equals_lower(str, "auto")) {
|
||||
SINFO("SetConfigJson: setting white balance to {}", "auto");
|
||||
SetWhiteBalanceAuto(status);
|
||||
} else if (wpi::equals_lower(str, "hold")) {
|
||||
} else if (wpi::util::equals_lower(str, "hold")) {
|
||||
SINFO("SetConfigJson: setting white balance to {}", "hold current");
|
||||
SetWhiteBalanceHoldCurrent(status);
|
||||
} else {
|
||||
@@ -307,7 +307,7 @@ bool SourceImpl::SetConfigJson(const wpi::json& config, CS_Status* status) {
|
||||
SINFO("SetConfigJson: setting white balance to {}", val);
|
||||
SetWhiteBalanceManual(val, status);
|
||||
}
|
||||
} catch (const wpi::json::exception& e) {
|
||||
} catch (const wpi::util::json::exception& e) {
|
||||
SWARNING("SetConfigJson: could not read white balance: {}", e.what());
|
||||
}
|
||||
}
|
||||
@@ -318,10 +318,10 @@ bool SourceImpl::SetConfigJson(const wpi::json& config, CS_Status* status) {
|
||||
auto& setting = config.at("exposure");
|
||||
if (setting.is_string()) {
|
||||
auto str = setting.get<std::string>();
|
||||
if (wpi::equals_lower(str, "auto")) {
|
||||
if (wpi::util::equals_lower(str, "auto")) {
|
||||
SINFO("SetConfigJson: setting exposure to {}", "auto");
|
||||
SetExposureAuto(status);
|
||||
} else if (wpi::equals_lower(str, "hold")) {
|
||||
} else if (wpi::util::equals_lower(str, "hold")) {
|
||||
SINFO("SetConfigJson: setting exposure to {}", "hold current");
|
||||
SetExposureHoldCurrent(status);
|
||||
} else {
|
||||
@@ -333,7 +333,7 @@ bool SourceImpl::SetConfigJson(const wpi::json& config, CS_Status* status) {
|
||||
SINFO("SetConfigJson: setting exposure to {}", val);
|
||||
SetExposureManual(val, status);
|
||||
}
|
||||
} catch (const wpi::json::exception& e) {
|
||||
} catch (const wpi::util::json::exception& e) {
|
||||
SWARNING("SetConfigJson: could not read exposure: {}", e.what());
|
||||
}
|
||||
}
|
||||
@@ -348,14 +348,14 @@ bool SourceImpl::SetConfigJson(const wpi::json& config, CS_Status* status) {
|
||||
|
||||
std::string SourceImpl::GetConfigJson(CS_Status* status) {
|
||||
std::string rv;
|
||||
wpi::raw_string_ostream os(rv);
|
||||
wpi::util::raw_string_ostream os(rv);
|
||||
GetConfigJsonObject(status).dump(os, 4);
|
||||
os.flush();
|
||||
return rv;
|
||||
}
|
||||
|
||||
wpi::json SourceImpl::GetConfigJsonObject(CS_Status* status) {
|
||||
wpi::json j;
|
||||
wpi::util::json SourceImpl::GetConfigJsonObject(CS_Status* status) {
|
||||
wpi::util::json j;
|
||||
|
||||
// pixel format
|
||||
std::string_view pixelFormat;
|
||||
@@ -409,7 +409,7 @@ wpi::json SourceImpl::GetConfigJsonObject(CS_Status* status) {
|
||||
// TODO: output brightness, white balance, and exposure?
|
||||
|
||||
// properties
|
||||
wpi::json props = GetPropertiesJsonObject(status);
|
||||
wpi::util::json props = GetPropertiesJsonObject(status);
|
||||
if (props.is_array()) {
|
||||
j.emplace("properties", props);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user