forked from OpenPHDGuiding/phd2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cam_INovaPLC.cpp
171 lines (152 loc) · 5.45 KB
/
cam_INovaPLC.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
/*
* cam_INovaPLC.cpp
* PHD Guiding
*
* Created by Craig Stark.
* Copyright (c) 2012 Craig Stark.
* 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 Craig Stark, Stark Labs 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"
#if defined (INOVA_PLC)
#include "camera.h"
#include "image_math.h"
#include "cam_INovaPLC.h"
#include "DSCAMAPI.h"
CameraINovaPLC::CameraINovaPLC()
{
Connected = FALSE;
Name=_T("i-Nova PLC-M");
FullSize = wxSize(1280,1024); // Current size of a full frame
m_hasGuideOutput = true; // Do we have an ST4 port?
HasGainControl = true; // Can we adjust gain?
}
wxByte CameraINovaPLC::BitsPerPixel()
{
return 16;
}
bool CameraINovaPLC::Connect(const wxString& camId)
{
DS_CAMERA_STATUS rval = DSCameraInit(R_FULL);
if (rval != STATUS_OK)
return CamConnectFailed(wxString::Format(_("Error on connection: %d"), rval));
DSCameraSetDataWide(true);
DSCameraSetAeState(false); // Turn off auto-exposure
DSCameraGetRowTime(&RowTime); // Figure the row-time in microseconds -- this lets me figure the actual exp time
RawData = new unsigned short[1280*1024];
Connected = true; // Set global flag for being connected
return false;
}
void CameraINovaPLC::InitCapture()
{
// Run after any exp change / at the start of a loop
DS_CAMERA_STATUS rval;
int ExpDur = pFrame->RequestedExposureDuration();
int exp_lines = ExpDur * 1000 / RowTime;
rval = DSCameraSetExposureTime(exp_lines);
wxMilliSleep(100);
if (rval != STATUS_OK)
pFrame->Alert(_("Error setting exposure duration"));
rval = DSCameraSetAnalogGain(GuideCameraGain);
wxMilliSleep(100);
if (rval != STATUS_OK)
pFrame->Alert(_("Error setting gain"));
}
bool CameraINovaPLC::ST4PulseGuideScope(int direction, int duration)
{
unsigned char dircode = 0;
/*Param: Value bit0 - RA+
bit1 - DEC+
bit2 - DEC-
bit3 - RA-*/
switch (direction) {
case WEST:
dircode = 0x01;
break;
case NORTH:
dircode = 0x02;
break;
case SOUTH:
dircode = 0x04;
break;
case EAST:
dircode = 0x08;
break;
default: return true; // bad direction passed in
}
DSCameraSetGuidingPort(dircode);
WorkerThread::MilliSleep(duration);
DSCameraSetGuidingPort(0);
return false;
}
bool CameraINovaPLC::Disconnect()
{
Connected = false;
DSCameraUnInit();
delete [] RawData;
return false;
}
bool CameraINovaPLC::Capture(int duration, usImage& img, int options, const wxRect& subframe)
{
int xsize = FullSize.GetWidth();
int ysize = FullSize.GetHeight();
DS_CAMERA_STATUS rval;
int ntries = 1;
if (img.Init(FullSize)) {
DisconnectWithAlert(CAPT_FAIL_MEMORY);
return true;
}
int ExpDur = pFrame->RequestedExposureDuration();
if (duration != ExpDur) { // reset the exp time - and pause -- we have had a change here from the current value
rval = DSCameraSetExposureTime(ExpDur * 1000 / RowTime);
wxMilliSleep(100);
}
rval = DSCameraGrabFrame((BYTE *) RawData);
while (rval != STATUS_OK) {
ntries++;
rval = DSCameraGrabFrame((BYTE *) RawData);
//pFrame->StatusMsg(wxString::Format("%d %d",ntries,rval));
if (ntries > 30) {
pFrame->Alert("Timeout capturing frames - >30 bad in a row");
return true;
}
}
for (unsigned int i = 0; i <xsize*ysize; i++) {
img.ImageData[i] = (RawData[i]>> 8) | (RawData[i] << 8);
}
if (options & CAPTURE_SUBTRACT_DARK) SubtractDark(img);
return false;
}
bool CameraINovaPLC::HasNonGuiCapture(void)
{
return true;
}
bool CameraINovaPLC::ST4HasNonGuiMove(void)
{
return true;
}
#endif // INOVA_PLC