Skip to content

Commit

Permalink
merged changes from v1.0.1 with master
Browse files Browse the repository at this point in the history
  • Loading branch information
bayosip committed Aug 9, 2021
1 parent 0e71c88 commit f58022e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ public void onCharacteristicRead(BluetoothGatt gatt,

}
broadcastUpdate(Constants.ACTION_DATA_AVAILABLE, characteristic);
broadcastUpdateRaw(Constants.ACTION_RAW_DATA_AVAILABLE, characteristic);
Log.i(TAG, "onCharacteristicRead: xchar: " + characteristic.getUuid() + ", read:"
+ characteristic.getStringValue(0));
break;
Expand Down Expand Up @@ -238,8 +239,11 @@ public void onCharacteristicChanged(BluetoothGatt gatt,
// Get the UUID of the characteristic that changed
String uuid = characteristic.getUuid().toString();
mydata= characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_SINT32,0);
Log.d(TAG, "onCharacteristicChanged: "+ mydata +
", hex: "+ characteristic.getStringValue(0));
// Tell the activity that new car data is available
broadcastUpdate(Constants.ACTION_DATA_AVAILABLE);
broadcastUpdate(Constants.ACTION_BLE_CHARX_DATA_CHANGE, characteristic);
broadcastUpdateRaw(Constants.ACTION_BLE_CHARX_DATA_CHANGE_RAW, characteristic);
}

@Override
Expand Down Expand Up @@ -284,7 +288,7 @@ private void broadcastUpdate(final String action,
private void broadcastUpdate(final String action,
final BluetoothGattCharacteristic characteristic) {
final Intent intent = new Intent(action);

intent.putExtra(Constants.EXTRA_UUID, characteristic.getUuid().toString());
// This is special handling for the Heart Rate Measurement profile. Data
// parsing is carried out as per profile specifications.
if (characteristic.getProperties() == BluetoothGattCharacteristic.PROPERTY_NOTIFY||
Expand All @@ -310,6 +314,16 @@ private void broadcastUpdate(final String action,
sendBroadcast(intent);
}

private void broadcastUpdateRaw(final String action,
final BluetoothGattCharacteristic characteristic){
final Intent intent = new Intent(action);
intent.putExtra(Constants.EXTRA_UUID, characteristic.getUuid().toString());

final byte[] data = characteristic.getValue();
intent.putExtra(Constants.EXTRA_DATA_RAW, data);
sendBroadcast(intent);
}

/**
* Initialize a reference to the local Bluetooth adapter.
* @return Return true if the initialization is successful.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public class Constants {
public final static String ACTION_DISCONNECTED ="BleGattService.ACTION_DISCONNECTED";
public final static String ACTION_BLE_SERVICES_DISCOVERED = "BleGattService.ACTION_BLE_SERVICES_DISCOVERED";
public final static String ACTION_DATA_AVAILABLE ="BleGattService.ACTION_DATA_AVAILABLE";
public final static String ACTION_RAW_DATA_AVAILABLE ="BleGattService.ACTION_RAW_DATA_AVAILABLE";
public final static String ACTION_BLE_CHARX_DATA_CHANGE = "BleGattService.ACTION_CHARX_CHANGE";
public final static String ACTION_BLE_CHARX_DATA_CHANGE_RAW = "BleGattService.ACTION_CHARX_CHANGE_RAW";
public final static String EXTRA_DATA = "BleGattService.EXTRA_DATA";
public final static String EXTRA_DATA_BATTERY = "Battery Data";
public final static String EXTRA_DATA_RAW= "BleGattService.EXTRA_DATA_RAW";
public final static String EXTRA_UUID = "BleGattService.CHARX_UUID";
public final static String EXTRA_DATA_BATTERY = "BleGattService.BATTERY_DATA";
}

0 comments on commit f58022e

Please sign in to comment.