Overview
Slc is a C++ software controller for Stingray SWIR lenses. The library implements the Lens interface and adds advanced autofocus features. All required libraries are bundled in the repository: Lens (interface and data structures), Logger (logging helpers), SerialPort (serial communication), StingrayParser (command encoder/decoder) and AFEngine (autofocus algorithms). The Slc API is straightforward to integrate into existing C++ projects. All dependencies ship with the source tree, so no additional packages need to be installed. The codebase targets the C++17 standard and supports Linux and Windows.
Documentation
Documentation: GO TO DOCUMENTATION
Lens control interface
class Slc : public Lens
{
public:
/// Class constructor.
Slc();
/// Class destructor.
~Slc();
/// Get class version.
static std::string getVersion();
/// Open serial port.
bool openLens(std::string initString) override;
/// Init lens controller.
bool initLens(LensParams& params) override;
/// Close serial port and stop communication thread.
void closeLens() override;
/// Get controller initialization status.
bool isLensOpen() override;
/// Get connection status.
bool isLensConnected() override;
/// Set the lens controller parameter.
bool setParam(LensParam id, float value) override;
/// Get the lens controller param.
float getParam(LensParam id) override;
/// Get the lens controller params.
void getParams(LensParams& params) override;
/// Execute command.
bool executeCommand(LensCommand id, float arg = 0) override;
/// Add video frame for auto focus purposes.
void addVideoFrame(cr::video::Frame& frame) override;
/// Decode and execute command.
bool decodeAndExecuteCommand(uint8_t* data, int size) override;
};
Simple example
#include <chrono>
#include <iostream>
#include <string>
#include <thread>
#include "Slc.h"
int main(void)
{
// Init lens controller.
cr::lens::Lens* lc = new cr::lens::Slc();
if (!lc->openLens("/dev/ttyUSB0"))
return -1;
// Get lens Zoom position
std:: cout<< "Zoom pos: " <<
lc->getParam(cr::lens::LensParam::ZOOM_POS) << std::endl;
// Set Zoom speed to 10%.
lc->setParam(cr::lens::LensParam::ZOOM_SPEED, 10);
// Go to zoom position 65535 (Full tele).
lc->executeCommand(cr::lens::LensCommand::ZOOM_TO_POS, 65535);
// Show zoom movement (changing position).
for (int i = 0; i < 50; ++i)
{
std:: cout<< "Zoom pos: " <<
lc->getParam(cr::lens::LensParam::ZOOM_POS) << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
return 1;
}

