mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-18 01:45:10 +03:00
cam: Allow selecting cameras by index
As camera names can be cumbersome to type, selection of cameras by index from a list can be useful. Print the list of detected cameras with an index for each item, and interpret the camera name as an index if it is a numerical value in the range from 1 to the number of cameras. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
parent
b2b3599b5b
commit
c6090542cd
1 changed files with 15 additions and 4 deletions
|
@ -73,7 +73,14 @@ int CamApp::init(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options_.isSet(OptCamera)) {
|
if (options_.isSet(OptCamera)) {
|
||||||
camera_ = cm_->get(options_[OptCamera]);
|
const std::string &cameraName = options_[OptCamera];
|
||||||
|
char *endptr;
|
||||||
|
unsigned long index = strtoul(cameraName.c_str(), &endptr, 10);
|
||||||
|
if (*endptr == '\0' && index > 0 && index <= cm_->cameras().size())
|
||||||
|
camera_ = cm_->cameras()[index - 1];
|
||||||
|
else
|
||||||
|
camera_ = cm_->get(cameraName);
|
||||||
|
|
||||||
if (!camera_) {
|
if (!camera_) {
|
||||||
std::cout << "Camera "
|
std::cout << "Camera "
|
||||||
<< std::string(options_[OptCamera])
|
<< std::string(options_[OptCamera])
|
||||||
|
@ -141,7 +148,7 @@ int CamApp::parseOptions(int argc, char *argv[])
|
||||||
|
|
||||||
OptionsParser parser;
|
OptionsParser parser;
|
||||||
parser.addOption(OptCamera, OptionString,
|
parser.addOption(OptCamera, OptionString,
|
||||||
"Specify which camera to operate on", "camera",
|
"Specify which camera to operate on, by name or by index", "camera",
|
||||||
ArgumentRequired, "camera");
|
ArgumentRequired, "camera");
|
||||||
parser.addOption(OptCapture, OptionNone,
|
parser.addOption(OptCapture, OptionNone,
|
||||||
"Capture until interrupted by user", "capture");
|
"Capture until interrupted by user", "capture");
|
||||||
|
@ -172,8 +179,12 @@ int CamApp::run()
|
||||||
{
|
{
|
||||||
if (options_.isSet(OptList)) {
|
if (options_.isSet(OptList)) {
|
||||||
std::cout << "Available cameras:" << std::endl;
|
std::cout << "Available cameras:" << std::endl;
|
||||||
for (const std::shared_ptr<Camera> &cam : cm_->cameras())
|
|
||||||
std::cout << "- " << cam->name() << std::endl;
|
unsigned int index = 1;
|
||||||
|
for (const std::shared_ptr<Camera> &cam : cm_->cameras()) {
|
||||||
|
std::cout << index << ": " << cam->name() << std::endl;
|
||||||
|
index++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options_.isSet(OptCapture)) {
|
if (options_.isSet(OptCapture)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue