Merge branch 'master' of git://git.gag.com/fw/altos
[fw/altos] / ao-tools / libaltos / libaltos.h
1 /*
2  * Copyright © 2010 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 #ifndef _LIBALTOS_H_
19 #define _LIBALTOS_H_
20
21 #if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
22 # ifndef BUILD_STATIC
23 #  ifdef BUILD_DLL
24 #   define PUBLIC __declspec(dllexport)
25 #  else
26 #   define PUBLIC __declspec(dllimport)
27 #  endif
28 # endif /* BUILD_STATIC */
29 #endif
30
31 #ifndef PUBLIC
32 # define PUBLIC
33 #endif
34
35 #define USB_VENDOR_FSF                  0xfffe
36 #define USB_VENDOR_ALTUSMETRUM          USB_VENDOR_FSF
37 #define USB_PRODUCT_ALTUSMETRUM         0x000a
38 #define USB_PRODUCT_TELEMETRUM          0x000b
39 #define USB_PRODUCT_TELEDONGLE          0x000c
40 #define USB_PRODUCT_TELETERRA           0x000d
41 #define USB_PRODUCT_ALTUSMETRUM_MIN     0x000a
42 #define USB_PRODUCT_ALTUSMETRUM_MAX     0x0013
43
44 #define USB_IS_ALTUSMETRUM(v,p) ((v) == USB_VENDOR_ALTUSMETRUM && \
45                 (USB_PRODUCT_ALTUSMETRUM_MIN <= (p) && \
46                  (p) <= USB_PRODUCT_ALTUSMETRUM_MAX))
47
48 struct altos_device {
49         //%immutable;
50         int                             vendor;
51         int                             product;
52         int                             serial;
53         char                            name[256];
54         char                            path[256];
55         //%mutable;
56 };
57
58 #define LIBALTOS_SUCCESS        0
59 #define LIBALTOS_ERROR          -1
60 #define LIBALTOS_TIMEOUT        -2
61
62 /* Returns 0 for success, < 0 on error */
63 PUBLIC int
64 altos_init(void);
65
66 PUBLIC void
67 altos_fini(void);
68
69 PUBLIC struct altos_list *
70 altos_list_start(void);
71
72 /* Returns 1 for success, zero on end of list */
73 PUBLIC int
74 altos_list_next(struct altos_list *list, struct altos_device *device);
75
76 PUBLIC void
77 altos_list_finish(struct altos_list *list);
78
79 PUBLIC struct altos_file *
80 altos_open(struct altos_device *device);
81
82 PUBLIC void
83 altos_close(struct altos_file *file);
84
85 PUBLIC void
86 altos_free(struct altos_file *file);
87
88 /* Returns < 0 for error */
89 PUBLIC int
90 altos_putchar(struct altos_file *file, char c);
91
92 /* Returns < 0 for error */
93 PUBLIC int
94 altos_flush(struct altos_file *file);
95
96 /* Returns < 0 for error or timeout. timeout of 0 == wait forever */
97 PUBLIC int
98 altos_getchar(struct altos_file *file, int timeout);
99
100 #endif /* _LIBALTOS_H_ */