-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcam_qhy.cpp
711 lines (619 loc) · 21 KB
/
cam_qhy.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
/*
* cam_qhy.cpp
* Open PHD Guiding
*
* Created by Andy Galasso.
* Copyright (c) 2015-2019 Andy Galasso.
* All rights reserved.
*
* This source code is distributed under the following "BSD" license
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of openphdguiding.org nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "phd.h"
#define QHY_CAMERA
#if defined(QHY_CAMERA)
#include "camera.h"
#include "cam_qhy.h"
#include "qhyccd.h"
#include <thread>
#include <iostream>
#include <mutex>
class Camera_QHY : public GuideCamera
{
qhyccd_handle *m_camhandle;
double m_gainMin;
double m_gainMax;
double m_gainStep;
double m_devicePixelSize;
unsigned char *RawBuffer;
wxSize m_maxSize;
int m_curGain;
int m_curExposure;
unsigned short m_curBin;
wxRect m_roi;
bool Color;
wxByte m_bpp;
public:
std::mutex sendMutex;
Camera_QHY();
~Camera_QHY();
bool CanSelectCamera() const override { return true; }
bool EnumCameras(wxArrayString& names, wxArrayString& ids) override;
bool Capture(int duration, usImage& img, int options, const wxRect& subframe) override;
bool Connect(const wxString& camId) override;
bool Disconnect() override;
bool ST4PulseGuideScope(int direction, int duration) override;
bool HasNonGuiCapture() override { return true; }
bool ST4HasNonGuiMove() override { return true; }
wxByte BitsPerPixel() override;
bool GetDevicePixelSize(double *devPixelSize) override;
int GetDefaultCameraGain() override;
};
static bool s_qhySdkInitDone = false;
static wxString GetQHYSDKVersion()
{
#if defined (__APPLE__)
return "V7.4.16.4"; // FIXME - remove this when we update to the newer SDK that implements GetQHYCCDSDKVersion
#else
uint32_t YMDS[4] = {};
GetQHYCCDSDKVersion(&YMDS[0], &YMDS[1], &YMDS[2], &YMDS[3]);
return wxString::Format("V20%02d%02d%02d_%d", YMDS[0], YMDS[1], YMDS[2], YMDS[3]);
#endif
}
static bool QHYSDKInit()
{
DEBUG_INFO("QHYSDKInit");
if (s_qhySdkInitDone)
return false;
Debug.Write(wxString::Format("QHYCCD: SDK Version %s\n", GetQHYSDKVersion()));
// setup log file (stdout), and log level (0..6) from
// QHY_LOG_LEVEL environment variable
uint8_t lvl = 0;
wxString s;
long ll;
if (wxGetEnv("QHY_LOG_LEVEL", &s) && s.ToLong(&ll))
lvl = static_cast<uint8_t>(std::min(std::max(ll, 0L), 6L));
#if !defined(__WINDOWS__)
EnableQHYCCDLogFile(false);
#endif
SetQHYCCDLogLevel(lvl);
uint32_t ret;
if ((ret = InitQHYCCDResource()) != 0)
{
Debug.Write(wxString::Format("InitQHYCCDResource failed: %d\n", (int)ret));
return true;
}
#if defined (__APPLE__)
Debug.Write("QHY: call OSXInitQHYCCDFirmwareArray()\n");
ret = OSXInitQHYCCDFirmwareArray();
Debug.Write(wxString::Format("QHY: OSXInitQHYCCDFirmwareArray() returns %d\n", ret));
if (ret == 0)
{
// firmware download succeeded, try scanning for cameras until they show up
for (unsigned int i = 0; i < 10; i++)
{
int num_cams = ScanQHYCCD();
Debug.Write(wxString::Format("QHY: found %d cameras\n", num_cams));
if (num_cams > 0)
break;
WorkerThread::MilliSleep(500);
}
}
// non-zero result indicates camera already has firmware
#endif
s_qhySdkInitDone = true;
return false;
}
static void QHYSDKUninit()
{
DEBUG_INFO("QHYSDKUnInit");
if (s_qhySdkInitDone)
{
ReleaseQHYCCDResource();
s_qhySdkInitDone = false;
}
}
Camera_QHY::Camera_QHY()
{
DEBUG_INFO("Camera_QHY::Camera_QHY()");
Connected = false;
m_hasGuideOutput = true;
HasGainControl = true;
RawBuffer = 0;
Color = false;
m_bpp = 8; // actual value will be determined when camera is connected
HasSubframes = true;
m_camhandle = 0;
}
Camera_QHY::~Camera_QHY()
{
delete[] RawBuffer;
QHYSDKUninit();
}
wxByte Camera_QHY::BitsPerPixel()
{
return m_bpp;
}
bool Camera_QHY::GetDevicePixelSize(double *devPixelSize)
{
if (!Connected)
return true;
*devPixelSize = m_devicePixelSize;
return false;
}
int Camera_QHY::GetDefaultCameraGain()
{
enum { DefaultQHYCameraGain = 40 };
return DefaultQHYCameraGain;
}
bool Camera_QHY::EnumCameras(wxArrayString& names, wxArrayString& ids)
{
DEBUG_INFO("EnumCameras");
if (QHYSDKInit())
return true;
int num_cams = ScanQHYCCD();
Debug.Write(wxString::Format("QHY: found %d cameras\n", num_cams));
int n = 1;
for (int i = 0; i < num_cams; i++)
{
char camid[32] = "";
GetQHYCCDId(i, camid);
bool st4 = false;
qhyccd_handle *h = OpenQHYCCD(camid);
if (h)
{
uint32_t ret = IsQHYCCDControlAvailable(h, CONTROL_ST4PORT);
if (ret == QHYCCD_SUCCESS)
st4 = true;
//CloseQHYCCD(h); // CloseQHYCCD() would proform a reset, so the other software that use QHY camera would be impacted.
// Do not call this,would not cause memory leak.The SDk has already process this.
}
Debug.Write(wxString::Format("QHY cam [%d] %s avail %s st4 %s\n", i, camid, h ? "Yes" : "No", st4 ? "Yes" : "No"));
if (st4)
{
names.Add(wxString::Format("%d: %s", n, camid));
ids.Add(camid);
++n;
}
}
return false;
}
bool Camera_QHY::Connect(const wxString& camId)
{
if (QHYSDKInit())
{
return CamConnectFailed(_("Failed to initialize QHY SDK"));
}
std::string qid;
std::string xxx_camId = std::string(camId.ToStdString());
DEBUG_INFO("%s",xxx_camId.c_str());
if (camId == DEFAULT_CAMERA_ID)
{
DEBUG_INFO("camId == DEFAULT_CAMERA_ID: yes");
wxArrayString names, ids;
EnumCameras(names, ids);
if (ids.size() == 0)
{
return CamConnectFailed(_("No compatible QHY cameras found"));
}
qid = ids[0];
}
else
{
// scanning for cameras is required, otherwise OpenQHYCCD will fail
DEBUG_INFO("camId == DEFAULT_CAMERA_ID: no");
int num_cams = ScanQHYCCD();
Debug.Write(wxString::Format("QHY: found %d cameras\n", num_cams));
qid = camId;
}
char *s = new char[qid.length() + 1];
memcpy(s, qid.c_str(), qid.length() + 1);
DEBUG_INFO("%s",s);
m_camhandle = OpenQHYCCD(s);
delete[] s;
Name = qid;
if (!m_camhandle)
return CamConnectFailed(_("Failed to connect to camera"));
// before calling InitQHYCCD() we must call SetQHYCCDStreamMode(camhandle, 0 or 1)
// 0: single frame mode
// 1: live frame mode
uint32_t ret = SetQHYCCDStreamMode(m_camhandle, 0);
if (ret != QHYCCD_SUCCESS)
{
CloseQHYCCD(m_camhandle);
m_camhandle = 0;
return CamConnectFailed(_("SetQHYCCDStreamMode failed"));
}
ret = InitQHYCCD(m_camhandle);
if (ret != QHYCCD_SUCCESS)
{
CloseQHYCCD(m_camhandle);
m_camhandle = 0;
return CamConnectFailed(_("Init camera failed"));
}
ret = GetQHYCCDParamMinMaxStep(m_camhandle, CONTROL_GAIN, &m_gainMin, &m_gainMax, &m_gainStep);
if (ret != QHYCCD_SUCCESS)
{
CloseQHYCCD(m_camhandle);
m_camhandle = 0;
return CamConnectFailed(_("Failed to get gain range"));
}
double chipw, chiph, pixelw, pixelh;
uint32_t imagew, imageh, bpp;
ret = GetQHYCCDChipInfo(m_camhandle, &chipw, &chiph, &imagew, &imageh, &pixelw, &pixelh, &bpp);
if (ret != QHYCCD_SUCCESS)
{
CloseQHYCCD(m_camhandle);
m_camhandle = 0;
return CamConnectFailed(_("Failed to get camera chip info"));
}
Debug.Write(wxString::Format("QHY: cam reports BPP = %u\n", bpp));
m_bpp = bpp <= 8 ? 8 : 16;
int bayer = IsQHYCCDControlAvailable(m_camhandle, CAM_COLOR);
Debug.Write(wxString::Format("QHY: cam reports bayer type %d\n", bayer));
Color = false;
switch ((BAYER_ID)bayer) {
case BAYER_GB:
case BAYER_GR:
case BAYER_BG:
case BAYER_RG:
Color = true;
}
// check bin modes
CONTROL_ID modes[] = { CAM_BIN2X2MODE, CAM_BIN3X3MODE, CAM_BIN4X4MODE, };
int bin[] = { 2, 3, 4, };
int maxBin = 1;
for (int i = 0; i < WXSIZEOF(modes); i++)
{
ret = IsQHYCCDControlAvailable(m_camhandle, modes[i]);
#if 0
// FIXME- IsQHYCCDControlAvailable is supposed to return QHYCCD_ERROR_NOTSUPPORT for a
// bin mode that is not supported, but in fact it returns QHYCCD_ERROR, so we cannot
// distinguish "not supported" from "error".
if (ret != QHYCCD_SUCCESS && ret != QHYCCD_ERROR_NOTSUPPORT)
{
CloseQHYCCD(m_camhandle);
m_camhandle = 0;
return CamConnectFailed(_("Failed to get camera bin info"));
}
#endif
if (ret == QHYCCD_SUCCESS)
maxBin = bin[i];
else
break;
}
Debug.Write(wxString::Format("QHY: max binning = %d\n", maxBin));
MaxBinning = maxBin;
if (Binning > MaxBinning)
Binning = MaxBinning;
Debug.Write(wxString::Format("QHY: call SetQHYCCDBinMode bin = %d\n", Binning));
ret = SetQHYCCDBinMode(m_camhandle, Binning, Binning);
if (ret != QHYCCD_SUCCESS)
{
CloseQHYCCD(m_camhandle);
m_camhandle = 0;
return CamConnectFailed(_("Failed to set camera binning"));
}
m_curBin = Binning;
m_maxSize = wxSize(imagew, imageh);
FullSize = wxSize(imagew / Binning, imageh / Binning);
delete[] RawBuffer;
size_t size = GetQHYCCDMemLength(m_camhandle);
RawBuffer = new unsigned char[size];
m_devicePixelSize = sqrt(pixelw * pixelh);
m_curGain = -1;
m_curExposure = -1;
m_roi = wxRect(0, 0, FullSize.GetWidth(), FullSize.GetHeight()); // binned coordinates
Debug.Write(wxString::Format("QHY: call SetQHYCCDResolution roi = %d,%d\n", m_roi.width, m_roi.height));
ret = SetQHYCCDResolution(m_camhandle, 0, 0, m_roi.GetWidth(), m_roi.GetHeight());
if (ret != QHYCCD_SUCCESS)
{
CloseQHYCCD(m_camhandle);
m_camhandle = 0;
return CamConnectFailed(_("Init camera failed"));
}
Debug.Write(wxString::Format("QHY: connect done\n"));
Connected = true;
return false;
}
static void StopCapture(qhyccd_handle *handle)
{
uint32_t ret = CancelQHYCCDExposingAndReadout(handle);
if (ret != QHYCCD_SUCCESS)
Debug.Write(wxString::Format("QHY: CancelQHYCCDExposingAndReadout returns status %u\n", ret));
}
bool Camera_QHY::Disconnect()
{
StopCapture(m_camhandle);
#if !defined(__APPLE__)
// this crashes on macOS, but seems to work ok without it
CloseQHYCCD(m_camhandle);
#endif
m_camhandle = 0;
Connected = false;
delete[] RawBuffer;
RawBuffer = 0;
return false;
}
bool Camera_QHY::ST4PulseGuideScope(int direction, int duration)
{
uint32_t qdir;
DEBUG_INFO("ST4PulseGuideScope_SDK %d,%d",direction,duration);
std::lock_guard<std::mutex> lock(sendMutex);
// 记录开始时间点
auto startTime = std::chrono::steady_clock::now();
// 循环等待直到 ControlStatus 变为 0 或超过 5 秒
while (pFrame->ControlStatus != 0)
{
// 计算经过的时间
auto currentTime = std::chrono::steady_clock::now();
auto elapsedTime = std::chrono::duration_cast<std::chrono::seconds>(currentTime - startTime).count();
// 如果超过 5 秒,强制将 ControlStatus 设置为 0
if (elapsedTime >= 5)
{
pFrame->ControlStatus = 0;
break; // 跳出循环
}
DEBUG_INFO("ST4PulseGuideScope_SDK_Status %d",pFrame->ControlStatus);
// 添加适当的延迟
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
DEBUG_INFO("ST4PulseGuideScope_SDK_Status %d",pFrame->ControlStatus);
pFrame->sdk_direction=direction;
pFrame->sdk_duration=duration;
unsigned int mem_offset=1024;
mem_offset=mem_offset+sizeof(unsigned int);
mem_offset=mem_offset+sizeof(unsigned int);
mem_offset=mem_offset+sizeof(unsigned char);
int ControlInstruct = (pFrame->ControlNum << 24) | (pFrame->sdk_direction << 12) | pFrame->sdk_duration;
memcpy(pFrame->qBuffer+mem_offset,&ControlInstruct,sizeof(int));
mem_offset=mem_offset+sizeof(int);
pFrame->getTimeNow(pFrame->ControlNum);
DEBUG_INFO("ST4PulseGuideScope_SDK %d,%d,%d",pFrame->ControlNum,direction,duration);
pFrame->ControlNum++;
pFrame->ControlStatus = 1;
switch (direction)
{
case NORTH: qdir = 1; break;
case SOUTH: qdir = 2; break;
case EAST: qdir = 0; break;
case WEST: qdir = 3; break;
default: return true; // bad direction passed in
}
if (duration > (uint16_t) (-1))
duration = (uint16_t) (-1);
ControlQHYCCDGuide(m_camhandle, qdir, static_cast<uint16_t>(duration));
WorkerThread::MilliSleep(duration + 10);
return false;
}
inline static int round_down(int v, int m)
{
return v & ~(m - 1);
}
inline static int round_up(int v, int m)
{
return round_down(v + m - 1, m);
}
// stopping capture causes problems on some cameras on Windows, disable it for now until we can test with a newer SDK
//#define CAN_STOP_CAPTURE
bool Camera_QHY::Capture(int duration, usImage& img, int options, const wxRect& subframe)
{
bool useSubframe = UseSubframes && !subframe.IsEmpty();
if (Binning != m_curBin)
{
FullSize = wxSize(m_maxSize.GetX() / Binning, m_maxSize.GetY() / Binning);
m_curBin = Binning;
useSubframe = false; // subframe may be out of bounds now
}
if (img.Init(FullSize))
{
DisconnectWithAlert(CAPT_FAIL_MEMORY);
return true;
}
wxRect frame = useSubframe ? subframe : wxRect(FullSize);
if (useSubframe)
img.Clear();
wxRect roi;
if (useSubframe)
{
// Use a larger ROI around the subframe to avoid changing the ROI as the centroid
// wobbles around. Changing the ROI introduces a lag of several seconds.
// This also satifies the constraint that ROI width and height must be multiples of 4.
enum { PAD = 1 << 5 };
roi.SetLeft(round_down(subframe.GetLeft(), PAD));
roi.SetRight(round_up(subframe.GetRight() + 1, PAD) - 1);
roi.SetTop(round_down(subframe.GetTop(), PAD));
roi.SetBottom(round_up(subframe.GetBottom() + 1, PAD) - 1);
}
else
{
roi = frame;
}
uint32_t ret = QHYCCD_ERROR;
// lzr from QHY says this needs to be set for every exposure
ret = SetQHYCCDBinMode(m_camhandle, Binning, Binning);
if (ret != QHYCCD_SUCCESS)
{
Debug.Write(wxString::Format("SetQHYCCDBinMode failed! ret = %d\n", (int)ret));
}
if (m_roi != roi)
{
// when roi changes, must call this
ret = CancelQHYCCDExposingAndReadout(m_camhandle);
if (ret == QHYCCD_SUCCESS)
{
Debug.Write("CancelQHYCCDExposingAndReadout success\n");
}
else
{
Debug.Write("CancelQHYCCDExposingAndReadout failed\n");
}
ret = SetQHYCCDResolution(m_camhandle, roi.GetLeft(), roi.GetTop(), roi.GetWidth(), roi.GetHeight());
if (ret == QHYCCD_SUCCESS)
{
m_roi = roi;
}
else
{
Debug.Write(wxString::Format("SetQHYCCDResolution(%d,%d,%d,%d) failed! ret = %d\n",
roi.GetLeft(), roi.GetTop(), roi.GetWidth(), roi.GetHeight(), (int)ret));
}
}
if (duration != m_curExposure)
{
ret = SetQHYCCDParam(m_camhandle, CONTROL_EXPOSURE, duration * 1000.0); // QHY duration is usec
if (ret == QHYCCD_SUCCESS)
{
m_curExposure = duration;
}
else
{
Debug.Write(wxString::Format("QHY set exposure ret %d\n", (int)ret));
pFrame->Alert(_("Failed to set camera exposure"));
}
}
if (GuideCameraGain != m_curGain)
{
double gain = m_gainMin + GuideCameraGain * (m_gainMax - m_gainMin) / 100.0;
gain = floor(gain / m_gainStep) * m_gainStep;
Debug.Write(wxString::Format("QHY set gain %g (%g..%g incr %g)\n", gain, m_gainMin, m_gainMax, m_gainStep));
ret = SetQHYCCDParam(m_camhandle, CONTROL_GAIN, gain);
if (ret == QHYCCD_SUCCESS)
{
m_curGain = GuideCameraGain;
}
else
{
Debug.Write(wxString::Format("QHY set gain ret %d\n", (int)ret));
pFrame->Alert(_("Failed to set camera gain"));
}
}
ret = ExpQHYCCDSingleFrame(m_camhandle);
if (ret == QHYCCD_ERROR)
{
Debug.Write(wxString::Format("QHY exp single frame ret %d\n", (int)ret));
DisconnectWithAlert(_("QHY exposure failed"), NO_RECONNECT);
return true;
}
#ifdef CAN_STOP_CAPTURE
if (WorkerThread::InterruptRequested())
{
StopCapture(m_camhandle);
return true;
}
#endif
if (ret == QHYCCD_SUCCESS)
{
Debug.Write(wxString::Format("QHY: 200ms delay needed\n"));
WorkerThread::MilliSleep(200);
}
if (ret == QHYCCD_READ_DIRECTLY)
{
//Debug.Write("QHYCCD_READ_DIRECTLY\n");
}
uint32_t w, h, bpp, channels;
ret = GetQHYCCDSingleFrame(m_camhandle, &w, &h, &bpp, &channels, RawBuffer);
if (ret != QHYCCD_SUCCESS || (bpp != 8 && bpp != 16))
{
Debug.Write(wxString::Format("QHY get single frame ret %d bpp %u\n", ret, bpp));
#ifdef CAN_STOP_CAPTURE
StopCapture(m_camhandle);
#endif
// users report that reconnecting the camera after this failure allows
// them to resume guiding so we'll try to reconnect automatically
DisconnectWithAlert(_("QHY get frame failed"), RECONNECT);
return true;
}
#ifdef CAN_STOP_CAPTURE
if (WorkerThread::InterruptRequested())
{
StopCapture(m_camhandle);
return true;
}
#endif
if (useSubframe)
{
img.Subframe = frame;
int xofs = subframe.GetLeft() - roi.GetLeft();
int yofs = subframe.GetTop() - roi.GetTop();
int dxr = w - frame.width - xofs;
if (bpp == 8)
{
const unsigned char *src = RawBuffer + yofs * w;
unsigned short *dst = img.ImageData + frame.GetTop() * FullSize.GetWidth() + frame.GetLeft();
for (int y = 0; y < frame.height; y++)
{
unsigned short *d = dst;
src += xofs;
for (int x = 0; x < frame.width; x++)
*d++ = (unsigned short) *src++;
src += dxr;
dst += FullSize.GetWidth();
}
}
else // bpp == 16
{
const unsigned short *src = (const unsigned short *) RawBuffer + yofs * w;
unsigned short *dst = img.ImageData + frame.GetTop() * FullSize.GetWidth() + frame.GetLeft();
for (int y = 0; y < frame.height; y++)
{
src += xofs;
memcpy(dst, src, frame.width * sizeof(unsigned short));
src += frame.width + dxr;
dst += FullSize.GetWidth();
}
}
}
else
{
if (bpp == 8)
{
const unsigned char *src = RawBuffer;
unsigned short *dst = img.ImageData;
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
*dst++ = (unsigned short) *src++;
}
}
}
else // bpp == 16
{
memcpy(img.ImageData, RawBuffer, w * h * sizeof(unsigned short));
}
}
if (options & CAPTURE_SUBTRACT_DARK)
SubtractDark(img);
if (Color && Binning == 1 && (options & CAPTURE_RECON))
QuickLRecon(img);
return false;
}
GuideCamera *QHYCameraFactory::MakeQHYCamera()
{
DEBUG_INFO("MakeQHYCamera");
return new Camera_QHY();
}
#endif