tc211_ccd.C

Go to the documentation of this file.
00001 /* Gnome gxsm - Gnome X Scanning Microscopy
00002  * universal STM/AFM/SARLS/SPALEED/... controlling and
00003  * data analysis software
00004  *
00005  * Gxsm Hardware Interface Plugin Name: tc211_ccd.C
00006  * ===============================================
00007  * 
00008  * Copyright (C) 1999 The Free Software Foundation
00009  *
00010  * Authors: Percy Zahl <zahl@fkp.uni-hannover.de>
00011  * additional features: Andreas Klust <klust@fkp.uni-hannover.de>
00012  *
00013  * This program is free software; you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation; either version 2 of the License, or
00016  * (at your option) any later version.
00017  *
00018  * This program is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program; if not, write to the Free Software
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00026  */
00027 
00028 
00029 /* Please do not change the Begin/End lines of this comment section!
00030  * this is a LaTeX style section used for auto generation of the PlugIn Manual 
00031  * Chapter. Add a complete PlugIn documentation inbetween the Begin/End marks!
00032  * All "% PlugInXXX" commentary tags are mandatory
00033  * All "% OptPlugInXXX" tags are optional and can be removed or commented in
00034  * --------------------------------------------------------------------------------
00035 % BeginPlugInDocuSection
00036 % PlugInDocuCaption: TC211 CCD Interface
00037 % PlugInName: tc211_ccd
00038 % PlugInAuthor: Percy Zahl
00039 % PlugInAuthorEmail: zahl@users.sf.net
00040 % PlugInMenuPath: Hardware/TC211-CCD-HwI
00041 
00042 % PlugInDescription
00043 This is an experimental hardware interface plugin.  Grabbing video
00044 data from a parport attached TC211 CCD camera based on the design
00045 presented in the ''c't magazine f\"ur computer technik'', Januar 1992,
00046 p.162ff.
00047 
00048 % PlugInUsage
00049 Configure the \GxsmPref{Hardware}{Card} to ''TC211-CCD''. Load
00050 the ''ccd.o'' kernel module before starting the GXSM, setup /dev/ccd
00051 correct. Check the module source code for correct LPT port.
00052 
00053 % OptPlugInSources
00054 
00055 % OptPlugInDest
00056 Usual scan destination channel.
00057 
00058 % OptPlugInNote
00059 Used for my very old experimental Astro CCD camera. The special kernel
00060 module ''ccd'' is used for data transfer.
00061 
00062 % EndPlugInDocuSection
00063  * -------------------------------------------------------------------------------- 
00064  */
00065 
00066 #include <sys/ioctl.h>
00067 
00068 #include "config.h"
00069 #include "plugin.h"
00070 #include "glbvars.h"
00071 #include "xsmhard.h"
00072 
00073 #include "plug-ins/hard/modules/ccd.h"
00074 
00075 // Define HwI PlugIn reference name here, this is what is listed later within "Preferenced Dialog"
00076 // i.e. the string selected for "Hardware/Card"!
00077 #define THIS_HWI_PLUGIN_NAME "TC211-CCD"
00078 
00079 // Plugin Prototypes
00080 static void tc211_ccd_init( void );
00081 static void tc211_ccd_about( void );
00082 static void tc211_ccd_configure( void );
00083 static void tc211_ccd_cleanup( void );
00084 
00085 // Fill in the GxsmPlugin Description here
00086 GxsmPlugin tc211_ccd_pi = {
00087   NULL,                   // filled in and used by Gxsm, don't touch !
00088   NULL,                   // filled in and used by Gxsm, don't touch !
00089   0,                      // filled in and used by Gxsm, don't touch !
00090   NULL,                   // The Gxsm-App Class Ref.pointer (called "gapp" in Gxsm) is 
00091                           // filled in here by Gxsm on Plugin load, 
00092                           // just after init() is called !!!
00093   // ----------------------------------------------------------------------
00094   // Plugins Name, CodeStly is like: Name-M1S|M2S-BG|F1D|F2D|ST|TR|Misc
00095   "tc211_ccd-"
00096   "HW-INT-1S-SHORT",
00097   // Plugin's Category - used to autodecide on Pluginloading or ignoring
00098   // In this case of Hardware-Interface-Plugin here is the interface-name required
00099   // this is the string selected for "Hardware/Card"!
00100   THIS_HWI_PLUGIN_NAME,
00101   // Description, is shown by PluginViewer (Plugin: listplugin, Tools->Plugin Details)
00102   "TC211 CCD interface.",                   
00103   // Author(s)
00104   "Percy Zahl",
00105   // Menupath to position where it is appendet to -- not used by HwI PIs
00106   N_("Hardware/"),
00107   // Menuentry -- not used by HwI PIs
00108   N_(THIS_HWI_PLUGIN_NAME"-HwI"),
00109   // help text shown on menu
00110   N_("This is the "THIS_HWI_PLUGIN_NAME" - GXSM Hardware Interface"),
00111   // more info...
00112   "N/A",
00113   NULL,          // error msg, plugin may put error status msg here later
00114   NULL,          // Plugin Status, managed by Gxsm, plugin may manipulate it too
00115   // init-function pointer, can be "NULL", 
00116   // called if present at plugin load
00117   tc211_ccd_init,  
00118   // query-function pointer, can be "NULL", 
00119   // called if present after plugin init to let plugin manage it install itself
00120   NULL, // query should be "NULL" for Gxsm-Math-Plugin !!!
00121   // about-function, can be "NULL"
00122   // can be called by "Plugin Details"
00123   tc211_ccd_about,
00124   // configure-function, can be "NULL"
00125   // can be called by "Plugin Details"
00126   tc211_ccd_configure,
00127   // run-function, can be "NULL", if non-Zero and no query defined, 
00128   // it is called on menupath->"plugin"
00129   NULL, // run should be "NULL" for Gxsm-Math-Plugin !!!
00130   // cleanup-function, can be "NULL"
00131   // called if present at plugin removeal
00132   tc211_ccd_cleanup
00133 };
00134 
00135 
00136 // Text used in Aboutbox, please update!!
00137 static const char *about_text = N_("GXSM tc211_ccd Plugin\n\n"
00138                                    "Video for Linux frame grabber.");
00139 
00140 /* Here we go... */
00141 
00142 /*
00143  * GXSM V4L Hardware Interface Class
00144  * ============================================================
00145  */
00146 
00147 class gxsm_TC211_CCD : public XSM_Hardware{
00148 public:
00149         gxsm_TC211_CCD();
00150         virtual ~gxsm_TC211_CCD();
00151         
00152         /* Parameter  */
00153         virtual long GetMaxPointsPerLine(){ return CCD_Xpixel; };
00154         virtual long GetMaxLines(){ return CCD_Ypixel; };
00155         virtual long GetMaxChannels(){ return 1L; };
00156         virtual void SetDxDy(int dx, int dy);
00157         virtual void SetOffset(long x, long y);
00158         virtual void SetNx(long nx);
00159         virtual void SetAlpha(double alpha);
00160         
00161         virtual void MovetoXY(long x, long y);
00162         virtual void StartScan2D();
00163         virtual void ScanLineM(int yindex, int xdir, int muxmode, Mem2d *Mob[MAX_SRCS_CHANNELS], int ix0=0 );
00164         virtual void EndScan2D();
00165  
00166         virtual gchar* get_info(){ 
00167                 return g_strdup("*--GXSM HwI Plugin: TC211_CCD::XSM_Hardware --*\n"
00168                                 "CCD TC211 on /dev/ccd is connected!\n"
00169                                 "*--Features--*\n"
00170                                 "SCAN: Yes\n"
00171                                 "*--ExecCMD options--*\n"
00172                                 "MONITORENABLE, EXPOSURE\n"
00173                                 "*--EOF--*\n"
00174                         );
00175         };
00176         void ExecCmd(int Cmd);
00177 
00178         double CCD_exptime;
00179 private:
00180   int  ccd;
00181   SHT  ccdline[CCD_Xpixel];
00182 };
00183 
00184 /*
00185  * PI global
00186  */
00187 
00188 gxsm_TC211_CCD *TC211_CCD_hardware = NULL;
00189 
00190 /* Konstruktor: device open
00191  * ==================================================
00192  */
00193 gxsm_TC211_CCD::gxsm_TC211_CCD():XSM_Hardware(){
00194         CCD_exptime = 1.;
00195         ccd = open(xsmres.DSPDev, O_RDWR);
00196         if(ccd <= 0){ 
00197                 printf("open %s failed, err=%d\ndo you need root to do \"insmod ccd\" ?\n", xsmres.DSPDev, ccd);
00198                 exit(0);
00199         }
00200         ioctl(ccd, CCD_CMD_MONITORENABLE, 0);
00201 }
00202 
00203 /* Destruktor:
00204  * ==================================================
00205  * Hardware "abtrennen"
00206  */
00207 gxsm_TC211_CCD::~gxsm_TC211_CCD(){
00208         close(ccd);
00209 }
00210 
00211 /* Übergeordnete Parameterübergabefunktionen PC => PC31/DSP
00212  * ========================================================
00213  * virtual !
00214  */
00215 void gxsm_TC211_CCD::ExecCmd(int Cmd){
00216         switch(Cmd){
00217         case CCD_CMD_MONITORENABLE:
00218                 ioctl(ccd, CCD_CMD_MONITORENABLE, 0);
00219                 break;
00220         case CCD_CMD_EXPOSURE:
00221                 ioctl(ccd, CCD_CMD_EXPOSURE, (unsigned long)(CCD_exptime));
00222                 break;
00223         }
00224 }
00225 void gxsm_TC211_CCD::MovetoXY(long x, long y){ rx=x; ry=y; }
00226 void gxsm_TC211_CCD::SetDxDy(int dx, int dy){  
00227         Dx = dx; 
00228         Dy = dy;
00229 }
00230 void gxsm_TC211_CCD::SetOffset(long x, long y){
00231         rotoffx = x; rotoffy = y;
00232 }
00233 void gxsm_TC211_CCD::SetAlpha(double alpha){ 
00234         Alpha=M_PI*alpha/180.;
00235         rotmyy = rotmxx = cos(Alpha);
00236         rotmyx = -(rotmxy = sin(Alpha));
00237 }
00238 void gxsm_TC211_CCD::SetNx(long nx){ 
00239         Nx=nx;
00240 }
00241 
00242 
00243 void gxsm_TC211_CCD::StartScan2D(){ 
00244         XSM_DEBUG (DBG_L4, "CCD belichten");
00245         // CCD löschen
00246         ioctl(ccd, CCD_CMD_CLEAR, 0);
00247         // CCD belichten
00248         ioctl(ccd, CCD_CMD_EXPOSURE, (unsigned long)(CCD_exptime));
00249         ioctl(ccd, CCD_CMD_INITLESEN, 0);
00250 }
00251 
00252 void gxsm_TC211_CCD::EndScan2D(){ 
00253         ioctl(ccd, CCD_CMD_MONITORENABLE, 0);
00254         XSM_DEBUG (DBG_L4, "CCD gelesen");
00255 }
00256 
00257 
00258 
00259 
00260 void gxsm_TC211_CCD::ScanLineM(int yindex, int xdir, int muxmode, Mem2d *Mob[MAX_SRCS_CHANNELS], int ix0 ){
00261         if (yindex < 0){ // 2D capture
00262                 if (yindex != -1) return; // XP/XM init cycle
00263                 if(Mob[0])
00264                         for(int j=0; j<CCD_Ypixel && j<Mob[0]->GetNy (); j++){
00265                                 for(int i=0; i<CCD_Xpixel && i < Mob[0]->GetNx (); i++)
00266                                         Mob[0]->PutDataPkt ((double)ioctl (ccd, CCD_CMD_GETPIXEL,0), i, j);
00267                                 if(!(j%32))
00268                                         gapp->check_events();
00269                         }
00270                 return;
00271         }
00272 
00273         if(yindex >= CCD_Ypixel) 
00274                 return;
00275 
00276         if(Mob[0])
00277                 for(int i=0; i<CCD_Xpixel && i < Mob[0]->GetNx (); i++)
00278                         Mob[0]->PutDataPkt((double)ioctl(ccd, CCD_CMD_GETPIXEL,0),i,yindex);
00279 
00280         if(!(yindex%32))
00281                 gapp->check_events();
00282 }
00283 
00284 
00285 /* 
00286  * PI essential members
00287  */
00288 
00289 // Symbol "get_gxsm_plugin_info" is resolved by dlsym from Gxsm, used to get Plugin's info!! 
00290 // Essential Plugin Function!!
00291 GxsmPlugin *get_gxsm_plugin_info ( void ){ 
00292   tc211_ccd_pi.description = g_strdup_printf(N_("GXSM HwI tc211_ccd plugin %s"), VERSION);
00293   return &tc211_ccd_pi; 
00294 }
00295 
00296 // Symbol "get_gxsm_hwi_hardware_class" is resolved by dlsym from Gxsm for all HwI type PIs, 
00297 // Essential Plugin Function!!
00298 XSM_Hardware *get_gxsm_hwi_hardware_class ( void *data ) {
00299         return TC211_CCD_hardware;
00300 }
00301 
00302 // init-Function
00303 static void tc211_ccd_init(void)
00304 {
00305         PI_DEBUG (DBG_L2, "tc211_ccd Plugin Init");
00306         TC211_CCD_hardware = new gxsm_TC211_CCD ();
00307  }
00308 
00309 // about-Function
00310 static void tc211_ccd_about(void)
00311 {
00312         const gchar *authors[] = { tc211_ccd_pi.authors, NULL};
00313         gtk_widget_show(gnome_about_new ( tc211_ccd_pi.name,
00314                                           VERSION,
00315                                           N_("(C) 2000 the Free Software Foundation"),
00316                                           about_text,
00317                                           authors,
00318                                           NULL, NULL, NULL
00319                                 ));
00320 }
00321 
00322 // configure-Function
00323 static void tc211_ccd_configure(void)
00324 {
00325         if(tc211_ccd_pi.app)
00326                 tc211_ccd_pi.app->message("tc211_ccd Plugin Configuration");
00327 }
00328 
00329 // cleanup-Function
00330 static void tc211_ccd_cleanup(void)
00331 {
00332         PI_DEBUG (DBG_L2, "tc211_ccd Plugin Cleanup");
00333         delete TC211_CCD_hardware;
00334         TC211_CCD_hardware = NULL;
00335 }
00336 
00337 
00338 

Generated on Sat Apr 1 09:04:20 2006 for GXSM by  doxygen 1.4.6