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; 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 package org.altusmetrum.altosuilib_14;
23 import org.altusmetrum.altoslib_14.*;
25 public class AltosUSBDevice extends altos_device implements AltosDevice {
27 public String toString() {
28 String name = getName();
30 name = "Altus Metrum";
31 return String.format("%-20.20s %4d %s",
32 name, getSerial(), getPath());
35 public String toShortString() {
36 String name = getName();
38 name = "Altus Metrum";
39 return String.format("%s %d %s",
40 name, getSerial(), getPath());
44 public String getErrorString() {
45 altos_error error = new altos_error();
47 libaltos.altos_get_last_error(error);
48 return String.format("%s (%d)", error.getString(), error.getCode());
51 public SWIGTYPE_p_altos_file open() {
52 return libaltos.altos_open(this);
55 public boolean isAltusMetrum() {
56 if (getVendor() != AltosUILib.vendor_altusmetrum)
58 if (getProduct() < AltosUILib.product_altusmetrum_min)
60 if (getProduct() > AltosUILib.product_altusmetrum_max)
65 public boolean matchProduct(int want_product) {
70 if (want_product == AltosUILib.product_any)
73 int have_product = getProduct();
75 if (want_product == AltosUILib.product_basestation)
76 return have_product == AltosUILib.product_teledongle ||
77 have_product == AltosUILib.product_telebt ||
78 have_product == AltosUILib.product_megadongle;
80 if (want_product == AltosUILib.product_altimeter)
81 return have_product == AltosUILib.product_telemetrum ||
82 have_product == AltosUILib.product_telemega ||
83 have_product == AltosUILib.product_easytimer ||
84 have_product == AltosUILib.product_easymega ||
85 have_product == AltosUILib.product_telegps ||
86 have_product == AltosUILib.product_easymini ||
87 have_product == AltosUILib.product_telemini;
89 if (have_product == AltosUILib.product_altusmetrum) /* old devices match any request */
92 if (want_product == have_product)
98 public int hashCode() {
99 return getVendor() ^ getProduct() ^ getSerial() ^ getPath().hashCode();
102 public AltosUsbId usb_id() {
103 return new AltosUsbId(getVendor(), getProduct());
106 public String usb_product() {
110 public boolean equals(Object o) {
114 if (!(o instanceof AltosUSBDevice))
116 AltosUSBDevice other = (AltosUSBDevice) o;
118 return getVendor() == other.getVendor() &&
119 getProduct() == other.getProduct() &&
120 getSerial() == other.getSerial() &&
121 getPath().equals(other.getPath());
124 static public java.util.List<AltosDevice> list(int product) {
125 if (!AltosUILib.load_library())
128 SWIGTYPE_p_altos_list list = libaltos.altos_list_start();
130 ArrayList<AltosDevice> device_list = new ArrayList<AltosDevice>();
133 AltosUSBDevice device = new AltosUSBDevice();
134 if (libaltos.altos_list_next(list, device) == 0)
136 if (device.matchProduct(product))
137 device_list.add(device);
139 libaltos.altos_list_finish(list);