summaryrefslogtreecommitdiff
path: root/altosdroid/src
diff options
context:
space:
mode:
authorMike Beattie <mike@ethernal.org>2012-08-27 19:37:16 +1200
committerMike Beattie <mike@ethernal.org>2012-08-27 19:37:16 +1200
commit6441437d3b0e848b225a3d6c78ab00e2590c6988 (patch)
tree111c2d41bd27cbf1d1281af3eb270eb1a90cbddc /altosdroid/src
parent58d2b70575f3616a056d2356a737b3be15ed3d66 (diff)
altosdroid: remove complexity around message passing
* Don't really need to use bundles * TelemetryService: Use a local variable to store the bluetooth device object Signed-off-by: Mike Beattie <mike@ethernal.org>
Diffstat (limited to 'altosdroid/src')
-rw-r--r--altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java10
-rw-r--r--altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java5
-rw-r--r--altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java24
3 files changed, 18 insertions, 21 deletions
diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java
index 37e977ad..bb188d80 100644
--- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java
+++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java
@@ -26,9 +26,9 @@ import java.util.UUID;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
-import android.os.Bundle;
+//import android.os.Bundle;
import android.os.Handler;
-import android.os.Message;
+//import android.os.Message;
import android.util.Log;
import org.altusmetrum.AltosLib.*;
@@ -116,11 +116,7 @@ public class AltosBluetooth extends AltosLink {
// Send the device name back to the Telemetry Service
name = device.getName();
- Message msg = handler.obtainMessage(TelemetryService.MSG_CONNECTED);
- Bundle b = new Bundle();
- b.putString(TelemetryService.KEY_DEVNAME, name);
- msg.setData(b);
- handler.sendMessage(msg);
+ handler.obtainMessage(TelemetryService.MSG_CONNECTED).sendToTarget();
// Notify other waiting threads, now that we're connected
AltosBluetooth.this.notifyAll();
diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java
index 3e9998e5..5631ffb7 100644
--- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java
+++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java
@@ -123,8 +123,9 @@ public class AltosDroid extends Activity {
break;
case MSG_DEVNAME:
// save the connected device's name
- ad.mConnectedDeviceName = msg.getData().getString(KEY_DEVNAME);
- Toast.makeText(ad.getApplicationContext(), "Connected to "
+ ad.mConnectedDeviceName = (String) msg.obj;
+ if (ad.mConnectedDeviceName != null)
+ Toast.makeText(ad.getApplicationContext(), "Connected to "
+ ad.mConnectedDeviceName, Toast.LENGTH_SHORT).show();
break;
case MSG_TOAST:
diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java
index e3f0a739..c809f733 100644
--- a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java
+++ b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java
@@ -27,7 +27,7 @@ import android.app.PendingIntent;
import android.app.Service;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
-import android.os.Bundle;
+//import android.os.Bundle;
import android.os.IBinder;
import android.os.Handler;
import android.os.Message;
@@ -67,6 +67,7 @@ public class TelemetryService extends Service {
final Messenger mMessenger = new Messenger(mHandler); // Target we publish for clients to send messages to IncomingHandler.
// Name of the connected device
+ private BluetoothDevice device = null;
private String mConnectedDeviceName = null;
private AltosBluetooth mAltosBluetooth = null;
private int state = STATE_NONE;
@@ -96,16 +97,13 @@ public class TelemetryService extends Service {
break;
case MSG_CONNECT:
if (D) Log.d(TAG, "Connect command received");
- s.startAltosBluetooth((BluetoothDevice) msg.obj);
+ s.device = (BluetoothDevice) msg.obj;
+ s.startAltosBluetooth();
break;
case MSG_CONNECTED:
if (D) Log.d(TAG, "Connected to device");
- s.mConnectedDeviceName = msg.getData().getString(KEY_DEVNAME);
- Message m = Message.obtain(null, AltosDroid.MSG_DEVNAME);
- Bundle b = new Bundle();
- b.putString(AltosDroid.KEY_DEVNAME, s.mConnectedDeviceName);
- m.setData(b);
- s.sendMessageToClients(m);
+ s.mConnectedDeviceName = s.device.getName();
+ s.sendMessageToClients(Message.obtain(null, AltosDroid.MSG_DEVNAME, s.mConnectedDeviceName));
s.setState(STATE_CONNECTED);
s.mAltosBluetooth.add_monitor(s.telem);
break;
@@ -133,17 +131,19 @@ public class TelemetryService extends Service {
mAltosBluetooth.close();
mAltosBluetooth = null;
}
+ mConnectedDeviceName = null;
+ device = null;
telem.clear();
}
- private void startAltosBluetooth(BluetoothDevice d) {
+ private void startAltosBluetooth() {
if (mAltosBluetooth == null) {
- if (D) Log.i(TAG, "Connecting to " + d.getName());
- mAltosBluetooth = new AltosBluetooth(d, mHandler);
+ if (D) Log.i(TAG, "Connecting to " + device.getName());
+ mAltosBluetooth = new AltosBluetooth(device, mHandler);
setState(STATE_CONNECTING);
} else {
stopAltosBluetooth();
- mHandler.sendMessageDelayed(Message.obtain(null, MSG_CONNECT, d), 1000);
+ mHandler.sendMessageDelayed(Message.obtain(null, MSG_CONNECT, device), 1000);
}
}