diff options
author | Marcus Meissner <marcus@jet.franken.de> | 2006-11-19 20:31:27 +0000 |
---|---|---|
committer | Marcus Meissner <marcus@jet.franken.de> | 2006-11-19 20:31:27 +0000 |
commit | 0c20a0c777e3cd34955372b5ecf7432ecc3366e8 (patch) | |
tree | a888306582d66ec779da00493b2a74bcb640909f | |
parent | 9ff6401b48bcf56fc2b04a8d78a2da4a89f1acd9 (diff) | |
download | libgphoto2-0c20a0c777e3cd34955372b5ecf7432ecc3366e8.tar.gz |
pass port around to avoid storing it globally.
git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@9429 67ed7778-7388-44ab-90cf-0a291f65f57c
-rw-r--r-- | camlibs/sonydscf1/ChangeLog | 4 | ||||
-rw-r--r-- | camlibs/sonydscf1/chotplay.c | 92 | ||||
-rw-r--r-- | camlibs/sonydscf1/chotplay.h | 16 | ||||
-rw-r--r-- | camlibs/sonydscf1/command.c | 203 | ||||
-rw-r--r-- | camlibs/sonydscf1/command.h | 39 | ||||
-rw-r--r-- | camlibs/sonydscf1/sonydscf1.c | 40 |
6 files changed, 171 insertions, 223 deletions
diff --git a/camlibs/sonydscf1/ChangeLog b/camlibs/sonydscf1/ChangeLog index 4543c570b..4527190e1 100644 --- a/camlibs/sonydscf1/ChangeLog +++ b/camlibs/sonydscf1/ChangeLog @@ -1,3 +1,7 @@ +2006-11-19 Marcus Meissner <marcus@jet.franken.de> + + * *.[ch]: Pass GPPort*port around to avoid global variables. + 2002-03-24 Dan Fandrich <dan@coneharvesters.com> * Removed config.h as it clearly should not have been here. diff --git a/camlibs/sonydscf1/chotplay.c b/camlibs/sonydscf1/chotplay.c index e934f5d37..2e6956ac6 100644 --- a/camlibs/sonydscf1/chotplay.c +++ b/camlibs/sonydscf1/chotplay.c @@ -65,29 +65,7 @@ void Exit(code) } #endif -int write_file(u_char *buf, int len, FILE *outfp) -{ - int i, l; - int result; - - i = 0; - while( len > i) { - l = ( (len - i) < BUFSIZ) ? (len -i) : BUFSIZ; - result = fwrite(&buf[i], sizeof(u_char), l, outfp); - if(result != len){ - perror("chotplay"); - if(outfp != stdout); - fclose(outfp); - Exit(2); - } - - i = i + l; - } - return(i); -} - - -int make_jpeg_comment(u_char *buf, u_char *jpeg_comment) +static int make_jpeg_comment(u_char *buf, u_char *jpeg_comment) { int i, cur = 0; int reso, shutter; @@ -193,7 +171,7 @@ int make_jpeg_comment(u_char *buf, u_char *jpeg_comment) return cur; } -int get_picture_information(int *pmx_num, int outit) +int get_picture_information(GPPort *port,int *pmx_num, int outit) { u_char buforg[PMF_MAXSIZ]; char name[64]; @@ -203,8 +181,8 @@ int get_picture_information(int *pmx_num, int outit) char *buf = (char *) &buforg; sprintf(name, "/PIC_CAM/PIC00000/PIC_INF.PMF"); - F1ok(); - len = F1getdata(name, buf, 0); + F1ok(port); + len = F1getdata(port, name, buf, 0); n = buf[26] * 256 + buf[27]; /* how many files */ *pmx_num = buf[31]; /* ??? */ @@ -260,7 +238,7 @@ int get_picture_information(int *pmx_num, int outit) return(n); } -long get_file(char *name, char **data, int format, int verbose) +long get_file(GPPort *port,char *name, char **data, int format, int verbose) { u_long filelen; u_long total = 0; @@ -270,21 +248,21 @@ long get_file(char *name, char **data, int format, int verbose) u_char jpeg_comment[256]; /* verbose=1; */ - F1ok(); + F1ok(port); - F1status(0); + F1status(port,0); - filelen = F1finfo(name); + filelen = F1finfo(port,name); if(filelen == 0) return(0); - if(F1fopen(name) != 0) + if(F1fopen(port,name) != 0) return(0); /* printf("camfile: %s\n",name); */ if(format == JPEG){ - len = F1fread(buf, 126); + len = F1fread(port, buf, 126); if( len < 126){ - F1fclose(); + F1fclose(port); return(0); } /*write_file(jpeg_comment, make_jpeg_comment(buf, jpeg_comment), fp);*/ @@ -296,7 +274,7 @@ long get_file(char *name, char **data, int format, int verbose) ptr +=memcpylen; } - while((len = F1fread(buf, 0x0400)) != 0){ + while((len = F1fread(port, buf, 0x0400)) != 0){ if(len < 0) return(0); total = total + len; @@ -313,13 +291,13 @@ long get_file(char *name, char **data, int format, int verbose) } - F1fclose(); + F1fclose(port); if(verbose) fprintf(stderr, "\n"); return(total); } -long get_thumbnail(char *name, char **data, int format, int verbose, int n) +long get_thumbnail(GPPort *port,char *name, char **data, int format, int verbose, int n) { u_long filelen; u_long total = 0; @@ -331,22 +309,22 @@ long get_thumbnail(char *name, char **data, int format, int verbose, int n) /* printf("name %s,%d\n",name,n); */ p = buf; - F1ok(); - F1status(0); + F1ok(port); + F1status(port,0); - filelen = F1finfo(name); + filelen = F1finfo(port,name); if(filelen == 0) return(0); - if(F1fopen(name) != 0) + if(F1fopen(port,name) != 0) return(0); for( i = 0 ; i < n ; i++) - len = F1fseek(0x1000 , 1); + len = F1fseek(port, 0x1000, 1); - while((len = F1fread(p, 0x0400)) != 0){ + while((len = F1fread(port, p, 0x0400)) != 0){ if(len < 0){ - F1fclose(); + F1fclose(port); return(0); } total = total + len; @@ -359,7 +337,7 @@ long get_thumbnail(char *name, char **data, int format, int verbose, int n) if(total >= 0x1000) break; } - F1fclose(); + F1fclose(port); if(verbose) fprintf(stderr, "\n"); @@ -374,7 +352,7 @@ long get_thumbnail(char *name, char **data, int format, int verbose, int n) return(total); } -void get_date_info(char *name, char *outfilename ,char *newfilename) +void get_date_info(GPPort *port, char *name, char *outfilename ,char *newfilename) { char *p, *q; int year = 0; @@ -385,12 +363,12 @@ void get_date_info(char *name, char *outfilename ,char *newfilename) int second = 0; u_char buf[128]; - F1ok(); - F1status(0); + F1ok(port); + F1status(port,0); - (void) F1finfo(name); - if(F1fopen(name) ==0){ - if(F1fread(buf, 126) == 126){ + (void) F1finfo(port, name); + if(F1fopen(port, name) ==0){ + if(F1fread(port, buf, 126) == 126){ if(*(buf+PMP_TAKE_YEAR) != 0xff){ year = (int) *(buf+PMP_TAKE_YEAR); month = (int) *(buf+PMP_TAKE_MONTH); @@ -400,7 +378,7 @@ void get_date_info(char *name, char *outfilename ,char *newfilename) second = (int) *(buf+PMP_TAKE_SECOND); } } - F1fclose(); + F1fclose(port); } p = outfilename; @@ -456,14 +434,14 @@ void get_date_info(char *name, char *outfilename ,char *newfilename) } -long get_picture(int n, char **data, int format, int ignore, int all_pic_num) +long get_picture(GPPort *port, int n, char **data, int format, int ignore, int all_pic_num) { long len; char name[64]; char name2[64]; int i; - all_pic_num = get_picture_information(&i,0); + all_pic_num = get_picture_information(port,&i,0); retry: @@ -513,10 +491,10 @@ retry: } if(format == JPEG_T) - len = get_thumbnail(name, data, format, verbose, + len = get_thumbnail(port, name, data, format, verbose, 0xff & (picture_thumbnail_index[n] >> 8)); else - len = get_file(name, data, format, verbose); + len = get_file(port, name, data, format, verbose); if(len == 0 ) { if(verbose) fprintf(stderr, "\n"); @@ -529,7 +507,7 @@ retry: return(len); } -void delete_picture(int n, int all_pic_num) +void delete_picture(GPPort *port, int n, int all_pic_num) { if (all_pic_num < n) { fprintf(stderr, "picture number %d is too large. %d\n",all_pic_num,n); @@ -543,7 +521,7 @@ void delete_picture(int n, int all_pic_num) return; } - if (F1deletepicture(picture_index[n]) < 0) + if (F1deletepicture(port, picture_index[n]) < 0) errflg ++; } diff --git a/camlibs/sonydscf1/chotplay.h b/camlibs/sonydscf1/chotplay.h index 12714994b..e12802ba2 100644 --- a/camlibs/sonydscf1/chotplay.h +++ b/camlibs/sonydscf1/chotplay.h @@ -1,9 +1,7 @@ -int write_file(u_char *buf, int len, FILE *outfp); -int make_jpeg_comment(u_char *buf, u_char *jpeg_comment); -int get_picture_information (int *, int); -long get_file(char *name, char **data, int format, int verbose); -long get_thumbnail(char *name, char **data, int format, int verbose, int n); -void get_date_info (char *, char * ,char *); -long get_picture (int, char **, int, int, int); -void get_all_pictures (int, int, char *, int, int); -void delete_picture (int, int); +int get_picture_information (GPPort *,int *, int); +long get_file(GPPort*,char *name, char **data, int format, int verbose); +long get_thumbnail(GPPort*,char *name, char **data, int format, int verbose, int n); +void get_date_info (GPPort*,char *, char * ,char *); +long get_picture (GPPort*,int, char **, int, int, int); +void get_all_pictures (GPPort*,int, int, char *, int, int); +void delete_picture (GPPort*,int, int); diff --git a/camlibs/sonydscf1/command.c b/camlibs/sonydscf1/command.c index 4da624729..4d9758802 100644 --- a/camlibs/sonydscf1/command.c +++ b/camlibs/sonydscf1/command.c @@ -19,9 +19,6 @@ #define dprintf(x) #endif -extern gp_port *dev; - - /* static int F1fd = -1; */ static u_char address = 0; static u_char sendaddr[8] = { 0x00, 0x22, 0x44, 0x66, 0x88, 0xaa, 0xcc, 0xee }; @@ -32,24 +29,24 @@ static int pic_num2 = 0; static int year, month, date; static int hour, minutes; -void wbyte(u_char c) +static void wbyte(GPPort *port,u_char c) { char temp[2]; dprintf((stderr, "> %02x\n", c)); temp[0]=c; temp[1]='\0'; /* if (writetty(F1fd, &c, 1) < 0) { */ - if( gp_port_write(dev, (char*)temp, 1) <0) { + if( gp_port_write(port, (char*)temp, 1) <0) { perror("wbyte"); /* Exit(1); */ } } -u_char rbyte() +static u_char rbyte(GPPort *port) { u_char c[2]; /* if (readtty(F1fd, &c, 1) < 0) { */ - if (gp_port_read(dev,c, 1) <0) { + if (gp_port_read(port,c, 1) <0) { perror("rbtyte"); /* Exit(1); */ } @@ -58,23 +55,23 @@ u_char rbyte() return c[0]; } -inline void -wstr(u_char *p, int len) +static void +wstr(GPPort *port,u_char *p, int len) { dprintf((stderr, "> len=%d\n", len)); /* if (writetty(F1fd, p, len) < 0) { */ - if( gp_port_write(dev, p, len) <0) { + if( gp_port_write(port, p, len) <0) { perror("wstr"); /* Exit(1); */ } } -inline void rstr(u_char *p, int len) +static void rstr(GPPort *port,u_char *p, int len) { dprintf((stderr, "< len=%d\n", len)); /* if (readtty(F1fd, p, len) < 0) { */ - if (gp_port_read(dev,p, len) <0) { + if (gp_port_read(port,p, len) <0) { perror("rstr"); /* Exit(1); */ } @@ -88,57 +85,57 @@ u_char checksum(u_char addr, u_char *cp, int len) return(0x100 -(ret & 0xff) ); } -void sendcommand(u_char *p, int len) +static void sendcommand(GPPort *port,u_char *p, int len) { - wbyte(BOFRAME); - wbyte(sendaddr[address]); - wstr(p, len); - wbyte(checksum(sendaddr[address], p, len)); - wbyte(EOFRAME); + wbyte(port,BOFRAME); + wbyte(port,sendaddr[address]); + wstr(port,p, len); + wbyte(port,checksum(sendaddr[address], p, len)); + wbyte(port,EOFRAME); address ++; if(address >7 ) address = 0; } -void Abort(void) +static void Abort(GPPort *port) { u_char buf[4]; buf[0] = BOFRAME; buf[1] = 0x85; buf[2] = 0x7B; buf[3] = EOFRAME; - wstr(buf, 4); + wstr(port, buf, 4); } -int recvdata(u_char *p, int len) +static int recvdata(GPPort *port, u_char *p, int len) { u_char s, t; int sum; int i; - s = rbyte(); /* BOFL */ - t= rbyte(); /* recvaddr */ + s = rbyte(port); /* BOFL */ + t= rbyte(port); /* recvaddr */ #ifdef DEBUG fprintf(stderr,"BOFL %02x ", s); fprintf(stderr,"Raddr %02x %02x \n", t, recvaddr[address]); #endif if(t != recvaddr[address]){ - s = rbyte(); /* drain */ - s = rbyte(); /* drain */ - s = rbyte(); /* drain */ + s = rbyte(port); /* drain */ + s = rbyte(port); /* drain */ + s = rbyte(port); /* drain */ #ifdef DEBUG fprintf(stderr," abort \n"); #endif - Abort(); + Abort(port); return(-1); } i = len; sum = (int) t; - while ((s = rbyte()) != EOFRAME){ + while ((s = rbyte(port)) != EOFRAME){ sum = sum + s; if(i > 0){ if(s == CESCAPE){ - s = rbyte(); + s = rbyte(port); if(0x20 & s) s = 0xDF & s; else @@ -166,7 +163,7 @@ int recvdata(u_char *p, int len) /*------------------------------------------------------------*/ -char F1newstatus(int verbose, char *return_buf) +char F1newstatus(GPPort *port, int verbose, char *return_buf) { u_char buf[34]; int i; @@ -174,13 +171,13 @@ char F1newstatus(int verbose, char *return_buf) char tmp_buf[150]=""; buf[0] = 0x03; buf[1] = 0x02; - sendcommand(buf, 2); - i = recvdata(buf, 33); + sendcommand(port,buf, 2); + i = recvdata(port, buf, 33); #ifdef DEBUG fprintf(stderr,"Status: %02x%02x:%02x(len = %d)\n", buf[0], buf[1], buf[2], i); #endif if((buf[0] != 0x03) || (buf[1] != 0x02) ||(buf[2] != 0)){ - Abort(); + Abort(port); return(-1); } sw_mode = buf[3]; @@ -222,7 +219,7 @@ char F1newstatus(int verbose, char *return_buf) } -int F1status(int verbose) +int F1status(GPPort *port, int verbose) { u_char buf[34]; @@ -230,13 +227,13 @@ int F1status(int verbose) buf[0] = 0x03; buf[1] = 0x02; - sendcommand(buf, 2); - i = recvdata(buf, 33); + sendcommand(port,buf, 2); + i = recvdata(port, buf, 33); #ifdef DEBUG fprintf(stderr,"Status: %02x%02x:%02x(len = %d)\n", buf[0], buf[1], buf[2], i); #endif if((buf[0] != 0x03) || (buf[1] != 0x02) ||(buf[2] != 0)){ - Abort(); + Abort(port); return(-1); } sw_mode = buf[3]; @@ -271,13 +268,13 @@ int F1status(int verbose) return (buf[2]); /*ok*/ } -int F1howmany() +int F1howmany(GPPort *port) { - F1status(0); + F1status(port, 0); return(pic_num); } -int F1fopen(char *name) +int F1fopen(GPPort *port, char *name) { u_char buf[64]; int len; @@ -287,10 +284,10 @@ int F1fopen(char *name) buf[3] = 0x00; snprintf(&buf[4], sizeof(name), "%s", name); len = strlen(name) + 5; - sendcommand(buf, len); - recvdata(buf, 6); + sendcommand(port,buf, len); + recvdata(port, buf, 6); if((buf[0] != 0x02) || (buf[1] != 0x0A) || (buf[2] != 0x00)){ - Abort(); + Abort(port); fprintf(stderr,"F1fopen fail\n"); return(-1); } @@ -298,7 +295,7 @@ int F1fopen(char *name) return(buf[3]); } -int F1fclose() +int F1fclose(GPPort*port) { u_char buf[4]; @@ -306,20 +303,20 @@ int F1fclose() buf[1] = 0x0B; buf[2] = 0x00; buf[3] = 0x00; - sendcommand(buf, 4); - recvdata(buf, 3); + sendcommand(port,buf, 4); + recvdata(port, buf, 3); #ifdef DEBUG fprintf(stderr,"Fclose: %02x%02x:%02x\n", buf[0], buf[1], buf[2]); #endif if((buf[0] != 0x02) || (buf[1] != 0x0B) || (buf[2] != 0x00)){ fprintf(stderr,"F1fclose fail\n"); - Abort(); + Abort(port); return(-1); } return (buf[2]); /* ok == 0 */ } -long F1fread(u_char *data, long len) +long F1fread(GPPort *port, u_char *data, long len) { long len2; @@ -338,23 +335,23 @@ long F1fread(u_char *data, long len) buf[6] = (len >> 8) & 0xff; buf[7] = 0xff & len; - sendcommand(buf, 8); - rstr(buf, 9); + sendcommand(port,buf, 8); + rstr(port, buf, 9); if((buf[2] != 0x02) || (buf[3] != 0x0C) || (buf[4] != 0x00)){ - Abort(); + Abort(port); fprintf(stderr,"F1fread fail\n"); return(-1); } len2 = buf[7] * 0x100 + buf[8]; /* data size */ if(len2 == 0) { - s = rbyte(); /* last block checksum */ - s = rbyte(); /* last block EOFL */ + s = rbyte(port); /* last block checksum */ + s = rbyte(port); /* last block EOFL */ return(0); } - while((s = rbyte()) != EOFRAME){ + while((s = rbyte(port)) != EOFRAME){ if(s == CESCAPE){ - s = rbyte(); + s = rbyte(port); if(0x20 & s) s = 0xDF & s; else @@ -369,7 +366,7 @@ long F1fread(u_char *data, long len) return(i); } -long F1fseek(long offset, int base) +long F1fseek(GPPort *port,long offset, int base) { u_char buf[10]; @@ -386,17 +383,17 @@ long F1fseek(long offset, int base) buf[8] = (base >> 8) & 0xff; buf[9] = 0xff & base; - sendcommand(buf, 10); - recvdata(buf, 3); + sendcommand(port,buf, 10); + recvdata(port, buf, 3); if((buf[0] != 0x02) || (buf[1] != 0x0E) || (buf[2] != 0x00)){ - Abort(); + Abort(port); return(-1); } return(buf[2]); } -long F1fwrite(u_char *data, long len, u_char b) /* this function not work well */ +long F1fwrite(GPPort *port,u_char *data, long len, u_char b) /* this function not work well */ { long i = 0; @@ -407,16 +404,16 @@ long F1fwrite(u_char *data, long len, u_char b) /* this function not work well * int checksum; p = data; - wbyte(BOFRAME); - wbyte(sendaddr[address]); - wbyte(0x02); - wbyte(0x14); - wbyte(b); - wbyte(0x00); - wbyte(0x00); + wbyte(port,BOFRAME); + wbyte(port,sendaddr[address]); + wbyte(port,0x02); + wbyte(port,0x14); + wbyte(port,b); + wbyte(port,0x00); + wbyte(port,0x00); - wbyte((len >> 8) & 0xff); - wbyte(0xff & len); + wbyte(port,(len >> 8) & 0xff); + wbyte(port,0xff & len); checksum = sendaddr[address] + 0x02 + 0x14 + b + ((len >> 8) & 0xff) + (0xff & len); @@ -424,7 +421,7 @@ long F1fwrite(u_char *data, long len, u_char b) /* this function not work well * while(i < len){ s = *p; if((s == 0x7D) || (s == 0xC1) || (s == 0xC0)){ - wbyte(CESCAPE); + wbyte(port,CESCAPE); if(0x20 & s) s = 0xDF & s; else @@ -432,19 +429,19 @@ long F1fwrite(u_char *data, long len, u_char b) /* this function not work well * checksum = checksum + CESCAPE; i++; } - wbyte(s); + wbyte(port,s); checksum = checksum + s; i++; p++; } - wbyte(0x100 -(checksum & 0xff) ); - wbyte(EOFRAME); + wbyte(port,0x100 -(checksum & 0xff) ); + wbyte(port,EOFRAME); address ++; if(address >7 ) address = 0; - rstr(buf, 7); + rstr(port, buf, 7); if((buf[2] != 0x02) || (buf[3] != 0x14) || (buf[4] != 0x00)){ - Abort(); + Abort(port); fprintf(stderr,"F1fwrite fail\n"); return(-1); } @@ -452,7 +449,7 @@ long F1fwrite(u_char *data, long len, u_char b) /* this function not work well * return(i); } -u_long F1finfo(char *name) +u_long F1finfo(GPPort *port,char *name) { u_char buf[64]; int len; @@ -463,10 +460,10 @@ u_long F1finfo(char *name) snprintf(&buf[2], sizeof(name), "%s", name); len = strlen(name) + 3; - sendcommand(buf, len); - len = recvdata(buf, 37); + sendcommand(port,buf, len); + len = recvdata(port, buf, 37); if((buf[0] != 0x02) || (buf[1] != 0x0F) || (buf[2] != 00)){ - Abort(); + Abort(port); return(0); } @@ -488,25 +485,25 @@ u_long F1finfo(char *name) return(flen); } -long F1getdata(char *name, u_char *data, int verbose) +long F1getdata(GPPort*port,char *name, u_char *data, int verbose) { long filelen; long total = 0; long len; u_char *p; - F1status(0); + F1status(port,0); p = data; - filelen = F1finfo(name); + filelen = F1finfo(port,name); if(filelen < 0) return(0); - if(F1fopen(name) != 0) + if(F1fopen(port,name) != 0) return(0); - while((len = F1fread(p, 0x0400)) != 0){ + while((len = F1fread(port, p, 0x0400)) != 0){ if(len < 0){ - F1fclose(); + F1fclose(port); return(0); } p = p + len; @@ -517,29 +514,29 @@ long F1getdata(char *name, u_char *data, int verbose) fprintf(stderr, "\b\b\b\b\b\b\b\b\b\b\b\b\b"); } } - F1fclose(); + F1fclose(port); if(verbose) fprintf(stderr, "\n"); return(total); } -int F1deletepicture(int n) +int F1deletepicture(GPPort *port,int n) { u_char buf[4]; buf[0] = 0x02; buf[1] = 0x15; buf[2] = 0x00; buf[3] = 0xff & n; - sendcommand(buf, 4); - recvdata(buf, 3); + sendcommand(port,buf, 4); + recvdata(port, buf, 3); if((buf[0] != 0x02) || (buf[1] != 0x15) || (buf[2] != 0)){ - Abort(); + Abort(port); return(-1); } return(0); } -int F1ok() +int F1ok(GPPort*port) { int retrycount = RETRY; u_char buf[64]; @@ -549,29 +546,29 @@ int F1ok() sprintf(&buf[2],"SONY MKY-1001 1.00"); while(retrycount--){ - sendcommand(buf, 32); - recvdata(buf, 32); + sendcommand(port,buf, 32); + recvdata(port, buf, 32); #ifdef DEBUG fprintf(stderr,"OK:%02x%02x:%c%c%c%c\n", buf[0], buf[1], buf[3],buf[4],buf[5],buf[6]); #endif if((buf[0] != 0x01) || (buf[1] != 0x01) || (buf[2] != 0x00) ){ - Abort(); - F1reset(); + Abort(port); + F1reset(port); } else return 1; } return 0; /*ng*/ } -int F1reset() +int F1reset(GPPort *port) { u_char buf[3]; retryreset: buf[0] = 0x01; buf[1] = 0x02; - sendcommand(buf, 2); - recvdata(buf, 3); + sendcommand(port,buf, 2); + recvdata(port, buf, 3); #ifdef DEBUG fprintf(stderr,"Reset: %02x%02x:%02x\n", buf[0], buf[1], buf[2]); #endif @@ -579,13 +576,3 @@ int F1reset() goto retryreset; return (int) buf[2]; /*ok*/ } - -void Exit(code) - int code; -{ - /* if (!(F1getfd() < 0)){ - F1reset(); - closetty(F1getfd()); - } */ - /* exit(code); */ -} diff --git a/camlibs/sonydscf1/command.h b/camlibs/sonydscf1/command.h index ffebf615b..43b7a1502 100644 --- a/camlibs/sonydscf1/command.h +++ b/camlibs/sonydscf1/command.h @@ -3,30 +3,23 @@ #include "common.h" -void F1setfd P__((int)); -int F1getfd P__((void)); -int F1reset P__((void)); -void wbyte P__((u_char)); -u_char rbyte P__((void)); -void wstr P__((u_char *, int)); -void rstr P__((u_char *, int)); +void F1setfd P__((GPPort*,int)); +int F1getfd P__((GPPort*)); +int F1reset P__((GPPort*)); u_char checksum(u_char addr, u_char *cp, int len); -int F1ok P__((void)); -long F1getdata P__((char *, u_char *, int)); -void sendcommand(u_char *p, int len); -void Abort(void); -int recvdata(u_char *p, int len); -int F1status P__((int)); -char F1newstatus P__((int, char *)); -int F1howmany P__((void)); -int F1fopen P__((char *)); -long F1fread(u_char *data, long len); -long F1fwrite(u_char *data, long len, u_char b); -long F1fseek P__((long, int)); -u_long F1finfo P__((char *)); -int F1fclose P__((void)); +int F1ok P__((GPPort*)); +long F1getdata P__((GPPort*,char *, u_char *, int)); +int F1status P__((GPPort*,int)); +char F1newstatus P__((GPPort *port, int, char *)); +int F1howmany P__((GPPort *)); +int F1fopen P__((GPPort *,char *)); +long F1fread(GPPort *,u_char *data, long len); +long F1fwrite(GPPort *,u_char *data, long len, u_char b); +long F1fseek P__((GPPort *,long, int)); +u_long F1finfo P__((GPPort *,char *)); +int F1fclose P__((GPPort *)); -int F1deletepicture P__((int)); -int F1ffs P__((void)); +int F1deletepicture P__((GPPort*,int)); +int F1ffs P__((GPPort*)); #endif /* __COMMAND_H__ */ diff --git a/camlibs/sonydscf1/sonydscf1.c b/camlibs/sonydscf1/sonydscf1.c index 7d9e64c2d..9aff606c3 100644 --- a/camlibs/sonydscf1/sonydscf1.c +++ b/camlibs/sonydscf1/sonydscf1.c @@ -23,8 +23,6 @@ #include "command.h" #include "chotplay.h" -gp_port *dev; - int camera_id (CameraText *id) { strcpy(id->text, "sonydscf1-bvl"); @@ -57,9 +55,9 @@ int camera_abilities (CameraAbilitiesList *list) { } static int camera_exit (Camera *camera, GPContext *context) { - if(F1ok()) + if(F1ok(camera->port)) return(GP_ERROR); - return (F1fclose()); + return (F1fclose(camera->port)); } static int get_file_func (CameraFilesystem *fs, const char *folder, @@ -71,7 +69,7 @@ static int get_file_func (CameraFilesystem *fs, const char *folder, long int size; char *data = NULL; printf("folder: %s, file: %s\n", folder, filename); - if(!F1ok()) + if(!F1ok(camera->port)) return (GP_ERROR); gp_file_set_name (file, filename); @@ -82,10 +80,10 @@ static int get_file_func (CameraFilesystem *fs, const char *folder, switch (type) { case GP_FILE_TYPE_NORMAL: - size = get_picture (num, &data, JPEG, 0, F1howmany()); + size = get_picture (camera->port, num, &data, JPEG, 0, F1howmany(camera->port)); break; case GP_FILE_TYPE_PREVIEW: - size = get_picture (num, &data, JPEG_T, TRUE, F1howmany()); + size = get_picture (camera->port, num, &data, JPEG_T, TRUE, F1howmany(camera->port)); break; default: return (GP_ERROR_NOT_SUPPORTED); @@ -93,9 +91,7 @@ static int get_file_func (CameraFilesystem *fs, const char *folder, if (!data) return GP_ERROR; - gp_file_set_data_and_size (file, data, size); - return GP_OK; } @@ -109,9 +105,9 @@ static int delete_file_func (CameraFilesystem *fs, const char *folder, num = gp_filesystem_number(camera->fs, "/", filename, context); max = gp_filesystem_count(camera->fs,folder, context); printf("sony dscf1: file delete: %d\n",num); - if(!F1ok()) + if(!F1ok(camera->port)) return (GP_ERROR); - delete_picture(num,max); + delete_picture(camera->port,num,max); return(GP_OK); /*return (F1deletepicture(file_number));*/ } @@ -120,10 +116,10 @@ static int camera_summary (Camera *camera, CameraText *summary, GPContext *conte { /*printf("->camera summary");*/ int i; - if(!F1ok()) + if(!F1ok(camera->port)) return (GP_ERROR); - get_picture_information(&i,2); - return (F1newstatus(1, summary->text)); + get_picture_information(camera->port,&i,2); + return (F1newstatus(camera->port, 1, summary->text)); } static int camera_about (Camera *camera, CameraText *about, GPContext *context) @@ -137,17 +133,12 @@ _("Sony DSC-F1 Digital Camera Support\nM. Adam Kendall <joker@penguinpub.com>\nB static int file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list, void *data, GPContext *context) { -/* Camera *camera = data; */ - int count; - F1ok(); - /*if(F1ok()) + Camera *camera = data; + F1ok(camera->port); + /*if(F1ok(camera->port)) return(GP_ERROR);*/ - count = F1howmany(); - /* Populate the list */ - gp_list_populate(list, "PSN%05i.jpg", count); - - return GP_OK; + return gp_list_populate(list, "PSN%05i.jpg", F1howmany(camera->port)); } static CameraFilesystemFuncs fsfuncs = { @@ -163,9 +154,6 @@ int camera_init (Camera *camera, GPContext *context) { camera->functions->summary = camera_summary; camera->functions->about = camera_about; - /* FIXME: This won't work with several frontends. NO GLOBALS PLEASE! */ - dev = camera->port; - /* Configure the port */ gp_port_set_timeout (camera->port, 5000); gp_port_get_settings (camera->port, &settings); |