altos: Make telemega v0.1 compile with new quaternion code
[fw/altos] / altosui / AltosBTDevice.java
index ff2be49a66279009c6fc0f32ea69dce4d6ad89b7..727a9f6625ce7953e251c94817cc9f5832c4b1ad 100644 (file)
@@ -16,9 +16,8 @@
  */
 
 package altosui;
-import java.lang.*;
-import java.util.*;
 import libaltosJNI.*;
+import org.altusmetrum.altosuilib_1.*;
 
 public class AltosBTDevice extends altos_bt_device implements AltosDevice {
 
@@ -42,6 +41,13 @@ public class AltosBTDevice extends altos_bt_device implements AltosDevice {
                return getAddr();
        }
 
+       public String getErrorString() {
+               altos_error     error = new altos_error();
+
+               libaltos.altos_get_last_error(error);
+               return String.format("%s (%d)", error.getString(), error.getCode());
+       }
+
        public int getSerial() {
                String name = getName();
                if (name == null)
@@ -58,19 +64,13 @@ public class AltosBTDevice extends altos_bt_device implements AltosDevice {
        }
 
        public String toString() {
-               String  name = getName();
-               if (name == null)
-                       name = "Altus Metrum";
                return String.format("%-20.20s %4d %s",
                                     getProductName(), getSerial(), getAddr());
        }
 
        public String toShortString() {
-               String  name = getName();
-               if (name == null)
-                       name = "Altus Metrum";
                return String.format("%s %d %s",
-                                    getProduct(), getSerial(), getAddr());
+                                    getProductName(), getSerial(), getAddr());
 
        }
 
@@ -78,16 +78,18 @@ public class AltosBTDevice extends altos_bt_device implements AltosDevice {
                return libaltos.altos_bt_open(this);
        }
 
+       /*
        private boolean isAltusMetrum() {
                if (getName().startsWith(Altos.bt_product_telebt))
                        return true;
                return false;
        }
+       */
 
        public boolean matchProduct(int want_product) {
 
-               if (!isAltusMetrum())
-                       return false;
+//             if (!isAltusMetrum())
+//                     return false;
 
                if (want_product == Altos.product_any)
                        return true;
@@ -100,4 +102,23 @@ public class AltosBTDevice extends altos_bt_device implements AltosDevice {
 
                return false;
        }
+
+       public boolean equals(Object o) {
+               if (!(o instanceof AltosBTDevice))
+                       return false;
+               AltosBTDevice other = (AltosBTDevice) o;
+               return getName().equals(other.getName()) && getAddr().equals(other.getAddr());
+       }
+
+       public int hashCode() {
+               return getName().hashCode() ^ getAddr().hashCode();
+       }
+
+       public AltosBTDevice(String name, String addr) {
+               Altos.load_library();
+               libaltos.altos_bt_fill_in(name, addr,this);
+       }
+
+       public AltosBTDevice() {
+       }
 }
\ No newline at end of file