altosdroid: Add Connected/Connect_failed messages
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / TelemetryService.java
index e9254badc235994e81b905158a8a4b6a0a3d3b2a..ecafc74a0fd6b13c0898dac920e790047f0dd8c9 100644 (file)
@@ -47,6 +47,8 @@ public class TelemetryService extends Service {
        static final int MSG_UNREGISTER_CLIENT = 2;
        static final int MSG_CONNECT           = 3;
        static final int MSG_CONNECTED         = 4;
+       static final int MSG_CONNECT_FAILED    = 5;
+       static final int MSG_DISCONNECTED      = 6;
 
        public static final int STATE_NONE       = 0;
        public static final int STATE_READY      = 1;
@@ -101,6 +103,14 @@ public class TelemetryService extends Service {
                                s.setState(STATE_CONNECTED);
                                s.mAltosBluetooth.add_monitor(s.telem);
                                break;
+                       case MSG_CONNECT_FAILED:
+                               if (D) Log.d(TAG, "Connection failed... retrying");
+                               s.startAltosBluetooth();
+                               break;
+                       case MSG_DISCONNECTED:
+                               if (D) Log.d(TAG, "Disconnected from " + s.device.getName());
+                               s.stopAltosBluetooth();
+                               break;
                        default:
                                super.handleMessage(msg);
                        }