summaryrefslogtreecommitdiff
path: root/libgphoto2_port/libgphoto2_port/gphoto2/gphoto2-port.h
blob: 5645bf2983af591a4c456c3fe3eb5ca21a58c48b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/* gphoto2-port.h
 *
 * Copyright © 2001 Lutz Müller <lutz@users.sf.net>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser 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
 * Lesser General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifndef __GPHOTO2_PORT_H__
#define __GPHOTO2_PORT_H__

#include <gphoto2/gphoto2-port-info-list.h>

/* For portability */
#include <gphoto2/gphoto2-port-portability.h>
#ifdef OS2
#include <gphoto2/gphoto2-port-portability-os2.h>
#include <os2.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

#ifndef TRUE
#define TRUE (0==0)
#endif

#ifndef FALSE
#define FALSE (1==0)
#endif

/**
 * Use Parity. Enable/Disable, and Odd/Even.
 */

typedef enum _GPPortSerialParity
{
    GP_PORT_SERIAL_PARITY_OFF = 0,
    GP_PORT_SERIAL_PARITY_EVEN,
    GP_PORT_SERIAL_PARITY_ODD
} GPPortSerialParity;


#define GP_PORT_MAX_BUF_LEN 4096             /* max length of receive buffer */

typedef struct _GPPortSettingsSerial GPPortSettingsSerial;
struct _GPPortSettingsSerial {
	char port[128];		/** The portname (/dev/ttyX)*/
	int speed;		/** The baudrate of the device. */
	int bits;		/** How many bits data. */
	GPPortSerialParity parity;	/** parity data, see GP_PORT_SERIAL_PARITY_ 
				  defines */
	int stopbits;		/** How many stop bits are used. */
};

typedef struct _GPPortSettingsUSB GPPortSettingsUSB;
struct _GPPortSettingsUSB {
	int inep, outep, intep;
	int config;
	int interface;
	int altsetting;

	/* must be last to avoid binary incompatibility.
	 * luckily we just need to make sure this struct does not 
	 * get larger than _GPPortSettingsSerial. */
	char port[64];
};

typedef struct _GPPortSettingsDisk GPPortSettingsDisk;
struct _GPPortSettingsDisk {
	char mountpoint[128];
};

typedef union _GPPortSettings GPPortSettings;
union _GPPortSettings {
	GPPortSettingsSerial serial;
	GPPortSettingsUSB usb;
	GPPortSettingsDisk disk;
};

enum {
        GP_PORT_USB_ENDPOINT_IN,
        GP_PORT_USB_ENDPOINT_OUT,
        GP_PORT_USB_ENDPOINT_INT
};

typedef struct _GPPortPrivateLibrary GPPortPrivateLibrary;
typedef struct _GPPortPrivateCore    GPPortPrivateCore;

typedef struct _GPPort           GPPort;
struct _GPPort {

	/* For your convenience */
	GPPortType type;

        GPPortSettings settings;
        GPPortSettings settings_pending;

        int timeout; /* in milliseconds */

	GPPortPrivateLibrary *pl;
	GPPortPrivateCore    *pc;
};

int gp_port_new         (GPPort **port);
int gp_port_free        (GPPort *port);

int gp_port_set_info    (GPPort *port, GPPortInfo  info);
int gp_port_get_info    (GPPort *port, GPPortInfo *info);

int gp_port_open        (GPPort *port);
int gp_port_close       (GPPort *port);

int gp_port_write       (GPPort *port, const char *data, int size);
int gp_port_read        (GPPort *port,       char *data, int size);
int gp_port_check_int   (GPPort *port,       char *data, int size);
int gp_port_check_int_fast (GPPort *port,    char *data, int size);

int gp_port_get_timeout  (GPPort *port, int *timeout);
int gp_port_set_timeout  (GPPort *port, int  timeout);

int gp_port_set_settings (GPPort *port, GPPortSettings  settings);
int gp_port_get_settings (GPPort *port, GPPortSettings *settings);

enum _GPPin {
	GP_PIN_RTS,
	GP_PIN_DTR,
	GP_PIN_CTS,
	GP_PIN_DSR,
	GP_PIN_CD,
	GP_PIN_RING
};
typedef enum _GPPin GPPin;

enum _GPLevel {
	GP_LEVEL_LOW  = 0,
	GP_LEVEL_HIGH = 1
};
typedef enum _GPLevel GPLevel;

int gp_port_get_pin   (GPPort *port, GPPin pin, GPLevel *level);
int gp_port_set_pin   (GPPort *port, GPPin pin, GPLevel level);

int gp_port_send_break (GPPort *port, int duration);
int gp_port_flush      (GPPort *port, int direction);

int gp_port_usb_find_device (GPPort *port, int idvendor, int idproduct);
int gp_port_usb_find_device_by_class (GPPort *port, int mainclass, int subclass, int protocol);
int gp_port_usb_clear_halt  (GPPort *port, int ep);
int gp_port_usb_msg_write   (GPPort *port, int request, int value,
			     int index, char *bytes, int size);
int gp_port_usb_msg_read    (GPPort *port, int request, int value,
			     int index, char *bytes, int size);
int gp_port_usb_msg_interface_write    (GPPort *port, int request, 
			    int value, int index, char *bytes, int size);
int gp_port_usb_msg_interface_read    (GPPort *port, int request, 
			    int value, int index, char *bytes, int size);

/* Error reporting */
int         gp_port_set_error (GPPort *port, const char *format, ...)
#ifdef __GNUC__
	__attribute__((__format__(printf,2,3)))
#endif
;
const char *gp_port_get_error (GPPort *port);

/* DEPRECATED */
typedef GPPort gp_port;
typedef GPPortSettings gp_port_settings;
#define PIN_CTS GP_PIN_CTS

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* __GPHOTO2_PORT_H__ */