Skip to content

Instantly share code, notes, and snippets.

@tpickett66
Created December 1, 2022 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tpickett66/7c206bb4f3bdf08f0d3c2df39e1ac817 to your computer and use it in GitHub Desktop.
Save tpickett66/7c206bb4f3bdf08f0d3c2df39e1ac817 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <unistd.h>
#include <libcamera/camera.h>
#include <libcamera/camera_manager.h>
#include <libcamera/property_ids.h>
using namespace libcamera;
std::string cameraName(const ControlList &props, const std::string cam_id) {
bool addModel = true;
std::string name;
/*
* Construct the name from the camera location, model and ID. The model
* is only used if the location isn't present or is set to External.
*/
const auto &location = props.get(properties::Location);
if (location) {
switch (*location) {
case properties::CameraLocationFront:
addModel = false;
name = "Internal front camera ";
break;
case properties::CameraLocationBack:
addModel = false;
name = "Internal back camera ";
break;
case properties::CameraLocationExternal:
name = "External camera ";
break;
}
}
if (addModel) {
/*
* If the camera location is not availble use the camera model
* to build the camera name.
*/
const auto &model = props.get(properties::Model);
if (model)
name = "'" + *model + "' ";
}
name += "(" + cam_id + ")";
return name;
}
int main(int ac, char *av[]) {
auto cm = std::make_unique<CameraManager>();
int ret = cm->start();
if (ret) {
std::cerr << "libcamera::CameraManager failed to start, code " << std::to_string(-ret) << "\n";
return ret;
}
auto cams = cm->cameras();
std::cout << "Found " << cams.size() << " cameras.\n";
unsigned int index = 1;
for (const std::shared_ptr<libcamera::Camera> &cam : cams) {
const Camera *camera = cam.get();
const ControlList &props = cam->properties();
std::cout << index << ": " << cameraName(props, camera->id()) << std::endl;
ControlList::const_iterator prop;
for (prop = props.begin(); prop != props.end(); prop++) {
const auto id = prop->first;
const auto value = prop->second;
const auto ctrl = properties::properties.at(id);
std::cout << " " << ctrl->name() << ": " << value.toString() << std::endl;
}
index++;
}
cm->stop();
sleep(1);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment