Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ROI/Bin settings #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/ZwoCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,17 @@ class lima::Zwo::Camera

HwBufferCtrlObj *getBufferCtrlObj();

bool hasHwBinning(void);

private:
class _AcqThread;

friend class _AcqThread;

bool hasCooler(void);

bool isHwBinningEnabled(void);

private:
ASI_IMG_TYPE m_imageType;

Expand Down
Empty file modified sdk/include/ASICamera2.h
100755 → 100644
Empty file.
87 changes: 61 additions & 26 deletions src/ZwoCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void ::lima::Zwo::Camera::_AcqThread::threadFunction()
}

lima::Zwo::Camera::Camera(int id)
: m_imageType(ASI_IMG_END)
: m_imageType(ASI_IMG_RAW16)
, m_bin(1)
, m_cooler(false)
, m_quit(false)
Expand All @@ -122,46 +122,45 @@ lima::Zwo::Camera::Camera(int id)
, m_acq_thread_run(false)
{
DEB_CONSTRUCTOR();
m_controlCaps.clear();
int nCam = ASIGetNumOfConnectedCameras();
m_asiCameraInfo.CameraID = -1;
ASI_ERROR_CODE err = ASIOpenCamera(id);
ASI_ERROR_CODE err = ASIGetCameraProperty(&m_asiCameraInfo, id);
if (err == ASI_SUCCESS)
{
err = ASIGetCameraProperty(&m_asiCameraInfo, id);
m_cooler = m_asiCameraInfo.IsCoolerCam || std::string(m_asiCameraInfo.Name).find("-Cool") != std::string::npos;
err = ASIOpenCamera(id);
if (err == ASI_SUCCESS)
{
m_cooler = m_asiCameraInfo.IsCoolerCam || std::string(m_asiCameraInfo.Name).find("-Cool") != std::string::npos;
err = ASIInitCamera(id);
if (err == ASI_SUCCESS)
{
m_asiCameraInfo.CameraID = id;
int nCtrls = 0;
err = ASIGetNumOfControls(id, &nCtrls);
m_controlCaps.clear();
if (err == ASI_SUCCESS)
{
ASI_CONTROL_CAPS controlCaps;
DEB_WARNING() << "USB3 : " << isUsb3Camera();
for (int i = 0; i < nCtrls; i++)
for (int i = 0; i < ASI_ANTI_DEW_HEATER + 1 /* nCtrls */; i++)
{
ASIGetControlCaps(id, i, &controlCaps);
DEB_WARNING() << controlCaps.ControlType << " :" << controlCaps.Name << " :" << controlCaps.Description;
DEB_WARNING() << controlCaps.MinValue << "-" << controlCaps.MaxValue << ":" << controlCaps.DefaultValue;
if (controlCaps.ControlType == ASI_HARDWARE_BIN)
enableHwBinning(true);
if (ASIGetControlCaps(id, i, &controlCaps) != ASI_SUCCESS)
continue;
DEB_WARNING() << controlCaps.ControlType << ": " << controlCaps.Name << ": " << controlCaps.Description;
DEB_WARNING() << " " << controlCaps.MinValue << "-" << controlCaps.MaxValue << ": default = " << controlCaps.DefaultValue;
m_controlCaps.push_back(controlCaps);
}
getTemperature();
struct timespec t = {0, 70000000}; // 70 ms
// this sleep is needed to initialize the temperature sensor in the lib
nanosleep(&t, &t);
if (ASI_SUCCESS == ASISetROIFormat(id, m_asiCameraInfo.MaxWidth / m_bin, m_asiCameraInfo.MaxHeight / m_bin, m_bin, m_imageType))
{
setImageType(Bpp16);
if (hasHwBinning())
enableHwBinning(true);
}
}
else
DEB_ERROR() << "err : " << errorText(err);
int width,
height;
err = ASIGetROIFormat(id, &width, &height, &m_bin, &m_imageType);
setImageType(Bpp16);
}
}
}
Expand All @@ -172,6 +171,15 @@ lima::Zwo::Camera::Camera(int id)
m_acq_thread->start();
}


bool lima::Zwo::Camera::hasHwBinning(void)
{
ASI_CONTROL_CAPS ccap = getControlCap(ASI_HARDWARE_BIN);
// Disable the hardware binning for now. The new setting of the ROI due to change of binning won't work
// correctly. The values will not be given back to the framework
return false and ccap.ControlType == ASI_HARDWARE_BIN;
}

