don't crash when not connected

This commit is contained in:
2019-03-16 19:29:42 -04:00
parent d711ee6df6
commit c0c46972de
2 changed files with 6 additions and 7 deletions

View File

@@ -221,6 +221,7 @@ public class MainActivity extends Activity implements RadioGroup.OnCheckedChange
btnConnectDisconnect.setText("Disconnect");
edtMessage.setEnabled(true);
btnSend.setEnabled(true);
btnRainbow.setEnabled(true);
((TextView) findViewById(R.id.deviceName)).setText(mDevice.getName()+ " - ready");
listAdapter.add("["+currentDateTimeString+"] Connected to: "+ mDevice.getName());
messageListView.smoothScrollToPosition(listAdapter.getCount() - 1);
@@ -238,8 +239,9 @@ public class MainActivity extends Activity implements RadioGroup.OnCheckedChange
btnConnectDisconnect.setText("Connect");
edtMessage.setEnabled(false);
btnSend.setEnabled(false);
btnRainbow.setEnabled(false);
((TextView) findViewById(R.id.deviceName)).setText("Not Connected");
listAdapter.add("["+currentDateTimeString+"] Disconnected to: "+ mDevice.getName());
listAdapter.add("["+currentDateTimeString+"] Disconnected from: "+ mDevice.getName());
mState = UART_PROFILE_DISCONNECTED;
mService.close();
//setUiState();

View File

@@ -311,8 +311,7 @@ public class UartService extends Service {
*
* @return
*/
public void enableTXNotification()
{
public void enableTXNotification() {
/*
if (mBluetoothGatt == null) {
showMessage("mBluetoothGatt null" + mBluetoothGatt);
@@ -358,11 +357,9 @@ public class UartService extends Service {
writeRXCharacteristic(dataCrc);
}
public void writeRXCharacteristic(byte[] value)
{
public void writeRXCharacteristic(byte[] value) {
BluetoothGattService RxService = mBluetoothGatt.getService(RX_SERVICE_UUID);
showMessage("mBluetoothGatt null"+ mBluetoothGatt);
showMessage("mBluetoothGatt " + mBluetoothGatt);
if (RxService == null) {
showMessage("Rx service not found!");
broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART);