• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kstars

ApnCamera_USB.cpp

Go to the documentation of this file.
00001 // ApnCamera_USB.cpp: implementation of the CApnCamera_USB class.
00002 //
00003 // Copyright (c) 2003, 2004 Apogee Instruments, Inc.
00005 
00006 #include "stdafx.h"
00007 #include "ApnCamera_USB.h"
00008 
00009 #include "ApogeeUsb.h"
00010 #include "ApogeeUsbErr.h"
00011 
00012 
00014 // Construction/Destruction
00016 
00017 
00018 
00019 bool CApnCamera::InitDriver( unsigned long  CamIdA, 
00020                                  unsigned short /*CamIdB*/, 
00021                                  unsigned long  /*Option*/ )
00022 {
00023     if ( ApnUsbOpen( (unsigned short)CamIdA ) != APN_USB_SUCCESS )
00024     {
00025         return false;
00026     }
00027 
00028     m_CameraInterface = Apn_Interface_USB;
00029 
00030     // Before trying to initialize, perform a simple loopback test
00031     unsigned short  RegData;
00032     unsigned short  NewRegData;
00033 
00034     RegData = 0x5AA5;
00035     if ( Write( FPGA_REG_SCRATCH, RegData )     != APN_USB_SUCCESS ) return false;
00036     if ( Read( FPGA_REG_SCRATCH, NewRegData )   != APN_USB_SUCCESS ) return false;      
00037     if ( RegData != NewRegData ) return false;
00038 
00039     RegData = 0xA55A;
00040     if ( Write( FPGA_REG_SCRATCH, RegData )     != APN_USB_SUCCESS ) return false;
00041     if ( Read( FPGA_REG_SCRATCH, NewRegData )   != APN_USB_SUCCESS ) return false;      
00042     if ( RegData != NewRegData ) return false;
00043 
00044     // The loopback test was successful.  Proceed with initialization.
00045     if ( InitDefaults() != 0 )
00046         return false;
00047 
00048     return true;
00049 }
00050 
00051 
00052 bool CApnCamera::CloseDriver()
00053 {
00054     ApnUsbClose();
00055 
00056     return true;
00057 }
00058 
00059 void CApnCamera::SetNetworkTransferMode( Apn_NetworkMode /*TransferMode*/ )
00060 {
00061         return;
00062 } 
00063 
00064 bool CApnCamera::GetImageData( unsigned short *pImageBuffer, 
00065                                    unsigned short &Width,
00066                                    unsigned short &Height,
00067                                    unsigned long  &Count )
00068 {
00069         unsigned short  Offset(0);
00070     unsigned short  *pTempBuffer;
00071     long            i, j;
00072 
00073 
00074     // Make sure it is okay to get the image data
00075     // The app *should* have done this on its own, but we have to make sure
00076     while ( !ImageReady() )
00077     {
00078         Sleep( 50 );
00079         read_ImagingStatus();
00080     }
00081 
00082     Width   = m_pvtWidth;
00083     Height  = m_pvtHeight;
00084 
00085     if ( m_pvtBitsPerPixel == 16 )
00086         Offset = 1;
00087 
00088     if ( m_pvtBitsPerPixel == 12 )
00089         Offset = 10;
00090 
00091     Width -= Offset;    // Calculate the true image width
00092 
00093     pTempBuffer = new unsigned short[(Width+Offset) * Height];
00094     
00095     ApnUsbGetImage( pTempBuffer );
00096 
00097     for ( i=0; i<Height; i++ )
00098     {
00099         for ( j=0; j<Width; j++ )
00100         {
00101             pImageBuffer[(i*Width)+j] = pTempBuffer[(i*(Width+Offset))+j+Offset];
00102         }
00103     }
00104 
00105     delete [] pTempBuffer;
00106  
00107 
00108     Count = read_ImageCount();
00109 
00110     SignalImagingDone();
00111 
00112     return true;
00113 }
00114 
00115 
00116 bool CApnCamera::GetLineData( unsigned short */*pLineBuffer*/,
00117                                   unsigned short &Size )
00118 {
00119     Size = 0;
00120 
00121     return false;
00122 }
00123 
00124 
00125 long CApnCamera::PreStartExpose( unsigned short BitsPerPixel )
00126 {
00127     m_pvtWidth  = GetExposurePixelsH();
00128     m_pvtHeight = GetExposurePixelsV();
00129 
00130     if ( (BitsPerPixel != 16) && (BitsPerPixel != 12) )
00131     {
00132         // Invalid bit depth request
00133         return 1;
00134     }
00135 
00136     m_pvtBitsPerPixel = BitsPerPixel;
00137 
00138 
00139     if ( BitsPerPixel == 16 )
00140         m_pvtWidth += 1;
00141 
00142     if ( BitsPerPixel == 12 )
00143         m_pvtWidth += 10;
00144 
00145     if ( ApnUsbStartExp( m_pvtWidth, m_pvtHeight ) != APN_USB_SUCCESS )
00146     {
00147         return 1;
00148     }
00149 
00150     return 0;
00151 }
00152 
00153 
00154 long CApnCamera::PostStopExposure( bool DigitizeData )
00155 {
00156     PUSHORT         pRequestData;
00157 
00158 
00159     if ( !DigitizeData )
00160     {
00161         while ( !ImageReady() )
00162         {
00163             Sleep( 50 );
00164             read_ImagingStatus();
00165         }
00166 
00167         pRequestData = new USHORT[m_pvtWidth*m_pvtHeight];
00168 
00169         ApnUsbGetImage( pRequestData );
00170 
00171         delete [] pRequestData;
00172 
00173         SignalImagingDone();
00174     }
00175 
00176     // The following code will eventually be the implementation of the STOP
00177     // command for USB.  Currently, this does not work correctly.
00178     // if ( ApnUsbStopExp( DigitizeData ) != APN_USB_SUCCESS )
00179     // {
00180     //  return 1;
00181     // }
00182 
00183     return 0;
00184 }
00185 
00186 
00187 long CApnCamera::Read( unsigned short reg, unsigned short& val )
00188 {
00189     if ( ApnUsbReadReg( reg, &val ) != APN_USB_SUCCESS )
00190     {
00191         return 1;       // Failure
00192     }
00193 
00194     return 0;
00195 }
00196 
00197 
00198 long CApnCamera::Write( unsigned short reg, unsigned short val )
00199 {
00200     if ( ApnUsbWriteReg( reg, val ) != APN_USB_SUCCESS )
00201     {
00202         return 1;       // Failure
00203     }
00204 
00205     return 0;
00206 }
00207 
00208 
00209 long CApnCamera::WriteMultiSRMD( unsigned short reg, unsigned short val[], unsigned short count )
00210 {
00211     if ( ApnUsbWriteRegMulti( reg, val, count ) != APN_USB_SUCCESS )
00212     {
00213         return 1;
00214     }
00215 
00216     return 0;
00217 }
00218 
00219 
00220 long CApnCamera::WriteMultiMRMD( unsigned short reg[], unsigned short val[], unsigned short count )
00221 {
00222     if ( ApnUsbWriteRegMultiMRMD( reg, val, count ) != APN_USB_SUCCESS )
00223     {
00224         return 1;
00225     }
00226 
00227     return 0;
00228 }
00229 
00230 
00231 long CApnCamera::QueryStatusRegs( unsigned short& StatusReg,
00232                                       unsigned short& HeatsinkTempReg,
00233                                       unsigned short& CcdTempReg,
00234                                       unsigned short& CoolerDriveReg,
00235                                       unsigned short& VoltageReg,
00236                                       unsigned short& TdiCounter,
00237                                       unsigned short& SequenceCounter )
00238 {
00239        /*unsigned short stat,heat,ccdt,cool,volt,tdic,sequ;*/
00240 
00241     if ( ApnUsbReadStatusRegs( &StatusReg,
00242                                &HeatsinkTempReg,
00243                                &CcdTempReg,
00244                                &CoolerDriveReg,
00245                                &VoltageReg,
00246                                &TdiCounter,
00247                                &SequenceCounter ) != APN_USB_SUCCESS )
00248     {
00249         return 1;
00250     }
00251     return 0;
00252 }
00253 
00254 
00255 
00256 

kstars

Skip menu "kstars"
  • Main Page
  • Modules
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • keduca
  • kstars
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal