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.altosuilib_3.*;
24 public class MicroUSB extends altos_device implements AltosDevice {
26 static boolean initialized = false;
27 static boolean loaded_library = false;
29 public static boolean load_library() {
32 System.loadLibrary("altos");
33 libaltos.altos_init();
34 loaded_library = true;
35 } catch (UnsatisfiedLinkError e) {
37 System.loadLibrary("altos64");
38 libaltos.altos_init();
39 loaded_library = true;
40 } catch (UnsatisfiedLinkError e2) {
41 loaded_library = false;
46 return loaded_library;
49 public String toString() {
50 String name = getName();
52 name = "Altus Metrum";
53 return String.format("%-24.24s %s",
57 public String toShortString() {
58 String name = getName();
60 name = "Altus Metrum";
61 return String.format("%s %s",
66 public String getErrorString() {
67 altos_error error = new altos_error();
69 libaltos.altos_get_last_error(error);
70 return String.format("%s (%d)", error.getString(), error.getCode());
73 public SWIGTYPE_p_altos_file open() {
74 return libaltos.altos_open(this);
77 private boolean isMicro() {
78 if (getVendor() != 0x0403)
80 if (getProduct() != 0x6015)
85 public boolean matchProduct(int product) {
89 static java.util.List<MicroUSB> list() {
93 SWIGTYPE_p_altos_list list = libaltos.altos_ftdi_list_start();
95 ArrayList<MicroUSB> device_list = new ArrayList<MicroUSB>();
98 MicroUSB device = new MicroUSB();
99 if (libaltos.altos_list_next(list, device) == 0)
101 if (device.isMicro())
102 device_list.add(device);
104 libaltos.altos_list_finish(list);