Update cscore examples for llvm to wpi rename. (#1016)

This commit is contained in:
Peter Johnson
2018-05-02 20:56:55 -07:00
committed by GitHub
parent 1043aef7f7
commit 6a49173cea
3 changed files with 64 additions and 64 deletions

View File

@@ -5,74 +5,74 @@
/* the project. */
/*----------------------------------------------------------------------------*/
#include <llvm/SmallString.h>
#include <llvm/raw_ostream.h>
#include <wpi/SmallString.h>
#include <wpi/raw_ostream.h>
#include "cscore.h"
int main() {
CS_Status status = 0;
llvm::SmallString<64> buf;
wpi::SmallString<64> buf;
for (const auto& caminfo : cs::EnumerateUsbCameras(&status)) {
llvm::outs() << caminfo.dev << ": " << caminfo.path << " (" << caminfo.name
<< ")\n";
wpi::outs() << caminfo.dev << ": " << caminfo.path << " (" << caminfo.name
<< ")\n";
cs::UsbCamera camera{"usbcam", caminfo.dev};
llvm::outs() << "Properties:\n";
wpi::outs() << "Properties:\n";
for (const auto& prop : camera.EnumerateProperties()) {
llvm::outs() << " " << prop.GetName();
wpi::outs() << " " << prop.GetName();
switch (prop.GetKind()) {
case cs::VideoProperty::kBoolean:
llvm::outs() << " (bool): "
<< "value=" << prop.Get()
<< " default=" << prop.GetDefault();
wpi::outs() << " (bool): "
<< "value=" << prop.Get()
<< " default=" << prop.GetDefault();
break;
case cs::VideoProperty::kInteger:
llvm::outs() << " (int): "
<< "value=" << prop.Get() << " min=" << prop.GetMin()
<< " max=" << prop.GetMax() << " step=" << prop.GetStep()
<< " default=" << prop.GetDefault();
wpi::outs() << " (int): "
<< "value=" << prop.Get() << " min=" << prop.GetMin()
<< " max=" << prop.GetMax() << " step=" << prop.GetStep()
<< " default=" << prop.GetDefault();
break;
case cs::VideoProperty::kString:
llvm::outs() << " (string): " << prop.GetString(buf);
wpi::outs() << " (string): " << prop.GetString(buf);
break;
case cs::VideoProperty::kEnum: {
llvm::outs() << " (enum): "
<< "value=" << prop.Get();
wpi::outs() << " (enum): "
<< "value=" << prop.Get();
auto choices = prop.GetChoices();
for (size_t i = 0; i < choices.size(); ++i) {
if (choices[i].empty()) continue;
llvm::outs() << "\n " << i << ": " << choices[i];
wpi::outs() << "\n " << i << ": " << choices[i];
}
break;
}
default:
break;
}
llvm::outs() << '\n';
wpi::outs() << '\n';
}
llvm::outs() << "Video Modes:\n";
wpi::outs() << "Video Modes:\n";
for (const auto& mode : camera.EnumerateVideoModes()) {
llvm::outs() << " PixelFormat:";
wpi::outs() << " PixelFormat:";
switch (mode.pixelFormat) {
case cs::VideoMode::kMJPEG:
llvm::outs() << "MJPEG";
wpi::outs() << "MJPEG";
break;
case cs::VideoMode::kYUYV:
llvm::outs() << "YUYV";
wpi::outs() << "YUYV";
break;
case cs::VideoMode::kRGB565:
llvm::outs() << "RGB565";
wpi::outs() << "RGB565";
break;
default:
llvm::outs() << "Unknown";
wpi::outs() << "Unknown";
break;
}
llvm::outs() << " Width:" << mode.width;
llvm::outs() << " Height:" << mode.height;
llvm::outs() << " FPS:" << mode.fps << '\n';
wpi::outs() << " Width:" << mode.width;
wpi::outs() << " Height:" << mode.height;
wpi::outs() << " FPS:" << mode.fps << '\n';
}
}
}

View File

@@ -8,21 +8,21 @@
#include <chrono>
#include <thread>
#include <llvm/SmallString.h>
#include <llvm/raw_ostream.h>
#include <wpi/SmallString.h>
#include <wpi/raw_ostream.h>
#include "cscore.h"
int main(int argc, char** argv) {
if (argc < 2) {
llvm::errs() << "Usage: settings camera [prop val] ... -- [prop val]...\n";
llvm::errs() << " Example: settings 1 brightness 30 raw_contrast 10\n";
wpi::errs() << "Usage: settings camera [prop val] ... -- [prop val]...\n";
wpi::errs() << " Example: settings 1 brightness 30 raw_contrast 10\n";
return 1;
}
int id;
if (llvm::StringRef{argv[1]}.getAsInteger(10, id)) {
llvm::errs() << "Expected number for camera\n";
if (wpi::StringRef{argv[1]}.getAsInteger(10, id)) {
wpi::errs() << "Expected number for camera\n";
return 2;
}
@@ -30,75 +30,75 @@ int main(int argc, char** argv) {
// Set prior to connect
int arg = 2;
llvm::StringRef propName;
for (; arg < argc && llvm::StringRef{argv[arg]} != "--"; ++arg) {
wpi::StringRef propName;
for (; arg < argc && wpi::StringRef{argv[arg]} != "--"; ++arg) {
if (propName.empty()) {
propName = argv[arg];
} else {
llvm::StringRef propVal{argv[arg]};
wpi::StringRef propVal{argv[arg]};
int intVal;
if (propVal.getAsInteger(10, intVal))
camera.GetProperty(propName).SetString(propVal);
else
camera.GetProperty(propName).Set(intVal);
propName = llvm::StringRef{};
propName = wpi::StringRef{};
}
}
if (arg < argc && llvm::StringRef{argv[arg]} == "--") ++arg;
if (arg < argc && wpi::StringRef{argv[arg]} == "--") ++arg;
// Wait to connect
while (!camera.IsConnected())
std::this_thread::sleep_for(std::chrono::milliseconds(10));
// Set rest
propName = llvm::StringRef{};
propName = wpi::StringRef{};
for (; arg < argc; ++arg) {
if (propName.empty()) {
propName = argv[arg];
} else {
llvm::StringRef propVal{argv[arg]};
wpi::StringRef propVal{argv[arg]};
int intVal;
if (propVal.getAsInteger(10, intVal))
camera.GetProperty(propName).SetString(propVal);
else
camera.GetProperty(propName).Set(intVal);
propName = llvm::StringRef{};
propName = wpi::StringRef{};
}
}
// Print settings
llvm::SmallString<64> buf;
llvm::outs() << "Properties:\n";
wpi::SmallString<64> buf;
wpi::outs() << "Properties:\n";
for (const auto& prop : camera.EnumerateProperties()) {
llvm::outs() << " " << prop.GetName();
wpi::outs() << " " << prop.GetName();
switch (prop.GetKind()) {
case cs::VideoProperty::kBoolean:
llvm::outs() << " (bool): "
<< "value=" << prop.Get()
<< " default=" << prop.GetDefault();
wpi::outs() << " (bool): "
<< "value=" << prop.Get()
<< " default=" << prop.GetDefault();
break;
case cs::VideoProperty::kInteger:
llvm::outs() << " (int): "
<< "value=" << prop.Get() << " min=" << prop.GetMin()
<< " max=" << prop.GetMax() << " step=" << prop.GetStep()
<< " default=" << prop.GetDefault();
wpi::outs() << " (int): "
<< "value=" << prop.Get() << " min=" << prop.GetMin()
<< " max=" << prop.GetMax() << " step=" << prop.GetStep()
<< " default=" << prop.GetDefault();
break;
case cs::VideoProperty::kString:
llvm::outs() << " (string): " << prop.GetString(buf);
wpi::outs() << " (string): " << prop.GetString(buf);
break;
case cs::VideoProperty::kEnum: {
llvm::outs() << " (enum): "
<< "value=" << prop.Get();
wpi::outs() << " (enum): "
<< "value=" << prop.Get();
auto choices = prop.GetChoices();
for (size_t i = 0; i < choices.size(); ++i) {
if (choices[i].empty()) continue;
llvm::outs() << "\n " << i << ": " << choices[i];
wpi::outs() << "\n " << i << ": " << choices[i];
}
break;
}
default:
break;
}
llvm::outs() << '\n';
wpi::outs() << '\n';
}
}

View File

@@ -7,15 +7,15 @@
#include <cstdio>
#include <llvm/raw_ostream.h>
#include <wpi/raw_ostream.h>
#include "cscore.h"
int main() {
llvm::outs() << "hostname: " << cs::GetHostname() << '\n';
llvm::outs() << "IPv4 network addresses:\n";
wpi::outs() << "hostname: " << cs::GetHostname() << '\n';
wpi::outs() << "IPv4 network addresses:\n";
for (const auto& addr : cs::GetNetworkInterfaces())
llvm::outs() << " " << addr << '\n';
wpi::outs() << " " << addr << '\n';
cs::UsbCamera camera{"usbcam", 0};
camera.SetVideoMode(cs::VideoMode::kMJPEG, 320, 240, 30);
cs::MjpegServer mjpegServer{"httpserver", 8081};
@@ -24,9 +24,9 @@ int main() {
CS_Status status = 0;
cs::AddListener(
[&](const cs::RawEvent& event) {
llvm::outs() << "FPS=" << camera.GetActualFPS()
<< " MBPS=" << (camera.GetActualDataRate() / 1000000.0)
<< '\n';
wpi::outs() << "FPS=" << camera.GetActualFPS()
<< " MBPS=" << (camera.GetActualDataRate() / 1000000.0)
<< '\n';
},
cs::RawEvent::kTelemetryUpdated, false, &status);
cs::SetTelemetryPeriod(1.0);