diff options
105 files changed, 4593 insertions, 672 deletions
diff --git a/camlibs/barbie/barbie.c b/camlibs/barbie/barbie.c index 331d8e741..4ba21664b 100644 --- a/camlibs/barbie/barbie.c +++ b/camlibs/barbie/barbie.c @@ -3,7 +3,6 @@ #include <stdlib.h> #include <string.h> #include <gphoto2.h> -#include <gpio.h> #include "barbie.h" extern char packet_1[]; @@ -54,7 +53,7 @@ int camera_abilities (CameraAbilitiesList *list) { int camera_init(Camera *camera) { - gpio_device_settings settings; + gp_port_settings settings; BarbieStruct *b; /* First, set up all the function pointers */ @@ -75,8 +74,8 @@ int camera_init(Camera *camera) { b = (BarbieStruct*)malloc(sizeof(BarbieStruct)); camera->camlib_data = b; - b->dev = gpio_new(GPIO_DEVICE_SERIAL); - gpio_set_timeout(b->dev, 5000); + b->dev = gp_port_new(GP_PORT_SERIAL); + gp_port_set_timeout(b->dev, 5000); strcpy(settings.serial.port, camera->port->path); settings.serial.speed = 57600; @@ -84,8 +83,8 @@ int camera_init(Camera *camera) { settings.serial.parity = 0; settings.serial.stopbits= 1; - gpio_set_settings(b->dev, settings); - gpio_open(b->dev); + gp_port_set_settings(b->dev, settings); + gp_port_open(b->dev); /* Create the filesystem */ b->fs = gp_filesystem_new(); @@ -97,7 +96,7 @@ int camera_exit(Camera *camera) { BarbieStruct *b = (BarbieStruct*)camera->camlib_data; - gpio_close(b->dev); + gp_port_close(b->dev); gp_filesystem_free(b->fs); return GP_OK; diff --git a/camlibs/barbie/barbie.h b/camlibs/barbie/barbie.h index f1529a233..065ef2f81 100644 --- a/camlibs/barbie/barbie.h +++ b/camlibs/barbie/barbie.h @@ -108,8 +108,8 @@ #define PICTURE_SIZE(n1, n2, n3, n4) (n1*(n2+n3)+n4) typedef struct { - gpio_device *dev; - gpio_device_settings settings; + gp_port *dev; + gp_port_settings settings; CameraFilesystem *fs; } BarbieStruct; diff --git a/camlibs/barbie/library.c b/camlibs/barbie/library.c index edb288c20..0f0759dc1 100644 --- a/camlibs/barbie/library.c +++ b/camlibs/barbie/library.c @@ -3,7 +3,6 @@ #include <stdlib.h> #include <string.h> #include <gphoto2.h> -#include <gpio.h> #include "barbie.h" /* packet headers/footers */ @@ -42,8 +41,8 @@ int barbie_write_command(BarbieStruct *b, char *command, int size) { int x; barbie_packet_dump(b, 1, command, size); - x=gpio_write(b->dev, command, size); - return (x == GPIO_OK); + x=gp_port_write(b->dev, command, size); + return (x == GP_OK); } int barbie_read_response(BarbieStruct *b, char *response, int size) { @@ -52,7 +51,7 @@ int barbie_read_response(BarbieStruct *b, char *response, int size) { char ack = 0; /* Read the ACK */ - x=gpio_read(b->dev, &ack, 1); + x=gp_port_read(b->dev, &ack, 1); barbie_packet_dump(b, 0, &ack, 1); if ((ack != ACK)||(x<0)) @@ -60,7 +59,7 @@ int barbie_read_response(BarbieStruct *b, char *response, int size) { /* Read the Response */ memset(response, 0, size); - x=gpio_read(b->dev,response, size); + x=gp_port_read(b->dev,response, size); barbie_packet_dump(b, 0, response, x); return (x > 0); } @@ -78,7 +77,7 @@ int barbie_exchange (BarbieStruct *b, char *cmd, int cmd_size, char *resp, int r if (resp[RESPONSE_BYTE] != '!') return (1); /* if busy, sleep 2 seconds */ - GPIO_SLEEP(2000); + GP_SYSTEM_SLEEP(2000); } return (0); @@ -173,7 +172,7 @@ char *barbie_read_data (BarbieStruct *bs, char *cmd, int cmd_size, int data_type s = (char *)malloc(sizeof(char)*(*size)); memset(s, 0, *size); s[0] = resp[3]; - if (gpio_read(bs->dev, &s[1], (*size)-1) < 0) { + if (gp_port_read(bs->dev, &s[1], (*size)-1) < 0) { free(s); return (NULL); } @@ -183,10 +182,10 @@ char *barbie_read_data (BarbieStruct *bs, char *cmd, int cmd_size, int data_type /* we're getting a picture */ n1 = (unsigned char)resp[2]; n2 = (unsigned char)resp[3]; - if (gpio_read(bs->dev, &c, 1) < 0) + if (gp_port_read(bs->dev, &c, 1) < 0) return (NULL); n3 = (unsigned char)c; - if (gpio_read(bs->dev, &c, 1) < 0) + if (gp_port_read(bs->dev, &c, 1) < 0) return (NULL); n4 = (unsigned char)c; *size = PICTURE_SIZE(n1, n2, n3, n4); @@ -198,7 +197,7 @@ printf("\tn1=%i n2=%i n3=%i n4=%i size=%i\n", n1, n2 ,n3, n4, *size); memset(us, 0, *size); memset(rg, 0, *size); memset(s , 0, *size+strlen(ppmhead)); - if (gpio_read(bs->dev, us, *size)<0) { + if (gp_port_read(bs->dev, us, *size)<0) { free(us); free(rg); free(s); @@ -238,7 +237,7 @@ printf("\tn1=%i n2=%i n3=%i n4=%i size=%i\n", n1, n2 ,n3, n4, *size); break; } /* read the footer */ - if (gpio_read(bs->dev, &c, 1) < 0) { + if (gp_port_read(bs->dev, &c, 1) < 0) { free(us); free(rg); free(s); diff --git a/camlibs/canon/Makefile.am b/camlibs/canon/Makefile.am index 2a92123ec..b35967b90 100644 --- a/camlibs/canon/Makefile.am +++ b/camlibs/canon/Makefile.am @@ -1,8 +1,8 @@ camlibdir = $(prefix)/lib/gphoto2 camlib_LTLIBRARIES = libgphoto2_canon.la -CFLAGS = @CFLAGS@ `gpio-config --cflags` -g -Wall -LDFLAGS = @LDFLAGS@ -g `gpio-config --libs` +CFLAGS = @CFLAGS@ -g -Wall +LDFLAGS = @LDFLAGS@ -g INCLUDES = -I$(top_srcdir)/include libgphoto2_canon_la_SOURCES =\ diff --git a/camlibs/canon/canon.c b/camlibs/canon/canon.c index 52f6d6e10..8798aea1a 100644 --- a/camlibs/canon/canon.c +++ b/camlibs/canon/canon.c @@ -29,7 +29,6 @@ #include <ctype.h> #include <gphoto2.h> -#include <gpio.h> #include "util.h" #include "serial.h" diff --git a/camlibs/canon/canon.h b/camlibs/canon/canon.h index e0efeadf2..ddebce44e 100644 --- a/camlibs/canon/canon.h +++ b/camlibs/canon/canon.h @@ -16,8 +16,8 @@ ****************************************************************************/ typedef struct { - gpio_device *dev; - gpio_device_settings settings; + gp_port *dev; + gp_port_settings settings; int speed; int debug; } CanonDataStruct; diff --git a/camlibs/canon/psa50.c b/camlibs/canon/psa50.c index 9280f743a..b0974fb4c 100644 --- a/camlibs/canon/psa50.c +++ b/camlibs/canon/psa50.c @@ -37,9 +37,9 @@ #include "canon.h" /************ new stuff ********/ -#include <gpio.h> -gpio_device *gdev; -gpio_device_settings settings; + +gp_port *gdev; +gp_port_settings settings; /************ new stuff ********/ #define MAX_TRIES 10 @@ -623,7 +623,7 @@ void intatpos(unsigned char *block, int pos, int integer ) */ static unsigned char *psa50_usb_dialogue(Camera *camera,char cmd1, char cmd2, int cmd3, int *retlen, const char *payload, int pay_length) { -#ifdef GPIO_USB +#ifdef GP_PORT_USB struct canon_info *cs = (struct canon_info*)camera->camlib_data; int msgsize; char packet[0x3000]; @@ -649,23 +649,23 @@ static unsigned char *psa50_usb_dialogue(Camera *camera,char cmd1, char cmd2, in * } */ - gpio_usb_msg_write(cs->gdev,0x10,packet,msgsize); + gp_port_usb_msg_write(cs->gdev,0x10,packet,msgsize); if (cmd3==0x202) { - gpio_read(cs->gdev, buffer, 0x40); + gp_port_read(cs->gdev, buffer, 0x40); lonlen=*(unsigned *)(buffer+0x6); //fprintf(stderr,"Internal lonlen: %x\n",lonlen); if (lonlen>0x3000) - gpio_read(cs->gdev,buffer,0x2000); + gp_port_read(cs->gdev,buffer,0x2000); else - gpio_read(cs->gdev,buffer,lonlen); + gp_port_read(cs->gdev,buffer,lonlen); *retlen=lonlen; return buffer; } else { //fprintf(stderr,"Internal retlen: %x\n",*retlen); - gpio_read(cs->gdev, buffer, *retlen+0x50); + gp_port_read(cs->gdev, buffer, *retlen+0x50); return buffer+0x50; } @@ -1502,7 +1502,7 @@ unsigned char *psa50_get_file_serial(Camera *camera, const char *name,int *lengt unsigned char *psa50_get_file_usb(Camera *camera, const char *name,int *length) { -#ifdef GPIO_USB +#ifdef GP_PORT_USB struct canon_info *cs = (struct canon_info*)camera->camlib_data; unsigned char *file = NULL; unsigned char msg[0x3000]; @@ -1573,8 +1573,8 @@ unsigned char *psa50_get_file_usb(Camera *camera, const char *name,int *length) else size=0x2000; - /* FIXME: (pm) a direct call to gpio_read here ??????? */ - gpio_read(cs->gdev,msg,size); + /* FIXME: (pm) a direct call to gp_port_read here ??????? */ + gp_port_read(cs->gdev,msg,size); } free(file); return NULL; diff --git a/camlibs/canon/psa50.h b/camlibs/canon/psa50.h index 31f5671f4..ba3f696b1 100644 --- a/camlibs/canon/psa50.h +++ b/camlibs/canon/psa50.h @@ -52,7 +52,7 @@ typedef enum { typedef struct canon_info { canonCamModel model; - gpio_device *gdev; + gp_port *gdev; int speed; /* The speed we're using for this camera */ char ident[32]; /* Model ID string given by the camera */ char owner[32]; /* Owner name */ diff --git a/camlibs/canon/serial.c b/camlibs/canon/serial.c index 374745ab2..bd84ea63d 100644 --- a/camlibs/canon/serial.c +++ b/camlibs/canon/serial.c @@ -28,7 +28,7 @@ /**** new stuff ********/ -#include <gpio.h> +#include <gphoto2-port.h> struct camera_to_usb { char *name; unsigned short idVendor; @@ -49,15 +49,15 @@ struct camera_to_usb { * ****************************************************************************/ -// gpio_device *gdev; -gpio_device_settings settings; +// gp_port *gdev; +gp_port_settings settings; -void serial_flush_input(gpio_device *gdev) +void serial_flush_input(gp_port *gdev) { } -void serial_flush_output(gpio_device *gdev) +void serial_flush_output(gp_port *gdev) { } @@ -74,12 +74,12 @@ void serial_flush_output(gpio_device *gdev) * ****************************************************************************/ -int canon_serial_change_speed(gpio_device *gdev, int speed) +int canon_serial_change_speed(gp_port *gdev, int speed) { /* set speed */ - gpio_get_settings(gdev, &settings); + gp_port_get_settings(gdev, &settings); settings.serial.speed = speed; - gpio_set_settings(gdev, settings); + gp_port_set_settings(gdev, settings); usleep(70000); @@ -99,9 +99,9 @@ int canon_serial_change_speed(gpio_device *gdev, int speed) * Returns 0 on CTS low. * ****************************************************************************/ -int canon_serial_get_cts(gpio_device *gdev) +int canon_serial_get_cts(gp_port *gdev) { - return gpio_get_pin(gdev,PIN_CTS); + return gp_port_get_pin(gdev,PIN_CTS); } /***************************************************************************** @@ -112,20 +112,20 @@ int canon_serial_get_cts(gpio_device *gdev) * * looks for USB cameras * - * gdev a valid gpio_device + * gdev a valid gp_port * i an entry of camera_to_usb * * return 1 on success, 0 on failure ****************************************************************************/ -#ifdef GPIO_USB -int canon_usb_probe(gpio_device *gdev, int i) +#ifdef GP_PORT_USB +int canon_usb_probe(gp_port *gdev, int i) { if (i >= sizeof(camera_to_usb) / sizeof(struct camera_to_usb)) goto err; - if (gpio_usb_find_device(gdev, camera_to_usb[i].idVendor, - camera_to_usb[i].idProduct) == GPIO_OK) { + if (gp_port_usb_find_device(gdev, camera_to_usb[i].idVendor, + camera_to_usb[i].idProduct) == GP_OK) { printf("found '%s' @ %s/%s\n", camera_to_usb[i].name, gdev->usb_device->bus->dirname, gdev->usb_device->filename); return 1; @@ -154,22 +154,22 @@ err: int canon_serial_init(Camera *camera, const char *devname) { struct canon_info *cs = (struct canon_info*)camera->camlib_data; -#ifdef GPIO_USB +#ifdef GP_PORT_USB int i; char msg[65536]; // char mem; char buffer[65536]; #endif - gpio_device_settings settings; + gp_port_settings settings; gp_debug_printf(GP_DEBUG_LOW,"canon","Initializing the camera.\n"); -// gpio_init(); +// gp_port_init(); switch (canon_comm_method) { case CANON_USB: -#ifdef GPIO_USB - cs->gdev = gpio_new(GPIO_DEVICE_USB); +#ifdef GP_PORT_USB + cs->gdev = gp_port_new(GP_PORT_USB); if (!cs->gdev) { return -1; } @@ -194,21 +194,21 @@ int canon_serial_init(Camera *camera, const char *devname) /* canon_send = canon_usb_send; canon_read = canon_usb_read; */ - gpio_set_settings(cs->gdev, settings); - if (gpio_open(cs->gdev) < 0) { + gp_port_set_settings(cs->gdev, settings); + if (gp_port_open(cs->gdev) < 0) { fprintf(stderr,"Camera used by other USB device!\n"); //exit(1); return -1; } - gpio_usb_msg_read(cs->gdev,0x55,msg,1); + gp_port_usb_msg_read(cs->gdev,0x55,msg,1); // fprintf(stderr,"%c\n",msg[0]); - gpio_usb_msg_read(cs->gdev,0x1,msg,0x58); - gpio_usb_msg_write(cs->gdev,0x11,msg+0x48,0x10); - gpio_read(cs->gdev, buffer, 0x44); + gp_port_usb_msg_read(cs->gdev,0x1,msg,0x58); + gp_port_usb_msg_write(cs->gdev,0x11,msg+0x48,0x10); + gp_port_read(cs->gdev, buffer, 0x44); // fprintf(stderr,"Antal b: %x\n",buffer[0]); if (buffer[0]==0x54) - gpio_read(cs->gdev, buffer, 0x40); + gp_port_read(cs->gdev, buffer, 0x40); return 0; /* #else return -1;*/ @@ -228,7 +228,7 @@ int canon_serial_init(Camera *camera, const char *devname) gp_debug_printf(GP_DEBUG_LOW,"canon","canon_init_serial(): Using serial port on %s\n", devname); - cs->gdev = gpio_new(GPIO_DEVICE_SERIAL); + cs->gdev = gp_port_new(GP_PORT_SERIAL); if (!cs->gdev) { return -1; @@ -239,8 +239,8 @@ int canon_serial_init(Camera *camera, const char *devname) settings.serial.parity = 0; settings.serial.stopbits = 1; - gpio_set_settings(cs->gdev, settings); /* Sets the serial device name */ - if ( gpio_open(cs->gdev) == GPIO_ERROR) { /* open the device */ + gp_port_set_settings(cs->gdev, settings); /* Sets the serial device name */ + if ( gp_port_open(cs->gdev) == GP_ERROR) { /* open the device */ perror("Unable to open the serial port"); return -1; } @@ -257,10 +257,10 @@ int canon_serial_init(Camera *camera, const char *devname) * * ****************************************************************************/ -int canon_serial_close(gpio_device *gdev) +int canon_serial_close(gp_port *gdev) { - gpio_close(gdev); - gpio_free(gdev); + gp_port_close(gdev); + gp_port_free(gdev); return 0; } @@ -280,7 +280,7 @@ int canon_serial_restore(Camera *camera) { struct canon_info *cs = (struct canon_info*)camera->camlib_data; - gpio_close(cs->gdev); + gp_port_close(cs->gdev); return 0; } @@ -311,12 +311,12 @@ int canon_serial_send(Camera *camera, const unsigned char *buf, int len, int sle * The S10 and S20 do not have this problem */ if (sleep>0 && cs->slow_send == 1) { for(i=0;i<len;i++) { - gpio_write(cs->gdev,(char*)buf,1); + gp_port_write(cs->gdev,(char*)buf,1); buf++; usleep(sleep); } } else { - gpio_write(cs->gdev,(char*)buf,len); + gp_port_write(cs->gdev,(char*)buf,len); } return 0; @@ -326,11 +326,11 @@ int canon_serial_send(Camera *camera, const unsigned char *buf, int len, int sle /** * Sets the timeout, in miliseconds. */ -void serial_set_timeout(gpio_device *gdev, int to) +void serial_set_timeout(gp_port *gdev, int to) { // struct canon_info *cs = (struct canon_info*)camera->camlib_data; - gpio_set_timeout(gdev,to); + gp_port_set_timeout(gdev,to); } /***************************************************************************** @@ -344,7 +344,7 @@ void serial_set_timeout(gpio_device *gdev, int to) * Returns the byte on success, -1 on error. * ****************************************************************************/ -int canon_serial_get_byte(gpio_device *gdev) +int canon_serial_get_byte(gp_port *gdev) { static unsigned char cache[512]; static unsigned char *cachep = cache; @@ -358,8 +358,8 @@ int canon_serial_get_byte(gpio_device *gdev) } - recv = gpio_read(gdev, cache, 1); - if (recv == GPIO_ERROR || recv == GPIO_TIMEOUT) + recv = gp_port_read(gdev, cache, 1); + if (recv == GP_ERROR || recv == GP_ERROR_TIMEOUT) return -1; cachep = cache; cachee = cache + recv; diff --git a/camlibs/canon/serial.h b/camlibs/canon/serial.h index 256f21d11..58ea72807 100644 --- a/camlibs/canon/serial.h +++ b/camlibs/canon/serial.h @@ -13,17 +13,17 @@ * ****************************************************************************/ -int canon_serial_change_speed(gpio_device *gdev, int speed); +int canon_serial_change_speed(gp_port *gdev, int speed); int canon_serial_init(Camera *camera, const char *devname); -int canon_serial_close(gpio_device *gdev); +int canon_serial_close(gp_port *gdev); int canon_serial_restore(Camera *camera); int canon_serial_send(Camera *camera, const unsigned char *buf, int len, int sleep); -int canon_serial_get_byte(gpio_device *gdev); -int canon_serial_get_cts(gpio_device *gdev); +int canon_serial_get_byte(gp_port *gdev); +int canon_serial_get_cts(gp_port *gdev); -void serial_flush_input(gpio_device *gdev); -void serial_flush_output(gpio_device *gdev); -void serial_set_timeout(gpio_device *gdev, int to); +void serial_flush_input(gp_port *gdev); +void serial_flush_output(gp_port *gdev); +void serial_set_timeout(gp_port *gdev, int to); #endif /* _SERIAL_H */ diff --git a/camlibs/digita/commands.c b/camlibs/digita/commands.c index e887c4ec8..9b18e85ea 100644 --- a/camlibs/digita/commands.c +++ b/camlibs/digita/commands.c @@ -14,7 +14,7 @@ #include "digita.h" -#include <gpio.h> +#include <gphoto2-port.h> void build_command(struct digita_command *cmd, int length, short command) { diff --git a/camlibs/digita/digita.c b/camlibs/digita/digita.c index 6c3aa6e4e..4fb0be471 100644 --- a/camlibs/digita/digita.c +++ b/camlibs/digita/digita.c @@ -16,7 +16,7 @@ #include "digita.h" -#include <gpio.h> +#include <gphoto2-port.h> int (*digita_send)(struct digita_device *dev, void *buffer, int buflen) = NULL; int (*digita_read)(struct digita_device *dev, void *buffer, int buflen) = NULL; diff --git a/camlibs/digita/digita.h b/camlibs/digita/digita.h index 2a17321a9..c15465694 100644 --- a/camlibs/digita/digita.h +++ b/camlibs/digita/digita.h @@ -3,7 +3,7 @@ #include <gphoto2.h> -#include <gpio.h> +#include <gphoto2-port.h> #define DIGITA_GET_PRODUCT_INFO 0x01 #define DIGITA_GET_IMAGE_SPECS 0x02 @@ -111,7 +111,7 @@ struct erase_file { }; struct digita_device { - gpio_device *gpdev; + gp_port *gpdev; int num_pictures; struct file_item *file_list; diff --git a/camlibs/digita/serial.c b/camlibs/digita/serial.c index 0054a1ab6..07ec626eb 100644 --- a/camlibs/digita/serial.c +++ b/camlibs/digita/serial.c @@ -16,8 +16,8 @@ #include "digita.h" -#include <gpio.h> -int gpio_serial_set_baudrate(gpio_device * dev); +#include <gphoto2-port.h> +int gp_port_serial_set_baudrate(gp_port * dev); struct beacon { unsigned short intro; @@ -70,7 +70,7 @@ static unsigned int checksum(const unsigned char *buffer, int len) return sum & 0xff; } -static int poll_and_wait(gpio_device *dev, int length, int bob, int eob) +static int poll_and_wait(gp_port *dev, int length, int bob, int eob) { unsigned short s, poll, poll_reply; @@ -79,9 +79,9 @@ static int poll_and_wait(gpio_device *dev, int length, int bob, int eob) (bob ? POLL_BOB : 0) | (eob ? POLL_EOB : 0); s = htons(poll); - if (gpio_write(dev, (void *)&s, sizeof(s)) < 0) + if (gp_port_write(dev, (void *)&s, sizeof(s)) < 0) return -1; - if (gpio_read(dev, (void *)&s, sizeof(s)) < 0) + if (gp_port_read(dev, (void *)&s, sizeof(s)) < 0) return -1; poll_reply = ntohs(s); if (poll_reply & POLL_ACK) @@ -107,24 +107,24 @@ static int digita_serial_send(struct digita_device *dev, void *_buffer, int len) poll_and_wait(dev->gpdev, size, sent == 0, (size + sent) == len); - if (gpio_write(dev->gpdev, buffer + sent, size) < 0) + if (gp_port_write(dev->gpdev, buffer + sent, size) < 0) return -1; sent += size; } s = 0; - if (gpio_write(dev->gpdev, (void *)&s, sizeof(s)) < 0) + if (gp_port_write(dev->gpdev, (void *)&s, sizeof(s)) < 0) return -1; return len; } -static int poll_and_reply(gpio_device *dev, int *length, int *eob, int nak) +static int poll_and_reply(gp_port *dev, int *length, int *eob, int nak) { unsigned short s, poll, poll_reply; - if (gpio_read(dev, (void *)&s, sizeof(s)) < 0) + if (gp_port_read(dev, (void *)&s, sizeof(s)) < 0) return -1; poll = ntohs(s); @@ -139,7 +139,7 @@ static int poll_and_reply(gpio_device *dev, int *length, int *eob, int nak) poll_reply = POLL_ACK; s = htons(poll_reply); - if (gpio_write(dev, (void *)&s, sizeof(s)) < 0) + if (gp_port_write(dev, (void *)&s, sizeof(s)) < 0) return -1; return 0; @@ -154,7 +154,7 @@ static int digita_serial_read(struct digita_device *dev, void *_buffer, int len) while (received < len) { poll_and_reply(dev->gpdev, &size, &eob, 0); - if (gpio_read(dev->gpdev, buffer + received, size) < 0) + if (gp_port_read(dev->gpdev, buffer + received, size) < 0) return -1; received += size; @@ -162,7 +162,7 @@ static int digita_serial_read(struct digita_device *dev, void *_buffer, int len) break; } - if (gpio_read(dev->gpdev, (void *)&s, sizeof(s)) < 0) + if (gp_port_read(dev->gpdev, (void *)&s, sizeof(s)) < 0) return -1; return received; @@ -170,12 +170,12 @@ static int digita_serial_read(struct digita_device *dev, void *_buffer, int len) int digita_serial_open(struct digita_device *dev, Camera *camera) { - gpio_device_settings settings; + gp_port_settings settings; struct beacon beacon; struct beacon_ack beacon_ack; struct beacon_comp beacon_comp; - dev->gpdev = gpio_new(GPIO_DEVICE_SERIAL); + dev->gpdev = gp_port_new(GP_PORT_SERIAL); if (!dev->gpdev) return -1; @@ -189,8 +189,8 @@ int digita_serial_open(struct digita_device *dev, Camera *camera) digita_send = digita_serial_send; digita_read = digita_serial_read; - gpio_set_settings(dev->gpdev, settings); - if (gpio_open(dev->gpdev) < 0) { + gp_port_set_settings(dev->gpdev, settings); + if (gp_port_open(dev->gpdev) < 0) { fprintf(stderr, "error opening device\n"); return 0; } @@ -198,17 +198,17 @@ int digita_serial_open(struct digita_device *dev, Camera *camera) tcsendbreak(dev->gpdev->device_fd, 4); dev->gpdev->settings.serial.speed = 0; - gpio_serial_set_baudrate(dev->gpdev); + gp_port_serial_set_baudrate(dev->gpdev); usleep(50); dev->gpdev->settings.serial.speed = camera->port->speed; - gpio_serial_set_baudrate(dev->gpdev); + gp_port_serial_set_baudrate(dev->gpdev); usleep(2000); memset((void *)&beacon, 0, sizeof(beacon)); - if (gpio_read(dev->gpdev, (void *)&beacon, sizeof(beacon)) < 0) { + if (gp_port_read(dev->gpdev, (void *)&beacon, sizeof(beacon)) < 0) { perror("reading beacon"); return 0; } @@ -228,12 +228,12 @@ printf("%04X %04X %04X %02X\n", beacon_ack.checksum = 0; beacon_ack.checksum = checksum((void *)&beacon_ack, sizeof(beacon_ack)); - if (gpio_write(dev->gpdev, (void *)&beacon_ack, sizeof(beacon_ack)) < 0) { + if (gp_port_write(dev->gpdev, (void *)&beacon_ack, sizeof(beacon_ack)) < 0) { perror("writing beacon_ack"); return -1; } - if (gpio_read(dev->gpdev, (void *)&beacon_comp, sizeof(beacon_comp)) < 0) { + if (gp_port_read(dev->gpdev, (void *)&beacon_comp, sizeof(beacon_comp)) < 0) { perror("reading beacon_comp"); return -1; } @@ -244,7 +244,7 @@ printf("%d\n", ntohl(beacon_comp.dataspeed)); dev->deviceframesize = ntohs(beacon_comp.deviceframesize); dev->gpdev->settings.serial.speed = ntohl(beacon_comp.dataspeed); - gpio_serial_set_baudrate(dev->gpdev); + gp_port_serial_set_baudrate(dev->gpdev); usleep(100000); diff --git a/camlibs/digita/usb.c b/camlibs/digita/usb.c index 4ea5649c8..fb854fee1 100644 --- a/camlibs/digita/usb.c +++ b/camlibs/digita/usb.c @@ -13,23 +13,23 @@ #include "digita.h" -#include <gpio.h> +#include <gphoto2-port.h> static int digita_usb_read(struct digita_device *dev, void *buffer, int len) { -#ifdef GPIO_USB - return gpio_read(dev->gpdev, buffer, len); +#ifdef GP_PORT_USB + return gp_port_read(dev->gpdev, buffer, len); #else - return GPIO_ERROR; + return GP_ERROR; #endif } static int digita_usb_send(struct digita_device *dev, void *buffer, int len) { -#ifdef GPIO_USB - return gpio_write(dev->gpdev, buffer, len); +#ifdef GP_PORT_USB + return gp_port_write(dev->gpdev, buffer, len); #else - return GPIO_ERROR; + return GP_ERROR; #endif } @@ -44,14 +44,14 @@ struct camera_to_usb { { "Kodak DC290", 0x040A, 0x0112 }, }; -#ifdef GPIO_USB +#ifdef GP_PORT_USB int digita_usb_probe(struct digita_device *dev, int i) { if (i >= sizeof(camera_to_usb) / sizeof(struct camera_to_usb)) goto err; - if (gpio_usb_find_device(dev->gpdev, camera_to_usb[i].idVendor, - camera_to_usb[i].idProduct) == GPIO_OK) { + if (gp_port_usb_find_device(dev->gpdev, camera_to_usb[i].idVendor, + camera_to_usb[i].idProduct) == GP_OK) { printf("found '%s' @ %s/%s\n", camera_to_usb[i].name, dev->gpdev->usb_device->bus->dirname, dev->gpdev->usb_device->filename); @@ -67,13 +67,13 @@ err: int digita_usb_open(struct digita_device *dev, Camera *camera) { -#ifdef GPIO_USB - gpio_device_settings settings; +#ifdef GP_PORT_USB + gp_port_settings settings; int i; fprintf(stderr, "digita: user selected %s\n", camera->model); - dev->gpdev = gpio_new(GPIO_DEVICE_USB); + dev->gpdev = gp_port_new(GP_PORT_USB); if (!dev->gpdev) return -1; @@ -96,8 +96,8 @@ int digita_usb_open(struct digita_device *dev, Camera *camera) digita_send = digita_usb_send; digita_read = digita_usb_read; - gpio_set_settings(dev->gpdev, settings); - if (gpio_open(dev->gpdev) < 0) { + gp_port_set_settings(dev->gpdev, settings); + if (gp_port_open(dev->gpdev) < 0) { fprintf(stderr, "error opening device\n"); return -1; } diff --git a/camlibs/directory/directory.c b/camlibs/directory/directory.c index e977728f7..0fb521554 100644 --- a/camlibs/directory/directory.c +++ b/camlibs/directory/directory.c @@ -9,7 +9,7 @@ #include <stdlib.h> #include <string.h> #include <gphoto2.h> -#include <gpio.h> +#include <gphoto2-port.h> #include "directory.h" @@ -122,11 +122,11 @@ int camera_exit (Camera *camera) { int camera_file_list(Camera *camera, CameraList *list, char *folder) { - GPIO_DIR d; - GPIO_DIRENT de; + GP_SYSTEM_DIR d; + GP_SYSTEM_DIRENT de; char buf[1024], f[1024]; - if ((d = GPIO_OPENDIR(folder))==NULL) + if ((d = GP_SYSTEM_OPENDIR(folder))==NULL) return (GP_ERROR); /* Make sure we have 1 delimiter */ @@ -135,12 +135,12 @@ int camera_file_list(Camera *camera, CameraList *list, char *folder) { else strcpy(f, folder); - while ((de = GPIO_READDIR(d))) { - if ((strcmp(GPIO_FILENAME(de), "." )!=0) && - (strcmp(GPIO_FILENAME(de), "..")!=0)) { - sprintf(buf, "%s%s", f, GPIO_FILENAME(de)); - if (GPIO_IS_FILE(buf) && (is_image(buf))) - gp_list_append(list, GPIO_FILENAME(de), GP_LIST_FILE); + while ((de = GP_SYSTEM_READDIR(d))) { + if ((strcmp(GP_SYSTEM_FILENAME(de), "." )!=0) && + (strcmp(GP_SYSTEM_FILENAME(de), "..")!=0)) { + sprintf(buf, "%s%s", f, GP_SYSTEM_FILENAME(de)); + if (GP_SYSTEM_IS_FILE(buf) && (is_image(buf))) + gp_list_append(list, GP_SYSTEM_FILENAME(de), GP_LIST_FILE); } } @@ -149,15 +149,15 @@ int camera_file_list(Camera *camera, CameraList *list, char *folder) { int camera_folder_list(Camera *camera, CameraList *list, char *folder) { - GPIO_DIR d; - GPIO_DIRENT de; + GP_SYSTEM_DIR d; + GP_SYSTEM_DIRENT de; char buf[1024], f[1024]; char *dirname; int view_hidden=1; if (gp_setting_get("directory", "hidden", buf)==GP_OK) view_hidden = atoi(buf); - if ((d = GPIO_OPENDIR(folder))==NULL) + if ((d = GP_SYSTEM_OPENDIR(folder))==NULL) return (GP_ERROR); /* Make sure we have 1 delimiter */ @@ -166,17 +166,17 @@ int camera_folder_list(Camera *camera, CameraList *list, char *folder) { else strcpy(f, folder); - while ((de = GPIO_READDIR(d))) { - if ((strcmp(GPIO_FILENAME(de), "." )!=0) && - (strcmp(GPIO_FILENAME(de), "..")!=0)) { - sprintf(buf, "%s%s", f, GPIO_FILENAME(de)); - dirname = GPIO_FILENAME(de); - if (GPIO_IS_DIR(buf)) { + while ((de = GP_SYSTEM_READDIR(d))) { + if ((strcmp(GP_SYSTEM_FILENAME(de), "." )!=0) && + (strcmp(GP_SYSTEM_FILENAME(de), "..")!=0)) { + sprintf(buf, "%s%s", f, GP_SYSTEM_FILENAME(de)); + dirname = GP_SYSTEM_FILENAME(de); + if (GP_SYSTEM_IS_DIR(buf)) { if (dirname[0] != '.') - gp_list_append(list, GPIO_FILENAME(de), GP_LIST_FOLDER); + gp_list_append(list, GP_SYSTEM_FILENAME(de), GP_LIST_FOLDER); else if (view_hidden) - gp_list_append(list, GPIO_FILENAME(de), GP_LIST_FOLDER); + gp_list_append(list, GP_SYSTEM_FILENAME(de), GP_LIST_FOLDER); } } } @@ -186,26 +186,26 @@ int camera_folder_list(Camera *camera, CameraList *list, char *folder) { int folder_index(Camera *camera) { - GPIO_DIR dir; - GPIO_DIRENT de; + GP_SYSTEM_DIR dir; + GP_SYSTEM_DIRENT de; char fname[1024]; DirectoryStruct *d = (DirectoryStruct*)camera->camlib_data; d->num_images = 0; - dir = GPIO_OPENDIR(d->directory); + dir = GP_SYSTEM_OPENDIR(d->directory); if (!dir) return (GP_ERROR); - de = GPIO_READDIR(dir); + de = GP_SYSTEM_READDIR(dir); while (de) { - sprintf(fname, "%s/%s", d->directory, GPIO_FILENAME(de)); - if (GPIO_IS_FILE(fname)) { - strcpy(d->images[d->num_images++], GPIO_FILENAME(de)); - gp_debug_printf(GP_DEBUG_LOW, "directory", "found \"%s\"\n", GPIO_FILENAME(de)); + sprintf(fname, "%s/%s", d->directory, GP_SYSTEM_FILENAME(de)); + if (GP_SYSTEM_IS_FILE(fname)) { + strcpy(d->images[d->num_images++], GP_SYSTEM_FILENAME(de)); + gp_debug_printf(GP_DEBUG_LOW, "directory", "found \"%s\"\n", GP_SYSTEM_FILENAME(de)); } - de = GPIO_READDIR(dir); + de = GP_SYSTEM_READDIR(dir); } - GPIO_CLOSEDIR(dir); + GP_SYSTEM_CLOSEDIR(dir); return (GP_OK); } diff --git a/camlibs/kodak/dc120/dc120.c b/camlibs/kodak/dc120/dc120.c index 6fb3c6339..b1594f5c9 100644 --- a/camlibs/kodak/dc120/dc120.c +++ b/camlibs/kodak/dc120/dc120.c @@ -2,7 +2,7 @@ #include <stdio.h> #include <string.h> #include <gphoto2.h> -#include <gpio.h> +#include <gphoto2-port.h> #include "dc120.h" #include "library.h" @@ -44,7 +44,7 @@ int camera_abilities (CameraAbilitiesList *list) { int camera_init (Camera *camera) { - gpio_device_settings settings; + gp_port_settings settings; DC120Data *dd; if (!camera) @@ -71,7 +71,7 @@ int camera_init (Camera *camera) { camera->functions->manual = camera_manual; camera->functions->about = camera_about; - dd->dev = gpio_new(GPIO_DEVICE_SERIAL); + dd->dev = gp_port_new(GP_PORT_SERIAL); if (!dd->dev) { free(dd); return (GP_ERROR); @@ -83,37 +83,37 @@ int camera_init (Camera *camera) { settings.serial.parity = 0; settings.serial.stopbits = 1; - if (gpio_set_settings(dd->dev, settings) == GPIO_ERROR) { - gpio_free(dd->dev); + if (gp_port_set_settings(dd->dev, settings) == GP_ERROR) { + gp_port_free(dd->dev); free(dd); return (GP_ERROR); } - if (gpio_open(dd->dev) == GPIO_ERROR) { - gpio_free(dd->dev); + if (gp_port_open(dd->dev) == GP_ERROR) { + gp_port_free(dd->dev); free(dd); return (GP_ERROR); } - gpio_set_timeout(dd->dev, TIMEOUT); + gp_port_set_timeout(dd->dev, TIMEOUT); /* Reset the camera to 9600 */ - gpio_send_break(dd->dev, 2); + gp_port_send_break(dd->dev, 2); /* Wait for it to update */ - GPIO_SLEEP(1500); + GP_SYSTEM_SLEEP(1500); if (dc120_set_speed(dd, camera->port->speed) == GP_ERROR) { - gpio_close(dd->dev); - gpio_free(dd->dev); + gp_port_close(dd->dev); + gp_port_free(dd->dev); free(dd); return (GP_ERROR); } /* Try to talk after speed change */ if (dc120_get_status(dd) == GP_ERROR) { - gpio_close(dd->dev); - gpio_free(dd->dev); + gp_port_close(dd->dev); + gp_port_free(dd->dev); free(dd); return (GP_ERROR); } @@ -135,9 +135,9 @@ int camera_exit (Camera *camera) { gp_filesystem_free(dd->fs); if (dd->dev) { - if (gpio_close(dd->dev) == GPIO_ERROR) + if (gp_port_close(dd->dev) == GP_ERROR) { /* camera did a bad, bad thing */ } - gpio_free(dd->dev); + gp_port_free(dd->dev); } free(dd); diff --git a/camlibs/kodak/dc120/dc120.h b/camlibs/kodak/dc120/dc120.h index e81a80a7f..4852f08b9 100644 --- a/camlibs/kodak/dc120/dc120.h +++ b/camlibs/kodak/dc120/dc120.h @@ -97,7 +97,7 @@ #define RETRIES 5 typedef struct { - gpio_device *dev; + gp_port *dev; CameraFilesystem *fs; /* anything else? :P */ } DC120Data; diff --git a/camlibs/kodak/dc120/library.c b/camlibs/kodak/dc120/library.c index 5ab069771..9ed01de8a 100644 --- a/camlibs/kodak/dc120/library.c +++ b/camlibs/kodak/dc120/library.c @@ -29,18 +29,18 @@ int dc120_packet_write (DC120Data *dd, char *packet, int size, int read_response write_again: /* If retry, give camera some recup time */ if (x > 0) - GPIO_SLEEP(SLEEP_TIMEOUT); + GP_PORT_SLEEP(SLEEP_TIMEOUT); /* Return error if too many retries */ if (x++ > RETRIES) return (GP_ERROR); - if (gpio_write(dd->dev, packet, size) < 0) + if (gp_port_write(dd->dev, packet, size) < 0) goto write_again; /* Read in the response from the camera if requested */ if (read_response) { - if (gpio_read(dd->dev, in, 1) < 0) + if (gp_port_read(dd->dev, in, 1) < 0) /* On error, write again */ goto write_again; @@ -58,7 +58,7 @@ write_again: int dc120_packet_read (DC120Data *dd, char *packet, int size) { - return (gpio_read(dd->dev, packet, size)); + return (gp_port_read(dd->dev, packet, size)); } int dc120_packet_read_data (DC120Data *dd, CameraFile *file, char *cmd_packet, int *size, int block_size) { @@ -88,8 +88,8 @@ read_data_write_again: while (x < num_packets) { retval = dc120_packet_read(dd, packet, block_size+1); switch (retval) { - case GPIO_ERROR: - case GPIO_TIMEOUT: + case GP_ERROR: + case GP_ERROR_TIMEOUT: /* Write that packet was bad and resend */ if (retries++ > RETRIES) return (GP_ERROR); @@ -159,9 +159,9 @@ read_data_write_again: int dc120_set_speed (DC120Data *dd, int speed) { char *p = dc120_packet_new(0x41); - gpio_device_settings settings; + gp_port_settings settings; - gpio_get_settings(dd->dev, &settings); + gp_port_get_settings(dd->dev, &settings); switch (speed) { case 9600: @@ -204,12 +204,12 @@ int dc120_set_speed (DC120Data *dd, int speed) { if (dc120_packet_write(dd, p, 8, 1) == GP_ERROR) return (GP_ERROR); - if (gpio_set_settings (dd->dev, settings) == GP_ERROR) + if (gp_port_set_settings (dd->dev, settings) == GP_ERROR) return (GP_ERROR); free (p); - GPIO_SLEEP(300); + GP_PORT_SLEEP(300); /* Speed change went OK. */ return (GP_OK); @@ -322,7 +322,7 @@ int dc120_get_file_preview (DC120Data *dd, CameraFile *file, int file_number, ch gp_file_append(file, buf, strlen(buf)); } - GPIO_SLEEP(1000); + GP_PORT_SLEEP(1000); return (GP_OK); } @@ -364,10 +364,10 @@ int dc120_wait_for_completion (DC120Data *dd) { while ((x++ < 25)&&(!done)) { retval = dc120_packet_read(dd, p, 1); switch (retval) { - case GPIO_ERROR: + case GP_ERROR: return (GP_ERROR); break; - case GPIO_TIMEOUT: + case GP_ERROR_TIMEOUT: break; default: done = 1; diff --git a/camlibs/kodak/dc240/dc240.c b/camlibs/kodak/dc240/dc240.c index 1910ba36f..122c9a8ac 100644 --- a/camlibs/kodak/dc240/dc240.c +++ b/camlibs/kodak/dc240/dc240.c @@ -2,7 +2,7 @@ #include <stdio.h> #include <string.h> #include <gphoto2.h> -#include <gpio.h> +#include <gphoto2-port.h> #include "dc240.h" #include "library.h" @@ -43,7 +43,7 @@ int camera_abilities (CameraAbilitiesList *list) { int camera_init (Camera *camera) { - gpio_device_settings settings; + gp_port_settings settings; DC240Data *dd; if (!camera) @@ -72,7 +72,7 @@ int camera_init (Camera *camera) { switch (camera->port->type) { case GP_PORT_SERIAL: - dd->dev = gpio_new(GPIO_DEVICE_SERIAL); + dd->dev = gp_port_new(GP_PORT_SERIAL); if (!dd->dev) { free(dd); return (GP_ERROR); @@ -83,15 +83,14 @@ int camera_init (Camera *camera) { settings.serial.parity = 0; settings.serial.stopbits = 1; break; -#ifdef GPIO_USB case GP_PORT_USB: - dd->dev = gpio_new(GPIO_DEVICE_USB); + dd->dev = gp_port_new(GP_PORT_USB); if (!dd->dev) { free(dd); return (GP_ERROR); } - if (gpio_usb_find_device(dd->dev, 0x040A, 0x0120) == GPIO_ERROR) { - gpio_free(dd->dev); + if (gp_port_usb_find_device(dd->dev, 0x040A, 0x0120) == GP_ERROR) { + gp_port_free(dd->dev); free (dd); return (GP_ERROR); } @@ -101,35 +100,34 @@ int camera_init (Camera *camera) { settings.usb.interface = 0; settings.usb.altsetting = 0; break; -#endif default: return (GP_ERROR); } - if (gpio_set_settings(dd->dev, settings) == GPIO_ERROR) { - gpio_free(dd->dev); + if (gp_port_set_settings(dd->dev, settings) == GP_ERROR) { + gp_port_free(dd->dev); free(dd); return (GP_ERROR); } - if (gpio_open(dd->dev) == GPIO_ERROR) { - gpio_free(dd->dev); + if (gp_port_open(dd->dev) == GP_ERROR) { + gp_port_free(dd->dev); free(dd); return (GP_ERROR); } - gpio_set_timeout(dd->dev, TIMEOUT); + gp_port_set_timeout(dd->dev, TIMEOUT); if (camera->port->type == GP_PORT_SERIAL) { /* Reset the camera to 9600 */ - gpio_send_break(dd->dev, 1); + gp_port_send_break(dd->dev, 1); /* Wait for it to reset */ - GPIO_SLEEP(1500); + GP_SYSTEM_SLEEP(1500); if (dc240_set_speed(dd, camera->port->speed) == GP_ERROR) { - gpio_close(dd->dev); - gpio_free(dd->dev); + gp_port_close(dd->dev); + gp_port_free(dd->dev); free(dd); return (GP_ERROR); } @@ -137,15 +135,15 @@ int camera_init (Camera *camera) { /* Open the CF card */ if (dc240_open(dd) == GP_ERROR) { - gpio_close(dd->dev); - gpio_free(dd->dev); + gp_port_close(dd->dev); + gp_port_free(dd->dev); free(dd); return (GP_ERROR); } if (dc240_packet_set_size(dd, HPBS+2) == GP_ERROR) { - gpio_close(dd->dev); - gpio_free(dd->dev); + gp_port_close(dd->dev); + gp_port_free(dd->dev); free(dd); return (GP_ERROR); } @@ -165,9 +163,9 @@ int camera_exit (Camera *camera) { dc240_close(dd); if (dd->dev) { - if (gpio_close(dd->dev) == GPIO_ERROR) + if (gp_port_close(dd->dev) == GP_ERROR) { /* camera did a bad, bad thing */ } - gpio_free(dd->dev); + gp_port_free(dd->dev); } free(dd); diff --git a/camlibs/kodak/dc240/dc240.h b/camlibs/kodak/dc240/dc240.h index d884ae5db..5cb23d01d 100644 --- a/camlibs/kodak/dc240/dc240.h +++ b/camlibs/kodak/dc240/dc240.h @@ -16,6 +16,6 @@ #define HPBS 1024*1 typedef struct { - gpio_device *dev; + gp_port *dev; /* anything else? :P */ } DC240Data; diff --git a/camlibs/kodak/dc240/library.c b/camlibs/kodak/dc240/library.c index 9d8f16b92..d7243104c 100644 --- a/camlibs/kodak/dc240/library.c +++ b/camlibs/kodak/dc240/library.c @@ -63,18 +63,18 @@ int dc240_packet_write (DC240Data *dd, char *packet, int size, int read_response write_again: /* If retry, give camera some recup time */ if (x > 0) - GPIO_SLEEP(SLEEP_TIMEOUT); + GP_SYSTEM_SLEEP(SLEEP_TIMEOUT); /* Return error if too many retries */ if (x++ > RETRIES) return (GP_ERROR); - if (gpio_write(dd->dev, packet, size) < 0) + if (gp_port_write(dd->dev, packet, size) < 0) goto write_again; /* Read in the response from the camera if requested */ if (read_response) { - if (gpio_read(dd->dev, in, 1) < 0) + if (gp_port_read(dd->dev, in, 1) < 0) /* On error, write again */ goto write_again; } @@ -84,7 +84,7 @@ write_again: int dc240_packet_read (DC240Data *dd, char *packet, int size) { - return (gpio_read(dd->dev, packet, size)); + return (gp_port_read(dd->dev, packet, size)); } int dc240_packet_write_ack (DC240Data *dd) { @@ -92,7 +92,7 @@ int dc240_packet_write_ack (DC240Data *dd) { char p[2]; p[0] = PACK1; - if (gpio_write(dd->dev, p, 1) < 0) + if (gp_port_write(dd->dev, p, 1) < 0) return GP_ERROR; return GP_OK; @@ -103,7 +103,7 @@ int dc240_packet_write_nak (DC240Data *dd) { char p[2]; p[0] = PACK0; - if (gpio_write(dd->dev, p, 1) < 0) + if (gp_port_write(dd->dev, p, 1) < 0) return GP_ERROR; return GP_OK; } @@ -118,10 +118,10 @@ int dc240_wait_for_completion (DC240Data *dd) { while ((x++ < 25)&&(!done)) { retval = dc240_packet_read(dd, p, 1); switch (retval) { - case GPIO_ERROR: + case GP_ERROR: return (GP_ERROR); break; - case GPIO_TIMEOUT: + case GP_ERROR_TIMEOUT: break; default: done = 1; @@ -132,7 +132,7 @@ int dc240_wait_for_completion (DC240Data *dd) { if (x==25) return (GP_ERROR); -// GPIO_SLEEP(500); +// GP_PORT_SLEEP(500); return (GP_OK); } @@ -175,7 +175,7 @@ read_data_read_again: /* Read the response/data */ retval = dc240_packet_read(dd, packet, block_size+2); - if ((retval == GPIO_ERROR) || (retval == GPIO_TIMEOUT)) { + if ((retval == GP_ERROR) || (retval == GP_ERROR_TIMEOUT)) { /* ERROR reading response/data */ if (retries++ > RETRIES) return (GP_ERROR); @@ -290,9 +290,9 @@ int dc240_get_file_size (DC240Data *dd, char *folder, char *filename, int thumb) int dc240_set_speed (DC240Data *dd, int speed) { char *p = dc240_packet_new(0x41); - gpio_device_settings settings; + gp_port_settings settings; - gpio_get_settings(dd->dev, &settings); + gp_port_get_settings(dd->dev, &settings); switch (speed) { case 9600: @@ -335,12 +335,12 @@ int dc240_set_speed (DC240Data *dd, int speed) { if (dc240_packet_write(dd, p, 8, 1) == GP_ERROR) return (GP_ERROR); - if (gpio_set_settings (dd->dev, settings) == GP_ERROR) + if (gp_port_set_settings (dd->dev, settings) == GP_ERROR) return (GP_ERROR); free (p); - GPIO_SLEEP(300); + GP_SYSTEM_SLEEP(300); if (dc240_wait_for_completion(dd) == GP_ERROR) return (GP_ERROR); diff --git a/camlibs/konica/konica.c b/camlibs/konica/konica.c index efe4d9dd9..0c23288d5 100644 --- a/camlibs/konica/konica.c +++ b/camlibs/konica/konica.c @@ -101,21 +101,21 @@ GP_RESULT (guchar byte1, guchar byte2) gint -k_init (gpio_device* device) +k_init (gp_port* device) { return (l_init (device)); } gint -k_exit (gpio_device* device) +k_exit (gp_port* device) { return (l_exit (device)); } gint -k_erase_image (gpio_device* device, gboolean image_id_long, gulong image_id) +k_erase_image (gp_port* device, gboolean image_id_long, gulong image_id) { /************************************************/ /* Command to erase one image. */ @@ -163,7 +163,7 @@ k_erase_image (gpio_device* device, gboolean image_id_long, gulong image_id) gint -k_format_memory_card (gpio_device* device) +k_format_memory_card (gp_port* device) { /************************************************/ /* Command to format the memory card. */ @@ -195,7 +195,7 @@ k_format_memory_card (gpio_device* device) } -gint k_erase_all (gpio_device* device, guint* number_of_images_not_erased) +gint k_erase_all (gp_port* device, guint* number_of_images_not_erased) { /************************************************/ /* Command to erase all images in the camera, */ @@ -236,7 +236,7 @@ gint k_erase_all (gpio_device* device, guint* number_of_images_not_erased) } -gint k_set_protect_status (gpio_device *device, gboolean image_id_long, gulong image_id, gboolean protected) +gint k_set_protect_status (gp_port *device, gboolean image_id_long, gulong image_id, gboolean protected) { /************************************************/ /* Command to set the protect status of one */ @@ -292,7 +292,7 @@ gint k_set_protect_status (gpio_device *device, gboolean image_id_long, gulong i gint k_get_image ( - gpio_device* device, + gp_port* device, gboolean image_id_long, gulong image_id, k_image_type_t image_type, @@ -370,7 +370,7 @@ k_get_image ( gint k_get_image_information ( - gpio_device* device, + gp_port* device, gboolean image_id_long, gulong image_number, gulong* image_id, @@ -461,7 +461,7 @@ k_get_image_information ( gint -k_get_preview (gpio_device* device, gboolean thumbnail, guchar** image_buffer, guint* image_buffer_size) +k_get_preview (gp_port* device, gboolean thumbnail, guchar** image_buffer, guint* image_buffer_size) { /************************************************/ /* Command to get the preview from the camera. */ @@ -502,7 +502,7 @@ k_get_preview (gpio_device* device, gboolean thumbnail, guchar** image_buffer, g gint k_get_io_capability ( - gpio_device* device, + gp_port* device, gboolean* bit_rate_300, gboolean* bit_rate_600, gboolean* bit_rate_1200, @@ -588,7 +588,7 @@ gint k_get_io_capability ( gint k_get_information ( - gpio_device* device, + gp_port* device, gchar** model, gchar** serial_number, guchar* hardware_version_major, @@ -764,7 +764,7 @@ k_get_information ( gint k_get_status ( - gpio_device* device, + gp_port* device, guint* self_test_result, k_power_level_t* power_level, k_power_source_t* power_source, @@ -954,7 +954,7 @@ k_get_status ( gint k_get_date_and_time ( - gpio_device* device, + gp_port* device, guchar* year, guchar* month, guchar* day, @@ -1015,7 +1015,7 @@ k_get_date_and_time ( gint k_get_preferences ( - gpio_device* device, + gp_port* device, guint* shutoff_time, guint* self_timer_time, guint* beep, @@ -1072,7 +1072,7 @@ k_get_preferences ( gint k_set_io_capability ( - gpio_device* device, + gp_port* device, guint bit_rate, gboolean bit_flag_7_or_8_bits, gboolean bit_flag_stop_2_bits, @@ -1148,7 +1148,7 @@ k_set_io_capability ( gint -k_set_date_and_time (gpio_device* device, guchar year, guchar month, guchar day, guchar hour, guchar minute, guchar second) +k_set_date_and_time (gp_port* device, guchar year, guchar month, guchar day, guchar hour, guchar minute, guchar second) { /************************************************/ /* Command to set date and time of the camera. */ @@ -1189,7 +1189,7 @@ k_set_date_and_time (gpio_device* device, guchar year, guchar month, guchar day, gint -k_set_preference (gpio_device* device, k_preference_t preference, guint value) +k_set_preference (gp_port* device, k_preference_t preference, guint value) { /************************************************/ /* Command to set a preference of the camera. */ @@ -1255,7 +1255,7 @@ k_set_preference (gpio_device* device, k_preference_t preference, guint value) gint -k_reset_preferences (gpio_device* device) +k_reset_preferences (gp_port* device) { /************************************************/ /* Command to reset the preferences of the */ @@ -1286,7 +1286,7 @@ k_reset_preferences (gpio_device* device) gint k_take_picture ( - gpio_device* device, + gp_port* device, gboolean image_id_long, gulong* image_id, guint* exif_size, @@ -1357,7 +1357,7 @@ k_take_picture ( gint -k_localization_tv_output_format_set (gpio_device* device, k_tv_output_format_t tv_output_format) +k_localization_tv_output_format_set (gp_port* device, k_tv_output_format_t tv_output_format) { /************************************************/ /* Command for various localization issues. */ @@ -1412,7 +1412,7 @@ k_localization_tv_output_format_set (gpio_device* device, k_tv_output_format_t t gint -k_localization_date_format_set (gpio_device* device, k_date_format_t date_format) +k_localization_date_format_set (gp_port* device, k_date_format_t date_format) { /************************************************/ /* Command for various localization issues. */ @@ -1467,7 +1467,7 @@ k_localization_date_format_set (gpio_device* device, k_date_format_t date_format gint -k_localization_data_put (gpio_device* device, guchar* data, gulong data_size) +k_localization_data_put (gp_port* device, guchar* data, gulong data_size) { /************************************************/ /* Command for various localization issues. */ @@ -1575,7 +1575,7 @@ k_localization_data_put (gpio_device* device, guchar* data, gulong data_size) gint -k_cancel (gpio_device* device, k_command_t* command) +k_cancel (gp_port* device, k_command_t* command) { /************************************************/ /* Command to cancel a command. */ diff --git a/camlibs/konica/konica.h b/camlibs/konica/konica.h index 8f3966a2b..a11d647fa 100644 --- a/camlibs/konica/konica.h +++ b/camlibs/konica/konica.h @@ -252,14 +252,14 @@ typedef enum { /* for image IDs (qm100, unsigned int), the other one uses four */ /* (qm200, unsigned long). */ /****************************************************************/ -gint k_init (gpio_device *device); +gint k_init (gp_port *device); -gint k_exit (gpio_device *device); +gint k_exit (gp_port *device); gint k_get_io_capability ( - gpio_device *device, + gp_port *device, gboolean *bit_rate_300, gboolean *bit_rate_600, gboolean *bit_rate_1200, @@ -278,7 +278,7 @@ gint k_get_io_capability ( gint k_set_io_capability ( - gpio_device *device, + gp_port *device, guint bit_rate, gboolean bit_flag_7_or_8_bits, gboolean bit_flag_stop_2_bits, @@ -287,14 +287,14 @@ gint k_set_io_capability ( gboolean bit_flag_use_hw_flow_control); -gint k_erase_all (gpio_device *device, guint *number_of_images_not_erased); +gint k_erase_all (gp_port *device, guint *number_of_images_not_erased); -gint k_format_memory_card (gpio_device *device); +gint k_format_memory_card (gp_port *device); gint k_take_picture ( - gpio_device *device, + gp_port *device, gboolean image_id_long, gulong *image_id, guint *exif_size, @@ -303,23 +303,23 @@ gint k_take_picture ( gboolean *protected); -gint k_get_preview (gpio_device *device, gboolean thumbnail, guchar **image_buffer, guint *image_buffer_size); +gint k_get_preview (gp_port *device, gboolean thumbnail, guchar **image_buffer, guint *image_buffer_size); -gint k_set_preference (gpio_device *device, k_preference_t preference, guint value); +gint k_set_preference (gp_port *device, k_preference_t preference, guint value); -gint k_set_protect_status (gpio_device *device, gboolean image_id_long, gulong image_id, gboolean protected); +gint k_set_protect_status (gp_port *device, gboolean image_id_long, gulong image_id, gboolean protected); -gint k_erase_image (gpio_device *device, gboolean image_id_long, gulong image_id); +gint k_erase_image (gp_port *device, gboolean image_id_long, gulong image_id); -gint k_reset_preferences (gpio_device *device); +gint k_reset_preferences (gp_port *device); gint k_get_date_and_time ( - gpio_device *device, + gp_port *device, guchar *year, guchar *month, guchar *day, @@ -329,7 +329,7 @@ gint k_get_date_and_time ( gint k_set_date_and_time ( - gpio_device *device, + gp_port *device, guchar year, guchar month, guchar day, @@ -339,7 +339,7 @@ gint k_set_date_and_time ( gint k_get_preferences ( - gpio_device *device, + gp_port *device, guint *shutoff_time, guint *self_timer_time, guint *beep, @@ -347,7 +347,7 @@ gint k_get_preferences ( gint k_get_status ( - gpio_device *device, + gp_port *device, guint *self_test_result, k_power_level_t *power_level, k_power_source_t *power_source, @@ -373,7 +373,7 @@ gint k_get_status ( gint k_get_information ( - gpio_device *device, + gp_port *device, gchar **model, gchar **serial_number, guchar *hardware_version_major, @@ -387,7 +387,7 @@ gint k_get_information ( gint k_get_image_information ( - gpio_device *device, + gp_port *device, gboolean image_id_long, gulong image_number, gulong *image_id, @@ -398,7 +398,7 @@ gint k_get_image_information ( gint k_get_image ( - gpio_device *device, + gp_port *device, gboolean image_id_long, gulong image_id, k_image_type_t image_type, @@ -406,17 +406,17 @@ gint k_get_image ( guint *image_buffer_size); -gint k_set_protect_status (gpio_device *device, gboolean image_id_long, gulong image_id, gboolean protected); +gint k_set_protect_status (gp_port *device, gboolean image_id_long, gulong image_id, gboolean protected); -gint k_localization_tv_output_format_set (gpio_device *device, k_tv_output_format_t tv_output_format); +gint k_localization_tv_output_format_set (gp_port *device, k_tv_output_format_t tv_output_format); -gint k_localization_date_format_set (gpio_device *device, k_date_format_t date_format); +gint k_localization_date_format_set (gp_port *device, k_date_format_t date_format); -gint k_localization_data_put (gpio_device *device, guchar *data, gulong data_size); +gint k_localization_data_put (gp_port *device, guchar *data, gulong data_size); -gint k_cancel (gpio_device *device, k_command_t *command); +gint k_cancel (gp_port *device, k_command_t *command); diff --git a/camlibs/konica/library.c b/camlibs/konica/library.c index e9a2abad3..91893badd 100644 --- a/camlibs/konica/library.c +++ b/camlibs/konica/library.c @@ -159,8 +159,8 @@ camera_init (Camera* camera) gint result; guint speed; konica_data_t* konica_data; - gpio_device_settings device_settings; - gpio_device* device; + gp_port_settings device_settings; + gp_port* device; g_return_val_if_fail (camera, GP_ERROR_BAD_PARAMETERS); @@ -188,7 +188,7 @@ camera_init (Camera* camera) camera->functions->result_as_string = camera_result_as_string; /* Create device. */ - device = gpio_new (GPIO_DEVICE_SERIAL); + device = gp_port_new (GP_PORT_SERIAL); /* Store some data we constantly need. */ konica_data = g_new (konica_data_t, 1); @@ -225,7 +225,7 @@ camera_init (Camera* camera) if (camera->port->speed != 0) { gp_debug_printf (GP_DEBUG_LOW, "konica", "-> Quick test for given speed %i.\n", camera->port->speed); device_settings.serial.speed = camera->port->speed; - gpio_set_settings (device, device_settings); + gp_port_set_settings (device, device_settings); if (k_init (device) == GP_OK) return (GP_OK); } @@ -235,7 +235,7 @@ camera_init (Camera* camera) for (i = 0; i < 10; i++) { gp_debug_printf (GP_DEBUG_LOW, "konica", "-> Testing speed %i.\n", test_bit_rate[i]); device_settings.serial.speed = test_bit_rate[i]; - gpio_set_settings (device, device_settings); + gp_port_set_settings (device, device_settings); if (k_init (device) == GP_OK) break; } if ((i == 1) && (camera->port->speed == 0)) { @@ -246,7 +246,7 @@ camera_init (Camera* camera) } if (i == 10) { - gpio_free (device); + gp_port_free (device); return (GP_ERROR_IO); } @@ -270,7 +270,7 @@ camera_init (Camera* camera) &bit_flag_parity_odd, &bit_flag_use_hw_flow_control); if (result != GP_OK) { - gpio_free (device); + gp_port_free (device); return (result); } if (camera->port->speed == 0) { @@ -278,22 +278,22 @@ camera_init (Camera* camera) /* We are given 0. Set the highest speed. */ for (i = 9; i >= 0; i--) if (bit_rate_supported[i]) break; if (i < 0) { - gpio_free (device); + gp_port_free (device); return (GP_ERROR_NOT_SUPPORTED); } gp_debug_printf (GP_DEBUG_LOW, "konica", "-> Setting speed to %i.\n", bit_rate[i]); if ((result = k_set_io_capability (device, bit_rate[i], TRUE, FALSE, FALSE, FALSE, FALSE)) != GP_OK) { - gpio_free (device); + gp_port_free (device); return (result); } if ((result = k_exit (device)) != GP_OK) { - gpio_free (device); + gp_port_free (device); return (result); } device_settings.serial.speed = bit_rate[i]; - gpio_set_settings (device, device_settings); + gp_port_set_settings (device, device_settings); if ((result = k_init (device)) != GP_OK) { - gpio_free (device); + gp_port_free (device); return (result); } @@ -323,20 +323,20 @@ camera_init (Camera* camera) (speed != 38400) && (speed != 57600) && (speed != 115200))) { - gpio_free (device); + gp_port_free (device); return (GP_ERROR_NOT_SUPPORTED); } /* Now we can set the given speed. */ if ((result = k_set_io_capability (device, camera->port->speed, TRUE, FALSE, FALSE, FALSE, FALSE)) != GP_OK) { - gpio_free (device); + gp_port_free (device); return (result); } if ((result = k_exit (device)) != GP_OK) { - gpio_free (device); + gp_port_free (device); return (result); } if ((result = k_init (device)) != GP_OK) { - gpio_free (device); + gp_port_free (device); return (result); } @@ -357,7 +357,7 @@ camera_exit (Camera* camera) if ((result = k_exit (konica_data->device)) != GP_OK) return (result); if ((result = gp_filesystem_free (konica_data->filesystem)) != GP_OK) return (result); - if ((result = gpio_free (konica_data->device)) != GPIO_OK) return (GP_ERROR); + if ((result = gp_port_free (konica_data->device)) != GP_OK) return (GP_ERROR); return (GP_OK); } diff --git a/camlibs/konica/library.h b/camlibs/konica/library.h index 859ff9888..85e8286db 100644 --- a/camlibs/konica/library.h +++ b/camlibs/konica/library.h @@ -2,7 +2,7 @@ /* Type definitions */ /********************/ typedef struct { - gpio_device* device; + gp_port* device; gboolean image_id_long; CameraFilesystem* filesystem; } konica_data_t; diff --git a/camlibs/konica/lowlevel.c b/camlibs/konica/lowlevel.c index 63e93e250..e7279ab0c 100644 --- a/camlibs/konica/lowlevel.c +++ b/camlibs/konica/lowlevel.c @@ -33,40 +33,40 @@ /**************/ /* Prototypes */ /**************/ -gint l_esc_read (gpio_device* device, guchar* c); +gint l_esc_read (gp_port* device, guchar* c); -gint l_send (gpio_device* device, guchar* send_buffer, guint send_buffer_size); +gint l_send (gp_port* device, guchar* send_buffer, guint send_buffer_size); -gint l_receive (gpio_device* device, guchar** rb, guint* rbs, guint timeout); +gint l_receive (gp_port* device, guchar** rb, guint* rbs, guint timeout); /*************/ /* Functions */ /*************/ gint -l_init (gpio_device* device) +l_init (gp_port* device) { guchar c; gint i; g_return_val_if_fail (device, GP_ERROR_BAD_PARAMETERS); - gpio_set_timeout (device, DEFAULT_TIMEOUT); - if (gpio_open (device) == GPIO_ERROR) return GP_ERROR_IO; + gp_port_set_timeout (device, DEFAULT_TIMEOUT); + if (gp_port_open (device) == GP_ERROR) return GP_ERROR_IO; for (i = 0; ; i++) { /****************/ /* Write ENQ. */ /****************/ - if (gpio_write (device, "\5", 1) == GPIO_ERROR) return GP_ERROR_IO; - if (gpio_read (device, &c, 1) < 1) { + if (gp_port_write (device, "\5", 1) == GP_ERROR) return GP_ERROR_IO; + if (gp_port_read (device, &c, 1) < 1) { /******************************************************/ /* We didn't receive anything. We'll try up to five */ /* time. */ /******************************************************/ if (i == 4) { - gpio_close (device); + gp_port_close (device); return (GP_ERROR_IO); } continue; @@ -82,7 +82,7 @@ l_init (gpio_device* device) /* The camera seems to be sending something. We'll */ /* dump all bytes we get and try again. */ /******************************************************/ - while (gpio_read (device, &c, 1) > 0); + while (gp_port_read (device, &c, 1) > 0); i--; break; } @@ -91,21 +91,21 @@ l_init (gpio_device* device) gint -l_exit (gpio_device* device) +l_exit (gp_port* device) { g_return_val_if_fail (device, GP_ERROR_BAD_PARAMETERS); - if (gpio_close (device) == GPIO_ERROR) return (GP_ERROR_IO); + if (gp_port_close (device) == GP_ERROR) return (GP_ERROR_IO); return (GP_OK); } gint -l_esc_read (gpio_device* device, guchar* c) +l_esc_read (gp_port* device, guchar* c) { g_return_val_if_fail (device, GP_ERROR_BAD_PARAMETERS); - if (gpio_read (device, c, 1) < 1) return GP_ERROR_IO; + if (gp_port_read (device, c, 1) < 1) return GP_ERROR_IO; /**********************************************************************/ /* STX, ETX, ENQ, ACK, XOFF, XON, NACK, and ETB have to be masked by */ /* ESC. If we receive one of those (except ETX and ETB) without mask, */ @@ -124,7 +124,7 @@ l_esc_read (gpio_device* device, guchar* c) if ((*c == ETX) || (*c == ETB)) return (GP_ERROR_CORRUPTED_DATA); } else if (*c == ESC) { - if (gpio_read (device, c, 1) < 1) return GP_ERROR_IO; + if (gp_port_read (device, c, 1) < 1) return GP_ERROR_IO; *c = (~*c & 0xff); if ((*c != STX ) && (*c != ETX ) && (*c != ENQ) && (*c != ACK ) && (*c != XOFF) && (*c != XON) && (*c != NACK) && (*c != ETB ) && (*c != ESC)) gp_debug_printf (GP_DEBUG_HIGH, "konica", "Wrong ESC masking!"); @@ -134,7 +134,7 @@ l_esc_read (gpio_device* device, guchar* c) gint -l_send (gpio_device* device, guchar* send_buffer, guint send_buffer_size) +l_send (gp_port* device, guchar* send_buffer, guint send_buffer_size) { guchar c; guchar checksum; @@ -153,11 +153,11 @@ l_send (gpio_device* device, guchar* send_buffer, guint send_buffer_size) /****************/ /* Write ENQ. */ /****************/ - if (gpio_write (device, "\5", 1) == GPIO_ERROR) return (GP_ERROR_IO); + if (gp_port_write (device, "\5", 1) == GP_ERROR) return (GP_ERROR_IO); /****************/ /* Read. */ /****************/ - if (gpio_read (device, &c, 1) < 1) { + if (gp_port_read (device, &c, 1) < 1) { /************************************/ /* Let's try for a couple of times. */ /************************************/ @@ -189,9 +189,9 @@ l_send (gpio_device* device, guchar* send_buffer, guint send_buffer_size) /* Write NACK. */ /****************/ c = NACK; - if (gpio_write (device, &c, 1) == GPIO_ERROR) return (GP_ERROR_IO); + if (gp_port_write (device, &c, 1) == GP_ERROR) return (GP_ERROR_IO); for (;;) { - if (gpio_read (device, &c, 1) < 1) return (GP_ERROR_IO); + if (gp_port_read (device, &c, 1) < 1) return (GP_ERROR_IO); switch (c) { case ENQ: /**************************************/ @@ -276,11 +276,11 @@ l_send (gpio_device* device, guchar* send_buffer, guint send_buffer_size) /************************/ /* Write data as above. */ /************************/ - if (gpio_write (device, sb, sbs) == GPIO_ERROR) { + if (gp_port_write (device, sb, sbs) == GP_ERROR) { g_free (sb); return (GP_ERROR_IO); } - if (gpio_read (device, &c, 1) < 1) { + if (gp_port_read (device, &c, 1) < 1) { g_free (sb); return GP_ERROR_IO; } @@ -294,7 +294,7 @@ l_send (gpio_device* device, guchar* send_buffer, guint send_buffer_size) /* Write EOT. */ /****************/ c = EOT; - if (gpio_write (device, &c, 1) == GPIO_ERROR) return (GP_ERROR_IO); + if (gp_port_write (device, &c, 1) == GP_ERROR) return (GP_ERROR_IO); return (GP_OK); case NACK: /******************************************************/ @@ -315,7 +315,7 @@ l_send (gpio_device* device, guchar* send_buffer, guint send_buffer_size) gint -l_receive (gpio_device* device, guchar** rb, guint* rbs, guint timeout) +l_receive (gp_port* device, guchar** rb, guint* rbs, guint timeout) { guchar c, d; gboolean error_flag; @@ -326,9 +326,9 @@ l_receive (gpio_device* device, guchar** rb, guint* rbs, guint timeout) g_return_val_if_fail (device, GP_ERROR_BAD_PARAMETERS); for (i = 0; ; ) { - gpio_set_timeout (device, timeout); - if (gpio_read (device, &c, 1) < 1) return (GP_ERROR_IO); - gpio_set_timeout (device, DEFAULT_TIMEOUT); + gp_port_set_timeout (device, timeout); + if (gp_port_read (device, &c, 1) < 1) return (GP_ERROR_IO); + gp_port_set_timeout (device, DEFAULT_TIMEOUT); switch (c) { case ENQ: /******************************************************/ @@ -361,7 +361,7 @@ l_receive (gpio_device* device, guchar** rb, guint* rbs, guint timeout) /* error). */ /******************************************************/ for (;;) { - if (gpio_read (device, &c, 1) < 0) return (GP_ERROR_CORRUPTED_DATA); + if (gp_port_read (device, &c, 1) < 0) return (GP_ERROR_CORRUPTED_DATA); if (c == ENQ) break; } break; @@ -371,10 +371,10 @@ l_receive (gpio_device* device, guchar** rb, guint* rbs, guint timeout) /**************/ /* Write ACK. */ /**************/ - if (gpio_write (device, "\6", 1) == GPIO_ERROR) return (GP_ERROR_IO); + if (gp_port_write (device, "\6", 1) == GP_ERROR) return (GP_ERROR_IO); for (*rbs = 0; ; ) { for (j = 0; ; j++) { - if (gpio_read (device, &c, 1) < 1) return (GP_ERROR_IO); + if (gp_port_read (device, &c, 1) < 1) return (GP_ERROR_IO); switch (c) { case STX: /**********************************************/ @@ -428,7 +428,7 @@ l_receive (gpio_device* device, guchar** rb, guint* rbs, guint timeout) if (error_flag) break; } if (!error_flag) { - if (gpio_read (device, &d, 1) < 1) return (GP_ERROR_IO); + if (gp_port_read (device, &d, 1) < 1) return (GP_ERROR_IO); switch (d) { case ETX: /**************************************/ @@ -452,7 +452,7 @@ l_receive (gpio_device* device, guchar** rb, guint* rbs, guint timeout) /* reject the packet. */ /**************************************/ while ((d != ETX) && (d != ETB)) { - if (gpio_read (device, &d, 1) < 1) return (GP_ERROR_IO); + if (gp_port_read (device, &d, 1) < 1) return (GP_ERROR_IO); } error_flag = TRUE; break; @@ -469,7 +469,7 @@ l_receive (gpio_device* device, guchar** rb, guint* rbs, guint timeout) /****************/ /* Write ACK. */ /****************/ - if (gpio_write (device, "\6", 1) == GPIO_ERROR) return (GP_ERROR_IO); + if (gp_port_write (device, "\6", 1) == GP_ERROR) return (GP_ERROR_IO); break; } else { /**********************************************/ @@ -482,11 +482,11 @@ l_receive (gpio_device* device, guchar** rb, guint* rbs, guint timeout) /* Write NACK. */ /****************/ c = NACK; - if (gpio_write (device, &c, 1) == GPIO_ERROR) return (GP_ERROR_IO); + if (gp_port_write (device, &c, 1) == GP_ERROR) return (GP_ERROR_IO); continue; } } - if (gpio_read (device, &c, 1) < 1) + if (gp_port_read (device, &c, 1) < 1) return (GP_ERROR_IO); switch (c) { case EOT: @@ -520,7 +520,7 @@ l_receive (gpio_device* device, guchar** rb, guint* rbs, guint timeout) /****************/ /* Read ENQ. */ /****************/ - if (gpio_read (device, &c, 1) < 1) return (GP_ERROR_IO); + if (gp_port_read (device, &c, 1) < 1) return (GP_ERROR_IO); switch (c) { case ENQ: /**********************************************/ @@ -536,7 +536,7 @@ l_receive (gpio_device* device, guchar** rb, guint* rbs, guint timeout) /****************/ /* Write ACK. */ /****************/ - if (gpio_write (device, "\6", 1) == GPIO_ERROR) + if (gp_port_write (device, "\6", 1) == GP_ERROR) return (GP_ERROR_IO); break; default: @@ -551,7 +551,7 @@ l_receive (gpio_device* device, guchar** rb, guint* rbs, guint timeout) gint -l_send_receive (gpio_device* device, guchar* send_buffer, guint send_buffer_size, guchar** receive_buffer, guint* receive_buffer_size) +l_send_receive (gp_port* device, guchar* send_buffer, guint send_buffer_size, guchar** receive_buffer, guint* receive_buffer_size) { gint result; @@ -578,7 +578,7 @@ l_send_receive (gpio_device* device, guchar* send_buffer, guint send_buffer_size gint l_send_receive_receive ( - gpio_device* device, + gp_port* device, guchar* send_buffer, guint send_buffer_size, guchar** image_buffer, diff --git a/camlibs/konica/lowlevel.h b/camlibs/konica/lowlevel.h index 3440458e1..6c9d0129d 100644 --- a/camlibs/konica/lowlevel.h +++ b/camlibs/konica/lowlevel.h @@ -29,10 +29,10 @@ /****************************************************************/ /* Prototypes */ /****************************************************************/ -gint l_init (gpio_device* device); +gint l_init (gp_port* device); -gint l_exit (gpio_device* device); +gint l_exit (gp_port* device); /****************************************************************/ @@ -55,7 +55,7 @@ gint l_exit (gpio_device* device); /* status, other bytes will follow. */ /****************************************************************/ gint l_send_receive ( - gpio_device* device, + gp_port* device, guchar* send_buffer, guint send_buffer_size, guchar** receive_buffer, @@ -63,7 +63,7 @@ gint l_send_receive ( gint l_send_receive_receive ( - gpio_device* device, + gp_port* device, guchar* send_buffer, guint send_buffer_size, guchar** image_buffer, diff --git a/camlibs/minolta/dimagev/capture.c b/camlibs/minolta/dimagev/capture.c index 0fa70ee6d..b0f24f5e3 100644 --- a/camlibs/minolta/dimagev/capture.c +++ b/camlibs/minolta/dimagev/capture.c @@ -65,14 +65,14 @@ int dimagev_shutter(dimagev_t *dimagev) { return GP_ERROR; } - if ( gpio_write(dimagev->dev, p->buffer, p->length) == GPIO_ERROR ) { + if ( gp_port_write(dimagev->dev, p->buffer, p->length) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_shutter::unable to write packet"); return GP_ERROR; } sleep(1); - if ( gpio_read(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + if ( gp_port_read(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_shutter::no response from camera"); return GP_ERROR; } @@ -120,12 +120,12 @@ int dimagev_shutter(dimagev_t *dimagev) { sleep(1); char_buffer = DIMAGEV_EOT; - if ( gpio_write(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + if ( gp_port_write(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_shutter::unable to send EOT"); return GP_ERROR; } - if ( gpio_read(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + if ( gp_port_read(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_shutter::no response from camera"); return GP_ERROR; } diff --git a/camlibs/minolta/dimagev/data.c b/camlibs/minolta/dimagev/data.c index 7cfd9e4ec..e84bf90b3 100644 --- a/camlibs/minolta/dimagev/data.c +++ b/camlibs/minolta/dimagev/data.c @@ -43,10 +43,10 @@ int dimagev_get_camera_data(dimagev_t *dimagev) { return GP_ERROR; } - if ( gpio_write(dimagev->dev, p->buffer, p->length) == GPIO_ERROR ) { + if ( gp_port_write(dimagev->dev, p->buffer, p->length) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_get_camera_data::unable to write packet"); return GP_ERROR; - } else if ( gpio_read(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + } else if ( gp_port_read(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_get_camera_data::no response from camera"); return GP_ERROR; } @@ -76,12 +76,12 @@ int dimagev_get_camera_data(dimagev_t *dimagev) { } char_buffer = DIMAGEV_EOT; - if ( gpio_write(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + if ( gp_port_write(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_get_camera_data::unable to send EOT"); return GP_ERROR; } - if ( gpio_read(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + if ( gp_port_read(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_get_camera_data::no response from camera"); return GP_ERROR; } @@ -146,10 +146,10 @@ int dimagev_send_data(dimagev_t *dimagev) { return GP_ERROR; } - if ( gpio_write(dimagev->dev, p->buffer, p->length) == GPIO_ERROR ) { + if ( gp_port_write(dimagev->dev, p->buffer, p->length) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_send_data::unable to send set_data packet"); return GP_ERROR; - } else if ( gpio_read(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + } else if ( gp_port_read(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_send_data::no response from camera"); return GP_ERROR; } @@ -178,12 +178,12 @@ int dimagev_send_data(dimagev_t *dimagev) { return GP_ERROR; } - if ( gpio_write(dimagev->dev, p->buffer, p->length) == GPIO_ERROR ) { + if ( gp_port_write(dimagev->dev, p->buffer, p->length) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_send_data::unable to send data packet"); return GP_ERROR; } - if ( gpio_read(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + if ( gp_port_read(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_send_data::no response from camera"); return GP_ERROR; } @@ -207,12 +207,12 @@ int dimagev_send_data(dimagev_t *dimagev) { char_buffer = DIMAGEV_EOT; - if ( gpio_write(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + if ( gp_port_write(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_send_data::unable to send EOT"); return GP_ERROR; } - if ( gpio_read(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + if ( gp_port_read(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_send_data::no response from camera"); return GP_ERROR; } diff --git a/camlibs/minolta/dimagev/delete.c b/camlibs/minolta/dimagev/delete.c index f2a077a0a..1eb2af2da 100644 --- a/camlibs/minolta/dimagev/delete.c +++ b/camlibs/minolta/dimagev/delete.c @@ -59,10 +59,10 @@ int dimagev_delete_picture(dimagev_t *dimagev, int file_number) { return GP_ERROR; } - if ( gpio_write(dimagev->dev, p->buffer, p->length) == GPIO_ERROR ) { + if ( gp_port_write(dimagev->dev, p->buffer, p->length) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_delete_picture::unable to send set_data packet"); return GP_ERROR; - } else if ( gpio_read(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + } else if ( gp_port_read(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_delete_picture::no response from camera"); return GP_ERROR; } @@ -105,12 +105,12 @@ int dimagev_delete_picture(dimagev_t *dimagev, int file_number) { } char_buffer=DIMAGEV_EOT; - if ( gpio_write(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + if ( gp_port_write(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_get_picture::unable to send ACK"); return GP_ERROR; } - if ( gpio_read(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + if ( gp_port_read(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_delete_picture::no response from camera"); return GP_ERROR; } diff --git a/camlibs/minolta/dimagev/dimagev.c b/camlibs/minolta/dimagev/dimagev.c index a4d347b33..d0eb8d790 100644 --- a/camlibs/minolta/dimagev/dimagev.c +++ b/camlibs/minolta/dimagev/dimagev.c @@ -87,12 +87,12 @@ int camera_init (Camera *camera) { camera->camlib_data = dimagev; /* Now open a port. */ - if ( ( dimagev->dev = gpio_new(GPIO_DEVICE_SERIAL) ) == NULL ) { - gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "camera_init::unable to allocate gpio_dev"); + if ( ( dimagev->dev = gp_port_new(GP_PORT_SERIAL) ) == NULL ) { + gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "camera_init::unable to allocate gp_port_dev"); return GP_ERROR; } - gpio_set_timeout(dimagev->dev, 5000); + gp_port_set_timeout(dimagev->dev, 5000); #if defined HAVE_STRNCPY strncpy(dimagev->settings.serial.port, camera->port->path, sizeof(dimagev->settings.serial.port)); @@ -109,8 +109,8 @@ int camera_init (Camera *camera) { return GP_ERROR; } - gpio_set_settings(dimagev->dev, dimagev->settings); - gpio_open(dimagev->dev); + gp_port_set_settings(dimagev->dev, dimagev->settings); + gp_port_open(dimagev->dev); if ( dimagev_get_camera_data(dimagev) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "camera_init::unable to get current camera data"); @@ -150,8 +150,8 @@ int camera_exit (Camera *camera) { } if ( dimagev->dev != NULL ) { - gpio_close(dimagev->dev); - gpio_free(dimagev->dev); + gp_port_close(dimagev->dev); + gp_port_free(dimagev->dev); } if ( dimagev->fs != NULL ) { @@ -338,7 +338,7 @@ int camera_capture (Camera *camera, CameraFile *file, CameraCaptureInfo *info) { if ( dimagev_delete_picture(dimagev, dimagev->status->number_images ) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "camera_capture::unable to delete new image"); gp_debug_printf(GP_DEBUG_NONE, "dimagev", "Unable to delete image. Please delete image %d\n", dimagev->status->number_images); - return GP_ERROR_NONCRITICAL; + return GP_ERROR; } return GP_OK; diff --git a/camlibs/minolta/dimagev/dimagev.h b/camlibs/minolta/dimagev/dimagev.h index d37667876..32f36f516 100644 --- a/camlibs/minolta/dimagev/dimagev.h +++ b/camlibs/minolta/dimagev/dimagev.h @@ -45,7 +45,7 @@ /* These better be around. */ #include <gphoto2.h> -#include <gpio.h> +#include <gphoto2-port.h> /* There should be a better way to do this. */ #include "../../../libgphoto2/exif.h" @@ -197,8 +197,8 @@ typedef struct { /* This struct is used as the camera->camlib_data value in this library. */ typedef struct { int size; - gpio_device *dev; - gpio_device_settings settings; + gp_port *dev; + gp_port_settings settings; dimagev_data_t *data; dimagev_status_t *status; dimagev_info_t *info; diff --git a/camlibs/minolta/dimagev/download.c b/camlibs/minolta/dimagev/download.c index 610e1b9bb..4b424a391 100644 --- a/camlibs/minolta/dimagev/download.c +++ b/camlibs/minolta/dimagev/download.c @@ -54,10 +54,10 @@ int dimagev_get_picture(dimagev_t *dimagev, int file_number, CameraFile *file) { return GP_ERROR; } - if ( gpio_write(dimagev->dev, p->buffer, p->length) == GPIO_ERROR ) { + if ( gp_port_write(dimagev->dev, p->buffer, p->length) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_get_picture::unable to send set_data packet"); return GP_ERROR; - } else if ( gpio_read(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + } else if ( gp_port_read(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_get_picture::no response from camera"); return GP_ERROR; } @@ -110,7 +110,7 @@ int dimagev_get_picture(dimagev_t *dimagev, int file_number, CameraFile *file) { for ( i = 0 ; i < ( total_packets -1 ) ; i++ ) { char_buffer=DIMAGEV_ACK; - if ( gpio_write(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + if ( gp_port_write(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_get_picture::unable to send ACK"); return GP_ERROR; } @@ -136,12 +136,12 @@ int dimagev_get_picture(dimagev_t *dimagev, int file_number, CameraFile *file) { file->size++; char_buffer=DIMAGEV_EOT; - if ( gpio_write(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + if ( gp_port_write(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_get_picture::unable to send ACK"); return GP_ERROR; } - if ( gpio_read(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + if ( gp_port_read(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_get_picture::no response from camera"); return GP_ERROR; } @@ -202,10 +202,10 @@ int dimagev_get_thumbnail(dimagev_t *dimagev, int file_number, CameraFile *file) return GP_ERROR; } - if ( gpio_write(dimagev->dev, p->buffer, p->length) == GPIO_ERROR ) { + if ( gp_port_write(dimagev->dev, p->buffer, p->length) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_get_thumbnail::unable to send set_data packet"); return GP_ERROR; - } else if ( gpio_read(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + } else if ( gp_port_read(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_get_thumbnail::no response from camera"); return GP_ERROR; } @@ -257,7 +257,7 @@ int dimagev_get_thumbnail(dimagev_t *dimagev, int file_number, CameraFile *file) while ( file->size < 9599 ) { char_buffer=DIMAGEV_ACK; - if ( gpio_write(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + if ( gp_port_write(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_get_thumbnail::unable to send ACK"); return GP_ERROR; } @@ -285,12 +285,12 @@ int dimagev_get_thumbnail(dimagev_t *dimagev, int file_number, CameraFile *file) file->size++; char_buffer=DIMAGEV_EOT; - if ( gpio_write(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + if ( gp_port_write(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_get_thumbnail::unable to send ACK"); return GP_ERROR; } - if ( gpio_read(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + if ( gp_port_read(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_get_thumbnail::no response from camera"); return GP_ERROR; } diff --git a/camlibs/minolta/dimagev/info.c b/camlibs/minolta/dimagev/info.c index 2024e3c91..9401ccc0a 100644 --- a/camlibs/minolta/dimagev/info.c +++ b/camlibs/minolta/dimagev/info.c @@ -47,10 +47,10 @@ int dimagev_get_camera_info(dimagev_t *dimagev) { return GP_ERROR; } - if ( gpio_write(dimagev->dev, p->buffer, p->length) == GPIO_ERROR ) { + if ( gp_port_write(dimagev->dev, p->buffer, p->length) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_get_camera_info::unable to write packet"); return GP_ERROR; - } else if ( gpio_read(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + } else if ( gp_port_read(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_get_camera_info::no response from camera"); return GP_ERROR; } @@ -80,12 +80,12 @@ int dimagev_get_camera_info(dimagev_t *dimagev) { } char_buffer = DIMAGEV_EOT; - if ( gpio_write(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + if ( gp_port_write(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_get_camera_info::unable to send EOT"); return GP_ERROR; } - if ( gpio_read(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + if ( gp_port_read(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_get_camera_info::no response from camera"); return GP_ERROR; } diff --git a/camlibs/minolta/dimagev/packet.c b/camlibs/minolta/dimagev/packet.c index 8a444dbf6..8272b9ca0 100644 --- a/camlibs/minolta/dimagev/packet.c +++ b/camlibs/minolta/dimagev/packet.c @@ -104,14 +104,14 @@ dimagev_packet *dimagev_read_packet(dimagev_t *dimagev) { return NULL; } - if ( gpio_read(dimagev->dev, p->buffer, 4) == GPIO_ERROR ) { + if ( gp_port_read(dimagev->dev, p->buffer, 4) == GP_ERROR ) { perror("dimagev_read_packet::unable to read packet header"); return NULL; } p->length = ( p->buffer[2] * 256 ) + ( p->buffer[3] ); - if ( gpio_read(dimagev->dev, &(p->buffer[4]), ( p->length - 4)) == GPIO_ERROR ) { + if ( gp_port_read(dimagev->dev, &(p->buffer[4]), ( p->length - 4)) == GP_ERROR ) { perror("dimagev_read_packet::unable to read packet body"); return NULL; } @@ -124,7 +124,7 @@ dimagev_packet *dimagev_read_packet(dimagev_t *dimagev) { /* Send a NAK */ char_buffer = DIMAGEV_NAK; - if ( gpio_write(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + if ( gp_port_write(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { perror("dimagev_read_packet::unable to send NAK"); return NULL; } diff --git a/camlibs/minolta/dimagev/status.c b/camlibs/minolta/dimagev/status.c index 63befcbe4..5f6bf40e7 100644 --- a/camlibs/minolta/dimagev/status.c +++ b/camlibs/minolta/dimagev/status.c @@ -43,10 +43,10 @@ int dimagev_get_camera_status(dimagev_t *dimagev) { return GP_ERROR; } - if ( gpio_write(dimagev->dev, p->buffer, p->length) == GPIO_ERROR ) { + if ( gp_port_write(dimagev->dev, p->buffer, p->length) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_get_camera_status::unable to write packet"); return GP_ERROR; - } else if ( gpio_read(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + } else if ( gp_port_read(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_get_camera_status::no response from camera"); return GP_ERROR; } @@ -76,12 +76,12 @@ int dimagev_get_camera_status(dimagev_t *dimagev) { } char_buffer = DIMAGEV_EOT; - if ( gpio_write(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + if ( gp_port_write(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_get_camera_status::unable to send EOT"); return GP_ERROR; } - if ( gpio_read(dimagev->dev, &char_buffer, 1) == GPIO_ERROR ) { + if ( gp_port_read(dimagev->dev, &char_buffer, 1) == GP_ERROR ) { gp_debug_printf(GP_DEBUG_HIGH, "dimagev", "dimagev_get_camera_status::no response from camera"); return GP_ERROR; } diff --git a/camlibs/panasonic/dc.c b/camlibs/panasonic/dc.c index c1ac5510b..5287e1114 100644 --- a/camlibs/panasonic/dc.c +++ b/camlibs/panasonic/dc.c @@ -57,7 +57,7 @@ int dsc1_sendcmd(dsc_t *dsc, u_int8_t cmd, void *data, int size) { if (data && 0 < size) memcpy(&dsc->buf[DSC1_BUF_DATA], data, size); - return gpio_write(dsc->dev, dsc->buf, 17 + size); + return gp_port_write(dsc->dev, dsc->buf, 17 + size); } int dsc1_retrcmd(dsc_t *dsc) { @@ -65,7 +65,7 @@ int dsc1_retrcmd(dsc_t *dsc) { int result = GP_ERROR; int s; - if ((s = gpio_read(dsc->dev, dsc->buf, 17)) == GP_ERROR) + if ((s = gp_port_read(dsc->dev, dsc->buf, 17)) == GP_ERROR) return GP_ERROR; if (0 < s) @@ -88,7 +88,7 @@ int dsc1_retrcmd(dsc_t *dsc) { /* overflow */ } - if (gpio_read(dsc->dev, dsc->buf, dsc->size) != dsc->size) + if (gp_port_read(dsc->dev, dsc->buf, dsc->size) != dsc->size) return GP_ERROR; DEBUG_PRINT(("Retrieved command: %i.", result)); @@ -138,7 +138,7 @@ int dsc1_setbaudrate(dsc_t *dsc, int speed) { sleep(DSC_PAUSE/2); dsc->settings.serial.speed = speed; - if (gpio_set_settings(dsc->dev, dsc->settings) != GP_OK) + if (gp_port_set_settings(dsc->dev, dsc->settings) != GP_OK) return GP_ERROR; DEBUG_PRINT(("Baudrate set to: %i.", speed)); diff --git a/camlibs/panasonic/dc.h b/camlibs/panasonic/dc.h index 89bfc2290..b0917d454 100644 --- a/camlibs/panasonic/dc.h +++ b/camlibs/panasonic/dc.h @@ -41,8 +41,8 @@ typedef enum { } dsc_quality_t; typedef struct { - gpio_device *dev; - gpio_device_settings settings; + gp_port *dev; + gp_port_settings settings; CameraFilesystem *fs; char *buf; int size; diff --git a/camlibs/panasonic/dc1000.c b/camlibs/panasonic/dc1000.c index 261b8cd32..d1ff13124 100644 --- a/camlibs/panasonic/dc1000.c +++ b/camlibs/panasonic/dc1000.c @@ -161,7 +161,7 @@ int dsc1_selectimage(dsc_t *dsc, u_int8_t index) return size; } -/* gpio_readimageblock - read #block block (1024 bytes) of an image into buf */ +/* gp_port_readimageblock - read #block block (1024 bytes) of an image into buf */ int dsc1_readimageblock(dsc_t *dsc, int block, char *buffer) { @@ -245,7 +245,7 @@ int dsc1_setimageres(dsc_t *dsc, int size) { return GP_OK; } -/* gpio_writeimageblock - write size bytes from buffer rounded to 1024 bytes to camera */ +/* gp_port_writeimageblock - write size bytes from buffer rounded to 1024 bytes to camera */ int dsc1_writeimageblock(dsc_t *dsc, int block, char *buffer, int size) { @@ -262,7 +262,7 @@ int dsc1_writeimageblock(dsc_t *dsc, int block, char *buffer, int size) { return GP_OK; } -/* gpio_writeimage - write an image to camera memory, size bytes at buffer */ +/* gp_port_writeimage - write an image to camera memory, size bytes at buffer */ int dsc1_writeimage(dsc_t *dsc, char *buffer, int size) { @@ -367,8 +367,8 @@ int camera_init (Camera *camera) { camera->functions->about = camera_about; if (dsc && dsc->dev) { - gpio_close(dsc->dev); - gpio_free(dsc->dev); + gp_port_close(dsc->dev); + gp_port_free(dsc->dev); } free(dsc); @@ -380,18 +380,18 @@ int camera_init (Camera *camera) { camera->camlib_data = dsc; - dsc->dev = gpio_new(GPIO_DEVICE_SERIAL); + dsc->dev = gp_port_new(GP_PORT_SERIAL); - gpio_set_timeout(dsc->dev, 5000); + gp_port_set_timeout(dsc->dev, 5000); strcpy(dsc->settings.serial.port, camera->port->path); dsc->settings.serial.speed = 9600; /* hand shake speed */ dsc->settings.serial.bits = 8; dsc->settings.serial.parity = 0; dsc->settings.serial.stopbits = 1; - gpio_set_settings(dsc->dev, dsc->settings); + gp_port_set_settings(dsc->dev, dsc->settings); - gpio_open(dsc->dev); + gp_port_open(dsc->dev); /* allocate memory for a dsc read/write buffer */ if ((dsc->buf = (char *)malloc(sizeof(char)*(DSC_BUFSIZE))) == NULL) { @@ -420,8 +420,8 @@ int camera_exit (Camera *camera) { dsc1_disconnect(dsc); if (dsc->dev) { - gpio_close(dsc->dev); - gpio_free(dsc->dev); + gp_port_close(dsc->dev); + gp_port_free(dsc->dev); } if (dsc->fs) gp_filesystem_free(dsc->fs); diff --git a/camlibs/panasonic/dc1580.c b/camlibs/panasonic/dc1580.c index 35f719581..550a0f05b 100644 --- a/camlibs/panasonic/dc1580.c +++ b/camlibs/panasonic/dc1580.c @@ -75,7 +75,7 @@ int dsc2_sendcmd(dsc_t *dsc, u_int8_t cmd, long int data, u_int8_t sequence) { dsc->buf[14] = dsc2_checksum(dsc->buf, 16); - return gpio_write(dsc->dev, dsc->buf, 16); + return gp_port_write(dsc->dev, dsc->buf, 16); } /* dsc2_retrcmd - retrieve command and its data from DSC */ @@ -85,7 +85,7 @@ int dsc2_retrcmd(dsc_t *dsc) { int result = GP_ERROR; int s; - if ((s = gpio_read(dsc->dev, dsc->buf, 16)) == GP_ERROR) + if ((s = gp_port_read(dsc->dev, dsc->buf, 16)) == GP_ERROR) return GP_ERROR; if (0 < s) @@ -230,7 +230,7 @@ int dsc2_selectimage(dsc_t *dsc, int index, int thumbnail) return size; } -/* gpio_readimageblock - read #block block (1024 bytes) of an image into buf */ +/* gp_port_readimageblock - read #block block (1024 bytes) of an image into buf */ int dsc2_readimageblock(dsc_t *dsc, int block, char *buffer) { @@ -239,7 +239,7 @@ int dsc2_readimageblock(dsc_t *dsc, int block, char *buffer) { if (dsc2_sendcmd(dsc, DSC2_CMD_GET_DATA, block, block) != GP_OK) return GP_ERROR; - if (gpio_read(dsc->dev, dsc->buf, DSC_BUFSIZE) != DSC_BUFSIZE) + if (gp_port_read(dsc->dev, dsc->buf, DSC_BUFSIZE) != DSC_BUFSIZE) RETURN_ERROR(EDSCBADRSP, dsc2_readimageblock); /* bad response */ @@ -315,7 +315,7 @@ int dsc2_setimagesize(dsc_t *dsc, int size) { return GP_OK; } -/* gpio_writeimageblock - write size bytes from buffer rounded to 1024 bytes to camera */ +/* gp_port_writeimageblock - write size bytes from buffer rounded to 1024 bytes to camera */ int dsc2_writeimageblock(dsc_t *dsc, int block, char *buffer, int size) { @@ -335,7 +335,7 @@ int dsc2_writeimageblock(dsc_t *dsc, int block, char *buffer, int size) { dsc->buf[DSC_BUFSIZE - 2] = dsc2_checksum(dsc->buf, DSC_BUFSIZE); - if (gpio_write(dsc->dev, dsc->buf, DSC_BUFSIZE) != GP_OK) + if (gp_port_write(dsc->dev, dsc->buf, DSC_BUFSIZE) != GP_OK) return GP_ERROR; if (dsc2_retrcmd(dsc) != DSC2_RSP_OK) @@ -460,8 +460,8 @@ int camera_init (Camera *camera) { camera->functions->about = camera_about; if (dsc && dsc->dev) { - gpio_close(dsc->dev); - gpio_free(dsc->dev); + gp_port_close(dsc->dev); + gp_port_free(dsc->dev); } free(dsc); @@ -473,18 +473,18 @@ int camera_init (Camera *camera) { camera->camlib_data = dsc; - dsc->dev = gpio_new(GPIO_DEVICE_SERIAL); + dsc->dev = gp_port_new(GP_PORT_SERIAL); - gpio_set_timeout(dsc->dev, 5000); + gp_port_set_timeout(dsc->dev, 5000); strcpy(dsc->settings.serial.port, camera->port->path); dsc->settings.serial.speed = 9600; /* hand shake speed */ dsc->settings.serial.bits = 8; dsc->settings.serial.parity = 0; dsc->settings.serial.stopbits = 1; - gpio_set_settings(dsc->dev, dsc->settings); + gp_port_set_settings(dsc->dev, dsc->settings); - gpio_open(dsc->dev); + gp_port_open(dsc->dev); /* allocate memory for a dsc read/write buffer */ if ((dsc->buf = (char *)malloc(sizeof(char)*(DSC_BUFSIZE))) == NULL) { @@ -513,8 +513,8 @@ int camera_exit (Camera *camera) { dsc2_disconnect(dsc); if (dsc->dev) { - gpio_close(dsc->dev); - gpio_free(dsc->dev); + gp_port_close(dsc->dev); + gp_port_free(dsc->dev); } if (dsc->fs) gp_filesystem_free(dsc->fs); diff --git a/camlibs/sierra/library.c b/camlibs/sierra/library.c index 360e5d7f7..cc8c05c4e 100644 --- a/camlibs/sierra/library.c +++ b/camlibs/sierra/library.c @@ -1,7 +1,6 @@ #include <stdio.h> #include <string.h> #include <gphoto2.h> -#include <gpio.h> #include <time.h> #include "sierra.h" #include "library.h" @@ -139,22 +138,22 @@ int sierra_write_packet (Camera *camera, char *packet) { /* For USB support */ if (fd->type == GP_PORT_USB) { - return (gpio_write(fd->dev, packet, length)); + return (gp_port_write(fd->dev, packet, length)); } r=0; x=0; while (x<length) { - ret = gpio_write(fd->dev, &packet[x], 1); + ret = gp_port_write(fd->dev, &packet[x], 1); - if (ret != GPIO_OK) { - if (ret == GPIO_TIMEOUT) { + if (ret != GP_OK) { + if (ret == GP_ERROR_TIMEOUT) { sierra_debug_print(fd, " write timed out. trying again."); if (r++ > RETRIES) { sierra_debug_print(fd, " write failed (too many retries)"); return (GP_ERROR); } - } else if (ret == GPIO_ERROR) { + } else if (ret == GP_ERROR) { sierra_debug_print(fd, " write failed"); return (GP_ERROR); } else { @@ -185,9 +184,9 @@ read_packet_again: // usleep(QUICKSLEEP); done = 0; -#ifdef GPIO_USB +#ifdef GP_PORT_USB if (fd->type == GP_PORT_USB) - gpio_usb_clear_halt(fd->dev, GPIO_USB_IN_ENDPOINT); + gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_IN_ENDPOINT); #endif while (!done && (r++<RETRIES)) { @@ -201,10 +200,10 @@ read_packet_again: default: return (GP_ERROR); } - bytes_read = gpio_read(fd->dev, packet, blocksize); + bytes_read = gp_port_read(fd->dev, packet, blocksize); - if (bytes_read == GPIO_ERROR) { + if (bytes_read == GP_ERROR) { sierra_debug_print(fd, " read error (packet type)"); return (GP_ERROR); } @@ -221,8 +220,8 @@ read_packet_again: (packet[0] == TYPE_DATA_END)) { /* It's a response/command packet */ if (fd->type == GP_PORT_SERIAL) { - bytes_read = gpio_read(fd->dev, &packet[1], 3); - if (bytes_read == GPIO_ERROR) { + bytes_read = gp_port_read(fd->dev, &packet[1], 3); + if (bytes_read == GP_ERROR) { sierra_debug_print(fd, " read error (header)"); return (GP_ERROR); } @@ -235,28 +234,28 @@ read_packet_again: } else { /* It's a single byte response. dump and validate */ sierra_dump_packet(camera, packet); -#ifdef GPIO_USB +#ifdef GP_PORT_USB if (fd->type == GP_PORT_USB) - gpio_usb_clear_halt(fd->dev, GPIO_USB_IN_ENDPOINT); + gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_IN_ENDPOINT); #endif return (sierra_valid_packet(camera, packet)); } for (y=bytes_read; y < length; y+=blocksize) { - ret = gpio_read(fd->dev, &packet[y], blocksize); - if (ret == GPIO_TIMEOUT) { + ret = gp_port_read(fd->dev, &packet[y], blocksize); + if (ret == GP_ERROR_TIMEOUT) { sierra_write_nak(camera); goto read_packet_again; } - if (ret ==GPIO_ERROR) + if (ret ==GP_ERROR) return (GP_ERROR); } } sierra_dump_packet(camera, packet); -#ifdef GPIO_USB +#ifdef GP_PORT_USB if (fd->type == GP_PORT_USB) - gpio_usb_clear_halt(fd->dev, GPIO_USB_IN_ENDPOINT); + gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_IN_ENDPOINT); #endif return (GP_OK); @@ -321,16 +320,16 @@ int sierra_write_ack(Camera *camera) { buf[0] = ACK; if (sierra_write_packet(camera, buf)==GP_OK) { -#ifdef GPIO_USB +#ifdef GP_PORT_USB if (fd->type == GP_PORT_USB) - gpio_usb_clear_halt(fd->dev, GPIO_USB_IN_ENDPOINT); + gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_IN_ENDPOINT); #endif return (GP_OK); } sierra_debug_print(fd, "Could not write ACK"); -#ifdef GPIO_USB +#ifdef GP_PORT_USB if (fd->type == GP_PORT_USB) - gpio_usb_clear_halt(fd->dev, GPIO_USB_IN_ENDPOINT); + gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_IN_ENDPOINT); #endif return (GP_ERROR); } @@ -344,17 +343,17 @@ int sierra_write_nak(Camera *camera) { buf[0] = NAK; if (sierra_write_packet(camera, buf)==GP_OK) { -#ifdef GPIO_USB +#ifdef GP_PORT_USB if (fd->type == GP_PORT_USB) - gpio_usb_clear_halt(fd->dev, GPIO_USB_IN_ENDPOINT); + gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_IN_ENDPOINT); #endif return (GP_OK); } sierra_debug_print(fd, "Could not write NAK"); -#ifdef GPIO_USB +#ifdef GP_PORT_USB if (fd->type == GP_PORT_USB) - gpio_usb_clear_halt(fd->dev, GPIO_USB_IN_ENDPOINT); + gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_IN_ENDPOINT); #endif return (GP_ERROR); } @@ -386,7 +385,7 @@ int sierra_ping(Camera *camera) { int sierra_set_speed (Camera *camera, int speed) { - gpio_device_settings settings; + gp_port_settings settings; char buf[1024]; SierraData *fd = (SierraData*)camera->camlib_data; @@ -395,7 +394,7 @@ int sierra_set_speed (Camera *camera, int speed) { fd->first_packet = 1; - gpio_get_settings(fd->dev, &settings); + gp_port_get_settings(fd->dev, &settings); switch (speed) { case 9600: @@ -430,10 +429,10 @@ int sierra_set_speed (Camera *camera, int speed) { if (sierra_set_int_register(camera, 17, speed)==GP_ERROR) return (GP_ERROR); - if (gpio_set_settings(fd->dev, settings)==GPIO_ERROR) + if (gp_port_set_settings(fd->dev, settings)==GP_ERROR) return (GP_ERROR); - GPIO_SLEEP(10); + GP_SYSTEM_SLEEP(10); return (GP_OK); } @@ -719,7 +718,7 @@ int sierra_delete(Camera *camera, int picture_number) { return (GP_ERROR); } - GPIO_SLEEP(QUICKSLEEP); + GP_SYSTEM_SLEEP(QUICKSLEEP); return (GP_OK); } @@ -837,12 +836,12 @@ int sierra_capture (Camera *camera, CameraFile *file, CameraCaptureInfo *info) { r = 0;done=0; while ((!done)&&(r++<RETRIES)) { /* read in the ENQ */ - retval = gpio_read(fd->dev, buf, 1); + retval = gp_port_read(fd->dev, buf, 1); switch(retval) { - case GPIO_ERROR: + case GP_ERROR: return (GP_ERROR); break; - case GPIO_TIMEOUT: + case GP_ERROR_TIMEOUT: break; default: done = 1; diff --git a/camlibs/sierra/sierra.c b/camlibs/sierra/sierra.c index 65d7b2936..f09d23c36 100644 --- a/camlibs/sierra/sierra.c +++ b/camlibs/sierra/sierra.c @@ -2,7 +2,6 @@ #include <stdio.h> #include <string.h> #include <gphoto2.h> -#include <gpio.h> #include "library.h" #include "sierra.h" @@ -135,11 +134,10 @@ int camera_abilities (CameraAbilitiesList *list) { int camera_init (Camera *camera) { int value=0, count; -#ifdef GPIO_USB int x=0; int vendor=0, product=0, inep=0, outep=0; -#endif - gpio_device_settings settings; + + gp_port_settings settings; SierraData *fd; if (!camera) @@ -170,9 +168,9 @@ int camera_init (Camera *camera) { switch (camera->port->type) { case GP_PORT_SERIAL: sierra_debug_print(fd, "Serial Device"); - fd->dev = gpio_new(GPIO_DEVICE_SERIAL); + fd->dev = gp_port_new(GP_PORT_SERIAL); if (!fd->dev) { - gpio_free(fd->dev); + gp_port_free(fd->dev); free(fd); return (GP_ERROR); } @@ -182,7 +180,6 @@ int camera_init (Camera *camera) { settings.serial.parity = 0; settings.serial.stopbits = 1; break; -#ifdef GPIO_USB case GP_PORT_USB: /* lookup the USB information */ while (strlen(sierra_cameras[x].model)>0) { @@ -200,44 +197,43 @@ int camera_init (Camera *camera) { return (GP_ERROR); sierra_debug_print(fd, "USB Device"); - fd->dev = gpio_new(GPIO_DEVICE_USB); + fd->dev = gp_port_new(GP_PORT_USB); if (!fd->dev) { - gpio_free(fd->dev); + gp_port_free(fd->dev); free(fd); return (GP_ERROR); } - if (gpio_usb_find_device(fd->dev, vendor, product) == GPIO_ERROR) { - gpio_free(fd->dev); + if (gp_port_usb_find_device(fd->dev, vendor, product) == GP_ERROR) { + gp_port_free(fd->dev); free (fd); return (GP_ERROR); } - gpio_set_timeout (fd->dev, 5000); + gp_port_set_timeout (fd->dev, 5000); settings.usb.inep = inep; settings.usb.outep = outep; settings.usb.config = 1; settings.usb.interface = 0; settings.usb.altsetting = 0; break; -#endif default: sierra_debug_print(fd, "Invalid Device"); free (fd); return (GP_ERROR); } - if (gpio_set_settings(fd->dev, settings) == GPIO_ERROR) { - gpio_free(fd->dev); + if (gp_port_set_settings(fd->dev, settings) == GP_ERROR) { + gp_port_free(fd->dev); free (fd); return (GP_ERROR); } - gpio_set_timeout(fd->dev, TIMEOUT); + gp_port_set_timeout(fd->dev, TIMEOUT); fd->type = camera->port->type; - if (gpio_open(fd->dev)==GPIO_ERROR) { - gpio_free(fd->dev); + if (gp_port_open(fd->dev)==GP_ERROR) { + gp_port_free(fd->dev); free (fd); return (GP_ERROR); } @@ -245,36 +241,34 @@ int camera_init (Camera *camera) { switch (camera->port->type) { case GP_PORT_SERIAL: if (sierra_ping(camera)==GP_ERROR) { - gpio_free(fd->dev); + gp_port_free(fd->dev); free (fd); return (GP_ERROR); } if (sierra_set_speed(camera, camera->port->speed)==GP_ERROR) { - gpio_free(fd->dev); + gp_port_free(fd->dev); free (fd); return (GP_ERROR); } fd->speed = camera->port->speed; break; -#ifdef GPIO_USB case GP_PORT_USB: - gpio_usb_clear_halt(fd->dev, GPIO_USB_IN_ENDPOINT); + gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_IN_ENDPOINT); break; -#endif default: break; } if (sierra_get_int_register(camera, 1, &value)==GP_ERROR) { - gpio_free(fd->dev); + gp_port_free(fd->dev); free (fd); return (GP_ERROR); } sierra_set_int_register(camera, 83, -1); - gpio_set_timeout(fd->dev, 50); + gp_port_set_timeout(fd->dev, 50); if (sierra_set_string_register(camera, 84, "\\", 1)==GP_ERROR) fd->folders = 0; else @@ -292,7 +286,7 @@ int camera_init (Camera *camera) { strcpy(fd->folder, "/"); - gpio_set_timeout(fd->dev, TIMEOUT); + gp_port_set_timeout(fd->dev, TIMEOUT); camera_stop(camera); return (GP_OK); @@ -372,8 +366,8 @@ int camera_exit (Camera *camera) { sierra_debug_print(fd, "Exiting camera"); - gpio_close(fd->dev); - gpio_free(fd->dev); + gp_port_close(fd->dev); + gp_port_free(fd->dev); free(fd); return (GP_OK); @@ -581,7 +575,7 @@ return (GP_ERROR); sierra_debug_print(fd, buf); ret = sierra_delete(camera, file_number+1); - if (ret == GPIO_OK) + if (ret == GP_OK) gp_filesystem_delete(fd->fs, folder, filename); if (camera_stop(camera)==GP_ERROR) diff --git a/camlibs/sierra/sierra.h b/camlibs/sierra/sierra.h index 6325ca94b..da790e467 100644 --- a/camlibs/sierra/sierra.h +++ b/camlibs/sierra/sierra.h @@ -3,7 +3,7 @@ typedef struct { int speed; int first_packet; int type; - gpio_device* dev; + gp_port* dev; char folder[128]; CameraFilesystem *fs; } SierraData; diff --git a/camlibs/stv0680/library.c b/camlibs/stv0680/library.c index 6a9916b6b..421d0ea7a 100644 --- a/camlibs/stv0680/library.c +++ b/camlibs/stv0680/library.c @@ -20,7 +20,7 @@ #include <stdlib.h> #include <stdio.h> #include <gphoto2.h> -#include <gpio.h> +#include <gphoto2-port.h> #include "stv0680.h" #include "library.h" @@ -43,14 +43,14 @@ #define CMD_IO_TIMEOUT 0x02 #define CMD_BAD_RESPONSE 0x03 -int stv0680_remap_gpio_error(int error) +int stv0680_remap_gp_port_error(int error) { switch(error) { - case GPIO_TIMEOUT: - printf("Remapping GPIO_TIMEOUT->CMD_IO_TIMEOUT\n"); + case GP_ERROR_TIMEOUT: + printf("Remapping GP_ERROR_TIMEOUT->CMD_IO_TIMEOUT\n"); return CMD_IO_TIMEOUT; - case GPIO_ERROR: - printf("Remapping GPIO_ERROR->CMD_IO_ERROR\n"); + case GP_ERROR: + printf("Remapping GP_ERROR->CMD_IO_ERROR\n"); default: printf("(generic error %d actually)\n", error); return CMD_IO_ERROR; @@ -90,18 +90,18 @@ int stv0680_cmd(struct stv0680_s *device, unsigned char cmd, // write to device printf("Writing packet to device\n"); - if((ret = gpio_write(device->gpiod, packet, 8)) != GPIO_OK) - return stv0680_remap_gpio_error(ret); + if((ret = gp_port_write(device->gpiod, packet, 8)) != GP_OK) + return stv0680_remap_gp_port_error(ret); printf("Reading response header\n"); // read response header - if((ret = gpio_read(device->gpiod, rhdr, 6)) != 6) - return stv0680_remap_gpio_error(ret); + if((ret = gp_port_read(device->gpiod, rhdr, 6)) != 6) + return stv0680_remap_gp_port_error(ret); printf("Read response\n"); // read response - if((ret = gpio_read(device->gpiod, response, response_len)) != response_len) - return stv0680_remap_gpio_error(ret); + if((ret = gp_port_read(device->gpiod, response, response_len)) != response_len) + return stv0680_remap_gp_port_error(ret); printf("Validating packet [0x%X,0x%X,0x%X,0x%X,0x%X,0x%X]\n", rhdr[0], rhdr[1], rhdr[2], rhdr[3], rhdr[4], rhdr[5]); @@ -209,10 +209,10 @@ int stv0680_get_image(struct stv0680_s *device, int image_no, raw = malloc(*size); - switch(gpio_read(device->gpiod, raw, *size)) { - case GPIO_TIMEOUT: + switch(gp_port_read(device->gpiod, raw, *size)) { + case GP_ERROR_TIMEOUT: printf("read timeout\n"); break; - case GPIO_ERROR: + case GP_ERROR: printf("IO error\n"); break; default: printf("Read bytes!\n"); break; @@ -260,10 +260,10 @@ int stv0680_get_image_preview(struct stv0680_s *device, int image_no, raw = malloc(*size); - switch(gpio_read(device->gpiod, raw, *size)) { - case GPIO_TIMEOUT: + switch(gp_port_read(device->gpiod, raw, *size)) { + case GP_ERROR_TIMEOUT: printf("read timeout\n"); break; - case GPIO_ERROR: + case GP_ERROR: printf("IO error\n"); break; default: printf("Read bytes!\n"); break; diff --git a/camlibs/stv0680/stv0680.c b/camlibs/stv0680/stv0680.c index bbb3387d6..6bc1e0300 100644 --- a/camlibs/stv0680/stv0680.c +++ b/camlibs/stv0680/stv0680.c @@ -18,7 +18,7 @@ */ #include <string.h> #include <gphoto2.h> -#include <gpio.h> +#include <gphoto2-port.h> #include "stv0680.h" #include "library.h" @@ -53,7 +53,7 @@ int camera_abilities (CameraAbilitiesList *list) { int camera_init (Camera *camera) { - gpio_device_settings gpiod_settings; + gp_port_settings gpiod_settings; struct stv0680_s *device; /* First, set up all the function pointers */ @@ -81,8 +81,8 @@ int camera_init (Camera *camera) { camera->camlib_data = device; /* open and configure serial port */ - device->gpiod = gpio_new(GPIO_DEVICE_SERIAL); - gpio_set_timeout(device->gpiod, 1000); + device->gpiod = gp_port_new(GP_PORT_SERIAL); + gp_port_set_timeout(device->gpiod, 1000); strcpy(gpiod_settings.serial.port, camera->port->path); gpiod_settings.serial.speed = camera->port->speed; @@ -90,8 +90,8 @@ int camera_init (Camera *camera) { gpiod_settings.serial.parity = 0; gpiod_settings.serial.stopbits = 1; - gpio_set_settings(device->gpiod, gpiod_settings); - gpio_open(device->gpiod); + gp_port_set_settings(device->gpiod, gpiod_settings); + gp_port_open(device->gpiod); /* create camera filesystem */ device->fs = gp_filesystem_new(); @@ -105,7 +105,7 @@ int camera_exit (Camera *camera) { struct stv0680_s *device = camera->camlib_data; /* close serial port */ - gpio_close(device->gpiod); + gp_port_close(device->gpiod); /* free camera filesystem */ gp_filesystem_free(device->fs); diff --git a/camlibs/stv0680/stv0680.h b/camlibs/stv0680/stv0680.h index 8c477b4cf..b11d48e42 100644 --- a/camlibs/stv0680/stv0680.h +++ b/camlibs/stv0680/stv0680.h @@ -21,7 +21,7 @@ #define STV0680_H struct stv0680_s { - gpio_device *gpiod; + gp_port *gpiod; CameraFilesystem *fs; }; diff --git a/configure.in b/configure.in index 4ba061b10..484277c1e 100644 --- a/configure.in +++ b/configure.in @@ -50,19 +50,20 @@ AC_TYPE_SIZE_T dnl Checks for library functions. AC_CHECK_FUNCS(mkdir strdup strncpy strcpy snprintf sprintf) -AC_PATH_PROG(LIBGPIO_CONFIG,gpio-config) -if test -n "${LIBGPIO_CONFIG}"; then - CFLAGS="$CFLAGS `$LIBGPIO_CONFIG --cflags`" - LIBS="$LIBS `$LIBGPIO_CONFIG --libs`" -else +AC_PATH_PROG(LIBGPPORT_CONFIG,gphoto2-port-config) +if test -n "${LIBGPPORT_CONFIG}"; then + CFLAGS="$CFLAGS `$LIBGPPORT_CONFIG --cflags`" + LIBS="$LIBS `$LIBGPPORT_CONFIG --libs`" + else AC_MSG_ERROR([ -*** -*** libgpio is required. Available from gPhoto's SourceForge CVS. -*** Check http://www.gphoto.net/download.html for details. -***]) - exit 1 + *** + *** libgphoto2-port is not installed properly. + *** Type "cd libgphoto2_port; make; make install" to see what is wrong + ***]) + exit 1 fi + LIBGPHOTO2_INCLUDEDIR='-I${includedir}' LIBGPHOTO2_LIBDIR='-L${libdir}' LIBGPHOTO2_LIBS="-lgphoto2" diff --git a/frontends/command-line/Makefile.am b/frontends/command-line/Makefile.am index 7ae016a01..ff5ba9dc5 100644 --- a/frontends/command-line/Makefile.am +++ b/frontends/command-line/Makefile.am @@ -2,9 +2,8 @@ bin_PROGRAMS = gphoto2 -CFLAGS = @CFLAGS@ -g `gpio-config --cflags` -I$(top_srcdir)/include -I../libgphoto2_frontend -LDFLAGS = @LDFLAGS@ -g `gpio-config --libs` - +CFLAGS = @CFLAGS@ -g -I$(top_srcdir)/include -I../libgphoto2_frontend +LDFLAGS = @LDFLAGS@ -g gphoto2_SOURCES = \ actions.c actions.h \ foreach.c foreach.h \ diff --git a/frontends/command-line/main.c b/frontends/command-line/main.c index ecd7cb5cc..5b014f601 100644 --- a/frontends/command-line/main.c +++ b/frontends/command-line/main.c @@ -293,10 +293,10 @@ OPTION_CALLBACK(list_cameras) { OPTION_CALLBACK(list_ports) { - CameraPortInfo info; + gp_port_info info; int x, count; - if ((count = gp_port_count()) < 0) { + if ((count = gp_port_get_count()) < 0) { cli_error_print("Could not get number of ports"); return (count); } @@ -307,7 +307,7 @@ OPTION_CALLBACK(list_ports) { } else printf("%i\n", count); for(x=0; x<count; x++) { - gp_port_info(x, &info); + gp_port_get_info(x, &info); printf("%-32s %-32s\n",info.path,info.name); } @@ -507,7 +507,7 @@ int save_picture_to_file(char *folder, char *filename, int thumbnail) { sprintf(buf, "%s%s", out_folder, out_filename); if (!glob_quiet) { - while (GPIO_IS_FILE(buf)) { + while (GP_SYSTEM_IS_FILE(buf)) { sprintf(msg, "File %s exists. Overwrite?", buf); resp1 = gp_frontend_confirm(glob_camera, msg); if ((resp1==GP_CONFIRM_NO)||(resp1==GP_CONFIRM_NOTOALL)) { diff --git a/include/Makefile.am b/include/Makefile.am index 10b2a874a..6be2ec707 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -11,7 +11,6 @@ gphotohead_HEADERS= \ gphoto2-frontend.h \ gphoto2-library.h \ gphoto2-lists.h \ - gphoto2-port.h \ gphoto2-settings.h \ gphoto2-widget.h diff --git a/include/gphoto2-datatypes.h b/include/gphoto2-datatypes.h index a22c48780..35de949f7 100644 --- a/include/gphoto2-datatypes.h +++ b/include/gphoto2-datatypes.h @@ -5,7 +5,7 @@ This library is covered by the LGPL. */ -/* Constants +/* Constants ---------------------------------------------------------------- */ /* Return values. @@ -14,26 +14,18 @@ Don't forget to add the corresponding error descriptions in libgphoto2/core.c. */ -#define GP_OK 0 -#define GP_ERROR -1 /* generic */ -#define GP_ERROR_NONCRITICAL -2 /* deprecated */ -#define GP_ERROR_BAD_PARAMETERS -3 /* for checking function-param. */ -#define GP_ERROR_IO -4 /* IO problem */ -#define GP_ERROR_CORRUPTED_DATA -5 /* Corrupted data */ -#define GP_ERROR_FILE_EXISTS -6 /* File exists */ -#define GP_ERROR_NO_MEMORY -7 /* Insufficient memory */ -#define GP_ERROR_MODEL_NOT_FOUND -8 /* Model not found */ -#define GP_ERROR_NOT_SUPPORTED -9 /* Some op. is unsupported */ -#define GP_ERROR_DIRECTORY_NOT_FOUND -10/* Directory not found */ -#define GP_ERROR_FILE_NOT_FOUND -11 /* File not found */ - -#define GP_NUM_ERRORS 12 - -/* Debugging levels for gp_init */ -#define GP_DEBUG_NONE 0 -#define GP_DEBUG_LOW 1 -#define GP_DEBUG_MEDIUM 2 -#define GP_DEBUG_HIGH 3 + +#define GP_ERROR_BAD_PARAMETERS -100 /* for checking function-param. */ +#define GP_ERROR_IO -101 /* IO problem */ +#define GP_ERROR_CORRUPTED_DATA -102 /* Corrupted data */ +#define GP_ERROR_FILE_EXISTS -103 /* File exists */ +#define GP_ERROR_NO_MEMORY -104 /* Insufficient memory */ +#define GP_ERROR_MODEL_NOT_FOUND -105 /* Model not found */ +#define GP_ERROR_NOT_SUPPORTED -106 /* Some op. is unsupported */ +#define GP_ERROR_DIRECTORY_NOT_FOUND -107 /* Directory not found */ +#define GP_ERROR_FILE_NOT_FOUND -108 /* File not found */ + +/* #define GP_NUM_ERRORS 12 */ /* Macros @@ -51,14 +43,9 @@ ---------------------------------------------------------------- */ /* Physical Connection Types */ -typedef enum { - GP_PORT_NONE = 0, - GP_PORT_SERIAL = 1 << 0, - GP_PORT_PARALLEL = 1 << 1, - GP_PORT_USB = 1 << 2, - GP_PORT_IEEE1394 = 1 << 3, - GP_PORT_NETWORK = 1 << 4 -} CameraPortType; +typedef gp_port_type CameraPortType; + /* GP_PORT_SERIAL, GP_PORT_USB, GP_PORT_PARALLEL, + GP_PORT_IEEE1394, GP_PORT_NETWORK */ /* Capture Type */ typedef enum { @@ -110,44 +97,6 @@ typedef enum { #define WIDGET_CHOICE_MAX 32 struct Camera; -struct CameraWidget; - -/* CameraWidget structure */ -typedef struct CameraWidget { - CameraWidgetType type; - char label[32]; - - /* Current value of the widget */ - char *value_string; - int value_int; - float value_float; - - /* For Radio and Menu */ - char choice[WIDGET_CHOICE_MAX][64]; - int choice_count; - - /* For Range */ - float min; - float max; - float increment; - - /* Child info */ - struct CameraWidget *children[64]; - int children_count; - - /* Widget was changed */ - int changed; - - /* Reference count */ - int ref_count; - - /* Unique identifier */ - int id; - - /* Callback */ - int (*callback)(struct Camera*, struct CameraWidget*); - -} CameraWidget; /* Capture information structure */ typedef struct { @@ -157,7 +106,7 @@ typedef struct { /* Port information/settings */ typedef struct { - CameraPortType type; + CameraPortType type; char name[128]; char path[128]; /* path to serial port device */ @@ -165,14 +114,8 @@ typedef struct { /* For parallel port, "/dev/lpt0" or variants */ /* For usb, "usb" */ /* For ieee1394, "ieee1394" */ - /* For network, "network" */ - - /* Serial-specific members */ + /* For network, "IP:PORT" */ int speed; - - /* Network-specific members */ - char host[128]; - int host_port; } CameraPortInfo; /* Functions supported by the cameras */ @@ -270,6 +213,45 @@ typedef struct { char text[32*1024]; } CameraText; +/* CameraWidget structure */ +struct CameraWidget; +typedef struct CameraWidget { + CameraWidgetType type; + char label[32]; + + /* Current value of the widget */ + char *value_string; + int value_int; + float value_float; + + /* For Radio and Menu */ + char choice[WIDGET_CHOICE_MAX][64]; + int choice_count; + + /* For Range */ + float min; + float max; + float increment; + + /* Child info */ + struct CameraWidget *children[64]; + int children_count; + + /* Widget was changed */ + int changed; + + /* Reference count */ + int ref_count; + + /* Unique identifier */ + int id; + + /* Callback */ + int (*callback)(struct Camera*, struct CameraWidget*); + +} CameraWidget; + + struct Camera; /* Camera function pointers */ diff --git a/include/gphoto2.h b/include/gphoto2.h index a700a3584..694e12e2e 100644 --- a/include/gphoto2.h +++ b/include/gphoto2.h @@ -13,24 +13,22 @@ extern "C" { #endif #ifdef OS2 -#include <gphotoos2.h> +#include <gphoto2-portability-os2.h> #endif #ifdef WIN32 #define CAMLIBS "." #endif -#include <gpio.h> +#include <gphoto2-port.h> #include <gphoto2-datatypes.h> #include <gphoto2-camera.h> #include <gphoto2-core.h> -/* #include <gphoto2-dynamic.h> Not Yet -Scott */ #include <gphoto2-file.h> #include <gphoto2-filesys.h> #include <gphoto2-frontend.h> #include <gphoto2-library.h> #include <gphoto2-lists.h> -#include <gphoto2-port.h> #include <gphoto2-settings.h> #include <gphoto2-widget.h> diff --git a/libgphoto2/camera.c b/libgphoto2/camera.c index 90e8037cc..74473d5e0 100644 --- a/libgphoto2/camera.c +++ b/libgphoto2/camera.c @@ -1,6 +1,5 @@ #include <stdlib.h> #include <string.h> -#include <gpio.h> #include <gphoto2.h> #ifdef HAVE_CONFIG_H @@ -170,8 +169,8 @@ int gp_camera_session (Camera *camera) int gp_camera_init (Camera *camera) { int x; - int result; - CameraPortInfo info; + int result; + gp_port_info info; if (camera == NULL) return (GP_ERROR_BAD_PARAMETERS); @@ -186,14 +185,14 @@ int gp_camera_init (Camera *camera) /* Set the port type from the path in case the frontend didn't. */ if (camera->port->type == GP_PORT_NONE) { - for (x=0; x<gp_port_count(); x++) { - gp_port_info(x, &info); + for (x=0; x<gp_port_get_count(); x++) { + gp_port_get_info(x, &info); if (strcmp(info.path, camera->port->path)==0) { camera->port->type = info.type; break; } } - if (x == gp_port_count ()) + if (x == gp_port_get_count ()) return (GP_ERROR_BAD_PARAMETERS); } diff --git a/libgphoto2/core.c b/libgphoto2/core.c index 55685d504..b5582fe5c 100644 --- a/libgphoto2/core.c +++ b/libgphoto2/core.c @@ -2,7 +2,6 @@ #include <stdarg.h> #include <stdio.h> -#include <gpio.h> #include <gphoto2.h> #ifdef HAVE_CONFIG_H @@ -93,10 +92,10 @@ int gp_init (int debug) #else sprintf(buf, "%s/.gphoto", getenv("HOME")); #endif - (void)GPIO_MKDIR(buf); + (void)GP_SYSTEM_MKDIR(buf); gp_debug_printf(GP_DEBUG_LOW, "core", "Initializing gpio"); - if (gpio_init(debug) == GPIO_ERROR) + if (gp_port_init(debug) == GP_ERROR) return (GP_ERROR); /* Load settings */ diff --git a/libgphoto2/frontend.c b/libgphoto2/frontend.c index 8268f9d6c..913258b5f 100644 --- a/libgphoto2/frontend.c +++ b/libgphoto2/frontend.c @@ -1,4 +1,3 @@ -#include <gpio.h> #include <gphoto2.h> #ifdef HAVE_CONFIG_H diff --git a/libgphoto2/library.c b/libgphoto2/library.c index fed197372..84e63c41d 100644 --- a/libgphoto2/library.c +++ b/libgphoto2/library.c @@ -14,12 +14,12 @@ int is_library(char *library_filename) void *lh; c_id id; - if ((lh = GPIO_DLOPEN(library_filename)) == NULL) + if ((lh = GP_SYSTEM_DLOPEN(library_filename)) == NULL) return (GP_ERROR); - id = (c_id)GPIO_DLSYM(lh, "camera_id"); + id = (c_id)GP_SYSTEM_DLSYM(lh, "camera_id"); if (!id) ret = GP_ERROR; - GPIO_DLCLOSE(lh); + GP_SYSTEM_DLCLOSE(lh); return (ret); } @@ -31,16 +31,16 @@ int load_library(Camera *camera) for (x=0; x<glob_abilities_list->count; x++) { if (strcmp(glob_abilities_list->abilities[x]->model, camera->model)==0) { - if ((lh = GPIO_DLOPEN(glob_abilities_list->abilities[x]->library))==NULL) { + if ((lh = GP_SYSTEM_DLOPEN(glob_abilities_list->abilities[x]->library))==NULL) { if (glob_debug) perror("core:\tload_library"); return (GP_ERROR); } camera->library_handle = lh; - camera->functions->id = (c_id)GPIO_DLSYM(lh, "camera_id"); - camera->functions->abilities = (c_abilities)GPIO_DLSYM(lh, "camera_abilities"); - camera->functions->init = (c_init)GPIO_DLSYM(lh, "camera_init"); + camera->functions->id = (c_id)GP_SYSTEM_DLSYM(lh, "camera_id"); + camera->functions->abilities = (c_abilities)GP_SYSTEM_DLSYM(lh, "camera_abilities"); + camera->functions->init = (c_init)GP_SYSTEM_DLSYM(lh, "camera_init"); return GP_OK; } @@ -60,30 +60,30 @@ int load_camera_list(char *library_filename) int x, old_count; /* try to open the library */ - if ((lh = GPIO_DLOPEN(library_filename))==NULL) { + if ((lh = GP_SYSTEM_DLOPEN(library_filename))==NULL) { if (glob_debug) perror("core:\tload_camera_list"); return 0; } /* check to see if this library has been loaded */ - load_camera_id = (c_id)GPIO_DLSYM(lh, "camera_id"); + load_camera_id = (c_id)GP_SYSTEM_DLSYM(lh, "camera_id"); load_camera_id(&id); gp_debug_printf(GP_DEBUG_LOW, "core", "\t library id: %s", id.text); for (x=0; x<glob_abilities_list->count; x++) { if (strcmp(glob_abilities_list->abilities[x]->id, id.text)==0) { - GPIO_DLCLOSE(lh); + GP_SYSTEM_DLCLOSE(lh); return (GP_ERROR); } } /* load in the camera_abilities function */ - load_camera_abilities = (c_abilities)GPIO_DLSYM(lh, "camera_abilities"); + load_camera_abilities = (c_abilities)GP_SYSTEM_DLSYM(lh, "camera_abilities"); old_count = glob_abilities_list->count; if (load_camera_abilities(glob_abilities_list) != GP_OK) { - GPIO_DLCLOSE(lh); + GP_SYSTEM_DLCLOSE(lh); return 0; } @@ -93,22 +93,22 @@ int load_camera_list(char *library_filename) strcpy(glob_abilities_list->abilities[x]->library, library_filename); } - GPIO_DLCLOSE(lh); + GP_SYSTEM_DLCLOSE(lh); return x; } int load_cameras_search(char *directory) { - GPIO_DIR d; - GPIO_DIRENT de; + GP_SYSTEM_DIR d; + GP_SYSTEM_DIRENT de; char buf[1024]; gp_debug_printf(GP_DEBUG_LOW, "core","Trying to load camera libraries in:"); gp_debug_printf(GP_DEBUG_LOW, "core","\t%s", directory); /* Look for available camera libraries */ - d = GPIO_OPENDIR(directory); + d = GP_SYSTEM_OPENDIR(directory); if (!d) { gp_debug_printf(GP_DEBUG_LOW, "core", "couldn't open %s", directory); return GP_ERROR_DIRECTORY_NOT_FOUND; @@ -116,16 +116,16 @@ int load_cameras_search(char *directory) do { /* Read each entry */ - de = GPIO_READDIR(d); + de = GP_SYSTEM_READDIR(d); if (de) { - sprintf(buf, "%s%c%s", directory, GPIO_DIR_DELIM, GPIO_FILENAME(de)); + sprintf(buf, "%s%c%s", directory, GP_SYSTEM_DIR_DELIM, GP_SYSTEM_FILENAME(de)); gp_debug_printf(GP_DEBUG_LOW, "core", "\tis %s a library? ", buf); /* try to open the library */ if (is_library(buf) == GP_OK) { gp_debug_printf(GP_DEBUG_LOW, "core", "yes"); load_camera_list(buf); } else { - gp_debug_printf(GP_DEBUG_LOW, "core", "no. reason: %s", GPIO_DLERROR()); + gp_debug_printf(GP_DEBUG_LOW, "core", "no. reason: %s", GP_SYSTEM_DLERROR()); } } } while (de); @@ -171,7 +171,7 @@ int load_cameras() { int close_library(Camera *camera) { - GPIO_DLCLOSE(camera->library_handle); + GP_SYSTEM_DLCLOSE(camera->library_handle); return GP_OK; } diff --git a/libgphoto2/lists.c b/libgphoto2/lists.c index ead0911a7..555d2e8f0 100644 --- a/libgphoto2/lists.c +++ b/libgphoto2/lists.c @@ -1,6 +1,5 @@ #include <stdlib.h> #include <string.h> -#include <gpio.h> #include <gphoto2.h> #ifdef HAVE_CONFIG_H diff --git a/libgphoto2/port.c b/libgphoto2/port.c index 7e56ba43d..9353f3a57 100644 --- a/libgphoto2/port.c +++ b/libgphoto2/port.c @@ -1,45 +1,8 @@ #include <string.h> -#include <gpio.h> #include <gphoto2.h> #ifdef HAVE_CONFIG_H #include <config.h> #endif -int gp_port_count() -{ - return (gpio_get_device_count()); -} - -int gp_port_info(int port_number, CameraPortInfo *info) -{ - gpio_device_info i; - - if (gpio_get_device_info(port_number, &i)==GPIO_ERROR) - return (GP_ERROR); - - /* Translate to gPhoto types */ - switch (i.type) { - case GPIO_DEVICE_SERIAL: - info->type = GP_PORT_SERIAL; - break; - case GPIO_DEVICE_PARALLEL: - info->type = GP_PORT_PARALLEL; - break; - case GPIO_DEVICE_USB: - info->type = GP_PORT_USB; - break; - case GPIO_DEVICE_IEEE1394: - info->type = GP_PORT_IEEE1394; - break; - case GPIO_DEVICE_NETWORK: - info->type = GP_PORT_NETWORK; - break; - default: - info->type = GP_PORT_NONE; - } - strcpy(info->name, i.name); - strcpy(info->path, i.path); - - return (GP_OK); -} +/* deprecated with libgphoto2_port */
\ No newline at end of file diff --git a/libgphoto2_port/AUTHORS b/libgphoto2_port/AUTHORS new file mode 100644 index 000000000..89e6db8dd --- /dev/null +++ b/libgphoto2_port/AUTHORS @@ -0,0 +1,5 @@ +Scott Fritzinger <scottf@unr.edu> +Johannes Erdfelt <jerdfelt@valinux.com> (USB support) + +Based on work by: +Beat Christen <spiff@longstreet.ch> diff --git a/libgphoto2_port/COPYING.LIB b/libgphoto2_port/COPYING.LIB new file mode 100644 index 000000000..eb685a5ec --- /dev/null +++ b/libgphoto2_port/COPYING.LIB @@ -0,0 +1,481 @@ + GNU LIBRARY GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1991 Free Software Foundation, Inc. + 675 Mass Ave, Cambridge, MA 02139, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the library GPL. It is + numbered 2 because it goes with version 2 of the ordinary GPL.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Library General Public License, applies to some +specially designated Free Software Foundation software, and to any +other libraries whose authors decide to use it. You can use it for +your libraries, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if +you distribute copies of the library, or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link a program with the library, you must provide +complete object files to the recipients so that they can relink them +with the library, after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + Our method of protecting your rights has two steps: (1) copyright +the library, and (2) offer you this license which gives you legal +permission to copy, distribute and/or modify the library. + + Also, for each distributor's protection, we want to make certain +that everyone understands that there is no warranty for this free +library. If the library is modified by someone else and passed on, we +want its recipients to know that what they have is not the original +version, so that any problems introduced by others will not reflect on +the original authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that companies distributing free +software will individually obtain patent licenses, thus in effect +transforming the program into proprietary software. To prevent this, +we have made it clear that any patent must be licensed for everyone's +free use or not licensed at all. + + Most GNU software, including some libraries, is covered by the ordinary +GNU General Public License, which was designed for utility programs. This +license, the GNU Library General Public License, applies to certain +designated libraries. This license is quite different from the ordinary +one; be sure to read it in full, and don't assume that anything in it is +the same as in the ordinary license. + + The reason we have a separate public license for some libraries is that +they blur the distinction we usually make between modifying or adding to a +program and simply using it. Linking a program with a library, without +changing the library, is in some sense simply using the library, and is +analogous to running a utility program or application program. However, in +a textual and legal sense, the linked executable is a combined work, a +derivative of the original library, and the ordinary General Public License +treats it as such. + + Because of this blurred distinction, using the ordinary General +Public License for libraries did not effectively promote software +sharing, because most developers did not use the libraries. We +concluded that weaker conditions might promote sharing better. + + However, unrestricted linking of non-free programs would deprive the +users of those programs of all benefit from the free status of the +libraries themselves. This Library General Public License is intended to +permit developers of non-free programs to use free libraries, while +preserving your freedom as a user of such programs to change the free +libraries that are incorporated in them. (We have not seen how to achieve +this as regards changes in header files, but we have achieved it as regards +changes in the actual functions of the Library.) The hope is that this +will lead to faster development of free libraries. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, while the latter only +works together with the library. + + Note that it is possible for a library to be covered by the ordinary +General Public License rather than by this special one. + + GNU LIBRARY GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library which +contains a notice placed by the copyright holder or other authorized +party saying it may be distributed under the terms of this Library +General Public License (also called "this License"). Each licensee is +addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also compile or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + c) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + d) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the source code distributed need not include anything that is normally +distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Library General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + Appendix: How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + <one line to give the library's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + <signature of Ty Coon>, 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/libgphoto2_port/ChangeLog b/libgphoto2_port/ChangeLog new file mode 100644 index 000000000..a862db38d --- /dev/null +++ b/libgphoto2_port/ChangeLog @@ -0,0 +1,23 @@ +2000-07-15 Fabrice Bellet <Fabrice.Bellet@creatis.insa-lyon.fr> + + * gpio-usb.c : removed useless call to usb_release_interface() + because the usbdev close ioctl already does the job for us. + Compilation warning fix. + +2000-07-09 Fabrice Bellet <Fabrice.Bellet@creatis.insa-lyon.fr> + + * Makefile.am : fixed typo. + * gpio-usb.c : cosmetic namespace changes. + * gpio.c : fixed compilation warnings. + +2000-01-07 Ole Aamot <oka@ifi.uio.no> + + * Added USB patch from Johannes Erdfelt <jerdfelt@valinux.com> + +1999-12-28 Ole Aamot <oka@ifi.uio.no> + + * libgpio.spec.in: added + +1999-12-27 Ole Aamot <oka@ifi.uio.no> + + * Added auto* build scripts. diff --git a/libgphoto2_port/Makefile.am b/libgphoto2_port/Makefile.am new file mode 100644 index 000000000..1a70d55c6 --- /dev/null +++ b/libgphoto2_port/Makefile.am @@ -0,0 +1,35 @@ +## Process this file with automake to produce Makefile.in + +## Specify some includes and versioning +INCLUDES = -I@srcdir@ $(VERSION_FLAGS) +VERSION_FLAGS = -DLIBGPPORT_VERSION=\"@LIBGPPORT_VERSION@\" -DHAVE_TERMIOS_H + +## Executable files +bin_SCRIPTS = gphoto2-port-config + +SUBDIRS = libgphoto2_port include @IOLIB_SUBDIRS@ + +## GNOME configuration script +confexecdir=$(libdir) +confexec_DATA = gphoto2portConf.sh + +## Extra files +CLEANFILES=gphoto2portConf.sh +EXTRA_DIST = \ + AUTHORS \ + ChangeLog \ + COPYING.LIB \ + NEWS \ + README \ + libgphoto2_port.spec \ + gphoto2-port-config.in \ + gphoto2portConf.sh.in + +gphoto2portConf.sh: gphoto2portConf.sh.in Makefile +## Use sed and then mv to avoid problems if the user interrupts. + sed -e 's?\@GPPORT_LIBDIR\@?$(GPPORT_LIBDIR)?g' \ + -e 's?\@GPPORT_INCLUDEDIR\@?$(GPPORT_INCLUDEDIR)?g' \ + -e 's?\@GPPORT_LIBS\@?$(GPPORT_LIBS)?g' \ + -e 's?\@LIBGPPORT_VERSION\@?$(LIBGPPORT_VERSION)?g' \ + < $(srcdir)/gphoto2portConf.sh.in > gphoto2portConf.tmp \ + && mv gphoto2portConf.tmp gphoto2portConf.sh diff --git a/libgphoto2_port/NEWS b/libgphoto2_port/NEWS new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/libgphoto2_port/NEWS diff --git a/libgphoto2_port/README b/libgphoto2_port/README new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/libgphoto2_port/README diff --git a/libgphoto2_port/acconfig.h b/libgphoto2_port/acconfig.h new file mode 100644 index 000000000..e86bb4129 --- /dev/null +++ b/libgphoto2_port/acconfig.h @@ -0,0 +1,5 @@ +#undef HAVE_TERMIOS_H +#undef HAVE_STRFTIME +#undef HAVE_LOCALTIME +#undef HAVE_FCNTL_H +#undef HAVE_RTS_IOCTL diff --git a/libgphoto2_port/autogen.sh b/libgphoto2_port/autogen.sh new file mode 100755 index 000000000..733d1fba0 --- /dev/null +++ b/libgphoto2_port/autogen.sh @@ -0,0 +1,63 @@ +#!/bin/sh +# Run this to generate all the initial makefiles, etc. +# This was lifted from the Gimp, and adapted slightly by +# Raph Levien <raph@acm.org>. + +DIE=0 +srcdir=`dirname $0` +test -z "$srcdir" && srcdir=. + +PROJECT=libgphoto2_port + +(autoconf --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "You must have autoconf installed to compile $PROJECT." + echo "Download the appropriate package for your distribution," + echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/" + DIE=1 +} + +# Do we really need libtool? +(libtool --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "You must have libtool installed to compile $PROJECT." + echo "Get ftp://ftp.gnu.org/pub/gnu/libtool-1.2.tar.gz" + echo "(or a newer version if it is available)" + DIE=1 +} + +(automake --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "You must have automake installed to compile $PROJECT." + echo "Get ftp://ftp.gnu.org/pub/gnu/automake-1.3.tar.gz" + echo "(or a newer version if it is available)" + DIE=1 +} + +if test "$DIE" -eq 1; then + exit 1 +fi + +if test -z "$*"; then + echo "I am going to run ./configure with no arguments - if you wish " + echo "to pass any to it, please specify them on the $0 command line." +fi + +case $CC in +xlc ) + am_opt=--include-deps;; +esac + +for dir in $srcdir +do + echo processing $dir + (cd $dir; \ + aclocalinclude="$ACLOCAL_FLAGS"; \ + aclocal $aclocalinclude; \ + autoheader; automake --add-missing --gnu $am_opt; autoconf) +done + +$srcdir/configure "$@" + +echo +echo "Now type 'make' to compile $PROJECT." diff --git a/libgphoto2_port/configure.in b/libgphoto2_port/configure.in new file mode 100644 index 000000000..a0bc99daa --- /dev/null +++ b/libgphoto2_port/configure.in @@ -0,0 +1,120 @@ +dnl Process this file with autoconf to produce a configure script. + +AC_INIT(libgphoto2_port/gp_port.c) +AM_CONFIG_HEADER(config.h) + +LIBGPPORT_MAJOR_VERSION=0 +LIBGPPORT_MINOR_VERSION=0 +LIBGPPORT_MICRO_VERSION=3 +LIBGPPORT_VERSION=$LIBGPPORT_MAJOR_VERSION.$LIBGPPORT_MINOR_VERSION.$LIBGPPORT_MICRO_VERSION +LIBGPPORT_VERSION_INFO=`expr $LIBGPPORT_MAJOR_VERSION + $LIBGPPORT_MINOR_VERSION`:$LIBGPPORT_MICRO_VERSION:$LIBGPPORT_MINOR_VERSION + +AC_SUBST(LIBGPPORT_MAJOR_VERSION) +AC_SUBST(LIBGPPORT_MINOR_VERSION) +AC_SUBST(LIBGPPORT_MICRO_VERSION) +AC_SUBST(LIBGPPORT_VERSION) +AC_SUBST(LIBGPPORT_VERSION_INFO) + +VERSION=$LIBGPPORT_VERSION + +AM_INIT_AUTOMAKE(libgphoto2_port, $VERSION) +AM_MAINTAINER_MODE + +dnl Checks for programs. +AC_PROG_CC +AC_PROG_CPP +AM_PROG_LIBTOOL + +dnl Turn on debugging and catch GNU features incompatible with ANSI C. +CFLAGS="$CFLAGS -g -Wall -ansi" +LDFLAGS="$LDFLAGS -g -Wall -ansi" + +dnl Checks for header files. +AC_HEADER_DIRENT +AC_HEADER_STDC + +AC_CHECK_HEADERS(stdlib.h unistd.h stdio.h fcntl.h errno.h sys/time.h) +AC_CHECK_HEADERS(sys/param.h termios.h sgetty.h ttold.h ioctl-types.h \ + fcntl.h sgtty.h sys/ioctl.h sys/time.h termio.h unistd.h \ + endian.h byteswap.h asm/io.h) + +dnl Checks for library functions. +AC_FUNC_STRFTIME +AC_CHECK_FUNCS(strdup strndup strerror snprintf) +AC_CHECK_FUNCS(strftime localtime) + +dnl Check if TIOCM_RTS is included in one of several possible files +AC_TRY_COMPILE([#include <termios.h>], [int foo = TIOCM_RTS;], + AC_DEFINE(HAVE_RTS_IOCTL)) +AC_TRY_COMPILE([#include <termio.h>], [int foo = TIOCM_RTS;], + AC_DEFINE(HAVE_RTS_IOCTL)) +AC_TRY_COMPILE([#include <ioctl-types.h>], [int foo = TIOCM_RTS;], + AC_DEFINE(HAVE_RTS_IOCTL)) +AC_TRY_COMPILE([#include <sys/ioctl.h>], [int foo = TIOCM_RTS;], + AC_DEFINE(HAVE_RTS_IOCTL)) + +GPPORT_LIBDIR='-L${libdir}' +GPPORT_INCLUDEDIR='-I${includedir}' +GPPORT_LIBS="-lgphoto2_port" + +dnl Compile in serial support +IOLIB_SUBDIRS="serial" +IOLIB_LDFLAGS="-Lserial -lgphoto2_port_serial" +IOLIB_CFLAGS="-DGP_PORT_SUPPORTED_SERIAL" + +dnl Compile in usb support +AC_PATH_PROG(LIBUSB_CONFIG,libusb-config) +if test -n "${LIBUSB_CONFIG}"; then + IOLIB_SUBDIRS="$IOLIB_SUBDIRS usb" + IOLIB_LDFLAGS="$IOLIB_LDFLAGS `libusb-config --libs` -lgphoto2_port_usb" + IOLIB_CFLAGS="$IOLIB_CFLAGS -DGP_PORT_SUPPORTED_USB `libusb-config --cflags`" +else + AC_MSG_WARN([ + +*** You need Johannes Erdfelt's libusb library for USB support +*** http://download.sourceforge.net/libusb/libusb-0.1.2.tar.gz +]) +fi + +dnl Compile in parallel support +GP_PORT_PARALLEL=0 +if test "$GPPORT_PARALLEL" = "1"; then + IOLIB_SUBDIRS="$IOLIB_SUBDIRS parallel" + IOLIB_CFLAGS="$IOLIB_CFLAGS -DGP_PORT_SUPPORTED_PARALLEL" + IOLIB_LDFLAGS="$IOLIB_LDFLAGS -Lparallel -lgphoto2_port_parallel" +fi + +dnl Compile in network support +GP_PORT_NETWORK=0 +if test "$GPPORT_NETWORK" = "1"; then + IOLIB_SUBDIRS="$IOLIB_SUBDIRS network" + IOLIB_CFLAGS="$IOLIB_CFLAGS -DGP_PORT_SUPPORTED_NETWORK" + IOLIB_LDFLAGS="$IOLIB_LDFLAGS -Lnetwork -lgphoto2_port_network" +fi + +dnl Compile in firewire (oops, i said the word) support +GP_PORT_IEEE1394=0 +if test "$GPPORT_IEEE1394" = "1"; then + IOLIB_SUBDIRS="$IOLIB_SUBDIRS ieee1394" + IOLIB_CFLAGS="$IOLIB_CFLAGS -DGP_PORT_SUPPORTED_IEEE1394" + IOLIB_LDFLAGS="$IOLIB_LDFLAGS -Lieee1394 -lgphoto2_port_ieee1394" +fi + +AC_SUBST(GPPORT_LIBDIR) +AC_SUBST(GPPORT_LIBS) +AC_SUBST(GPPORT_INCLUDEDIR) +AC_SUBST(IOLIB_SUBDIRS) +AC_SUBST(IOLIB_LDFLAGS) +AC_SUBST(IOLIB_CFLAGS) + +AC_OUTPUT( \ +libgphoto2_port.spec \ +Makefile \ +libgphoto2_port/Makefile \ +serial/Makefile \ +parallel/Makefile \ +usb/Makefile \ +ieee1394/Makefile \ +network/Makefile \ +include/Makefile \ +gphoto2-port-config) diff --git a/libgphoto2_port/doc/Makefile.am b/libgphoto2_port/doc/Makefile.am new file mode 100644 index 000000000..f4f9ac278 --- /dev/null +++ b/libgphoto2_port/doc/Makefile.am @@ -0,0 +1,61 @@ +## Process this file with automake to produce Makefile.in + +# The name of the module. +DOC_MODULE=libgpio + +# The top-level SGML file. +DOC_MAIN_SGML_FILE=libgpio.sgml + +# The directory containing the source code (if it contains documentation). +DOC_SOURCE_DIR=.. + +HTML_DIR=$(prefix)/share/doc/libgpio$(LIBGPIO_MAJOR_VERSION).$(LIBGPIO_MINOR_VERSION)-dev/html + +TARGET_DIR=$(HTML_DIR)/$(DOC_MODULE) + + +scan: + gtkdoc-scan --module=$(DOC_MODULE) --source-dir=$(DOC_SOURCE_DIR) --ignore-headers="acconfig.h config.h examples/jmtransfer.h src/libgpio-private.h src/ftp.h" + +templates: scan + gtkdoc-mktmpl --module=$(DOC_MODULE) + +sgml: + gtkdoc-mkdb --module=$(DOC_MODULE) --source-dir=$(DOC_SOURCE_DIR) + +html: + if ! test -d html ; then mkdir html ; fi + -cd html && gtkdoc-mkhtml $(DOC_MODULE) ../$(DOC_MAIN_SGML_FILE) + +clean-local: + rm -f *~ *.bak *.hierarchy *.signals *-unused.txt + +maintainer-clean-local: clean + rm -rf sgml html $(DOC_MODULE)-decl-list.txt $(DOC_MODULE)-decl.txt + +libgpio-decl-list.txt : templates + +libgpio-sections.txt : scan + cp libgpio-decl-list.txt libgpio-sections.txt + +rebuild: libgpio-sections.txt templates sgml html + +install-data-local: + $(mkinstalldirs) $(DESTDIR)$(TARGET_DIR) + -@INSTALL@ -m 0644 $(srcdir)/html/*.html $(DESTDIR)$(TARGET_DIR) + -@INSTALL@ -m 0644 $(srcdir)/html/index.sgml $(DESTDIR)$(TARGET_DIR) + -(cd $(DESTDIR); gtkdoc-fixxref --module=$(DOC_MODULE) --html-dir=$(HTML_DIR)) + -mv $(HTML_DIR)/$(DOC_MODULE)/* $(HTML_DIR) + -rm -rf $(HTML_DIR)/$(DOC_MODULE) + -(cd $(HTML_DIR); ln -s book1.html index.html) + +dist-hook: + (cd $(srcdir) ; tar cvf - html/*.html html/*.sgml) | (cd $(distdir); tar xf -) + +copyweb: + rm -rf $(HOME)/public_html/libgpio/docs/* + cp -f html/*.html $(HOME)/public_html/libgpio/docs + cp -f $(HOME)/public_html/libgpio/docs/book1.html $(HOME)/public_html/libgpio/docs/index.html + chmod -R a+rX $(HOME)/public_html/libgpio/docs + +.PHONY : html sgml templates scan diff --git a/libgphoto2_port/doc/libgphoto2-port-sections.txt b/libgphoto2_port/doc/libgphoto2-port-sections.txt new file mode 100644 index 000000000..ab3342bf1 --- /dev/null +++ b/libgphoto2_port/doc/libgphoto2-port-sections.txt @@ -0,0 +1,136 @@ +<SECTION> +<FILE>gpio-ieee1394</FILE> +gpio_ieee1394_settings +</SECTION> + +<SECTION> +<FILE>gpio-network</FILE> +GPIO_NETWORK +gpio_network_settings +</SECTION> + +<SECTION> +<FILE>gpio-parallel</FILE> +GPIO_PARALLEL +GPIO_PARALLEL_PREFIX +GPIO_PARALLEL_RANGE_LOW +GPIO_PARALLEL_RANGE_HIGH +gpio_parallel_settings +</SECTION> + +<SECTION> +<FILE>gpio-serial</FILE> +GPIO_SERIAL +GPIO_SERIAL_PREFIX +GPIO_SERIAL_RANGE_LOW +GPIO_SERIAL_RANGE_HIGH +gpio_serial_settings +PIN_RTS +PIN_DTR +PIN_CTS +PIN_DSR +PIN_CD +PIN_RING +</SECTION> + +<SECTION> +<FILE>gpio-usb</FILE> +gpio_usb_settings +</SECTION> + +<SECTION> +<FILE>gpioos2</FILE> +CBAUD +B0 +B50 +B75 +B110 +B134 +B150 +B200 +B300 +B600 +B1200 +B1800 +B2400 +B4800 +B9600 +B19200 +B38400 +EXTA +EXTB +CSIZE +CS5 +CS6 +CS7 +CS8 +CSTOPB +CREAD +PARENB +PARODD +HUPCL +CLOCAL +CBAUDEX +B57600 +B115200 +B230400 +B460800 +B76800 +B153600 +B307200 +B614400 +B921600 +B500000 +B576000 +B1000000 +B1152000 +B1500000 +B2000000 +CIBAUD +CMSPAR +CRTSCTS +TIOCM_LE +TIOCM_DTR +TIOCM_RTS +TIOCM_ST +TIOCM_SR +TIOCM_CTS +TIOCM_CAR +TIOCM_RNG +TIOCM_DSR +TIOCM_CD +TIOCM_RI +TIOCMBIC +TIOCMBIS +TIOCMGET +</SECTION> + +<SECTION> +<FILE>gpio</FILE> +GPIO_USB +GPIO_IEEE1394 +GPIO_MAX_BUF_LEN +GPIO_OK +GPIO_ERROR +GPIO_TIMEOUT +gpio_device_type +gpio_device_info +gpio_init +gpio_get_device_count +gpio_get_device_info +gpio_new +gpio_new_by_number +gpio_new_by_port +gpio_free +gpio_open +gpio_close +gpio_set_timeout +gpio_get_timeout +gpio_set_settings +gpio_get_settings +gpio_write +gpio_read +gpio_get_pin +gpio_set_pin +</SECTION> + diff --git a/libgphoto2_port/doc/libgphoto2-port.sgml b/libgphoto2_port/doc/libgphoto2-port.sgml new file mode 100644 index 000000000..ab76b0dd0 --- /dev/null +++ b/libgphoto2_port/doc/libgphoto2-port.sgml @@ -0,0 +1,56 @@ +<!DOCTYPE BOOK PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [ +<!entity libgpio-gpio-ieee1394 SYSTEM "sgml/gpio-ieee1394.sgml"> +<!entity libgpio-gpio-network SYSTEM "sgml/gpio-network.sgml"> +<!entity libgpio-gpio-parallel SYSTEM "sgml/gpio-parallel.sgml"> +<!entity libgpio-gpio-serial SYSTEM "sgml/gpio-serial.sgml"> +<!entity libgpio-gpio-usb SYSTEM "sgml/gpio-usb.sgml"> +<!entity libgpio-gpioos2 SYSTEM "sgml/gpioos2.sgml"> +<!entity libgpio-gpio SYSTEM "sgml/gpio.sgml"> +]> + +<book> + <bookinfo> + <title>GPIO (gPhoto I/O) Library Reference Manual</title> + <abstract> + <para> + This manual documents the GPIO, the GPhoto I/O library. + It gives an overview of GPIO, discusses examples that + come with GPIO and includes detailed documentation of + the GPIO API. + </para> + </abstract> + </bookinfo> + + <chapter id="gpio-overview"> + <title>GPIO Overview</title> + + <para> + GPIO is the GPhoto I/O library. + </para> + + <para> + The benefit to using this library would be that all communications can be + done quickly and without worry for device specific functions; all devices + are abstracted to a point, allowing you to read/write to a device using + the same interface. For example, you can set all the options on the + serial port easily, and then read/write to that device. Additionally, + you could easily switch over to a USB device, and read/write without + having to learn the USB internals. + </para> + + <para> + The whole idea behind this is simplicity. It should be easy to write a + program that uses any sort of serial-based device. This will take the + hassle out of playing with low-level configurations and actually just + get on to writing the core of the application. + </para> + + &libgpio-gpio; + &libgpio-gpio-usb; + &libgpio-gpio-serial; + &libgpio-gpio-network; + &libgpio-gpio-parallel; + &libgpio-gpio-ieee1394; + &libgpio-gpioos2; + </chapter> +</book> diff --git a/libgphoto2_port/gphoto2-port-config.in b/libgphoto2_port/gphoto2-port-config.in new file mode 100644 index 000000000..1f1b008d0 --- /dev/null +++ b/libgphoto2_port/gphoto2-port-config.in @@ -0,0 +1,71 @@ +#! /bin/sh + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +includedir=@includedir@ + +usage() +{ + cat <<EOF +Usage: gphoto2-port-config [OPTION] + +Known values for OPTION are: + + --prefix=DIR change libgphoto2-port prefix [default $prefix] + --libs print library linking information + --cflags print pre-processor and compiler flags + --help display this help and exit + --version output version information +EOF + + exit $1 +} + +if test $# -eq 0; then + usage 1 +fi + +cflags=false +libs=false + +while test $# -gt 0; do + case "$1" in + -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; + *) optarg= ;; + esac + + case "$1" in + --prefix=*) + prefix=$optarg + ;; + + --prefix) + echo $prefix + ;; + + --version) + echo @PACKAGE@ @VERSION@ + exit 0 + ;; + + --help) + usage 0 + ;; + + --cflags) + echo -I${includedir}/gphoto2-port @GPPORT_INCLUDEDIR@ @IOLIB_CFLAGS@ + ;; + + --libs) + echo -L@libdir@ @GPPORT_LIBS@ @LIBS@ + ;; + + *) + usage + exit 1 + ;; + esac + shift +done + +exit 0 diff --git a/libgphoto2_port/gphoto2portConf.sh.in b/libgphoto2_port/gphoto2portConf.sh.in new file mode 100644 index 000000000..2b921935f --- /dev/null +++ b/libgphoto2_port/gphoto2portConf.sh.in @@ -0,0 +1,7 @@ +# +# Configuration file for using the GPHOTO-PORT library +# +GPPORT_LIBDIR="@GPPORT_LIBDIR@" +GPPORT_LIBS="@GPPORT_LIBS@" +GPPORT_INCLUDEDIR="@GPPORT_INCLUDEDIR@" +MODULE_VERSION="gphoto2-port-@LIBGPPORT_VERSION@" diff --git a/libgphoto2_port/ieee1394/Makefile.am b/libgphoto2_port/ieee1394/Makefile.am new file mode 100644 index 000000000..a927483df --- /dev/null +++ b/libgphoto2_port/ieee1394/Makefile.am @@ -0,0 +1,11 @@ +## Specify some includes and versioning +INCLUDES = -I../ $(VERSION_FLAGS) -I$(top_srcdir)/include +VERSION_FLAGS = -DLIBGPPORT_VERSION=\"@LIBGPPORT_VERSION@\" +CFLAGS = @CFLAGS@ @IOLIB_CFLAGS@ -g +LDFLAGS = @LDFLAGS@ -g + +## Compile the IO library into a shared library +iolibdir = $(prefix)/lib/gphoto2_port +iolib_LTLIBRARIES = libgphoto2_port_ieee1394.la +libgphoto2_port_ieee1394_la_LDFLAGS = -version-info @LIBGPPORT_VERSION_INFO@ -DHAVE_TERMIOS_H +libgphoto2_port_ieee1394_la_SOURCES = linux-raw.c gphoto2-port-ieee1394.h diff --git a/libgphoto2_port/ieee1394/linux-raw.c b/libgphoto2_port/ieee1394/linux-raw.c new file mode 100644 index 000000000..dc95d15d5 --- /dev/null +++ b/libgphoto2_port/ieee1394/linux-raw.c @@ -0,0 +1,119 @@ +/* -*- Mode: C { indent-tabs-mode: t { c-basic-offset: 8 { tab-width: 8 -*- */ +/* gphoto2-port-ieee1394.c - ieee1394 IO functions + + Modifications: + Copyright (C) 1999 Scott Fritzinger <scottf@unr.edu> + + The GPIO Library is free software { you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation { either version 2 of the + License, or (at your option) any later version. + + The GPIO Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY { without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GPIO Library { see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + */ + +#include "gphoto2-port.h" + +/* IEEE1394 prototypes + ------------------------------------------------------------------ */ +int gp_port_ieee1394_list(gp_port_info *list, int *count); + +int gp_port_ieee1394_init(gp_port *dev); +int gp_port_ieee1394_exit(gp_port *dev); + +int gp_port_ieee1394_open(gp_port *dev); +int gp_port_ieee1394_close(gp_port *dev); + +int gp_port_ieee1394_read(gp_port *dev, char *bytes, int size); +int gp_port_ieee1394_write(gp_port *dev, char *bytes, int size); + +int gp_port_ieee1394_get_pin(gp_port *dev, int pin); +int gp_port_ieee1394_set_pin(gp_port *dev, int pin, int level); + +int gp_port_ieee1394_update (gp_port *dev); + +int gp_port_ieee1394_set_baudrate(gp_port *dev); + + +/* Dynamic library functions + ------------------------------------------------------------------ */ + +gp_port_type gp_port_library_type () { + + return (GP_PORT_IEEE1394); +} + +gp_port_operations *gp_port_library_operations () { + + gp_port_operations *ops; + + ops = (gp_port_operations*)malloc(sizeof(gp_port_operations)); + memset(ops, 0, sizeof(gp_port_operations)); + + ops->init = gp_port_ieee1394_init; + ops->exit = gp_port_ieee1394_exit; + ops->open = gp_port_ieee1394_open; + ops->close = gp_port_ieee1394_close; + ops->read = gp_port_ieee1394_read; + ops->write = gp_port_ieee1394_write; + ops->update = gp_port_ieee1394_update; + return (ops); +} + +int gp_port_library_list(gp_port_info *list, int *count) { + + list[*count].type = GP_PORT_IEEE1394; + strcpy(list[*count].name, "IEEE1394 (Firewire(tm))"); + strcpy(list[*count].path, "ieee1394"); + list[*count].argument_needed = 0; + *count += 1; + + return (GP_OK); + +} + +/* IEEE1394 API functions + ------------------------------------------------------------------ */ + +int gp_port_ieee1394_init(gp_port *dev) { + +} + +int gp_port_ieee1394_exit(gp_port *dev) { + +} + +int gp_port_ieee1394_open(gp_port *dev) { + +} + +int gp_port_ieee1394_close(gp_port *dev) { + +} +int gp_port_ieee1394_read(gp_port *dev, char *bytes, int size) { + +} + +int gp_port_ieee1394_write(gp_port *dev, char *bytes, int size) { + +} + +int gp_port_ieee1394_get_pin(gp_port *dev, int pin) { + +} + +int gp_port_ieee1394_set_pin(gp_port *dev, int pin, int level) { + +} + +int gp_port_ieee1394_update (gp_port *dev) { + +} diff --git a/libgphoto2_port/include/Makefile.am b/libgphoto2_port/include/Makefile.am new file mode 100644 index 000000000..9cd7a83e2 --- /dev/null +++ b/libgphoto2_port/include/Makefile.am @@ -0,0 +1,8 @@ +gphoto2_port_incdir = $(includedir)/gphoto2-port +gphoto2_port_inc_HEADERS = gphoto2-port.h \ + gphoto2-portability.h \ + gphoto2-port-serial.h \ + gphoto2-port-parallel.h \ + gphoto2-port-usb.h \ + gphoto2-port-ieee1394.h \ + gphoto2-port-network.h diff --git a/libgphoto2_port/include/gphoto2-port-ieee1394.h b/libgphoto2_port/include/gphoto2-port-ieee1394.h new file mode 100644 index 000000000..35bd34fee --- /dev/null +++ b/libgphoto2_port/include/gphoto2-port-ieee1394.h @@ -0,0 +1,11 @@ +#ifndef _GP_PORT_IEEE1394_H_ +#define _GP_PORT_IEEE1394_H_ + +/* ieee1394 port specific settings */ +typedef struct { + int blah; +} gp_port_ieee1394_settings; + +extern struct gp_port_operations gp_port_ieee1394_operations; + +#endif /* _GP_PORT_IEEE1394_H_ */ diff --git a/libgphoto2_port/include/gphoto2-port-network.h b/libgphoto2_port/include/gphoto2-port-network.h new file mode 100644 index 000000000..026301ae0 --- /dev/null +++ b/libgphoto2_port/include/gphoto2-port-network.h @@ -0,0 +1,15 @@ +#ifndef _GP_PORT_NETWORK_H_ +#define _GP_PORT_NETWORK_H_ + +/* socket specific settings */ +typedef struct { + char address[20]; +} gp_port_network_settings; + +extern struct gp_port_operations gp_port_network_operations; + +#endif /* _GP_PORT_NETWORK_H_ */ + + + + diff --git a/libgphoto2_port/include/gphoto2-port-parallel.h b/libgphoto2_port/include/gphoto2-port-parallel.h new file mode 100644 index 000000000..8136aacb2 --- /dev/null +++ b/libgphoto2_port/include/gphoto2-port-parallel.h @@ -0,0 +1,75 @@ +#ifndef _GP_PORT_PARALLEL_H_ +#define _GP_PORT_PARALLEL_H_ + +/* PARALLEL port prefix for enumeration */ + +/* Linux */ +#ifdef __linux +#define GP_PORT_PARALLEL_PREFIX "/dev/lp%i" +#define GP_PORT_PARALLEL_RANGE_LOW 0 +#define GP_PORT_PARALLEL_RANGE_HIGH 16 +#endif + +/* BSD */ +#if defined(__FreeBSD__) || defined(__NetBSD__) +#define GP_PORT_PARALLEL_PREFIX NULL +#define GP_PORT_PARALLEL_RANGE_LOW 0 +#define GP_PORT_PARALLEL_RANGE_HIGH 0 +#endif + +/* Solaris */ +#ifdef sun +# ifdef i386 +# define GP_PORT_PARALLEL_PREFIX "/dev/lp%i" /* x86 parallel port prefix*/ +# define GP_PORT_PARALLEL_RANGE_LOW 1 +# define GP_PORT_PARALLEL_RANGE_HIGH 16 +# else +# define GP_PORT_PARALLEL_PREFIX "/dev/bpp%02i" /* Sparc parallel port prefix*/ +# define GP_PORT_PARALLEL_RANGE_LOW 0 +# define GP_PORT_PARALLEL_RANGE_HIGH 16 +# endif +#endif + + +/* BeOS */ +#ifdef beos +/* ????????????? */ +#define GP_PORT_PARALLEL_PREFIX NULL +#define GP_PORT_PARALLEL_RANGE_LOW 0 +#define GP_PORT_PARALLEL_RANGE_HIGH 0 +#endif + +/* Windows */ +#ifdef WIN +#define GP_PORT_PARALLEL_PREFIX "LPT%i:" +#define GP_PORT_PARALLEL_RANGE_LOW 0 +#define GP_PORT_PARALLEL_RANGE_HIGH 16 +#endif + +/* OS/2 */ +#ifdef OS2 +#define GP_PORT_PARALLEL_PREFIX "LPT%i" +#define GP_PORT_PARALLEL_RANGE_LOW 1 +#define GP_PORT_PARALLEL_RANGE_HIGH 4 +#endif + +/* Others? */ + +/* Default */ +#ifndef GP_PORT_PARALLEL_PREFIX +#warning GP_PORT_PARALLEL_PREFIX not defined. Enumeration will fail +#define GP_PORT_PARALLEL_PREFIX NULL +#define GP_PORT_PARALLEL_RANGE_LOW 0 +#define GP_PORT_PARALLEL_RANGE_HIGH 0 +#endif + +/* PARALLEL port specific settings */ +typedef struct { + char port[128]; +} gp_port_parallel_settings; + +extern struct gp_port_operations gp_port_parallel_operations; + +#endif /* _GP_PORT_PARALLEL_H_ */ + + diff --git a/libgphoto2_port/include/gphoto2-port-serial.h b/libgphoto2_port/include/gphoto2-port-serial.h new file mode 100644 index 000000000..e23b819d0 --- /dev/null +++ b/libgphoto2_port/include/gphoto2-port-serial.h @@ -0,0 +1,79 @@ +#ifndef _GP_PORT_SERIAL_H_ +#define _GP_PORT_SERIAL_H_ + +/* Serial port prefix for enumeration */ +/* %i for numbers, %c for letters */ +/* also define the low and high values of the range to check for devices */ + + +/* Linux */ +#ifdef __linux +/* devfs is accounted for in the implementation */ +#define GP_PORT_SERIAL_PREFIX "/dev/ttyS%i" +#define GP_PORT_SERIAL_RANGE_LOW 0 +#define GP_PORT_SERIAL_RANGE_HIGH 32 +#endif + +/* BSD */ +#if defined(__FreeBSD__) || defined(__NetBSD__) +#define GP_PORT_SERIAL_PREFIX "/dev/tty0%i" +#define GP_PORT_SERIAL_RANGE_LOW 0 +#define GP_PORT_SERIAL_RANGE_HIGH 32 +#endif + +/* Solaris */ +#ifdef sun +#define GP_PORT_SERIAL_PREFIX "/dev/tty%c" +#define GP_PORT_SERIAL_RANGE_LOW 'a' +#define GP_PORT_SERIAL_RANGE_HIGH 'z' +#endif + +/* BeOS */ +#ifdef beos +/* ????????????? */ +#define GP_PORT_SERIAL_PREFIX NULL +#define GP_PORT_SERIAL_RANGE_LOW 0 +#define GP_PORT_SERIAL_RANGE_HIGH 0 +#endif + +/* Windows */ +#ifdef WIN32 +#define GP_PORT_SERIAL_PREFIX "COM%i:" +#define GP_PORT_SERIAL_RANGE_LOW 1 +#define GP_PORT_SERIAL_RANGE_HIGH 4 +#endif + +#ifdef OS2 +#define GP_PORT_SERIAL_PREFIX "COM%i" +#define GP_PORT_SERIAL_RANGE_LOW 1 +#define GP_PORT_SERIAL_RANGE_HIGH 4 +#endif + +/* Others? */ + +/* Default */ +#ifndef GP_PORT_SERIAL_PREFIX +#define GP_PORT_SERIAL_PREFIX "/dev/cua%i" +#define GP_PORT_SERIAL_RANGE_LOW 0 +#define GP_PORT_SERIAL_RANGE_HIGH 0 +#endif + +/* Serial port specific settings */ +typedef struct { + char port[128]; + int speed; + int bits; + int parity; + int stopbits; +} gp_port_serial_settings; + +extern struct gp_port_operations gp_port_serial_operations; + +#define PIN_RTS 0 +#define PIN_DTR 1 +#define PIN_CTS 2 +#define PIN_DSR 3 +#define PIN_CD 4 +#define PIN_RING 5 + +#endif /* _GP_PORT_SERIAL_H_ */ diff --git a/libgphoto2_port/include/gphoto2-port-usb.h b/libgphoto2_port/include/gphoto2-port-usb.h new file mode 100644 index 000000000..08912bf53 --- /dev/null +++ b/libgphoto2_port/include/gphoto2-port-usb.h @@ -0,0 +1,15 @@ +#ifndef _GP_PORT_USB_H_ +#define _GP_PORT_USB_H_ + +/* USB port specific settings */ +typedef struct { + int inep; + int outep; + int config; + int interface; + int altsetting; +} gp_port_usb_settings; + +extern struct gp_port_operations gp_port_usb_operations; + +#endif /* _GP_PORT_USB_H_ */ diff --git a/libgphoto2_port/include/gphoto2-port.h b/libgphoto2_port/include/gphoto2-port.h new file mode 100644 index 000000000..b0101e7ee --- /dev/null +++ b/libgphoto2_port/include/gphoto2-port.h @@ -0,0 +1,294 @@ +#ifndef _GP_PORT_H_ +#define _GP_PORT_H_ + +#ifdef OS2 +#include <gphoto2-portability-os2.h> +#include <os2.h> +#endif + +/* Include the portability layer */ +#include "gphoto2-portability.h" + +/* Include the various headers for other devices */ +#include "gphoto2-port-serial.h" +#include "gphoto2-port-parallel.h" +#include "gphoto2-port-network.h" +#include "gphoto2-port-usb.h" +#include "gphoto2-port-ieee1394.h" + +#ifndef TRUE +#define TRUE (0==0) +#endif + +#ifndef FALSE +#define FALSE (1==0) +#endif + +/* Defines and enums + -------------------------------------------------------------- + Note: this is a base set of return values. */ + +/* Return values */ +/* Note: This lib should be allocated return values of 0 to -99 */ + +#define GP_OK 0 + +#define GP_ERROR -1 +#define GP_ERROR_TIMEOUT -2 + + +/* Debugging definitions for init */ +#define GP_DEBUG_NONE 0 +#define GP_DEBUG_LOW 1 +#define GP_DEBUG_MEDIUM 2 +#define GP_DEBUG_HIGH 3 + +#define GP_PORT_MAX_BUF_LEN 4096 /* max length of receive buffer */ + +/* Specify the types of devices */ +typedef enum { + GP_PORT_NONE = 0, + GP_PORT_SERIAL = 1 << 0, + GP_PORT_PARALLEL = 1 << 1, /* <- Not supported yet */ + GP_PORT_USB = 1 << 2, + GP_PORT_IEEE1394 = 1 << 3, /* <- Not supported yet */ + GP_PORT_NETWORK = 1 << 4, /* <- Not supported yet */ +} gp_port_type; + + +/* Device struct + -------------------------------------------------------------- */ + +typedef struct { + gp_port_type type; + char name[64]; + char path[64]; + + /* not used yet */ + int argument_needed; + char argument_description[128]; + char argument[128]; + + /* don't touch */ + char library_filename[1024]; +} gp_port_info; + + +/* Put the settings together in a union */ +typedef union { + gp_port_serial_settings serial; + gp_port_parallel_settings parallel; + gp_port_network_settings network; + gp_port_usb_settings usb; + gp_port_ieee1394_settings ieee1394; +} gp_port_settings; + +enum { + GP_PORT_USB_IN_ENDPOINT, + GP_PORT_USB_OUT_ENDPOINT +}; + +struct gp_port; +typedef struct gp_port gp_port; +struct gp_port_operations { + int (*init) (gp_port *); + int (*exit) (gp_port *); + int (*open) (gp_port *); + int (*close) (gp_port *); + int (*read) (gp_port *, char *, int); + int (*write) (gp_port *, char *, int); + int (*update) (gp_port *); + + /* Pointers to devices. Please note these are stubbed so there is + no need to #ifdef GP_PORT_* anymore. */ + + /* for serial and parallel devices */ + int (*get_pin) (gp_port *, int); + int (*set_pin) (gp_port *, int, int); + int (*send_break)(gp_port *, int); + + /* for USB devices */ + int (*find_device)(gp_port * dev, int idvendor, int idproduct); + int (*clear_halt) (gp_port * dev, int ep); + int (*msg_write) (gp_port * dev, int value, char *bytes, int size); + int (*msg_read) (gp_port * dev, int value, char *bytes, int size); + +}; + +typedef struct gp_port_operations gp_port_operations; + +/* Function pointers for the dynamic libraries */ +typedef int (*gp_port_ptr_type) (); +typedef int (*gp_port_ptr_list) (gp_port_info*, int *); +typedef gp_port_operations* (*gp_port_ptr_operations) (); + +/* Specify the device information */ +struct gp_port { + /* This struct is available via wrappers. don't modify + directly. */ + gp_port_type type; + + gp_port_operations *ops; + + gp_port_settings settings; + gp_port_settings settings_pending; + + gp_port_settings settings_saved; + + int device_fd; +#ifdef WIN32 + HANDLE device_handle; +#else + void *device_handle; +#endif + int timeout; /* in milli seconds */ + + void *library_handle; + + int debug_level; +}; + +/* Core functions + -------------------------------------------------------------- */ + + void gp_port_debug_printf (int target_debug_level, int debug_level, char *format, ...); + /* issues debugging messages */ + + int gp_port_init (int debug_level); + /* Initializes the library. + return values: + successful: GP_OK + unsuccessful: GP_ERROR + */ + + int gp_port_get_count (); + /* Get a count of available devices + return values: + successful: valid gp_port_list struct + unsuccessful: GP_ERROR + */ + + int gp_port_get_info (int device_number, gp_port_info *info); + /* Get information about a device + return values: + successful: valid gp_port_list struct + unsuccessful: GP_ERROR + */ + +gp_port *gp_port_new (gp_port_type type); + /* Create a new device of type "type" + return values: + successful: valid gp_port struct + unsuccessful: GP_ERROR + */ + + int gp_port_free (gp_port *dev); + /* Frees an IO device from memory + return values: + successful: GP_OK + unsuccessful: GP_ERROR + */ + + int gp_port_set_debug (gp_port *dev, int debug_level); + /* + Set the debugging level specific to a device + */ + + int gp_port_open (gp_port *dev); + /* Open the device for reading and writing + return values: + successful: GP_OK + unsuccessful: GP_ERROR + */ + + int gp_port_close (gp_port *dev); + /* Close the device to prevent reading and writing + return values: + successful: GP_OK + unsuccessful: GP_ERROR + */ + + int gp_port_set_timeout (gp_port *dev, int millisec_timeout); + /* Sets the read/write timeout + successful: GP_OK + unsuccessful: GP_ERROR + */ + + int gp_port_get_timeout (gp_port *dev, int *millisec_timeout); + /* Sets the read/write timeout + successful: GP_OK + unsuccessful: GP_ERROR + */ + + int gp_port_set_settings (gp_port *dev, + gp_port_settings settings); + /* Sets the settings + successful: GP_OK + unsuccessful: GP_ERROR + */ + + + int gp_port_get_settings (gp_port *dev, + gp_port_settings *settings); + /* Returns settings in "settings" + successful: GP_OK + unsuccessful: GP_ERROR + */ + + int gp_port_write (gp_port *dev, char *bytes, int size); + /* Writes "bytes" of size "size" to the device + return values: + successful: GP_OK + unsuccessful: GP_ERROR + */ + + int gp_port_read (gp_port *dev, char *bytes, int size); + /* Reads "size" bytes in to "bytes" from the device + return values: + successful: number of bytes read + unsuccessful: GP_ERROR + */ + + +/* Serial and Parallel specific functions + -------------------------------------------------------------- */ + + int gp_port_get_pin (gp_port *dev, int pin); + /* Give the status of pin from dev + pin values: + see PIN_ constants in the various .h files + return values: + successful: status + unsuccessful: GP_ERROR + */ + + int gp_port_set_pin (gp_port *dev, int pin, int level); + /* set the status of pin from dev to level + pin values: + see PIN_ constants in the various .h files + level values: + 0 for off + 1 for on + return values: + successful: status + unsuccessful: GP_ERROR + */ + + int gp_port_send_break (gp_port *dev, int duration); + /* send a break (duration is in seconds) */ + +/* USB specific functions + -------------------------------------------------------------- */ + + /* must port libusb to other platforms for this to drop-in */ + int gp_port_usb_find_device (gp_port * dev, int idvendor, int idproduct); + int gp_port_usb_clear_halt (gp_port * dev, int ep); + int gp_port_usb_msg_write (gp_port * dev, int value, char *bytes, int size); + int gp_port_usb_msg_read (gp_port * dev, int value, char *bytes, int size); + + + + +#endif /* _GP_PORT_H_ */ + + diff --git a/libgphoto2_port/include/gphoto2-portability-os2.h b/libgphoto2_port/include/gphoto2-portability-os2.h new file mode 100644 index 000000000..0c2b7863a --- /dev/null +++ b/libgphoto2_port/include/gphoto2-portability-os2.h @@ -0,0 +1,77 @@ +#ifndef GPIO_OS2_INCLUDED +#define GPIO_OS2_INCLUDED +#define IOLIBS getenv("IOLIBS") +#define RTLD_LAZY 0x001 +#ifndef HAVE_TERMIOS_H +/* c_cflag bit meaning */ +#define CBAUD 0x0000100f +#define B0 0x00000000 /* hang up */ +#define B50 0x00000001 +#define B75 0x00000002 +#define B110 0x00000003 +#define B134 0x00000004 +#define B150 0x00000005 +#define B200 0x00000006 +#define B300 0x00000007 +#define B600 0x00000008 +#define B1200 0x00000009 +#define B1800 0x0000000a +#define B2400 0x0000000b +#define B4800 0x0000000c +#define B9600 0x0000000d +#define B19200 0x0000000e +#define B38400 0x0000000f +#define EXTA B19200 +#define EXTB B38400 +#define CSIZE 0x00000030 +#define CS5 0x00000000 +#define CS6 0x00000010 +#define CS7 0x00000020 +#define CS8 0x00000030 +#define CSTOPB 0x00000040 +#define CREAD 0x00000080 +#define PARENB 0x00000100 +#define PARODD 0x00000200 +#define HUPCL 0x00000400 +#define CLOCAL 0x00000800 +#define CBAUDEX 0x00001000 +#define B57600 0x00001001 +#define B115200 0x00001002 +#define B230400 0x00001003 +#define B460800 0x00001004 +#define B76800 0x00001005 +#define B153600 0x00001006 +#define B307200 0x00001007 +#define B614400 0x00001008 +#define B921600 0x00001009 +#define B500000 0x0000100a +#define B576000 0x0000100b +#define B1000000 0x0000100c +#define B1152000 0x0000100d +#define B1500000 0x0000100e +#define B2000000 0x0000100f + +#endif + +#define CIBAUD 0x100f0000 /* input baud rate (not used) */ +#define CMSPAR 0x40000000 /* mark or space (stick) parity */ +//#define CRTSCTS 0x80000000 /* flow control */ + +/* modem lines */ +#define TIOCM_LE 0x001 +#define TIOCM_DTR 0x002 +#define TIOCM_RTS 0x004 +#define TIOCM_ST 0x008 +#define TIOCM_SR 0x010 +#define TIOCM_CTS 0x020 +#define TIOCM_CAR 0x040 +#define TIOCM_RNG 0x080 +#define TIOCM_DSR 0x100 +#define TIOCM_CD TIOCM_CAR +#define TIOCM_RI TIOCM_RNG + +#define TIOCMBIC 0x06C +#define TIOCMBIS 0x06B +#define TIOCMGET 0x06E + +#endif diff --git a/libgphoto2_port/include/gphoto2-portability.h b/libgphoto2_port/include/gphoto2-portability.h new file mode 100644 index 000000000..c52504c19 --- /dev/null +++ b/libgphoto2_port/include/gphoto2-portability.h @@ -0,0 +1,84 @@ + +/* Windows Portability + ------------------------------------------------------------------ */ + +#ifdef WIN32 + +#include <windows.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <string.h> +#include <stdio.h> +#include <direct.h> + +#define IOLIBS "." +#define strcasecmp _stricmp +#define snprintf _snprintf + +/* Work-around for readdir() */ +typedef struct { + HANDLE handle; + int got_first; + WIN32_FIND_DATA search; + char dir[1024]; + char drive[32][2]; + int drive_count; + int drive_index; +} GPPORTWINDIR; + +/* Sleep functionality */ +#define GP_SYSTEM_SLEEP(_ms) Sleep(_ms) + +/* Dynamic library functions */ +#define GP_SYSTEM_DLOPEN(_filename) LoadLibrary(_filename) +#define GP_SYSTEM_DLSYM(_handle, _funcname) GetProcAddress(_handle, _funcname) +#define GP_SYSTEM_DLCLOSE(_handle) FreeLibrary(_handle) +#define GP_SYSTEM_DLERROR() "Windows Error" + +/* Directory-oriented functions */ +#define GP_SYSTEM_DIR GPPORTWINDIR * +#define GP_SYSTEM_DIRENT WIN32_FIND_DATA * +#define GP_SYSTEM_DIR_DELIM '\\' + + +#else + +/* POSIX Portability + ------------------------------------------------------------------ */ + +/* yummy. :) */ + +#include <dirent.h> +#include <dlfcn.h> +#include <sys/param.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> + +/* Sleep functionality */ +#define GP_SYSTEM_SLEEP(_ms) usleep(_ms*1000) + +/* Dynamic library functions */ +#define GP_SYSTEM_DLOPEN(_filename) dlopen(_filename, RTLD_LAZY) +#define GP_SYSTEM_DLSYM(_handle, _funcname) dlsym(_handle, _funcname) +#define GP_SYSTEM_DLCLOSE(_handle) dlclose(_handle) +#define GP_SYSTEM_DLERROR() dlerror() + +/* Directory-oriented functions */ +#define GP_SYSTEM_DIR DIR * +#define GP_SYSTEM_DIRENT struct dirent * +#ifdef OS2 +#define GP_SYSTEM_DIR_DELIM '\\' +#else +#define GP_SYSTEM_DIR_DELIM '/' +#endif /* OS2 */ + +#endif /* else */ + +int GP_SYSTEM_MKDIR (char *dirname); +GP_SYSTEM_DIR GP_SYSTEM_OPENDIR (char *dirname); +GP_SYSTEM_DIRENT GP_SYSTEM_READDIR (GP_SYSTEM_DIR d); +char* GP_SYSTEM_FILENAME (GP_SYSTEM_DIRENT de); +int GP_SYSTEM_CLOSEDIR (GP_SYSTEM_DIR dir); +int GP_SYSTEM_IS_FILE (char *filename); +int GP_SYSTEM_IS_DIR (char *dirname); diff --git a/libgphoto2_port/libgphoto2_port.spec.in b/libgphoto2_port/libgphoto2_port.spec.in new file mode 100644 index 000000000..c93287036 --- /dev/null +++ b/libgphoto2_port/libgphoto2_port.spec.in @@ -0,0 +1,66 @@ +%define ver @VERSION@ +%define rel 1 +%define prefix /usr + +Summary: Portable I/O library +Name: libgphoto2-port +Version: %ver +Release: %rel +Copyright: LGPL +Group: System Environment/Libraries +Source: http://www.gphoto.net/dist/libgphoto2-port-%{ver}.tar.gz +BuildRoot: /var/tmp/libgphoto2-port-%{PACKAGE_VERSION}-root +URL: http://www.gphoto.net/ +Docdir: %{prefix}/doc +Requires: libusb + +%description +The benefit to using this library would be that all communications can be +done quickly and without worry for device specific functions; all devices +are abstracted to a point, allowing you to read/write to a device using +the same interface. For example, you can set all the options on the serial +port easily, and then read/write to that device. Additionally, you could +easily switch over to a USB device, and read/write without having to learn +the USB internals. + +%package devel +Summary: Libraries, includes, etc to develop applications using libgpio +Group: System Environment/Libraries +Requires: libgphoto2-port + +%description devel +Libraries, include files, etc you need to develop applications with libgphoto2-port + +%prep +%setup + +%build +CFLAGS="$RPM_OPT_FLAGS" ./configure --prefix=%prefix +make + +%install +rm -rf $RPM_BUILD_ROOT + +make prefix=$RPM_BUILD_ROOT%{prefix} install + +%clean +rm -rf $RPM_BUILD_ROOT + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + +%files +%defattr(-, root, root) + +%doc AUTHORS ChangeLog NEWS README COPYING COPYING.LIB TODO +%{prefix}/lib/lib*.so.* +%{prefix}/bin/gpio-config + +%files devel +%defattr(-, root, root) + +%{prefix}/lib/lib*.so +%{prefix}/lib/*a +%{prefix}/lib/*.sh +%{prefix}/include/* diff --git a/libgphoto2_port/libgphoto2_port/Makefile.am b/libgphoto2_port/libgphoto2_port/Makefile.am new file mode 100644 index 000000000..cbca96023 --- /dev/null +++ b/libgphoto2_port/libgphoto2_port/Makefile.am @@ -0,0 +1,15 @@ +## Specify some includes and versioning +INCLUDES = -I../ $(VERSION_FLAGS) -I$(top_srcdir)/include +VERSION_FLAGS = -DLIBGPPORT_VERSION=\"@LIBGPPORT_VERSION@\" +CFLAGS = @CFLAGS@ @IOLIB_CFLAGS@ \ + -DIOLIBS=\"$(prefix)/lib/gphoto2_port\" \ + -g +LDFLAGS = @LDFLAGS@ -g -ldl + +## Compile the IO library into a shared library +lib_LTLIBRARIES = libgphoto2_port.la +libgphoto2_port_la_LDFLAGS = -version-info @LIBGPPORT_VERSION_INFO@ +libgphoto2_port_la_SOURCES = \ + gp_port.c \ + library.c library.h \ + portability.c diff --git a/libgphoto2_port/libgphoto2_port/gp_port.c b/libgphoto2_port/libgphoto2_port/gp_port.c new file mode 100644 index 000000000..41f97d6f5 --- /dev/null +++ b/libgphoto2_port/libgphoto2_port/gp_port.c @@ -0,0 +1,432 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* gpio.c - Core IO library functions + + Modifications: + Copyright (C) 1999 Scott Fritzinger <scottf@unr.edu> + + The GPIO Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GPIO Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GPIO Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + */ + +#include <stdarg.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include "../include/gphoto2-port.h" +#include "library.h" + +gp_port_info device_list[256]; +int device_count; + +/* Toggle to turn on/off debugging */ +int glob_debug_level=0; + +void gp_port_debug_printf (int target_debug_level, int debug_level, char *format, ...) +{ + va_list arg; + + if ((debug_level > 0)&&(debug_level >= target_debug_level)) { + fprintf(stderr, "gpio: "); + va_start(arg, format); + vfprintf(stderr, format, arg); + va_end(arg); + fprintf(stderr, "\n"); + } +} + +/* + Required library functions + ---------------------------------------------------------------- + */ + +int gp_port_init(int debug) +{ + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, "Initializing..."); + /* Enumerate all the available devices */ + device_count = 0; + glob_debug_level = debug; + return (gp_port_library_list(device_list, &device_count)); +} + +int gp_port_get_count(void) +{ + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, "Device count: %i", device_count); + return device_count; +} + +int gp_port_get_info(int device_number, gp_port_info *info) +{ + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, "Getting device info..."); + + memcpy(info, &device_list[device_number], sizeof(device_list[device_number])); + + return GP_OK; +} + +gp_port *gp_port_new(gp_port_type type) + /* Create a new IO device */ +{ + gp_port *dev; + gp_port_settings settings; + char buf[1024]; + + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, "Creating new device... "); + + dev = (gp_port *) malloc(sizeof(gp_port)); + if (!dev) { + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, "Can not allocate device!"); + return NULL; + } + memset(dev, 0, sizeof(gp_port)); + + if (gp_port_library_load(dev, type)) { + /* whoops! that type of device isn't supported */ + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, "Device type not supported! (%i)", type); + free(dev); + return NULL; + } + + dev->debug_level = glob_debug_level; + + dev->type = type; + dev->device_fd = 0; + dev->ops->init(dev); + + switch (dev->type) { + case GP_PORT_SERIAL: + sprintf(buf, GP_PORT_SERIAL_PREFIX, GP_PORT_SERIAL_RANGE_LOW); + strcpy(settings.serial.port, buf); + /* set some defaults */ + settings.serial.speed = 9600; + settings.serial.bits = 8; + settings.serial.parity = 0; + settings.serial.stopbits = 1; + gp_port_set_settings(dev, settings); + gp_port_set_timeout(dev, 500); + break; + case GP_PORT_PARALLEL: +#ifdef GP_PORT_PARALLEL + sprintf(buf, GP_PORT_SERIAL_PREFIX, GP_PORT_SERIAL_RANGE_LOW); + strcpy(settings.parallel.port, buf); +#endif + break; + case GP_PORT_NETWORK: +#ifdef GP_PORT_NETWORK + gp_port_set_timeout(dev, 50000); +#endif + break; + case GP_PORT_USB: +#ifdef GP_PORT_USB + gp_port_set_timeout(dev, 5000); +#endif + break; + case GP_PORT_IEEE1394: +#ifdef GP_PORT_IEEE1394 + /* blah ? */ +#endif + break; + default: + /* ERROR! */ + break; + } + + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, "Created device successfully..."); + + return (dev); +} + +int gp_port_set_debug (gp_port *dev, int debug_level) +{ + dev->debug_level = debug_level; + + return (GP_OK); +} + +int gp_port_open(gp_port *dev) + /* Open a device for reading/writing */ +{ + int retval = 0; + + /* Try to open device */ + retval = dev->ops->open(dev); + if (retval == GP_OK) { + /* Now update the settings */ + retval = dev->ops->update(dev); + if (retval != GP_OK) { + dev->device_fd = 0; + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_open: update error"); + return GP_ERROR; + } + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_open: OK"); + return GP_OK; + } + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_open: open error"); + return GP_ERROR; +} + +int gp_port_close(gp_port *dev) + /* Close the device to prevent reading/writing */ +{ + int retval = 0; + + if (!dev) { + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_close: bad device"); + return GP_ERROR; + } + if (dev->type == GP_PORT_SERIAL && dev->device_fd == 0) { + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_close: OK"); + return GP_OK; + } + + retval = dev->ops->close(dev); + dev->device_fd = 0; + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_close: close %s", retval == GP_OK? "ok":"error"); + return retval; +} + +int gp_port_free(gp_port *dev) + /* Frees a device struct */ +{ + int retval = dev->ops->exit(dev); + + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_free: exit %s", retval < 0? "error":"ok"); + + gp_port_library_close(dev); + free(dev); + + return GP_OK; +} + +int gp_port_write(gp_port *dev, char *bytes, int size) + /* Called to write "bytes" to the IO device */ +{ + int x, retval; + char t[8]; + char *buf; + + if (glob_debug_level == GP_DEBUG_HIGH) { + buf = (char *)malloc(sizeof(char)*(4*size+64)); + buf[0] = 0; + for (x=0; x<size; x++) { + sprintf(t, "%02x ", (unsigned char)bytes[x]); + strcat(buf, t); + } + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_write: (size=%05i) DATA: %s", size, buf); + free(buf); + } + retval = dev->ops->write(dev, bytes, size); + + if (retval == GP_ERROR_TIMEOUT) + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_write: write timeout"); + if (retval == GP_ERROR) + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_write: write error"); + + return (retval); +} + +int gp_port_read(gp_port *dev, char *bytes, int size) + /* Reads data from the device into the "bytes" buffer. + "bytes" should be large enough to hold all the data. + */ +{ + int x, retval; + char t[8]; + char *buf; + + retval = dev->ops->read(dev, bytes, size); + + if ((retval > 0)&&(glob_debug_level == GP_DEBUG_HIGH)) { + buf = (char *)malloc(sizeof(char)*(4*retval+64)); + buf[0] = 0; + for (x=0; x<retval; x++) { + sprintf(t, "%02x ", (unsigned char)bytes[x]); + strcat(buf, t); + } + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_read: (size=%05i) DATA: %s", retval, buf); + free(buf); + } + + if (retval == GP_ERROR_TIMEOUT) + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_read: read timeout"); + if (retval == GP_ERROR) + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_read: read error"); + + return (retval); +} + +int gp_port_set_timeout(gp_port *dev, int millisec_timeout) +{ + dev->timeout = millisec_timeout; + + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_set_timeout: value=%ims", millisec_timeout); + + return GP_OK; +} + +int gp_port_get_timeout(gp_port *dev, int *millisec_timeout) +{ + *millisec_timeout = dev->timeout; + + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_get_timeout: value=%ims", *millisec_timeout); + + return GP_OK; +} + +int gp_port_set_settings(gp_port *dev, gp_port_settings settings) +{ + int retval; + + /* need to memcpy() settings to dev->settings */ + memcpy(&dev->settings_pending, &settings, sizeof(dev->settings_pending)); + + retval = dev->ops->update(dev); + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_set_settings: update %s", retval < 0? "error":"ok"); + return (retval); +} + + +int gp_port_get_settings(gp_port *dev, gp_port_settings * settings) +{ + memcpy(settings, &dev->settings, sizeof(gp_port_settings)); + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_get_settings: ok"); + + return GP_OK; +} + +/* Serial and Parallel-specific functions */ +/* ------------------------------------------------------------------ */ + +int gp_port_get_pin(gp_port *dev, int pin) +{ + int retval; + + if (!dev->ops->get_pin) { + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_get_pin: get_pin NULL"); + return (GP_ERROR); + } + + retval = dev->ops->get_pin(dev, pin); + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_get_pin: get_pin %s", retval < 0? "error":"ok"); + return (retval); +} + +int gp_port_set_pin(gp_port *dev, int pin, int level) +{ + int retval; + + if (!dev->ops->get_pin) { + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_set_pin: set_pin NULL"); + return (GP_ERROR); + } + + retval = dev->ops->set_pin(dev, pin, level); + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_set_pin: set_pin %s", retval < 0? "error":"ok"); + return (retval); +} + +int gp_port_send_break (gp_port *dev, int duration) +{ + int retval; + + if (!dev->ops->send_break) { + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_break: gp_port_break NULL"); + return (GP_ERROR); + } + + retval = dev->ops->send_break(dev, duration); + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_send_break: send_break %s", retval < 0? "error":"ok"); + return (retval); +} + +/* USB-specific functions */ +/* ------------------------------------------------------------------ */ + +#ifdef GP_PORT_USB + +int gp_port_usb_find_device (gp_port * dev, int idvendor, int idproduct) +{ + int retval; + + if (!dev->ops->find_device) { + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_usb_find_device: find_device NULL"); + return (GP_ERROR); + } + + retval = dev->ops->find_device(dev, idvendor, idproduct); + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_usb_find_device: find_device (0x%04x 0x%04x) %s", + idvendor, idproduct, retval < 0? "error":"ok"); + return (retval); +} +int gp_port_usb_clear_halt (gp_port * dev, int ep) +{ + int retval; + + if (!dev->ops->clear_halt) { + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_usb_clear_halt: clear_halt NULL"); + return (GP_ERROR); + } + + retval = dev->ops->clear_halt(dev, ep); + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_usb_clear_halt: clear_halt %s", retval < 0? "error":"ok"); + return (retval); +} + +int gp_port_usb_msg_write (gp_port * dev, int value, char *bytes, int size) +{ + int retval; + + if (!dev->ops->msg_write) { + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_usb_msg_write: msg_write NULL"); + return (GP_ERROR); + } + + retval = dev->ops->msg_write(dev, value, bytes, size); + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_usb_msg_write: msg_write %s", retval < 0? "error":"ok"); + return (retval); +} + +int gp_port_usb_msg_read (gp_port * dev, int value, char *bytes, int size) +{ + int retval; + + if (!dev->ops->msg_read) { + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_usb_msg_read: msg_read NULL"); + return (GP_ERROR); + } + + retval = dev->ops->msg_read(dev, value, bytes, size); + gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, + "gp_port_usb_msg_read: msg_read %s", retval < 0? "error":"ok"); + return (retval); +} +#endif diff --git a/libgphoto2_port/libgphoto2_port/library.c b/libgphoto2_port/libgphoto2_port/library.c new file mode 100644 index 000000000..1fed9d826 --- /dev/null +++ b/libgphoto2_port/libgphoto2_port/library.c @@ -0,0 +1,154 @@ +#include <sys/types.h> +#include <stdio.h> + +#include "gphoto2-port.h" +#include "library.h" + +extern int device_count; +extern int glob_debug_level; +extern gp_port_info device_list[]; +void *device_lh; + +int gp_port_library_is_valid (char *filename) { + + void *lh; + + if ((lh = GP_SYSTEM_DLOPEN(filename))==NULL) { + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, + "%s is not a library (%s) ", filename, GP_SYSTEM_DLERROR()); + return (GP_ERROR); + } + + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, "%s is a library ", filename); + GP_SYSTEM_DLCLOSE(lh); + + return (GP_OK); +} + +int gp_port_library_list_load(char *filename, int loaded[], gp_port_info *list, int *count) { + + void *lh; + int type, x; + gp_port_ptr_type lib_type; + gp_port_ptr_list lib_list; + int old_count = *count; + + if ((lh = GP_SYSTEM_DLOPEN(filename))==NULL) + return (GP_ERROR); + + lib_type = (gp_port_ptr_type)GP_SYSTEM_DLSYM(lh, "gp_port_library_type"); + lib_list = (gp_port_ptr_list)GP_SYSTEM_DLSYM(lh, "gp_port_library_list"); + + if ((!list) || (!lib_type)) { + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, + "could not find type/list symbols: %s ", GP_SYSTEM_DLERROR()); + GP_SYSTEM_DLCLOSE(lh); + return (GP_ERROR); + } + + type = lib_type(); + + if (loaded[type] == 1) { + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, + "%s (%i) already loaded ", filename, type); + GP_SYSTEM_DLCLOSE(lh); + return (GP_ERROR); + } else { + loaded[type] = 1; + } + + if (lib_list(list, count)==GP_ERROR) + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, + "%s could not list devices ", filename); + + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, + "Loaded these devices from %s:", filename); + /* copy in the library path */ + for (x=old_count; x<(*count); x++) { + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, + "\t%s path=\"%s\"", list[x].name, list[x].path); + strcpy(list[x].library_filename, filename); + } + + GP_SYSTEM_DLCLOSE(lh); + return (GP_OK); +} + +int gp_port_library_list (gp_port_info *list, int *count) { + + GP_SYSTEM_DIR d; + GP_SYSTEM_DIRENT de; + int loaded[256]; + int x; + char buf[1024]; + + *count = 0; + + for (x=0;x<256; x++) + loaded[x]=0; + + /* Look for available camera libraries */ + d = GP_SYSTEM_OPENDIR(IOLIBS); + if (!d) { + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, + "couldn't open %s ", IOLIBS); + return GP_ERROR; + } + + do { + /* Read each entry */ + de = GP_SYSTEM_READDIR(d); + if (de) { +#if defined(OS2) || defined(WIN32) + sprintf(buf, "%s\\%s", IOLIBS, GP_SYSTEM_FILENAME(de)); +#else + sprintf(buf, "%s/%s", IOLIBS, GP_SYSTEM_FILENAME(de)); +#endif + if (gp_port_library_is_valid(buf) == GP_OK) + gp_port_library_list_load(buf, loaded, list, count); + } + } while (de); + + GP_SYSTEM_CLOSEDIR(d); + + return (GP_OK); +} + +int gp_port_library_load (gp_port *device, gp_port_type type) { + + int x=0; + gp_port_ptr_operations ops_func; + + for (x=0; x<device_count; x++) { + if (device_list[x].type == type) { + /* Open the correct library */ + device->library_handle = GP_SYSTEM_DLOPEN(device_list[x].library_filename); + if (!device->library_handle) { + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, + "bad handle: %s %s ", + device_list[x].library_filename, GP_SYSTEM_DLERROR()); + return (GP_ERROR); + } + + /* Load the operations */ + ops_func = (gp_port_ptr_operations)GP_SYSTEM_DLSYM(device->library_handle, "gp_port_library_operations"); + if (!ops_func) { + gp_port_debug_printf(GP_DEBUG_LOW, glob_debug_level, + "can't load ops: %s %s ", + device_list[x].library_filename, GP_SYSTEM_DLERROR()); + GP_SYSTEM_DLCLOSE(device->library_handle); + return (GP_ERROR); + } + device->ops = ops_func(); + return (GP_OK); + } + } + return (GP_ERROR); +} + +int gp_port_library_close (gp_port *device) { + + GP_SYSTEM_DLCLOSE(device->library_handle); + + return (GP_OK); +} diff --git a/libgphoto2_port/libgphoto2_port/library.h b/libgphoto2_port/libgphoto2_port/library.h new file mode 100644 index 000000000..c14e773a2 --- /dev/null +++ b/libgphoto2_port/libgphoto2_port/library.h @@ -0,0 +1,3 @@ +int gp_port_library_list(gp_port_info *list, int *count); +int gp_port_library_load(gp_port *device, gp_port_type type); +int gp_port_library_close(gp_port *device); diff --git a/libgphoto2_port/libgphoto2_port/portability.c b/libgphoto2_port/libgphoto2_port/portability.c new file mode 100644 index 000000000..a862fd4c5 --- /dev/null +++ b/libgphoto2_port/libgphoto2_port/portability.c @@ -0,0 +1,172 @@ +#include <stdio.h> +#include <gphoto2-port.h> + +/* Windows Portability + ------------------------------------------------------------------ */ +#ifdef WIN32 + +void gp_port_win_convert_path (char *path) { + + int x; + + if (strchr(path, '\\')) + /* already converted */ + return; + + if (path[0] != '.') { + path[0] = path[1]; + path[1] = ':'; + path[2] = '\\'; + } + + for (x=0; x<strlen(path); x++) + if (path[x] == '/') + path[x] = '\\'; +} + +int GP_SYSTEM_MKDIR (char *dirname) { + + if (_mkdir(dirname) < 0) + return (GP_ERROR); + return (GP_OK); +} + +GP_SYSTEM_DIR GP_SYSTEM_OPENDIR (char *dirname) { + + GPIOWINDIR *d; + DWORD dr; + int x; + + d = (GPIOWINDIR*)malloc(sizeof(GPIOWINDIR)); + d->handle = INVALID_HANDLE_VALUE; + d->got_first = 0; + strcpy(d->dir, dirname); + d->drive_count = 0; + d->drive_index = 0; + + dr = GetLogicalDrives(); + + for (x=0; x<32; x++) { + if ((dr >> x) & 0x0001) { + sprintf(d->drive[d->drive_count], "%c", 'A' + x); + d->drive_count += 1; + } + } + + return (d); +} + +GP_SYSTEM_DIRENT GP_SYSTEM_READDIR (GP_SYSTEM_DIR d) { + + char dirn[1024]; + + if (strcmp(d->dir, "/")==0) { + if (d->drive_index == d->drive_count) + return (NULL); + strcpy(d->search.cFileName, d->drive[d->drive_index]); + d->drive_index += 1; + return (&(d->search)); + } + + + /* Append the wildcard */ + + strcpy(dirn, d->dir); + gp_port_win_convert_path(dirn); + + if (dirn[strlen(dirn)-1] != '\\') + strcat(dirn, "\\"); + strcat(dirn, "*"); + + + if (d->handle == INVALID_HANDLE_VALUE) { + d->handle = FindFirstFile(dirn, &(d->search)); + if (d->handle == INVALID_HANDLE_VALUE) + return NULL; + } else { + if (!FindNextFile(d->handle, &(d->search))) + return NULL; + } + + return (&(d->search)); +} + +char *GP_SYSTEM_FILENAME (GP_SYSTEM_DIRENT de) { + + return (de->cFileName); +} + +int GP_SYSTEM_CLOSEDIR (GP_SYSTEM_DIR d) { + FindClose(d->handle); + free(d); + return (1); +} + +int GP_SYSTEM_IS_FILE (char *filename) { + + struct stat st; + + gp_port_win_convert_path(filename); + + if (stat(filename, &st)!=0) + return 0; + return (st.st_mode & _S_IFREG); +} + +int GP_SYSTEM_IS_DIR (char *dirname) { + + struct stat st; + + if (strlen(dirname) <= 3) + return 1; + + gp_port_win_convert_path(dirname); + + if (stat(dirname, &st)!=0) + return 0; + return (st.st_mode & _S_IFDIR); +} + + +#else + +int GP_SYSTEM_MKDIR (char *dirname) { + + if (mkdir(dirname, 0700)<0) + return (GP_ERROR); + return (GP_OK); +} + +GP_SYSTEM_DIR GP_SYSTEM_OPENDIR (char *dirname) { + return (opendir(dirname)); +} + +GP_SYSTEM_DIRENT GP_SYSTEM_READDIR (GP_SYSTEM_DIR d) { + return (readdir(d)); +} + +char *GP_SYSTEM_FILENAME (GP_SYSTEM_DIRENT de) { + return (de->d_name); +} + +int GP_SYSTEM_CLOSEDIR (GP_SYSTEM_DIR dir) { + closedir(dir); + return (GP_OK); +} + +int GP_SYSTEM_IS_FILE (char *filename) { + struct stat st; + + if (stat(filename, &st)!=0) + return 0; + return (!S_ISDIR(st.st_mode)); +} + +int GP_SYSTEM_IS_DIR (char *dirname) { + struct stat st; + + if (stat(dirname, &st)!=0) + return 0; + return (S_ISDIR(st.st_mode)); +} +#endif diff --git a/libgphoto2_port/makefile.os2 b/libgphoto2_port/makefile.os2 new file mode 100644 index 000000000..6873b97fa --- /dev/null +++ b/libgphoto2_port/makefile.os2 @@ -0,0 +1,52 @@ +CCFLAGS=-O2 -c -I.. -I..\include -Zmtd -Zcrtdll -Zbin-files -D__ST_MT_ERRNO_ -I. -DOS2 -DHAVE_TERMIOS_H -Iinclude +CC=gcc +MKLIB=ar r + + +all: start \ + lib \ + serial\ + parallel\ + end + +start: + @echo **** + @echo Entering: $(MAKEDIR) + @echo using CCFLAGS: $(CCFLAGS) + @echo **** + @if not exist obj md obj + +end: + @echo **** + @echo Done: $(MAKEDIR) + @echo **** + + +serial: + @cd serial + @nmake /nologo -f makefile.os2 + @cd.. + +parallel: + @cd parallel + @nmake /nologo -f makefile.os2 + @cd.. + +#network: +# @cd network +# @nmake /nologo -f makefile.os2 +# @cd.. + +lib: ..\lib\libgpio.a + +obj\gpio.o: libgpio\gpio.c + @$(CC) -o $@ $** $(CCFLAGS) + +obj\port.o: libgpio\port.c + @$(CC) -o $@ $** $(CCFLAGS) + +obj\library.o: libgpio\library.c + @$(CC) -o $@ $** $(CCFLAGS) + +..\lib\libgpio.a: obj\gpio.o obj\library.o obj\port.o + @$(MKLIB) $@ $** diff --git a/libgphoto2_port/network/Makefile.am b/libgphoto2_port/network/Makefile.am new file mode 100644 index 000000000..20d46a0e5 --- /dev/null +++ b/libgphoto2_port/network/Makefile.am @@ -0,0 +1,11 @@ +## Specify some includes and versioning +INCLUDES = -I../ $(VERSION_FLAGS) -I$(top_srcdir)/include +VERSION_FLAGS = -DLIBGPIO_VERSION=\"@LIBGPIO_VERSION@\" +CFLAGS = @CFLAGS@ @IOLIB_CFLAGS@ -g +LDFLAGS = @LDFLAGS@ -g + +## Compile the IO library into a shared library +iolibdir = $(prefix)/lib/gpio +iolib_LTLIBRARIES = libgpio_network.la +libgpio_network_la_LDFLAGS = -version-info @LIBGPIO_VERSION_INFO@ -DHAVE_TERMIOS_H +libgpio_network_la_SOURCES = bsdsocket.c gpio-network.h diff --git a/libgphoto2_port/network/bsdsocket.c b/libgphoto2_port/network/bsdsocket.c new file mode 100644 index 000000000..e0633e144 --- /dev/null +++ b/libgphoto2_port/network/bsdsocket.c @@ -0,0 +1,124 @@ +/* -*- Mode: C { indent-tabs-mode: t { c-basic-offset: 8 { tab-width: 8 -*- */ +/* gphoto2-port-network.c - network IO functions + + Modifications: + Copyright (C) 1999 Scott Fritzinger <scottf@unr.edu> + + The GPIO Library is free software { you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation { either version 2 of the + License, or (at your option) any later version. + + The GPIO Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY { without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GPIO Library { see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + */ + +#include "gphoto2-port.h" + +/* network prototypes + --------------------------------------------------------------------- */ +int gp_port_network_list(gp_port_info *list, int *count); + +int gp_port_network_init(gp_port *dev); +int gp_port_network_exit(gp_port *dev); + +int gp_port_network_open(gp_port *dev); +int gp_port_network_close(gp_port *dev); + +int gp_port_network_read(gp_port *dev, char *bytes, int size); +int gp_port_network_write(gp_port *dev, char *bytes, int size); + +int gp_port_network_get_pin(gp_port *dev, int pin); +int gp_port_network_set_pin(gp_port *dev, int pin, int level); + +int gp_port_network_update (gp_port *dev); + +int gp_port_network_set_baudrate(gp_port *dev); + +/* Dynamic library functions + --------------------------------------------------------------------- */ + +gp_port_type gp_port_library_type () { + + return (GP_PORT_NETWORK); +} + +gp_port_operations *gp_port_library_operations () { + + gp_port_operations *ops; + + ops = (gp_port_operations*)malloc(sizeof(gp_port_operations)); + memset(ops, 0, sizeof(gp_port_operations)); + + ops->init = gp_port_network_init; + ops->exit = gp_port_network_exit; + ops->open = gp_port_network_open; + ops->close = gp_port_network_close; + ops->read = gp_port_network_read; + ops->write = gp_port_network_write; + ops->update = gp_port_network_update; + ops->get_pin = NULL; + ops->set_pin = NULL; + ops->clear_halt = NULL; + ops->msg_write = NULL; + ops->msg_read = NULL; + + return (ops); +} + +int gp_port_library_list(gp_port_info *list, int *count) { + + list[*count].type = GP_PORT_NETWORK; + strcpy(list[*count].name, "Network connection"); + strcpy(list[*count].path, "network"); + list[*count].argument_needed = 1; + strcpy(list[*count].argument_description, "host"); + *count += 1; + + return (GP_OK); +} + +/* Network API functions + --------------------------------------------------------------------- */ + +int gp_port_network_init(gp_port *dev) { + +} + +int gp_port_network_exit(gp_port *dev) { + +} + +int gp_port_network_open(gp_port *dev) { + +} + +int gp_port_network_close(gp_port *dev) { + +} +int gp_port_network_read(gp_port *dev, char *bytes, int size) { + +} + +int gp_port_network_write(gp_port *dev, char *bytes, int size) { + +} + +int gp_port_network_get_pin(gp_port *dev, int pin) { + +} + +int gp_port_network_set_pin(gp_port *dev, int pin, int level) { + +} + +int gp_port_network_update (gp_port *dev) { + +} diff --git a/libgphoto2_port/parallel/Makefile.am b/libgphoto2_port/parallel/Makefile.am new file mode 100644 index 000000000..ce564afb6 --- /dev/null +++ b/libgphoto2_port/parallel/Makefile.am @@ -0,0 +1,11 @@ +## Specify some includes and versioning +INCLUDES = -I../ $(VERSION_FLAGS) -I$(top_srcdir)/include +VERSION_FLAGS = -DLIBGPIO_VERSION=\"@LIBGPIO_VERSION@\" +CFLAGS = @CFLAGS@ @IOLIB_CFLAGS@ -g +LDFLAGS = @LDFLAGS@ -g + +## Compile the IO library into a shared library +iolibdir = $(prefix)/lib/gpio +iolib_LTLIBRARIES = libgpio_parallel.la +libgpio_parallel_la_LDFLAGS = -version-info @LIBGPIO_VERSION_INFO@ -DHAVE_TERMIOS_H +libgpio_parallel_la_SOURCES = unix.c gpio-parallel.h diff --git a/libgphoto2_port/parallel/makefile.os2 b/libgphoto2_port/parallel/makefile.os2 new file mode 100644 index 000000000..8bb76fb29 --- /dev/null +++ b/libgphoto2_port/parallel/makefile.os2 @@ -0,0 +1,36 @@ +CCFLAGS=-O2 -c -I.. -I..\..\include -I..\..\libgpio\include -Zmtd -Zcrtdll -Zbin-files -D__ST_MT_ERRNO_ -I. -DOS2 -DHAVE_TERMIOS_H -DEBUG +CC=gcc + +all: start \ + dll \ + lib \ + end + +start: + @echo **** + @echo Entering: $(MAKEDIR) + @echo using CCFLAGS: $(CCFLAGS) + @echo **** + +end: + @echo **** + @echo Done: $(MAKEDIR) + @echo **** + +dll: ..\giparall.dll + +..\obj\parallel.o : unix.c + @$(CC) -o $@ $** $(CCFLAGS) + +lib: ..\..\lib\giparall.a + +..\..\lib\giparall.a: + @implib giparall.lib ..\giparall.dll + @emximp -o ..\..\lib\giparall.a giparall.lib + +parallel.def: ..\obj\parallel.o + @copy parallel.df parallel.def + @emxexp $** >> parallel.def + +..\giparall.dll: ..\obj\parallel.o parallel.def + @$(CC) -Wall -Zdll -Zcrtdll -o $@ $** -lwrap -lgcc -L..\..\LIB -llibgphoto2 -llibgpio -ldllib diff --git a/libgphoto2_port/parallel/parallel.df b/libgphoto2_port/parallel/parallel.df new file mode 100644 index 000000000..52952357e --- /dev/null +++ b/libgphoto2_port/parallel/parallel.df @@ -0,0 +1,2 @@ +LIBRARY GIPARALL +EXPORTS diff --git a/libgphoto2_port/parallel/unix.c b/libgphoto2_port/parallel/unix.c new file mode 100644 index 000000000..8c03902ef --- /dev/null +++ b/libgphoto2_port/parallel/unix.c @@ -0,0 +1,167 @@ +/* -*- Mode: C { indent-tabs-mode: t { c-basic-offset: 8 { tab-width: 8 -*- */ +/* gphoto2-port-parallel.c - parallel IO functions + + Modifications: + Copyright (C) 1999 Scott Fritzinger <scottf@unr.edu> + + The GPIO Library is free software { you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation { either version 2 of the + License, or (at your option) any later version. + + The GPIO Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY { without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GPIO Library { see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + */ + +#include <stdlib.h> +#include <unistd.h> +#include <stdio.h> +#include <fcntl.h> +#include <errno.h> +#include <string.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/ioctl.h> + +#include "gphoto2-port-parallel.h" +#include "gphoto2-port.h" + +/* Parallel prototypes + --------------------------------------------------------------------- */ +int gp_port_parallel_list(gp_port_info *list, int *count); + +int gp_port_parallel_init(gp_port *dev); +int gp_port_parallel_exit(gp_port *dev); + +int gp_port_parallel_open(gp_port *dev); +int gp_port_parallel_close(gp_port *dev); + +int gp_port_parallel_read(gp_port *dev, char *bytes, int size); +int gp_port_parallel_write(gp_port *dev, char *bytes, int size); + +int gp_port_parallel_get_pin(gp_port *dev, int pin); +int gp_port_parallel_set_pin(gp_port *dev, int pin, int level); + +int gp_port_parallel_update (gp_port *dev); + + +/* Dynamic library functions + --------------------------------------------------------------------- */ + +gp_port_type gp_port_library_type () { + + return (GP_PORT_PARALLEL); +} + +gp_port_operations *gp_port_library_operations () { + + gp_port_operations *ops; + + ops = (gp_port_operations*)malloc(sizeof(gp_port_operations)); + memset(ops, 0, sizeof(gp_port_operations)); + + ops->init = gp_port_parallel_init; + ops->exit = gp_port_parallel_exit; + ops->open = gp_port_parallel_open; + ops->close = gp_port_parallel_close; + ops->read = gp_port_parallel_read; + ops->write = gp_port_parallel_write; + ops->update = gp_port_parallel_update; + ops->get_pin = gp_port_parallel_get_pin; + ops->set_pin = gp_port_parallel_set_pin; + + return (ops); +} + +int gp_port_library_list(gp_port_info *list, int *count) { + + char buf[1024], prefix[1024]; + int x, fd, use_int=0, use_char=0; +#ifdef __linux + /* devfs */ + struct stat s; +#endif + +#ifdef OS2 + int rc,fh,option; +#endif + + strcpy(prefix, GP_PORT_PARALLEL_PREFIX); + +#ifdef __linux + /* devfs */ + if (stat("/dev/parports", &s) == 0) + strcpy(prefix, "/dev/parports/%i"); +#endif + + for (x=GP_PORT_PARALLEL_RANGE_LOW; x<=GP_PORT_PARALLEL_RANGE_HIGH; x++) { + sprintf(buf, prefix, x); + #ifdef OS2 + rc = DosOpen(buf,&fh,&option,0,0,1,OPEN_FLAGS_FAIL_ON_ERROR|OPEN_SHARE_DENYREADWRITE,0); + if(rc==0) + { + #endif + + fd = open (buf, O_RDONLY | O_NDELAY); + if (fd != -1) { + close(fd); + list[*count].type = GP_PORT_PARALLEL; + strcpy(list[*count].path, buf); + sprintf(buf, "Parallel Port %i", x); + strcpy(list[*count].name, buf); + list[*count].argument_needed = 0; + *count += 1; + } + #ifdef OS2 + } + #endif + } + + return (GP_OK); +} + +/* Parallel API functions + --------------------------------------------------------------------- */ + +int gp_port_parallel_init(gp_port *dev) { + +} + +int gp_port_parallel_exit(gp_port *dev) { + +} + +int gp_port_parallel_open(gp_port *dev) { + +} + +int gp_port_parallel_close(gp_port *dev) { + +} +int gp_port_parallel_read(gp_port *dev, char *bytes, int size) { + +} + +int gp_port_parallel_write(gp_port *dev, char *bytes, int size) { + +} + +int gp_port_parallel_get_pin(gp_port *dev, int pin) { + +} + +int gp_port_parallel_set_pin(gp_port *dev, int pin, int level) { + +} + +int gp_port_parallel_update (gp_port *dev) { + +} diff --git a/libgphoto2_port/serial/Makefile.am b/libgphoto2_port/serial/Makefile.am new file mode 100644 index 000000000..893ceeefb --- /dev/null +++ b/libgphoto2_port/serial/Makefile.am @@ -0,0 +1,11 @@ +## Specify some includes and versioning +INCLUDES = -I../ $(VERSION_FLAGS) -I$(top_srcdir)/include +VERSION_FLAGS = -DLIBGPPORT_VERSION=\"@LIBGPPORT_VERSION@\" -DHAVE_TERMIOS_H +CFLAGS = @CFLAGS@ @IOLIB_CFLAGS@ -g +LDFLAGS = @LDFLAGS@ -g + +## Compile the IO library into a shared library +iolibdir = $(prefix)/lib/gphoto2_port +iolib_LTLIBRARIES = libgphoto2_port_serial.la +libgphoto2_port_serial_la_LDFLAGS = -version-info @LIBGPPORT_VERSION_INFO@ -DHAVE_TERMIOS_H +libgphoto2_port_serial_la_SOURCES = unix.c diff --git a/libgphoto2_port/serial/makefile.os2 b/libgphoto2_port/serial/makefile.os2 new file mode 100644 index 000000000..da0aa615a --- /dev/null +++ b/libgphoto2_port/serial/makefile.os2 @@ -0,0 +1,36 @@ +CCFLAGS=-O2 -c -I.. -I..\..\include -I..\..\libgpio\include -Zmtd -Zcrtdll -Zbin-files -D__ST_MT_ERRNO_ -I. -DOS2 -DHAVE_TERMIOS_H -DEBUG +CC=gcc + +all: start \ + dll \ + lib \ + end + +start: + @echo **** + @echo Entering: $(MAKEDIR) + @echo using CCFLAGS: $(CCFLAGS) + @echo **** + +end: + @echo **** + @echo Done: $(MAKEDIR) + @echo **** + +dll: ..\giserial.dll + +..\obj\serial.o : unix.c + @$(CC) -o $@ $** $(CCFLAGS) + +lib: ..\..\lib\giserial.a + +..\..\lib\giserial.a: + @implib giserial.lib ..\giserial.dll + @emximp -o ..\..\lib\giserial.a giserial.lib + +serial.def: ..\obj\serial.o + @copy serial.df serial.def + @emxexp $** >> serial.def + +..\giserial.dll: ..\obj\serial.o serial.def + @$(CC) -Wall -Zdll -Zcrtdll -o $@ $** -lwrap -lgcc -L..\..\lib -llibgphoto2 -llibgpio -ldllib diff --git a/libgphoto2_port/serial/serial.df b/libgphoto2_port/serial/serial.df new file mode 100644 index 000000000..3e9350913 --- /dev/null +++ b/libgphoto2_port/serial/serial.df @@ -0,0 +1,2 @@ +LIBRARY GISERIAL +EXPORTS diff --git a/libgphoto2_port/serial/unix.c b/libgphoto2_port/serial/unix.c new file mode 100644 index 000000000..37f871291 --- /dev/null +++ b/libgphoto2_port/serial/unix.c @@ -0,0 +1,529 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* gphoto2-port-serial.c - Serial IO functions + + Modifications: + Copyright (C) 2000 Philippe Marzouk <pmarzouk@bigfoot.com> + Copyright (C) 2000 Edouard Lafargue <Edouard.Lafargue@bigfoot.com> + Copyright (C) 1999 Johannes Erdfelt <johannes@erdfelt.com> + Copyright (C) 1999 Scott Fritzinger <scottf@unr.edu> + + Based on work by: + Copyright (C) 1999 Beat Christen <spiff@longstreet.ch> + for the toshiba gPhoto library. + + The GPIO Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GPIO Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GPIO Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + */ + +#include <stdlib.h> +#include <unistd.h> +#include <stdio.h> +#include <fcntl.h> +#include <errno.h> +#include <string.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/ioctl.h> + +#if HAVE_TERMIOS_H +#include <termios.h> +#define CRTSCTS 020000000000 +#else +#if HAVE_SYS_IOCTL_H +#include <sys/ioctl.h> +#endif +#include <sgtty.h> +#endif + +#include "../include/gphoto2-port-serial.h" +#include "../include/gphoto2-port.h" + +#ifdef HAVE_TERMIOS_H +static struct termios term_old; +#else +static struct sgttyb term_old; +#endif + +/* Serial prototypes + ------------------------------------------------------------------ */ +int gp_port_serial_init(gp_port *dev); +int gp_port_serial_exit(gp_port *dev); + +int gp_port_serial_open(gp_port *dev); +int gp_port_serial_close(gp_port *dev); + +int gp_port_serial_read(gp_port *dev, char *bytes, int size); +int gp_port_serial_write(gp_port *dev, char *bytes, int size); + +int gp_port_serial_update (gp_port *dev); + +/* Specific */ +int gp_port_serial_get_pin(gp_port *dev, int pin); +int gp_port_serial_set_pin(gp_port *dev, int pin, int level); +int gp_port_serial_send_break (gp_port *dev, int duration); + + +/* private */ +int gp_port_serial_set_baudrate(gp_port *dev); +static speed_t gp_port_serial_baudconv(int rate); + +/* Dynamic library functions + --------------------------------------------------------------------- */ + +gp_port_type gp_port_library_type () { + + return (GP_PORT_SERIAL); +} + +gp_port_operations *gp_port_library_operations () { + + gp_port_operations *ops; + + ops = (gp_port_operations*)malloc(sizeof(gp_port_operations)); + memset(ops, 0, sizeof(gp_port_operations)); + + ops->init = gp_port_serial_init; + ops->exit = gp_port_serial_exit; + ops->open = gp_port_serial_open; + ops->close = gp_port_serial_close; + ops->read = gp_port_serial_read; + ops->write = gp_port_serial_write; + ops->update = gp_port_serial_update; + ops->get_pin = gp_port_serial_get_pin; + ops->set_pin = gp_port_serial_set_pin; + ops->send_break = gp_port_serial_send_break; + + return (ops); +} + +int gp_port_library_list (gp_port_info *list, int *count) { + + + char buf[1024], prefix[1024]; + int x, fd; +#ifdef __linux + /* devfs */ + struct stat s; +#endif +#ifdef OS2 + int rc,fh,option; +#endif + + /* Copy in the serial port prefix */ + strcpy(prefix, GP_PORT_SERIAL_PREFIX); + +#ifdef __linux + /* devfs */ + if (stat("/dev/tts", &s)==0) + strcpy(prefix, "/dev/tts/%i"); +#endif + for (x=GP_PORT_SERIAL_RANGE_LOW; x<=GP_PORT_SERIAL_RANGE_HIGH; x++) { + sprintf(buf, prefix, x); +#ifdef OS2 + rc = DosOpen(buf,&fh,&option,0,0,1,OPEN_FLAGS_FAIL_ON_ERROR|OPEN_SHARE_DENYREADWRITE,0); + DosClose(fh); + if(rc==0) { +#endif + fd = open (buf, O_RDONLY | O_NDELAY); + if (fd != -1) { + close(fd); + list[*count].type = GP_PORT_SERIAL; + strcpy(list[*count].path, buf); + sprintf(buf, "Serial Port %i", x); + strcpy(list[*count].name, buf); + list[*count].argument_needed = 0; + *count += 1; + } +#ifdef OS2 + } +#endif + } + + return (GP_OK); +} + +/* Serial API functions + ------------------------------------------------------------------ */ + +int gp_port_serial_init (gp_port *dev) { + /* save previous setttings in to dev->settings_saved */ +#if HAVE_TERMIOS_H + if (tcgetattr(dev->device_fd, &term_old) < 0) { + perror("tcgetattr"); + return GP_ERROR; + } +#else + if (ioctl(dev->device_fd, TIOCGETP, &term_old) < 0) { + perror("ioctl(TIOCGETP)"); + return GP_ERROR; + } +#endif + return GP_OK; +} + +int gp_port_serial_exit (gp_port *dev) { + /* ... */ + return GP_OK; +} + +int gp_port_serial_open(gp_port * dev) +{ + +#ifdef __FreeBSD__ + dev->device_fd = open(dev->settings.serial.port, O_RDWR | O_NOCTTY | O_NONBLOCK); +#else + dev->device_fd = open(dev->settings.serial.port, O_RDWR | O_NOCTTY | O_SYNC | O_NONBLOCK); +#endif + if (dev->device_fd == -1) { + fprintf(stderr, "gp_port_serial_open: failed to open "); + perror(dev->settings.serial.port); + return GP_ERROR; + } + +/* if (ioctl (dev->device_fd, TIOCMBIC, &RTS) <0) { + perror("ioctl(TIOCMBIC)"); + return GP_ERROR; + } */ + return GP_OK; +} + +int gp_port_serial_close(gp_port * dev) +{ + if (close(dev->device_fd) == -1) { + perror("gp_port_serial_close: tried closing device file descriptor"); + return GP_ERROR; + } + return GP_OK; +} + +int gp_port_serial_write(gp_port * dev, char *bytes, int size) +{ + int len, ret; + + len = 0; + while (len < size) { /* Make sure we write all data while handling */ + /* the harmless errors */ + if ((ret = write(dev->device_fd, bytes, size - len)) == -1) + switch (errno) { + case EAGAIN: + case EINTR: + ret = 0; + break; + default: + perror("gp_port_serial_write"); + return GP_ERROR; + } + len += ret; + } + + /* wait till all bytes are really sent */ +#ifndef OS2 +#if HAVE_TERMIOS_H + tcdrain(dev->device_fd); +#else + ioctl(dev->device_fd, TCDRAIN, 0); +#endif +#endif + return GP_OK; +} + + +int gp_port_serial_read(gp_port * dev, char *bytes, int size) +{ + struct timeval timeout; + fd_set readfs; /* file descriptor set */ + int readen = 0; + int rc; + + FD_ZERO(&readfs); + FD_SET(dev->device_fd, &readfs); + + while (readen < size) { + /* set timeout value within input loop */ + timeout.tv_usec = (dev->timeout % 1000) * 1000; + timeout.tv_sec = (dev->timeout / 1000); /* = 0 + * if dev->timeout < 1000 + */ + + + rc = select(dev->device_fd + 1, &readfs, NULL, NULL, &timeout); +/* if ( (rc == 0) && (readen == 0)) { */ + /* Timeout before reading anything */ +/* printf("gp_port_serial_read (timeout)\n"); */ +/* return GP_ERROR_TIMEOUT; */ +/* } */ + if (0 == rc) { + return GP_ERROR_TIMEOUT; + } + if (FD_ISSET(dev->device_fd, &readfs)) { + int now = read(dev->device_fd, bytes, size - readen); + + if (now < 0) { + perror("gp_port_serial_read (read fails)"); + return GP_ERROR; + } else { + bytes += now; + readen += now; + } + } else { + perror("gp_port_serial_read (tty timeout)"); + return GP_ERROR; + } + } + return readen; +} + +/* + * Get the status of the lines of the serial port + * + */ +int gp_port_serial_get_pin(gp_port * dev, int pin) +{ + int j, bit; + + switch(pin) { + case PIN_RTS: + bit = TIOCM_RTS; + break; + case PIN_DTR: + bit = TIOCM_DTR; + break; + case PIN_CTS: + bit = TIOCM_CTS; + break; + case PIN_DSR: + bit = TIOCM_DSR; + break; + case PIN_CD: + bit = TIOCM_CD; + break; + case PIN_RING: + bit = TIOCM_RNG; + break; + default: + return GP_ERROR; + } + + if (ioctl(dev->device_fd, TIOCMGET, &j) < 0) { + perror("gp_port_serial_status (Getting hardware status bits)"); + return GP_ERROR; + } + return (j & bit); +} + +/* +* Set the status of lines in the serial port +* +* level is 0 for off and 1 for on +* +*/ +int gp_port_serial_set_pin(gp_port * dev, int pin, int level) +{ + int bit,request; + + switch(pin) { + case PIN_RTS: + bit = TIOCM_RTS; + break; + case PIN_DTR: + bit = TIOCM_DTR; + break; + case PIN_CTS: + bit = TIOCM_CTS; + break; + case PIN_DSR: + bit = TIOCM_DSR; + break; + case PIN_CD: + bit = TIOCM_CD; + break; + case PIN_RING: + bit = TIOCM_RNG; + break; + default: + return GP_ERROR; + } + + switch(level) { + case 0: + request = TIOCMBIS; + break; + case 1: + request = TIOCMBIC; + break; + default: + return GP_ERROR; + } + + if (ioctl (dev->device_fd, request, &bit) <0) { + perror("ioctl(TIOCMBI[CS])"); + return GP_ERROR; + } + + return GP_OK; +} + +/* + * This function will apply the settings to + * the device. The device has to be opened + */ +int gp_port_serial_update(gp_port * dev) +{ + memcpy(&dev->settings, &dev->settings_pending, sizeof(dev->settings)); + + if (dev->device_fd != 0) { + if (gp_port_serial_close(dev) == GP_ERROR) + return GP_ERROR; + if (gp_port_serial_open(dev) == GP_ERROR) + return GP_ERROR; + + return gp_port_serial_set_baudrate(dev); + } + return GP_OK; +} + +/* + Serial port specific helper functions + ---------------------------------------------------------------- + */ + +/* Called to set the baud rate */ +int gp_port_serial_set_baudrate(gp_port * dev) +{ +#if HAVE_TERMIOS_H + struct termios tio; + + if (tcgetattr(dev->device_fd, &tio) < 0) { + perror("tcgetattr"); + return GP_ERROR; + } + tio.c_cflag = (tio.c_cflag & ~CSIZE) | CS8; + + /* Set into raw, no echo mode */ +#if defined(__FreeBSD__) || defined(__NetBSD__) + tio.c_iflag &= ~(IGNBRK | IGNCR | INLCR | ICRNL | + IXANY | IXON | IXOFF | INPCK | ISTRIP); +#else + tio.c_iflag &= ~(IGNBRK | IGNCR | INLCR | ICRNL | IUCLC | + IXANY | IXON | IXOFF | INPCK | ISTRIP); +#endif + tio.c_iflag |= (BRKINT | IGNPAR); + tio.c_oflag &= ~OPOST; + tio.c_lflag &= ~(ICANON | ISIG | ECHO | ECHONL | ECHOE | + ECHOK | IEXTEN); + tio.c_cflag &= ~(CRTSCTS | PARENB | PARODD); + tio.c_cflag |= CLOCAL | CREAD; + + tio.c_cc[VMIN] = 1; + tio.c_cc[VTIME] = 0; + + cfsetispeed(&tio, gp_port_serial_baudconv(dev->settings.serial.speed)); + cfsetospeed(&tio, gp_port_serial_baudconv(dev->settings.serial.speed)); + + if (tcsetattr(dev->device_fd, TCSANOW, &tio) < 0) { + perror("tcsetattr"); + return GP_ERROR; + } + if (fcntl(dev->device_fd, F_SETFL, 0) < 0) { /* clear O_NONBLOCK */ + perror("fcntl F_SETFL"); + return -1; + } +#else + struct sgttyb ttyb; + + if (ioctl(dev->device_fd, TIOCGETP, &ttyb) < 0) { + perror("ioctl(TIOCGETP)"); + return GP_ERROR; + } + ttyb.sg_ispeed = dev->settings.serial.speed; + ttyb.sg_ospeed = dev->settings.serial.speed; + ttyb.sg_flags = 0; + + if (ioctl(dev->device_fd, TIOCSETP, &ttyb) < 0) { + perror("ioctl(TIOCSETP)"); + return GP_ERROR; + } +#endif + + return GP_OK; +} + +/* Called to convert a int baud to the POSIX enum value */ +static speed_t gp_port_serial_baudconv(int baud) +{ +#define BAUDCASE(x) case (x): { ret = B##x; break; } + speed_t ret; + + ret = (speed_t) baud; + switch (baud) { + /* POSIX defined baudrates */ + BAUDCASE(0); + BAUDCASE(50); + BAUDCASE(75); + BAUDCASE(110); + BAUDCASE(134); + BAUDCASE(150); + BAUDCASE(200); + BAUDCASE(300); + BAUDCASE(600); + BAUDCASE(1200); + BAUDCASE(1800); + BAUDCASE(2400); + BAUDCASE(4800); + BAUDCASE(9600); + BAUDCASE(19200); + BAUDCASE(38400); + + /* non POSIX values */ +#ifdef B7200 + BAUDCASE(7200); +#endif +#ifdef B14400 + BAUDCASE(14400); +#endif +#ifdef B28800 + BAUDCASE(28800); +#endif +#ifdef B57600 + BAUDCASE(57600); +#endif +#ifdef B115200 + BAUDCASE(115200); +#endif +#ifdef B230400 + BAUDCASE(230400); +#endif + + default: + fprintf(stderr, "baudconv: baudrate %d is undefined; using as is\n", baud); + } + + return ret; +#undef BAUDCASE +} + +int gp_port_serial_send_break (gp_port *dev, int duration) { + + /* Duration is in seconds */ + +#if HAVE_TERMIOS_H + tcsendbreak(dev->device_fd, duration / 3); + tcdrain(dev->device_fd); +#else + /* ioctl */ +#endif + return 0; +} diff --git a/libgphoto2_port/stamp-h.in b/libgphoto2_port/stamp-h.in new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/libgphoto2_port/stamp-h.in diff --git a/libgphoto2_port/test/gphoto2-port-test.c b/libgphoto2_port/test/gphoto2-port-test.c new file mode 100644 index 000000000..9656e8b30 --- /dev/null +++ b/libgphoto2_port/test/gphoto2-port-test.c @@ -0,0 +1,50 @@ + +#include <stdio.h> +#include <string.h> +#include "gpio.h" + +void dump(gp_port * dev) +{ + +} + +int main(int argc, char **argv) +{ + gp_port *dev; /* declare the device */ + gp_port_settings settings; + char buf[32]; + + dev = gp_port_new(0); + /* create a new serial device */ + gp_port_set_timeout(dev, 500); + + strcpy(settings.serial.port, "/dev/modem"); + settings.serial.speed = 19200; + settings.serial.bits = 8; + settings.serial.parity = 0; + settings.serial.stopbits = 1; + + gp_port_set_settings(dev, settings); + gp_port_open(dev); /* open the device */ + dump(dev); + + gp_port_get_settings(dev, &settings); + settings.serial.speed = 57600; + gp_port_set_settings(dev, settings); + + dump(dev); + + printf("CTS: %i", gp_port_get_pin(dev,PIN_CTS)); + + gp_port_write(dev, "AT\n", 3); /* write bytes to the device */ + + gp_port_read(dev, buf, 3); /* read bytes from the device */ + buf[3] = 0; + printf("recv: %s\n", buf); + + gp_port_close(dev); /* close the device */ + + gp_port_free(dev); + + return 0; +} diff --git a/libgphoto2_port/usb/Makefile.am b/libgphoto2_port/usb/Makefile.am new file mode 100644 index 000000000..9fdca54a3 --- /dev/null +++ b/libgphoto2_port/usb/Makefile.am @@ -0,0 +1,11 @@ +## Specify some includes and versioning +INCLUDES = -I../ $(VERSION_FLAGS) -I$(top_srcdir)/include +VERSION_FLAGS = -DLIBGPPORT_VERSION=\"@LIBGPPORT_VERSION@\" +CFLAGS = @CFLAGS@ @IOLIB_CFLAGS@ -g `libusb-config --cflags` +LDFLAGS = @LDFLAGS@ -g `libusb-config --libs` + +## Compile the IO library into a shared library +iolibdir = $(prefix)/lib/gphoto2_port +iolib_LTLIBRARIES = libgphoto2_port_usb.la +libgphoto2_port_usb_la_LDFLAGS = -version-info @LIBGPPORT_VERSION_INFO@ +libgphoto2_port_usb_la_SOURCES = libusb.c diff --git a/libgphoto2_port/usb/libusb.c b/libgphoto2_port/usb/libusb.c new file mode 100644 index 000000000..054b36337 --- /dev/null +++ b/libgphoto2_port/usb/libusb.c @@ -0,0 +1,260 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* gphoto2-port-usb.c - USB transport functions + + Copyright (C) 1999-2000 Johannes Erdfelt <johannes@erdfelt.com> + + The GPIO Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GPIO Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GPIO Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + */ + +#include <stdlib.h> +#include <unistd.h> +#include <stdio.h> +#include <fcntl.h> +#include <errno.h> +#include <sys/time.h> +#include <sys/param.h> +#include <dirent.h> +#include <string.h> + +#include <usb.h> +#include "gphoto2-port.h" + +#define GP_PORT_USB_DEBUG 1 + +int gp_port_usb_list(gp_port_info *list, int *count); +int gp_port_usb_init(gp_port *dev); +int gp_port_usb_exit(gp_port *dev); +int gp_port_usb_open(gp_port *dev); +int gp_port_usb_close(gp_port *dev); +int gp_port_usb_reset(gp_port *dev); +int gp_port_usb_write(gp_port * dev, char *bytes, int size); +int gp_port_usb_read(gp_port * dev, char *bytes, int size); +int gp_port_usb_update(gp_port * dev); + +int gp_port_usb_clear_halt_lib(gp_port * dev, int ep); +int gp_port_usb_msg_read_lib(gp_port * dev, int value, char *bytes, int size); +int gp_port_usb_msg_write_lib(gp_port * dev, int value, char *bytes, int size); +int gp_port_usb_find_device_lib(gp_port *dev, int idvendor, int idproduct); + +/* Dynamic library functions + --------------------------------------------------------------------- */ + +gp_port_type gp_port_library_type () { + + return (GP_PORT_USB); +} + +gp_port_operations *gp_port_library_operations () { + + gp_port_operations *ops; + + ops = (gp_port_operations*)malloc(sizeof(gp_port_operations)); + memset(ops, 0, sizeof(gp_port_operations)); + + ops->init = gp_port_usb_init; + ops->exit = gp_port_usb_exit; + ops->open = gp_port_usb_open; + ops->close = gp_port_usb_close; + ops->read = gp_port_usb_read; + ops->write = gp_port_usb_write; + ops->update = gp_port_usb_update; + ops->clear_halt = gp_port_usb_clear_halt_lib; + ops->msg_write = gp_port_usb_msg_write_lib; + ops->msg_read = gp_port_usb_msg_read_lib; + ops->find_device = gp_port_usb_find_device_lib; + + return (ops); +} + +int gp_port_library_list(gp_port_info *list, int *count) +{ + + list[*count].type = GP_PORT_USB; + strcpy(list[*count].name, "Universal Serial Bus"); + strcpy(list[*count].path, "usb"); + list[*count].argument_needed = 0; + *count += 1; + + return GP_OK; +} + +int gp_port_usb_init(gp_port *dev) +{ + usb_init(); + usb_find_busses(); + usb_find_devices(); + return (GP_OK); +} + +int gp_port_usb_exit(gp_port *dev) +{ + return (GP_OK); +} + +int gp_port_usb_open(gp_port *dev) +{ + int ret; + void *udev; + + if (GP_PORT_USB_DEBUG) + printf ("gp_port_usb_open() called\n"); + + /* Open the device using the previous usb_handle returned by find_device */ + udev = dev->device_handle; + dev->device_handle = usb_open(udev); + if (!dev->device_handle) + return GP_ERROR; + + ret = usb_set_configuration(dev->device_handle, dev->settings.usb.config); + if (ret < 0) { + fprintf(stderr, "gp_port_usb_open: could not set config %d: %s\n", + dev->settings.usb.config, strerror(errno)); + return GP_ERROR; + } + + ret = usb_claim_interface(dev->device_handle, dev->settings.usb.interface); + if (ret < 0) { + fprintf(stderr, "gp_port_usb_open: could not claim intf %d: %s\n", + dev->settings.usb.interface, strerror(errno)); + return GP_ERROR; + } + + ret = usb_set_altinterface(dev->device_handle, dev->settings.usb.altsetting); + if (ret < 0) { + fprintf(stderr, "gp_port_usb_open: could not set intf %d/%d: %s\n", + dev->settings.usb.interface, + dev->settings.usb.altsetting, strerror(errno)); + return GP_ERROR; + } + + return GP_OK; +} + +int gp_port_usb_close(gp_port *dev) +{ + if (GP_PORT_USB_DEBUG) + printf ("gp_port_usb_close() called\n"); + + if (usb_close(dev->device_handle) < 0) + fprintf(stderr, "gp_port_usb_close: %s\n", + strerror(errno)); + + dev->device_handle = NULL; + + return GP_OK; +} + +int gp_port_usb_reset(gp_port *dev) +{ + gp_port_usb_close(dev); + return gp_port_usb_open(dev); +} + +int gp_port_usb_clear_halt_lib(gp_port * dev, int ep) +{ + int ret=0; + + switch (ep) { + case GP_PORT_USB_IN_ENDPOINT : + ret=usb_clear_halt(dev->device_handle, dev->settings.usb.inep); + break; + case GP_PORT_USB_OUT_ENDPOINT : + ret=usb_clear_halt(dev->device_handle, dev->settings.usb.outep); + break; + default: + fprintf(stderr,"gp_port_usb_clear_halt: bad EndPoint argument\n"); + return GP_ERROR; + } + return (ret ? GP_ERROR : GP_OK); +} + +int gp_port_usb_write(gp_port * dev, char *bytes, int size) +{ + if (GP_PORT_USB_DEBUG) { + int i; + + printf("gp_port_usb_write(): "); + for (i = 0; i < size; i++) + printf("%02x ",(unsigned char)bytes[i]); + printf("\n"); + } + + return usb_bulk_write(dev->device_handle, dev->settings.usb.outep, + bytes, size, dev->timeout); +} + +int gp_port_usb_read(gp_port * dev, char *bytes, int size) +{ + int ret; + + ret = usb_bulk_read(dev->device_handle, dev->settings.usb.inep, + bytes, size, dev->timeout); + if (ret < 0) + return GP_ERROR; + + if (GP_PORT_USB_DEBUG) { + int i; + + printf("gp_port_usb_read(timeout=%d): ", dev->timeout); + for (i = 0; i < ret; i++) + printf("%02x ",(unsigned char)(bytes[i])); + printf("\n"); + } + + return ret; +} + +int gp_port_usb_msg_write_lib(gp_port * dev, int value, char *bytes, int size) +{ + return usb_control_msg(dev->device_handle, + USB_TYPE_VENDOR | USB_RECIP_DEVICE, + size > 1 ? 0x04 : 0x0c, value, 0, bytes, size, dev->timeout); +} + +int gp_port_usb_msg_read_lib(gp_port * dev, int value, char *bytes, int size) +{ + return usb_control_msg(dev->device_handle, + USB_TYPE_VENDOR | USB_RECIP_DEVICE | 0x80, + size > 1 ? 0x04 : 0x0c, value, 0, bytes, size, dev->timeout); +} + +/* + * This function applys changes to the device + * (At this time it does nothing) + */ +int gp_port_usb_update(gp_port * dev) +{ + memcpy(&dev->settings, &dev->settings_pending, sizeof(dev->settings)); + + return GP_OK; +} + +int gp_port_usb_find_device_lib(gp_port * d, int idvendor, int idproduct) +{ + struct usb_bus *bus; + struct usb_device *dev; + for (bus = usb_busses; bus; bus = bus->next) { + for (dev = bus->devices; dev; dev = dev->next) { + if ((dev->descriptor.idVendor == idvendor) && + (dev->descriptor.idProduct == idproduct)) { + d->device_handle = dev; + return GP_OK; + } + } + } + + return GP_ERROR; +} |