2 * Copyright © 2016 Keith Packard <keithp@keithp.com>
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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 #include "libaltos_private.h"
24 return LIBALTOS_SUCCESS;
32 struct altos_error altos_last_error;
35 altos_set_last_error(int code, char *string)
37 altos_last_error.code = code;
38 strncpy(altos_last_error.string, string, sizeof (altos_last_error.string) -1);
39 altos_last_error.string[sizeof(altos_last_error.string)-1] = '\0';
43 altos_get_last_error(struct altos_error *error)
45 *error = altos_last_error;
49 altos_getchar(struct altos_file *file, int timeout)
54 while (file->in_read == file->in_used) {
55 ret = altos_fill(file, timeout);
59 ret = file->in_data[file->in_read++];
66 altos_putchar(struct altos_file *file, char c)
70 if (file->out_used == USB_BUF_SIZE) {
71 ret = altos_flush(file);
76 file->out_data[file->out_used++] = c;
78 if (file->out_used == USB_BUF_SIZE)
79 ret = altos_flush(file);
83 struct bt_vendor_map {
84 const char vendor[10];
88 static const struct bt_vendor_map altos_bt_vendor_map[] = {
89 { .vendor = "00:12:6f:", 1 }, /* Rayson */
90 { .vendor = "8c:de:52:", 6 }, /* ISSC */
91 { .vendor = "d8:80:39:", 6 }, /* Microchip */
94 #define NUM_BT_VENDOR_MAP (sizeof altos_bt_vendor_map / sizeof altos_bt_vendor_map[0])
95 #define BT_PORT_DEFAULT 1
99 if ('A' <= c && c <= 'Z')
100 return c + 'a' - 'A';
104 int altos_bt_port(struct altos_bt_device *device) {
106 for (i = 0; i < NUM_BT_VENDOR_MAP; i++) {
107 const char *vendor = altos_bt_vendor_map[i].vendor;
109 if (vendor[j] == '\0')
110 return altos_bt_vendor_map[i].port;
111 if (device->addr[j] == '\0')
113 if (ao_tolower(device->addr[j]) != vendor[j])
117 return BT_PORT_DEFAULT;
121 altos_free(struct altos_file *file)
125 for (i = 0; i < 10 && file->busy; i++)
126 altos_pause_one_second();