2 * Copyright © 2010 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; version 2 of the License.
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.
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.
18 package org.altusmetrum.micropeak;
22 import org.altusmetrum.altoslib_9.*;
23 import org.altusmetrum.altosuilib_9.*;
25 public class MicroUSB extends altos_device implements AltosDevice {
27 static boolean initialized = false;
28 static boolean loaded_library = false;
30 public static boolean load_library() {
33 System.loadLibrary("altos");
34 libaltos.altos_init();
35 loaded_library = true;
36 } catch (UnsatisfiedLinkError e) {
38 System.loadLibrary("altos64");
39 libaltos.altos_init();
40 loaded_library = true;
41 } catch (UnsatisfiedLinkError e2) {
42 loaded_library = false;
47 return loaded_library;
50 public String toString() {
51 String name = getName();
53 name = "Altus Metrum";
54 return String.format("%-24.24s %s",
58 public String toShortString() {
59 String name = getName();
61 name = "Altus Metrum";
62 return String.format("%s %s",
67 public String getErrorString() {
68 altos_error error = new altos_error();
70 libaltos.altos_get_last_error(error);
71 return String.format("%s (%d)", error.getString(), error.getCode());
74 public SWIGTYPE_p_altos_file open() {
75 return libaltos.altos_open(this);
78 private boolean isFTDI() {
79 int vid = getVendor();
80 int pid = getProduct();
81 if (vid == 0x0403 && pid == 0x6015)
86 private boolean isMicro() {
87 int vid = getVendor();
88 int pid = getProduct();
89 if (vid == AltosLib.vendor_altusmetrum &&
90 pid == AltosLib.product_mpusb)
95 public boolean matchProduct(int product) {
96 return isFTDI() || isMicro();
99 static java.util.List<MicroUSB> list() {
103 ArrayList<MicroUSB> device_list = new ArrayList<MicroUSB>();
105 SWIGTYPE_p_altos_list list;
107 list = libaltos.altos_ftdi_list_start();
111 MicroUSB device = new MicroUSB();
112 if (libaltos.altos_list_next(list, device) == 0)
115 device_list.add(device);
117 libaltos.altos_list_finish(list);
120 list = libaltos.altos_list_start();
124 MicroUSB device = new MicroUSB();
125 if (libaltos.altos_list_next(list, device) == 0)
127 if (device.isMicro())
128 device_list.add(device);
130 libaltos.altos_list_finish(list);