lima::Zwo::Camera::~Camera()
{
DEB_DESTRUCTOR();
Expand All @@ -180,7 +188,6 @@ lima::Zwo::Camera::~Camera()
ASI_ERROR_CODE err = ASICloseCamera(id());
if (err != ASI_SUCCESS)
DEB_ERROR() << "Could not close camera: " << errorText(err);
m_asiCameraInfo.CameraID = -1;
}
m_quit = true;
}
Expand Down Expand Up @@ -227,7 +234,7 @@ lima::HwInterface::StatusType lima::Zwo::Camera::getStatus(void)
status.set(lima::HwInterface::StatusType::Ready);
if (id() != -1)
{
ASI_EXPOSURE_STATUS expStatus;
ASI_EXPOSURE_STATUS expStatus(ASI_EXP_IDLE);
if (ASIGetExpStatus(id(), &expStatus) == ASI_SUCCESS)
{
switch (expStatus)
Expand Down Expand Up @@ -418,6 +425,26 @@ void lima::Zwo::Camera::enableHwBinning(const bool enable)
DEB_ERROR() << "No camera available";
}

bool lima::Zwo::Camera::isHwBinningEnabled(void)
{
long enabled(false);
DEB_MEMBER_FUNCT();
if (id() != -1)
{
ASI_BOOL bAuto = ASI_FALSE;
ASI_ERROR_CODE err = ASIGetControlValue(id(), ASI_HARDWARE_BIN, &enabled, &bAuto);
if (err != ASI_SUCCESS)
{
DEB_ERROR() << "Could not get hardware binning: " << errorText(err);
}
}
else
DEB_ERROR() << "No camera available";
DEB_RETURN() << DEB_VAR1(enabled);
return bool(enabled);
}


void lima::Zwo::Camera::setBin(const Bin &bin)
{
DEB_MEMBER_FUNCT();
Expand All @@ -428,9 +455,14 @@ void lima::Zwo::Camera::setBin(const Bin &bin)
}
else if (id() != -1)
{
Bin cBin = getBin(); // get current bin
Roi cRoi = getRoi(); // get current roi

int width = m_asiCameraInfo.MaxWidth / bin.getX(),
height = m_asiCameraInfo.MaxHeight / bin.getY();
Roi roi(0, 0, width, height);
height = m_asiCameraInfo.MaxHeight / bin.getY(),
x = cRoi.getTopLeft().x * cBin.getX() / bin.getX(),
y = cRoi.getTopLeft().y * cBin.getY() / bin.getY();
Roi roi(x, y, width, height);
checkRoi(roi, roi);
width = roi.getSize().getWidth();
height = roi.getSize().getHeight();
Expand Down Expand Up @@ -486,8 +518,11 @@ void lima::Zwo::Camera::checkRoi(const Roi &set_roi, Roi &hw_roi)
{
int x = s.getWidth(),
y = s.getHeight();
x -= (x % 8);
y -= (y % 8);
if (isHwBinningEnabled())
{
x -= (x % 8);
y -= (y % 2);
}
if (x > hwSize().getWidth())
{
x = hwSize().getWidth();
Expand Down Expand Up @@ -519,13 +554,13 @@ void lima::Zwo::Camera::setRoi(const Roi &roi)
{
Size s = roi.getSize();
// 0 values in width and/or height will be interpreted as maximum values of the camera
if (!s.getWidth() || !s.getHeight())
if (s.isEmpty())
{
DEB_TRACE() << "Roi size is: " << s;
if (!s.getWidth())
s = Point(hwSize().getWidth(), s.getHeight());
s = Point(hwSize().getWidth() / m_bin, s.getHeight());
if (!s.getHeight())
s = Point(s.getWidth(), hwSize().getHeight());
s = Point(s.getWidth(), hwSize().getHeight() / m_bin);
DEB_TRACE() << "Roi size changed to: " << s;
}
status = ASISetROIFormat(id(), s.getWidth(), s.getHeight(), m_bin, m_imageType);
Expand Down
3 changes: 2 additions & 1 deletion src/ZwoInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ lima::Zwo::Interface::Interface(Camera &cam)
{
DEB_CONSTRUCTOR();

m_cap_list.push_back(HwCap(&m_bin));
if (m_cam.hasHwBinning())
m_cap_list.push_back(HwCap(&m_bin));
m_cap_list.push_back(HwCap(&m_det_info));
m_cap_list.push_back(HwCap(&m_flip));
m_cap_list.push_back(HwCap(&m_roi));
Expand Down