diff --git a/uvoscam.cpp b/uvoscam.cpp index 06020a2..f4cc11f 100644 --- a/uvoscam.cpp +++ b/uvoscam.cpp @@ -138,7 +138,7 @@ void Camera::aCallback(void* instance, int type, ArvBuffer *buffer) Camera* instance_ = reinterpret_cast(instance); if(type == ARV_STREAM_CALLBACK_TYPE_BUFFER_DONE) { - if(instance_->run) + if(instance_->run && instance_->aqmode != MODE_DISCARD) { gint inBuffers; gint outBuffers; @@ -147,8 +147,6 @@ void Camera::aCallback(void* instance, int type, ArvBuffer *buffer) std::unique_lock decodeBufferMutexLock(instance_->decodeBufferMutex); instance_->decodeBuffer = arv_stream_pop_buffer(instance_->aStream_); instance_->bufferCondition.notify_all(); - if(instance_->aqmode == MODE_SINGLE) - instance_->run = false; } else { @@ -194,13 +192,25 @@ bool Camera::chooseFormat() bool Camera::setupCamera() { + GError* error = nullptr; + bool doubleRate = arv_camera_is_feature_available(aCamera_, "DoubleRate_Enable", &error); + if(!error && doubleRate) + { + Log(Log::INFO)<<"Disable broken PhotonFocus DoubleRate implementation"; + arv_device_set_boolean_feature_value(arv_camera_get_device(aCamera_), "DoubleRate_Enable", false, &error); + if(error) + { + Log(Log::ERROR)<<"Failed to disable DoubleRate\n"; + return false; + } + } + if(!chooseFormat()) { Log(Log::ERROR)<<"Camera provides no supported pixel format"; return false; } - GError* error = nullptr; gint ymin, ymax; arv_camera_get_height_bounds(aCamera_, &ymin, &ymax, &error); if(error) @@ -253,18 +263,6 @@ bool Camera::setupCamera() } Log(Log::DEBUG)<<"Binning: "<<(binning ? "yes" : "no"); - bool doubleRate = arv_camera_is_feature_available(aCamera_, "DoubleRate_Enable", &error); - if(!error && doubleRate) - { - Log(Log::INFO)<<"Disable broken PhotonFocus DoubleRate implementation"; - arv_device_set_boolean_feature_value(arv_camera_get_device(aCamera_), "DoubleRate_Enable", false, &error); - if(error) - { - Log(Log::ERROR)<<"Failed to disable DoubleRate\n"; - return false; - } - } - decoderThread = new std::thread([this](){decoderThreadFunc();}); Log(Log::DEBUG)<<"Using "<(us), &error); + if(error) + Log(Log::WARN)<message; + return !error; } @@ -402,6 +406,8 @@ uint64_t Camera::getExposureTime() { GError* error = nullptr; double ret = arv_camera_get_exposure_time(aCamera_, &error); + if(error) + Log(Log::WARN)<message; return !error ? static_cast(ret) : 0; } @@ -409,6 +415,8 @@ double Camera::getFrameRate() { GError* error = nullptr; double ret = arv_camera_get_frame_rate(aCamera_, &error); + if(error) + Log(Log::WARN)<message; return !error ? ret : -1; } @@ -416,6 +424,8 @@ bool Camera::setFrameRate(double rate) { GError* error = nullptr; arv_camera_set_frame_rate(aCamera_, rate, &error); + if(error) + Log(Log::WARN)<message; return !error; } @@ -424,13 +434,61 @@ int64_t Camera::getPixelFormat() return static_cast(format); } +double Camera::getGain() +{ + GError* error = nullptr; + double gain = arv_camera_get_gain(aCamera_, &error); + if(error) + { + Log(Log::WARN)<message; + return -1; + } + return gain; +} + +bool Camera::setGain(double gain) +{ + GError* error = nullptr; + arv_camera_set_gain(aCamera_, gain, &error); + if(error) + Log(Log::WARN)<message; + return !error; +} + +bool Camera::getExposureTimeLimits(uint64_t& min, uint64_t& max) +{ + double minD = 0; + double maxD = 0; + GError* error; + arv_camera_get_exposure_time_bounds(aCamera_, &minD, &maxD, &error); + if(error) + Log(Log::WARN)<message; + min = static_cast(minD); + max = static_cast(maxD); + return !error; +} + +bool Camera::hasExposureAuto() +{ + GError* error = nullptr; + bool ret = arv_camera_is_exposure_auto_available(aCamera_, &error); + if(error) + { + Log(Log::WARN)<message; + return false; + } + return ret; +} + bool Camera::setExposureAuto(bool enable) { - if(!arv_camera_is_exposure_auto_available(aCamera_, nullptr)) + if(!hasExposureAuto()) return false; GError* error = nullptr; arv_camera_set_exposure_time(aCamera_, enable ? ARV_AUTO_CONTINUOUS : ARV_AUTO_OFF, &error); + if(error) + Log(Log::WARN)<message; return !error; } @@ -439,7 +497,14 @@ bool Camera::startAcquisition() GError* error = nullptr; arv_camera_start_acquisition(aCamera_, &error); if(!error) + { + aqRunning = true; run = true; + } + else + { + Log(Log::WARN)<message; + } return !error; } @@ -448,7 +513,12 @@ bool Camera::stopAcquisition() GError* error = nullptr; arv_camera_stop_acquisition(aCamera_, &error); if(!error) + { + aqRunning = false; run = false; + } + else + Log(Log::WARN)<message; return !error; } @@ -501,6 +571,7 @@ Camera::Description Camera::getDescription() description->model = arv_camera_get_model_name(aCamera_, &error); if(error) { + Log(Log::WARN)<message; delete description; description = nullptr; } diff --git a/uvoscam.h b/uvoscam.h index 0bfd215..50e93b8 100644 --- a/uvoscam.h +++ b/uvoscam.h @@ -82,6 +82,7 @@ public: typedef int AquisitionMode; static constexpr AquisitionMode MODE_FREE = 0; static constexpr AquisitionMode MODE_SINGLE = 1; + static constexpr AquisitionMode MODE_DISCARD = 2; private: ArvStream* aStream_ = nullptr; @@ -108,6 +109,8 @@ private: std::atomic_bool run; AquisitionMode aqmode = MODE_FREE; + int discardCount = 0; + bool aqRunning = false; void decoderThreadFunc(); @@ -132,12 +135,16 @@ public: ~Camera(); bool isOpen(); bool setAcquisitionMode(AquisitionMode mode); + bool setGain(double gain); + double getGain(); bool setExposureTime(uint64_t us); + bool getExposureTimeLimits(uint64_t& min, uint64_t& max); uint64_t getExposureTime(); double getFrameRate(); bool setFrameRate(double rate); int64_t getPixelFormat(); bool setExposureAuto(bool enable); + bool hasExposureAuto(); bool startAcquisition(); bool stopAcquisition(); void getSize(unsigned int* x, unsigned int* y);