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 public class MicroUSB extends altos_device {
24 static boolean initialized = false;
25 static boolean loaded_library = false;
27 public static boolean load_library() {
30 System.loadLibrary("altos");
31 libaltos.altos_init();
32 loaded_library = true;
33 } catch (UnsatisfiedLinkError e) {
35 System.loadLibrary("altos64");
36 libaltos.altos_init();
37 loaded_library = true;
38 } catch (UnsatisfiedLinkError e2) {
39 loaded_library = false;
44 return loaded_library;
47 public String toString() {
48 String name = getName();
50 name = "Altus Metrum";
51 return String.format("%-20.20s %4d %s",
52 name, getSerial(), getPath());
55 public String toShortString() {
56 String name = getName();
58 name = "Altus Metrum";
59 return String.format("%s %d %s",
60 name, getSerial(), getPath());
64 public String getErrorString() {
65 altos_error error = new altos_error();
67 libaltos.altos_get_last_error(error);
68 return String.format("%s (%d)", error.getString(), error.getCode());
71 public SWIGTYPE_p_altos_file open() {
72 return libaltos.altos_open(this);
75 private boolean isMicro() {
76 if (getVendor() != 0x0403)
78 if (getProduct() != 0x6001)
83 static java.util.List<MicroUSB> list() {
87 SWIGTYPE_p_altos_list list = libaltos.altos_list_start();
89 ArrayList<MicroUSB> device_list = new ArrayList<MicroUSB>();
92 MicroUSB device = new MicroUSB();
93 if (libaltos.altos_list_next(list, device) == 0)
96 device_list.add(device);
98 libaltos.altos_list_finish(list);