dd091e51333ceae96ca7a462c4dc24d3207bc426
[fw/altos] / altosui / 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 #include <stdlib.h>
22
23 #if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
24 # ifndef BUILD_STATIC
25 #  ifdef BUILD_DLL
26 #   define PUBLIC __declspec(dllexport)
27 #  else
28 #   define PUBLIC __declspec(dllimport)
29 #  endif
30 # endif /* BUILD_STATIC */
31 #endif
32
33 #ifndef PUBLIC
34 # define PUBLIC
35 #endif
36
37 #define HAS_BLUETOOTH   0
38
39 #define USB_VENDOR_FSF                  0xfffe
40 #define USB_VENDOR_ALTUSMETRUM          USB_VENDOR_FSF
41 #define USB_PRODUCT_ALTUSMETRUM         0x000a
42 #define USB_PRODUCT_TELEMETRUM          0x000b
43 #define USB_PRODUCT_TELEDONGLE          0x000c
44 #define USB_PRODUCT_TELETERRA           0x000d
45 #define USB_PRODUCT_TELEBT              0x000e
46 #define USB_PRODUCT_ALTUSMETRUM_MIN     0x000a
47 #define USB_PRODUCT_ALTUSMETRUM_MAX     0x0013
48
49 #define USB_IS_ALTUSMETRUM(v,p) ((v) == USB_VENDOR_ALTUSMETRUM && \
50                 (USB_PRODUCT_ALTUSMETRUM_MIN <= (p) && \
51                  (p) <= USB_PRODUCT_ALTUSMETRUM_MAX))
52
53 struct altos_device {
54         //%immutable;
55         int                             vendor;
56         int                             product;
57         int                             serial;
58         char                            name[256];
59         char                            path[256];
60         //%mutable;
61 };
62
63 #define BLUETOOTH_PRODUCT_TELEBT        "TeleBT"
64
65 struct altos_bt_device {
66         //%immutable;
67         char                            name[256];
68         char                            addr[20];
69         //%mutable;
70 };
71
72 #define LIBALTOS_SUCCESS        0
73 #define LIBALTOS_ERROR          -1
74 #define LIBALTOS_TIMEOUT        -2
75
76 /* Returns 0 for success, < 0 on error */
77 PUBLIC int
78 altos_init(void);
79
80 PUBLIC void
81 altos_fini(void);
82
83 PUBLIC struct altos_list *
84 altos_list_start(void);
85
86 /* Returns 1 for success, zero on end of list */
87 PUBLIC int
88 altos_list_next(struct altos_list *list, struct altos_device *device);
89
90 PUBLIC void
91 altos_list_finish(struct altos_list *list);
92
93 PUBLIC struct altos_file *
94 altos_open(struct altos_device *device);
95
96 PUBLIC void
97 altos_close(struct altos_file *file);
98
99 PUBLIC void
100 altos_free(struct altos_file *file);
101
102 /* Returns < 0 for error */
103 PUBLIC int
104 altos_putchar(struct altos_file *file, char c);
105
106 /* Returns < 0 for error */
107 PUBLIC int
108 altos_flush(struct altos_file *file);
109
110 /* Returns < 0 for error or timeout. timeout of 0 == wait forever */
111 PUBLIC int
112 altos_getchar(struct altos_file *file, int timeout);
113
114 #if HAS_BLUETOOTH
115
116 PUBLIC struct altos_bt_list *
117 altos_bt_list_start(int inquiry_time);
118
119 PUBLIC int
120 altos_bt_list_next(struct altos_bt_list *list, struct altos_bt_device *device);
121
122 PUBLIC void
123 altos_bt_list_finish(struct altos_bt_list *list);
124
125 PUBLIC void
126 altos_bt_fill_in(char *name, char *addr, struct altos_bt_device *device);
127
128 PUBLIC struct altos_file *
129 altos_bt_open(struct altos_bt_device *device);
130
131 #endif
132
133 #endif /* _LIBALTOS_H_ */