3333#include " qhyimagingworker.h"
3434#include < chrono>
3535#include " c++/stlutils.h"
36+ #include " qhycontrol.h"
3637#include < boost/lexical_cast.hpp>
3738
3839using namespace std ;
@@ -45,10 +46,8 @@ DPTR_IMPL(QHYCCDImager) {
4546 QHYCCDImager *q;
4647 qhyccd_handle *handle;
4748 Properties chip;
48- Controls controls;
49+ QList<QHYControl::ptr> controls;
4950 QHYImagingWorker::ptr imaging_worker;
50- void load_controls ();
51- void load (Control &setting);
5251};
5352
5453
@@ -63,9 +62,6 @@ QHYCCDImager::QHYCCDImager(const QString &cameraName, const char *id, const Imag
6362 QHY_CHECK << InitQHYCCD (d->handle ) << " Initializing Camera %1" _q % cameraName;
6463 qDebug () << " camera initialized" ;
6564 uint8_t buffer[1024 ];
66- // Not implemented in QHY Library
67- // GetQHYCCDCFWStatus(d->handle, buf);
68- // qDebug() << "firmware status: " << QByteArray{buf};
6965 QHY_CHECK << GetQHYCCDFWVersion (d->handle , buffer) << " Getting firmware version" ;
7066 qDebug () << " firmware version: " << QString::fromLocal8Bit (reinterpret_cast <const char *>(buffer));
7167 double chipwidth, chipheight, pixelwidth, pixelheight;
@@ -75,10 +71,8 @@ QHYCCDImager::QHYCCDImager(const QString &cameraName, const char *id, const Imag
7571 d->chip << Properties::Property{" bpp" , bpp};
7672 d->chip << LiveStream;
7773 qDebug () << d->chip ;
78- d->load_controls ();
79- qDebug () << d->controls ;
74+ d->controls = QHYControl::availableControls (d->handle );
8075 qDebug () << " Finished initializing QHY camera" << d->name ;
81- // GetQHYCCDCameraStatus(d->handle, st); // NOT IMPLEMENTED IN QHY Library
8276}
8377
8478
@@ -99,93 +93,25 @@ QString QHYCCDImager::name() const
9993 return d->name ;
10094}
10195
102- QList< QHYCCDImager ::Control > QHYCCDImager::controls () const
96+ QList<Imager ::Control> QHYCCDImager::controls () const
10397{
104- return d->controls ;
105- }
106-
107- void QHYCCDImager::Private::load_controls ()
108- {
109- controls.clear ();
110- static QList<QPair<QString,CONTROL_ID>>qhy_controls{
111- { " control_brightness" , CONTROL_BRIGHTNESS },
112- { " control_contrast" , CONTROL_CONTRAST },
113- { " control_wbr" , CONTROL_WBR },
114- { " control_wbb" , CONTROL_WBB },
115- { " control_wbg" , CONTROL_WBG },
116- { " control_gamma" , CONTROL_GAMMA },
117- { " control_gain" , CONTROL_GAIN },
118- { " control_offset" , CONTROL_OFFSET },
119- { " control_exposure" , CONTROL_EXPOSURE },
120- { " control_speed" , CONTROL_SPEED },
121- { " control_transferbit" , CONTROL_TRANSFERBIT },
122- { " control_channels" , CONTROL_CHANNELS },
123- { " control_usbtraffic" , CONTROL_USBTRAFFIC },
124- { " control_rownoisere" , CONTROL_ROWNOISERE },
125- { " control_curtemp" , CONTROL_CURTEMP },
126- { " control_curpwm" , CONTROL_CURPWM },
127- { " control_manulpwm" , CONTROL_MANULPWM },
128- { " control_cfwport" , CONTROL_CFWPORT },
129- { " control_cooler" , CONTROL_COOLER },
130- { " control_st4port" , CONTROL_ST4PORT },
131- { " cam_color" , CAM_COLOR },
132- { " cam_bin1x1mode" , CAM_BIN1X1MODE },
133- { " cam_bin2x2mode" , CAM_BIN2X2MODE },
134- { " cam_bin3x3mode" , CAM_BIN3X3MODE },
135- { " cam_bin4x4mode" , CAM_BIN4X4MODE },
136- { " CAM_MECHANICALSHUTTER" , CAM_MECHANICALSHUTTER },
137- { " CAM_TRIGER_INTERFACE" , CAM_TRIGER_INTERFACE },
138- { " CAM_TECOVERPROTECT_INTERFACE" , CAM_TECOVERPROTECT_INTERFACE },
139- { " CAM_SINGNALCLAMP_INTERFACE" , CAM_SINGNALCLAMP_INTERFACE },
140- { " CAM_FINETONE_INTERFACE" , CAM_FINETONE_INTERFACE },
141- { " CAM_SHUTTERMOTORHEATING_INTERFACE" , CAM_SHUTTERMOTORHEATING_INTERFACE },
142- { " CAM_CALIBRATEFPN_INTERFACE" , CAM_CALIBRATEFPN_INTERFACE },
143- { " CAM_CHIPTEMPERATURESENSOR_INTERFACE" , CAM_CHIPTEMPERATURESENSOR_INTERFACE },
144- { " CAM_USBREADOUTSLOWEST_INTERFACE" , CAM_USBREADOUTSLOWEST_INTERFACE },
145- };
146- for (auto qhy_control: qhy_controls) {
147- try {
148- QHY_CHECK << IsQHYCCDControlAvailable (handle, qhy_control.second ) << GuLinux::stringbuilder () << " checking control availability for control " << qhy_control.second ;
149- double min, max, step;
150- QHY_CHECK << GetQHYCCDParamMinMaxStep (handle, qhy_control.second , &min, &max, &step) << GuLinux::stringbuilder () << " checking control range for control " << qhy_control.second ;
151-
152- if (qhy_control.second == CONTROL_GAIN)
153- step /= 10 .;
154- auto control = Control{qhy_control.second , qhy_control.first }.set_range (min, max, step);
155- if (control.id == CONTROL_TRANSFERBIT ) {
156- qDebug () << " Changing transferbit setting for " << q->name () << id;
157- control.type = Control::Combo;
158- control.add_choice (" 8" , 8 ).add_choice (" 16" , 16 );
159- }
160- if (control.id == CONTROL_EXPOSURE) {
161- control.is_duration = true ;
162- control.duration_unit = 1us;
163- control.set_is_exposure (true );
164- }
165- load (control);
166- // setting.value = GetQHYCCDParam(handle, control.second);
167- qDebug () << control;
168- controls << control;
169- } catch (const QHYException &e) {
170- qWarning () << e.what ();
171- }
172- }
173- }
174-
175- void QHYCCDImager::Private::load ( QHYCCDImager::Control& setting )
176- {
177- setting.value = GetQHYCCDParam (handle, static_cast <CONTROL_ID>(setting.id ));
98+ QList< Imager::Control > controls;
99+ transform (begin (d->controls ), end (d->controls ), back_inserter (controls), [](const auto &c) { return c->control (); });
100+ return controls;
178101}
179102
180103
181- void QHYCCDImager::setControl (const QHYCCDImager ::Control& setting )
104+ void QHYCCDImager::setControl (const Imager ::Control& control )
182105{
106+ auto qhyControlIt = find_if (begin (d->controls ), end (d->controls ), [&](const auto &c) { return c->id () == control.id ; });
107+ if (qhyControlIt == end (d->controls ))
108+ // TODO: error check?
109+ return ;
110+ auto qhyControl = *qhyControlIt;
183111 wait_for (push_job_on_thread ([=]{
184- QHY_CHECK << SetQHYCCDParam (d->handle , static_cast <CONTROL_ID>(setting.id ), setting.value .toDouble ()) << " Setting control " << setting.name << " to value " << setting.value .toDouble ();
185- Control &setting_ref = *find_if (begin (d->controls ), end (d->controls ), [setting](const Control &s) { return s.id == setting.id ; });
186- d->load (setting_ref);
187- qDebug () << " setting" << setting.name << " updated to value" << setting_ref.value ;
188- emit changed (setting_ref);
112+ qhyControl->setValue (control.value .toDouble ());
113+ qhyControl->reload ();
114+ emit changed (qhyControl->control ());
189115 }));
190116}
191117
0 commit comments