moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kstars / kstars / indi / apogee / CameraIO_Linux.h
blobd6a61e1ca410ea0d6d005e8f5ea234ba084b1c7b
1 // CameraIO.h: interface for the CCameraIO class.
2 //
3 // Copyright (c) 2000 Apogee Instruments Inc.
4 //////////////////////////////////////////////////////////////////////
6 #if !defined(AFX_CAMERAIO_H__A2882C82_7CFB_11D4_9155_0060676644C1__INCLUDED_)
7 #define AFX_CAMERAIO_H__A2882C82_7CFB_11D4_9155_0060676644C1__INCLUDED_
9 #include "Apogee.h"
11 enum Camera_Interface{
12 Camera_Interface_ISA = 0,
13 Camera_Interface_PPI,
14 Camera_Interface_PCI
17 enum Camera_SensorType{
18 Camera_SensorType_CCD = 0,
19 Camera_SensorType_CMOS
22 const long MAXCOLUMNS = 16383;
23 const long MAXROWS = 16383;
24 const long MAXHBIN = 8;
25 const long MAXVBIN = 255;
27 // Number of write only registers
28 const long NumWriteRegisters = 8;
30 const long RegISA_Command = 0x000; // Register 1 in ISA firmware
31 const long Reg_Command = 0; // Register 1 shadow
32 const unsigned short RegBit_TDIMode = 0x1; // Bit 0
33 const unsigned short RegBit_StartTimer = 0x2; // Bit 1
34 const unsigned short RegBit_ShutterOverride = 0x4; // Bit 2
35 const unsigned short RegBit_ResetSystem = 0x8; // Bit 3
36 const unsigned short RegBit_FIFOCache = 0x10; // Bit 4
37 const unsigned short RegBit_TriggerEnable = 0x20; // Bit 5
38 const unsigned short RegBit_StopFlushing = 0x40; // Bit 6
39 const unsigned short RegBit_ShutterEnable = 0x80; // Bit 7
40 const unsigned short RegBit_CoolerShutdown = 0x100; // Bit 8
41 const unsigned short RegBit_DoneReading = 0x200; // Bit 9
42 const unsigned short RegBit_TimerLoad = 0x400; // Bit 10
43 const unsigned short RegBit_StartNextLine = 0x800; // Bit 11
44 const unsigned short RegBit_StartFlushing = 0x1000; // Bit 12
45 const unsigned short RegBit_Focus = 0x2000; // Bit 13
46 const unsigned short RegBit_CableLength = 0x4000; // Bit 14
47 const unsigned short RegBit_CoolerEnable = 0x8000; // Bit 15
49 const long RegISA_Timer = 0x002; // Register 2 in ISA firmware
50 const long Reg_Timer = 1; // Register 2 shadow
51 const unsigned short RegBitShift_Timer = 0; // Bit 0
52 const unsigned short RegBitMask_Timer = 0xFFFF; // 16 bits
54 const long RegISA_VBinning = 0x004; // Register 3 in ISA firmware
55 const long Reg_VBinning = 2; // Register 3 shadow
56 const unsigned short RegBitShift_Timer2 = 0; // Bit 0
57 const unsigned short RegBitMask_Timer2 = 0xF; // 4 bits
58 const unsigned short RegBitShift_VBinning = 0x8; // Bit 8
59 const unsigned short RegBitMask_VBinning = 0xFF; // 8 bits
61 const long RegISA_AICCounter = 0x006; // Register 4 in ISA firmware
62 const long Reg_AICCounter = 3; // Register 4 shadow
63 const unsigned short RegBitShift_AICCounter = 0; // Bit 0
64 const unsigned short RegBitMask_AICCounter = 0xFFF; // 12 bits
65 const unsigned short RegBitShift_Test2 = 0xC; // Bit 12
66 const unsigned short RegBitMask_Test2 = 0xF; // 4 bits
68 const long RegISA_TempSetPoint = 0x008; // Register 5 in ISA firmware
69 const long Reg_TempSetPoint = 4; // Register 5 shadow
70 const unsigned short RegBitShift_TempSetPoint = 0; // Bit 0
71 const unsigned short RegBitMask_TempSetPoint = 0xFF;// 8 bits
72 const unsigned short RegBitShift_PortControl = 0x8; // Bit 8
73 const unsigned short RegBitMask_PortControl = 0xFF; // 8 bits
75 const long RegISA_PixelCounter = 0x00a; // Register 6 in ISA firmware
76 const long Reg_PixelCounter = 5; // Register 6 shadow
77 const unsigned short RegBitShift_PixelCounter = 0; // Bit 0
78 const unsigned short RegBitMask_PixelCounter = 0xFFF; // 12 bits
79 const unsigned short RegBitShift_HBinning = 0xC; // Bit 12
80 const unsigned short RegBitMask_HBinning = 0x7; // 3 bits
81 const unsigned short RegBit_LoopLock = 0x8000; // Bit 15
83 const long RegISA_LineCounter = 0x00c; // Register 7 in ISA firmware
84 const long Reg_LineCounter = 6; // Register 7 shadow
85 const unsigned short RegBitShift_LineCounter = 0; // Bit 0
86 const unsigned short RegBitMask_LineCounter = 0xFFF; // 12 bits
87 const unsigned short RegBitShift_Mode = 0xC; // Bit 12
88 const unsigned short RegBitMask_Mode = 0xF; // 4 bits
90 const long RegISA_BICCounter = 0x00e; // Register 8 in ISA firmware
91 const long Reg_BICCounter = 7; // Register 8 shadow
92 const unsigned short RegBitShift_BICCounter = 0; // Bit 0
93 const unsigned short RegBitMask_BICCounter = 0xFFF; // 12 bits
94 const unsigned short RegBitShift_Test = 0xC; // Bit 12
95 const unsigned short RegBitMask_Test = 0xF; // 4 bits
97 const long RegISA_ImageData = 0x000; // Register 9 in ISA firmware
98 const long Reg_ImageData = 8; // Register 9
99 const unsigned short RegBitShift_ImageData = 0; // Bit 0
100 const unsigned short RegBitMask_ImageData = 0xFFFF; // 16 bits
102 const long RegISA_TempData = 0x002; // Register 10 in ISA firmware
103 const long Reg_TempData = 9; // Register 10
104 const unsigned short RegBitShift_TempData = 0; // Bit 0
105 const unsigned short RegBitMask_TempData = 0xFF; // 8 bits
107 const long RegISA_Status = 0x006; // Register 11 in firmware
108 const long Reg_Status = 10; // Register 11
109 const unsigned short RegBit_Exposing = 0x1; // Bit 0
110 const unsigned short RegBit_LineDone = 0x2; // Bit 1
111 const unsigned short RegBit_CacheReadOK = 0x4; // Bit 2
112 const unsigned short RegBit_TempAtMin = 0x10; // Bit 4
113 const unsigned short RegBit_TempAtMax = 0x20; // Bit 5
114 const unsigned short RegBit_ShutdownComplete = 0x40;// Bit 6
115 const unsigned short RegBit_TempAtSetPoint = 0x80; // Bit 7
116 const unsigned short RegBit_GotTrigger = 0x400; // Bit 10
117 const unsigned short RegBit_FrameDone = 0x800; // Bit 11
118 const unsigned short RegBit_LoopbackTest = 0x8000; // Bit 15
120 const long RegISA_CommandReadback = 0x008; // Register 12 in ISA firmware
121 const long Reg_CommandReadback = 11; // Register 12
122 // Use RegBit offsets from Reg_Command
124 const long RegPCI_Command = 0x000; // Register 1 in PCI firmware
125 const long RegPCI_CommandRead = 0x020;
126 const long RegPCI_Timer = 0x004; // Register 2 in PCI firmware
127 const long RegPCI_TimerRead = 0x024;
128 const long RegPCI_VBinning = 0x008; // Register 3 in PCI firmware
129 const long RegPCI_VBinningRead = 0x028;
130 const long RegPCI_AICCounter = 0x00C; // Register 4 in PCI firmware
131 const long RegPCI_AICCounterRead = 0x02C;
132 const long RegPCI_TempSetPoint = 0x010; // Register 5 in PCI firmware
133 const long RegPCI_TempSetPointRead = 0x030;
134 const long RegPCI_PixelCounter = 0x014; // Register 6 in PCI firmware
135 const long RegPCI_PixelCounterRead = 0x034;
136 const long RegPCI_LineCounter = 0x018; // Register 7 in PCI firmware
137 const long RegPCI_LineCounterRead = 0x038;
138 const long RegPCI_BICCounter = 0x01C; // Register 8 in PCI firmware
139 const long RegPCI_BICCounterRead = 0x03C;
140 const long RegPCI_ImageData = 0x000; // Register 9 in PCI firmware
141 const long RegPCI_TempData = 0x004; // Register 10 in PCI firmware
142 const long RegPCI_Status = 0x00C; // Register 11 in firmware
143 const long RegPCI_CommandReadback = 0x010; // Register 12 in PCI firmware
147 class CCameraIO
149 public:
151 CCameraIO();
152 virtual ~CCameraIO();
154 ////////////////////////////////////////////////////////////
155 // Low level read write methods - Overridables
156 bool InitDriver(unsigned short camnum);
157 long ReadLine( long SkipPixels, long Pixels, unsigned short* pLineBuffer );
158 long Write( unsigned short reg, unsigned short val );
159 long Read( unsigned short reg, unsigned short& val );
161 ////////////////////////////////////////////////////////////
162 // Camera Settings
164 Camera_Status read_Status(); // Current camera state
165 // <0: error codes
166 // 0: idle
167 // 1: flushing
168 // 2: waiting for trigger
169 // 3: exposing
170 // 4: reading
171 // 5: downloading
172 // 6: line ready
173 // 7: image ready
175 bool read_Present(); // True if camera is present, false otherwise.
177 bool read_Shutter(); // Current shutter state, true = open, false = closed.
178 void write_Shutter( bool val );
180 bool read_ForceShutterOpen(); // True: Forces shutter permanently open. False: allows
181 void write_ForceShutterOpen( bool val ); // normal shutter operation.
183 bool read_LongCable(); // Long cable mode.
184 void write_LongCable( bool val );
186 short read_Mode(); // First four bits map to Mode bits used for
187 void write_Mode( short val ); // special functions or camera configurations.
189 short read_TestBits(); // First four bits to Test bits used for
190 void write_TestBits( short val ); // troubleshooting.
192 short read_Test2Bits(); // First four bits map to Test2 bits used for
193 void write_Test2Bits( short val ); // special functions or camera configurations.
195 bool read_FastReadout(); // Fast readout mode (used for focusing).
196 void write_FastReadout( bool val ); // True means fast focus is on
198 bool read_UseTrigger(); // Triggered exposure mode.
199 void write_UseTrigger( bool val ); // True means triggered exposure is on.
201 bool m_HighPriority; // Bost thread priority level during download
203 short m_PPRepeat; // Delay used on parallel port systems.
205 short m_DataBits; // Digitization resolution, 8 - 18.
207 bool m_FastShutter; // Capable of 0.001 sec exposure resolution
209 bool m_GuiderRelays; // Capable of outputing autoguider signals
211 short m_MaxBinX, m_MaxBinY; // Maximum binning factors
213 double m_MaxExposure; // Maximum exposure length
214 double m_MinExposure; // Minimum exposure length
216 double m_Timeout; // camera polling timeout value
218 ////////////////////////////////////////////////////////////
219 // Cooler Settings
220 // N.B. DAC units = ( m_TempScale * CoolerSetPoint (deg. C ) ) + m_TempCalibration;
221 // N.B. Temperature (deg. C) = (DAC units - m_TempCalibration) / m_TempScale
223 double read_CoolerSetPoint(); // Returns/sets setpoint temperature in degrees
224 void write_CoolerSetPoint( double val ); // Celcius.
226 Camera_CoolerStatus read_CoolerStatus(); // Returns current cooler status
228 Camera_CoolerMode read_CoolerMode(); // Returns/sets current cooler operation mode.
229 void write_CoolerMode( Camera_CoolerMode val );
231 double read_Temperature(); // Current temperature in degrees Celcius.
233 bool m_TempControl; // Temperature can be externally controlled
234 short m_TempCalibration; // Temperature calibration factor.
235 double m_TempScale; // Temperature scaling factor.
237 ////////////////////////////////////////////////////////////
238 // Exposure Settings
239 // The following variables are latched in Expose method, until next Reset or GetImage
241 short m_BinX, m_BinY; // Horizontal and vertical binning.
242 short m_StartX, m_StartY; // Zero based subframe start position in unbinned pixels.
243 short m_NumX, m_NumY; // Subframe size in binned pixels.
245 ////////////////////////////////////////////////////////////
246 // Geometry Settings
247 // The following variables are latched in Expose method, until next Reset or GetImage
249 short m_Columns, m_Rows; // Total columns/rows on CCD (physical).
250 short m_ImgColumns, m_ImgRows; // Unbinned columns/rows in imaging area
251 short m_SkipC, m_SkipR; // Deleted data columns/rows not to be displayed or saved
252 short m_HFlush, m_VFlush; // Horizontal/Vertical flush binning.
253 short m_BIC, m_BIR; // Before Image Column/Row count (dark non-imaging pixels).
255 ////////////////////////////////////////////////////////////
256 // CCD Settings
258 char m_Sensor[ 256 ]; // Sensor model installed in camera (i.e. Sensor = SITe 502).
259 bool m_Color; // Sensor has color dyes
260 double m_Noise; // Read out noise in e-.
261 double m_Gain; // Gain in e-/ADU units.
262 double m_PixelXSize; // Size of pixel in X direction in micrometers.
263 double m_PixelYSize; // Size of pixel in Y direction in micrometers.
265 ////////////////////////////////////////////////////////////
266 // System methods
268 // Resets camera to idle state, will terminate current exposure.
269 void Reset();
271 // Mask user requested set of IRQS
272 // void MaskIrqs();
274 // Restore default IRQ mask
275 // void UnmaskIrqs();
277 // Starts flushing the camera (which should be the normal idle state)
278 // If Rows is non-negative, only the specified number of rows are flushed,
279 // in which case the method will return only when flushing is completed.
280 void Flush( short Rows = -1 );
282 // Output byte to auxillary output port (e.g. for driving guider relays).
283 void AuxOutput( unsigned char val );
285 // Write a 16 bit value to register 1 to 8.
286 void RegWrite( short reg, unsigned short val );
288 // Read a 16 bit value from register 9 to 12.
289 void RegRead( short reg, unsigned short& val );
291 // Move the filterwheel to the home position - failure indicates no filterwheel
292 //attached or broken filterwheel
293 bool FilterHome();
295 // Move filterwheel to the given slot
296 void FilterSet( short Slot );
298 ////////////////////////////////////////////////////////////
299 // Normal exposure methods
301 // The Duration parameter is the exposure time in seconds. The Light parameter controls
302 // the status of the shutter during the exposure, Light = True opens the shutter, Light
303 // = False closes the shutter. Returns immediately after invocation, poll the CameraStatus
304 // property to determine the start time of a triggered exposure and the end of an exposure.
305 bool Expose( double Duration, bool Light );
307 // Returns the pImageData parameter which is a pointer to unsigned short data with NumX*NumY
308 // elements. Can be overridden if necessary
309 virtual bool GetImage( unsigned short* pImageData, short& xSize, short& ySize );
311 /*virtual bool BufferImage(char *bufferName );*/
313 ////////////////////////////////////////////////////////////
314 // Drift scan methods
316 // Begins clocking and digitization of a single line of data begining with a vertical clock
317 // sequence and ending with a buffer full of line data. Poll the CameraStatus property to
318 // determine when the data is ready for download.
319 bool DigitizeLine();
321 // Returns the pLineData parameter which is a pointer to unsigned short data with NumX elements.
322 bool GetLine( unsigned short* pLineData, short& xSize );
324 /* TODO enable this back after removing some deps */
325 /*bool BufferDriftScan(char *bufferName, int delay, int rowCount, int nblock , int npipe);*/
327 ////////////////////////////////////////////////////////////
328 // Easy to use methods
330 // Combination of the Expose and GetImage methods. Blocks calling thread for duration
331 // of exposure and readout.
332 bool Snap( double Duration, bool Light, unsigned short* pImageData, short& xSize, short& ySize );
334 // Internal variables to keep track of things that can not be read from the firmware
335 // directly, or are a combination of firmware setting
337 bool m_TDI; // Time drift integration mode
339 bool m_WaitingforTrigger; // camera is waiting for external trigger
340 bool m_WaitingforImage; // camera is exposing and wiating for an to available
341 bool m_WaitingforLine; // camera is clocking and digitizing a row of data
343 short m_RegisterOffset; // Offset from base address used in parallel port systems.
345 short m_FilterPosition; // Current filter position
346 short m_FilterStepPos; // Current filter position in our internal array
348 bool m_Shutter; // Last known shutter state
349 Camera_Status m_Status; // Last known camera status
351 Camera_Interface m_Interface; // String acronyms may be used in INI file.
352 // 0 or ISA: Industry Standard Architecture bus
353 // 1 or PPI: Parallel Port Interface
354 // 2 or PCI: Peripheral Component Interface
356 Camera_SensorType m_SensorType; // 0 or CCD: Charge Coupled Device
357 // 1 or CMOS: Complementary Metal-Oxide-Silicon
359 Camera_CoolerStatus m_CoolerStatus; // Last known cooler status.
360 unsigned int m_IRQMask; // Set of IRQs masked on user request // 0: Off
361 // 1: Ramping to set point
362 // 2: Correcting
363 // 3: Ramping to ambient
364 // 4: At ambient
365 // 5: Max cooling limit
366 // 6: Min cooling limit
367 // 7: At set point
369 // Latched public variables used during Exposure..GetImage sequence
370 short m_ExposureBinX, m_ExposureBinY; // Horizontal and vertical binning.
371 short m_ExposureStartX, m_ExposureStartY; // Subframe start position in unbinned pixels.
372 short m_ExposureNumX, m_ExposureNumY; // Subframe size in binned pixels.
373 short m_ExposureColumns, m_ExposureRows; // Total columns/rows on CCD (physical).
374 short m_ExposureSkipC, m_ExposureSkipR; // Deleted data columns/rows not to be displayed or saved to disk.
375 short m_ExposureHFlush, m_ExposureVFlush; // Horizontal/Vertical flush binning.
376 short m_ExposureBIC, m_ExposureBIR; // Before Image Column/Row count (dark non-imaging pixels).
377 unsigned short m_ExposureAIC; // Calculated After Image Column count (dark non-imaging pixels).
378 unsigned short m_ExposureRemainingLines; // Number of lines to be clocked out by GetImage
379 unsigned short m_ExposureAIR; // Number of lines to be flushed after GetImage
381 ////////////////////////////////////////////////////////////
382 // Write register shadow variables
383 unsigned short m_RegShadow[ NumWriteRegisters ];
385 unsigned short m_FastShutterBits_Mode; // Mask to enable fast shutter mode
386 unsigned short m_FastShutterBits_Test; // Mask to enable fast shutter mode
388 ////////////////////////////////////////////////////////////
389 // Internal helper routines
391 void LoadLineCounter( unsigned short rows );
392 void LoadColumnLayout( unsigned short aic, unsigned short bic, unsigned short pixels );
393 void LoadTimerAndBinning( double Duration, unsigned short HBin, unsigned short VBin );
395 void StartFlushing();
396 void StopFlushing();
398 void InitDefaults();
399 #ifndef WITHPPI
400 long ReadImage(short unsigned int *);
401 long InternalReadLine(bool, long int, long int, unsigned short *);
402 #endif
404 private:
405 unsigned short m_BaseAddressp2;
406 unsigned int saveIRQS;
407 int fileHandle;
408 #ifdef WITHPPI
409 inline void RegisterSelect( unsigned short reg );
410 inline unsigned short INPW();
411 inline void OUTPW( unsigned short val );
412 #endif
416 #endif // !defined(AFX_CAMERAIO_H__A2882C82_7CFB_11D4_9155_0060676644C1__INCLUDED_)