Skip to content
This repository was archived by the owner on Oct 10, 2022. It is now read-only.

Commit 06a59f4

Browse files
committed
Move temperature checking into main thread, fixes #12. Please test and confirm
1 parent eabeefd commit 06a59f4

7 files changed

Lines changed: 32 additions & 26 deletions

File tree

src/drivers/imager.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ void Imager::destroy()
101101
d->destroyed = true;
102102
}
103103

104+
void Imager::readTemperature()
105+
{
106+
}
107+
104108
void Imager::restart(const ImagerThread::Worker::factory& worker)
105109
{
106110
LOG_F_SCOPE

src/drivers/imager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public slots:
6363
void import_controls(const QVariantList &controls, bool by_id = true);
6464
virtual void startLive() = 0;
6565
virtual void destroy();
66+
virtual void readTemperature();
6667
signals:
6768
void fps(double rate);
6869
void temperature(double celsius);

src/drivers/simulator/simulatorimager.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ using namespace GuLinux;
3333
typedef QMap<QString, Imager::Control> SimulatorSettings;
3434
class SimulatorImagerWorker;
3535
DPTR_IMPL(SimulatorImager) {
36-
unique_ptr<QTimer> refresh_temperature;
3736
SimulatorSettings settings;
3837
shared_ptr<SimulatorImagerWorker> worker;
3938

@@ -58,7 +57,7 @@ class SimulatorImagerWorker : public ImagerThread::Worker {
5857

5958
Q_DECLARE_METATYPE(SimulatorImagerWorker::ImageType)
6059

61-
SimulatorImager::SimulatorImager(const ImageHandler::ptr& handler) : Imager(handler), dptr(make_unique<QTimer>())
60+
SimulatorImager::SimulatorImager(const ImageHandler::ptr& handler) : Imager(handler), dptr()
6261
{
6362
d->roi_validator = make_shared<ROIValidator>(list<ROIValidator::Rule>{
6463
ROIValidator::x_multiple(2),
@@ -81,13 +80,6 @@ SimulatorImager::SimulatorImager(const ImageHandler::ptr& handler) : Imager(hand
8180
{"max_speed", Control{8l, "max_speed", Control::Bool}.set_value(false) },
8281
};
8382
qDebug() << "Max speed: " << d->settings["max_speed"];
84-
connect(d->refresh_temperature.get(), &QTimer::timeout, this, [this]{
85-
push_job_on_thread([&]{
86-
double celsius = SimulatorImager::rand(200, 500) / 10.;
87-
emit temperature(celsius);
88-
});
89-
});
90-
d->refresh_temperature->start(2000);
9183
}
9284

9385
SimulatorImager::~SimulatorImager()
@@ -124,6 +116,14 @@ void SimulatorImager::setControl(const Imager::Control& setting)
124116
}));
125117
}
126118

119+
void SimulatorImager::readTemperature()
120+
{
121+
push_job_on_thread([&]{
122+
double celsius = SimulatorImager::rand(200, 500) / 10.;
123+
emit temperature(celsius);
124+
});
125+
}
126+
127127
Imager::Controls SimulatorImager::controls() const
128128
{
129129
return d->settings.values();

src/drivers/simulator/simulatorimager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public slots:
3838
void setROI(const QRect &) override;
3939
void clearROI() override;
4040
void setControl(const Control& setting) override;
41+
void readTemperature() override;
4142
private:
4243
DPTR
4344
};

src/drivers/zwo_asi/zwo_asi_imager.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ const int64_t BinControlID = 10001;
4949

5050
DPTR_IMPL(ZWO_ASI_Imager) {
5151
ASI_CAMERA_INFO info;
52-
shared_ptr<QTimer> reload_temperature_timer;
5352
ZWO_ASI_Imager *q;
5453

5554
Properties properties;
@@ -61,25 +60,14 @@ DPTR_IMPL(ZWO_ASI_Imager) {
6160
ROIValidator::ptr roi_validator;
6261
QRect maxROI(int bin) const;
6362
void restart_worker(int bin, const QRect &roi, ASI_IMG_TYPE format);
64-
void read_temperature();
6563
void update_worker_exposure_timeout();
6664
ASI_IMG_TYPE format() { return worker.expired() ? ASI_IMG_END : worker.lock()->format(); }
6765
int bin() { return worker.expired() ? -1 : worker.lock()->bin(); }
6866
QRect roi() { return worker.expired() ? QRect{} : worker.lock()->roi(); }
6967
};
7068

71-
void ZWO_ASI_Imager::Private::read_temperature() {
72-
qDebug() << "Refreshing ASI_TEMPERATURE if found..";
73-
if(temperature_control)
74-
q->push_job_on_thread([=]{
75-
emit q->temperature(temperature_control->reload().control().value.toDouble());
76-
});
77-
}
78-
79-
8069

81-
82-
ZWO_ASI_Imager::ZWO_ASI_Imager(const ASI_CAMERA_INFO &info, const ImageHandler::ptr &imageHandler) : Imager{imageHandler}, dptr(info, make_shared<QTimer>(), this)
70+
ZWO_ASI_Imager::ZWO_ASI_Imager(const ASI_CAMERA_INFO &info, const ImageHandler::ptr &imageHandler) : Imager{imageHandler}, dptr(info, this)
8371
{
8472
d->roi_validator = make_shared<ROIValidator>(initializer_list<ROIValidator::Rule>{
8573
ROIValidator::x_multiple(2),
@@ -109,8 +97,6 @@ ZWO_ASI_Imager::ZWO_ASI_Imager(const ASI_CAMERA_INFO &info, const ImageHandler::
10997
d->properties << LiveStream << ROI << Temperature;
11098
ASI_CHECK << ASIOpenCamera(info.CameraID) << "Open Camera";
11199
ASI_CHECK << ASIInitCamera(info.CameraID) << "Init Camera";
112-
connect(d->reload_temperature_timer.get(), &QTimer::timeout, this, bind(&Private::read_temperature, d.get() ));
113-
d->reload_temperature_timer->start(5000);
114100
connect(this, &Imager::exposure_changed, this, bind(&Private::update_worker_exposure_timeout, d.get()));
115101
}
116102

@@ -121,10 +107,17 @@ ZWO_ASI_Imager::~ZWO_ASI_Imager()
121107
void ZWO_ASI_Imager::destroy() {
122108
Imager::destroy();
123109
d->worker.reset();
124-
d->reload_temperature_timer->stop();
125110
ASI_CHECK << ASICloseCamera(d->info.CameraID) << "Close Camera";
126111
}
127112

113+
void ZWO_ASI_Imager::readTemperature() {
114+
qDebug() << "Refreshing ASI_TEMPERATURE if found..";
115+
if(d->temperature_control)
116+
push_job_on_thread([=]{
117+
emit temperature(d->temperature_control->reload().control().value.toDouble());
118+
});
119+
}
120+
128121
Imager::Properties ZWO_ASI_Imager::properties() const
129122
{
130123
return d->properties;

src/drivers/zwo_asi/zwo_asi_imager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public slots:
3636
void startLive() override;
3737
void setROI(const QRect &) override;
3838
void clearROI() override;
39-
virtual void destroy();
39+
void destroy() override;
40+
void readTemperature() override;
4041
private:
4142
DPTR
4243
};

src/planetaryimager_mainwindow.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,12 @@ PlanetaryImagerMainWindow::PlanetaryImagerMainWindow(
353353
d->imageHandler = ImageHandler::ptr{new ThreadImageHandler{compositeImageHandler}};
354354
d->editROIDialog = new EditROIDialog(this);
355355
connect(d->editROIDialog, &EditROIDialog::roiSelected, this, [=](const QRect &roi){ d->imager->setROI(roi); });
356+
auto readTemperature = new QTimer{this};
357+
connect(readTemperature, &QTimer::timeout, this, [=] {
358+
if(d->imager)
359+
QMetaObject::invokeMethod(d->imager, "readTemperature", Qt::QueuedConnection);
360+
});
361+
readTemperature->start(2000);
356362
}
357363

358364
void PlanetaryImagerMainWindow::closeEvent(QCloseEvent* event)

0 commit comments

Comments
 (0)