mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-06 21:54:15 +01:00
AndroidGCS: Clean up messaging from TelemetryService
This commit is contained in:
parent
97445007fb
commit
22513bf6c8
@ -10,14 +10,9 @@ import org.openpilot.uavtalk.UAVObjectManager;
|
|||||||
import org.openpilot.uavtalk.UAVTalk;
|
import org.openpilot.uavtalk.UAVTalk;
|
||||||
import org.openpilot.uavtalk.uavobjects.UAVObjectsInitialize;
|
import org.openpilot.uavtalk.uavobjects.UAVObjectsInitialize;
|
||||||
|
|
||||||
import android.app.Notification;
|
|
||||||
import android.app.NotificationManager;
|
|
||||||
import android.app.PendingIntent;
|
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
@ -47,6 +42,7 @@ public class OPTelemetryService extends Service {
|
|||||||
// Variables for local message handler thread
|
// Variables for local message handler thread
|
||||||
private Looper mServiceLooper;
|
private Looper mServiceLooper;
|
||||||
private ServiceHandler mServiceHandler;
|
private ServiceHandler mServiceHandler;
|
||||||
|
private static HandlerThread thread;
|
||||||
|
|
||||||
// Message ids
|
// Message ids
|
||||||
static final int MSG_START = 0;
|
static final int MSG_START = 0;
|
||||||
@ -118,7 +114,7 @@ public class OPTelemetryService extends Service {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case MSG_TOAST:
|
case MSG_TOAST:
|
||||||
Toast.makeText(OPTelemetryService.this, (String) msg.obj, Toast.LENGTH_SHORT);
|
Toast.makeText(OPTelemetryService.this, (String) msg.obj, Toast.LENGTH_SHORT).show();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
System.out.println(msg.toString());
|
System.out.println(msg.toString());
|
||||||
@ -130,8 +126,7 @@ public class OPTelemetryService extends Service {
|
|||||||
public void startup() {
|
public void startup() {
|
||||||
Toast.makeText(getApplicationContext(), "Telemetry service starting", Toast.LENGTH_SHORT).show();
|
Toast.makeText(getApplicationContext(), "Telemetry service starting", Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
HandlerThread thread = new HandlerThread("TelemetryServiceHandler",
|
thread = new HandlerThread("TelemetryServiceHandler", Process.THREAD_PRIORITY_BACKGROUND);
|
||||||
Process.THREAD_PRIORITY_BACKGROUND);
|
|
||||||
thread.start();
|
thread.start();
|
||||||
|
|
||||||
// Get the HandlerThread's Looper and use it for our Handler
|
// Get the HandlerThread's Looper and use it for our Handler
|
||||||
@ -139,8 +134,8 @@ public class OPTelemetryService extends Service {
|
|||||||
mServiceHandler = new ServiceHandler(mServiceLooper);
|
mServiceHandler = new ServiceHandler(mServiceLooper);
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(OPTelemetryService.this);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(OPTelemetryService.this);
|
||||||
if(prefs.getBoolean("autoconnect", false) || true) {
|
if(prefs.getBoolean("autoconnect", false)) {
|
||||||
Toast.makeText(getApplicationContext(), "Should auto connect", Toast.LENGTH_SHORT);
|
Toast.makeText(getApplicationContext(), "Should auto connect", Toast.LENGTH_SHORT).show();
|
||||||
Message msg = mServiceHandler.obtainMessage();
|
Message msg = mServiceHandler.obtainMessage();
|
||||||
msg.arg1 = MSG_CONNECT;
|
msg.arg1 = MSG_CONNECT;
|
||||||
msg.arg2 = 0;
|
msg.arg2 = 0;
|
||||||
@ -177,7 +172,7 @@ public class OPTelemetryService extends Service {
|
|||||||
return (TelemTask) activeTelem;
|
return (TelemTask) activeTelem;
|
||||||
}
|
}
|
||||||
public void openConnection() {
|
public void openConnection() {
|
||||||
Toast.makeText(getApplicationContext(), "Requested open connection", Toast.LENGTH_SHORT);
|
Toast.makeText(getApplicationContext(), "Requested open connection", Toast.LENGTH_SHORT).show();
|
||||||
Message msg = mServiceHandler.obtainMessage();
|
Message msg = mServiceHandler.obtainMessage();
|
||||||
msg.arg1 = MSG_CONNECT;
|
msg.arg1 = MSG_CONNECT;
|
||||||
mServiceHandler.sendMessage(msg);
|
mServiceHandler.sendMessage(msg);
|
||||||
@ -296,9 +291,10 @@ public class OPTelemetryService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( ! bt.getConnected() ) {
|
if( ! bt.getConnected() ) {
|
||||||
|
toastMessage("BT connection failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
toastMessage("BT Connected");
|
||||||
|
|
||||||
if (DEBUG) Log.d(TAG, "Connected via bluetooth");
|
if (DEBUG) Log.d(TAG, "Connected via bluetooth");
|
||||||
|
|
||||||
@ -352,8 +348,8 @@ public class OPTelemetryService extends Service {
|
|||||||
|
|
||||||
tcp.connect(objMngr);
|
tcp.connect(objMngr);
|
||||||
|
|
||||||
if (DEBUG) Log.d(TAG, "Done attempting connection");
|
|
||||||
if( tcp.getConnected() )
|
if( tcp.getConnected() )
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -364,10 +360,11 @@ public class OPTelemetryService extends Service {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( ! tcp.getConnected() ) {
|
if( ! tcp.getConnected() || terminate ) {
|
||||||
|
toastMessage("TCP connection failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
toastMessage("TCP Connected");
|
||||||
|
|
||||||
if (DEBUG) Log.d(TAG, "Connected via network");
|
if (DEBUG) Log.d(TAG, "Connected via network");
|
||||||
|
|
||||||
@ -395,20 +392,4 @@ public class OPTelemetryService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void postNotification(int id, String message) {
|
|
||||||
String ns = Context.NOTIFICATION_SERVICE;
|
|
||||||
NotificationManager mNManager = (NotificationManager) getSystemService(ns);
|
|
||||||
final Notification msg = new Notification(R.drawable.icon, message, System.currentTimeMillis());
|
|
||||||
|
|
||||||
Context context = getApplicationContext();
|
|
||||||
CharSequence contentTitle = "OpenPilot";
|
|
||||||
CharSequence contentText = message;
|
|
||||||
Intent msgIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://forums.openpilot.org"));
|
|
||||||
PendingIntent intent = PendingIntent.getActivity(this, 0, msgIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
|
|
||||||
msg.setLatestEventInfo(context, contentTitle, contentText, intent);
|
|
||||||
|
|
||||||
mNManager.notify(id, msg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user