From d1f4d5cb6e2f0a37357a1a2e4dee673a1f02aad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Kr=C3=BCger?= Date: Fri, 14 Apr 2023 21:24:50 +0200 Subject: [PATCH] Fix ROI/Bin settings --- include/ZwoCamera.h | 4 ++ sdk/include/ASICamera2.h | 0 src/ZwoCamera.cpp | 87 ++++++++++++++++++++++++++++------------ src/ZwoInterface.cpp | 3 +- 4 files changed, 67 insertions(+), 27 deletions(-) mode change 100755 => 100644 sdk/include/ASICamera2.h diff --git a/include/ZwoCamera.h b/include/ZwoCamera.h index 304cb50..c7742cd 100644 --- a/include/ZwoCamera.h +++ b/include/ZwoCamera.h @@ -128,6 +128,8 @@ class lima::Zwo::Camera HwBufferCtrlObj *getBufferCtrlObj(); + bool hasHwBinning(void); + private: class _AcqThread; @@ -135,6 +137,8 @@ class lima::Zwo::Camera bool hasCooler(void); + bool isHwBinningEnabled(void); + private: ASI_IMG_TYPE m_imageType; diff --git a/sdk/include/ASICamera2.h b/sdk/include/ASICamera2.h old mode 100755 new mode 100644 diff --git a/src/ZwoCamera.cpp b/src/ZwoCamera.cpp index 107ad85..57ff28e 100644 --- a/src/ZwoCamera.cpp +++ b/src/ZwoCamera.cpp @@ -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) @@ -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); } } } @@ -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(); @@ -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; } @@ -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) @@ -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(); @@ -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(); @@ -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(); @@ -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); diff --git a/src/ZwoInterface.cpp b/src/ZwoInterface.cpp index 3df7c91..efcc267 100644 --- a/src/ZwoInterface.cpp +++ b/src/ZwoInterface.cpp @@ -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));