Java Code Examples for android.bluetooth.BluetoothGattCharacteristic#equals()
The following examples show how to use
android.bluetooth.BluetoothGattCharacteristic#equals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SensorTagMovementProfile.java From SensorTag-CC2650 with Apache License 2.0 | 6 votes |
@Override public void didUpdateValueForCharacteristic(BluetoothGattCharacteristic c) { byte[] value = c.getValue(); if (c.equals(this.dataC)){ Point3D v; v = Sensor.MOVEMENT_ACC.convert(value); if (this.tRow.config == false) this.tRow.value.setText(Html.fromHtml(String.format("<font color=#FF0000>X:%.2fG</font>, <font color=#00967D>Y:%.2fG</font>, <font color=#00000>Z:%.2fG</font>", v.x, v.y, v.z))); this.tRow.sl1.addValue((float)v.x); this.tRow.sl2.addValue((float)v.y); this.tRow.sl3.addValue((float)v.z); v = Sensor.MOVEMENT_GYRO.convert(value); SensorTagMovementTableRow row = (SensorTagMovementTableRow)this.tRow; row.gyroValue.setText(Html.fromHtml(String.format("<font color=#FF0000>X:%.2f°/s</font>, <font color=#00967D>Y:%.2f°/s</font>, <font color=#00000>Z:%.2f°/s</font>", v.x, v.y, v.z))); row.sl4.addValue((float)v.x); row.sl5.addValue((float)v.y); row.sl6.addValue((float)v.z); v = Sensor.MOVEMENT_MAG.convert(value); row.magValue.setText(Html.fromHtml(String.format("<font color=#FF0000>X:%.2fuT</font>, <font color=#00967D>Y:%.2fuT</font>, <font color=#00000>Z:%.2fuT</font>", v.x, v.y, v.z))); row.sl7.addValue((float)v.x); row.sl8.addValue((float)v.y); row.sl9.addValue((float)v.z); } }
Example 2
Source File: SensorTagBarometerProfile.java From SensorTag-CC2650 with Apache License 2.0 | 6 votes |
@Override public void didUpdateValueForCharacteristic(BluetoothGattCharacteristic c) { byte[] value = c.getValue(); if (c.equals(this.dataC)){ Point3D v; v = Sensor.BAROMETER.convert(value); if (!(this.isHeightCalibrated)) { BarometerCalibrationCoefficients.INSTANCE.heightCalibration = v.x; //Toast.makeText(this.tRow.getContext(), "Height measurement calibrated", // Toast.LENGTH_SHORT).show(); this.isHeightCalibrated = true; } double h = (v.x - BarometerCalibrationCoefficients.INSTANCE.heightCalibration) / PA_PER_METER; h = (double) Math.round(-h * 10.0) / 10.0; //msg = decimal.format(v.x / 100.0f) + "\n" + h; if (this.tRow.config == false) this.tRow.value.setText(String.format("%.1f mBar %.1f meter", v.x / 100, h)); this.tRow.sl1.addValue((float)v.x / 100.0f); //mBarValue.setText(msg); } }
Example 3
Source File: CharacteristicDetailsAdapter.java From BLEService with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void newValueForCharacteristic(final BluetoothGattCharacteristic ch, final String strVal, final int intVal, final byte[] rawValue, final String timestamp) { if(!ch.equals(this.mCharacteristic)) return; mIntValue = intVal; mStrValue = strVal; mRawValue = rawValue; if (mRawValue != null && mRawValue.length > 0) { final StringBuilder stringBuilder = new StringBuilder(mRawValue.length); for(byte byteChar : mRawValue) stringBuilder.append(String.format("%02X", byteChar)); mAsciiValue = "0x" + stringBuilder.toString(); } else mAsciiValue = ""; mLastUpdateTime = timestamp; if(mLastUpdateTime == null) mLastUpdateTime = ""; }
Example 4
Source File: SensorTagAmbientTemperatureProfile.java From SensorTag-CC2650 with Apache License 2.0 | 5 votes |
@Override public void didUpdateValueForCharacteristic(BluetoothGattCharacteristic c) { byte[] value = c.getValue(); if (c.equals(this.dataC)){ Point3D v = Sensor.IR_TEMPERATURE.convert(value); if (this.tRow.config == false) { if ((this.isEnabledByPrefs("imperial")) == true) this.tRow.value.setText(String.format("%.1f°F", (v.x * 1.8) + 32)); else this.tRow.value.setText(String.format("%.1f°C", v.x)); } this.tRow.sl1.addValue((float)v.x); } }
Example 5
Source File: SensorTagAccelerometerProfile.java From SensorTag-CC2650 with Apache License 2.0 | 5 votes |
@Override public void didUpdateValueForCharacteristic(BluetoothGattCharacteristic c) { if (c.equals(this.dataC)){ Point3D v = Sensor.ACCELEROMETER.convert(this.dataC.getValue()); if (this.tRow.config == false) this.tRow.value.setText(String.format("X:%.2fG, Y:%.2fG, Z:%.2fG", v.x,v.y,v.z)); this.tRow.sl1.addValue((float)v.x); this.tRow.sl2.addValue((float)v.y); this.tRow.sl3.addValue((float)v.z); } }
Example 6
Source File: SensorTagLuxometerProfile.java From SensorTag-CC2650 with Apache License 2.0 | 5 votes |
@Override public void didUpdateValueForCharacteristic(BluetoothGattCharacteristic c) { byte[] value = c.getValue(); if (c.equals(this.dataC)){ Point3D v = Sensor.LUXOMETER.convert(value); if (this.tRow.config == false) this.tRow.value.setText(String.format("%.1f Lux", v.x)); this.tRow.sl1.addValue((float)v.x); } }
Example 7
Source File: SensorTagHumidityProfile.java From SensorTag-CC2650 with Apache License 2.0 | 5 votes |
@Override public void didUpdateValueForCharacteristic(BluetoothGattCharacteristic c) { byte[] value = c.getValue(); if (c.equals(this.dataC)){ Point3D v; if (SensorTagUtil.isSensorTag2(mBTDevice)) { v = Sensor.HUMIDITY2.convert(value); } else v = Sensor.HUMIDITY.convert(value); if (this.tRow.config == false) this.tRow.value.setText(String.format("%.1f %%rH", v.x)); this.tRow.sl1.maxVal = 100; this.tRow.sl1.minVal = 0; this.tRow.sl1.addValue((float)v.x); } }
Example 8
Source File: GenericBluetoothProfile.java From SensorTag-CC2650 with Apache License 2.0 | 5 votes |
public void didReadValueForCharacteristic(BluetoothGattCharacteristic c) { if (this.periodC != null) { if (c.equals(this.periodC)) { byte[] value = c.getValue(); this.periodWasUpdated(value[0] * 10); } } }
Example 9
Source File: Node.java From BlueSTSDK_Android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * receive the notification change * @param gatt connection with the device * @param characteristic updated characteristic */ @Override public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { //Log.d(TAG,"Change Char: "+characteristic.getUuid().toString()); //if it comes form the console service we send to it if(mDebugConsole!=null && BLENodeDefines.Services.Debug.isDebugCharacteristics(characteristic.getUuid())) mDebugConsole.receiveCharacteristicsUpdate(characteristic); else if(characteristic.equals(mFeatureCommand)) //if it is the commandCharacteristics dispatchCommandResponseData(characteristic); else if (mConfigControl != null && characteristic.getUuid().equals(BLENodeDefines.Services.Config.REGISTERS_ACCESS_UUID)) mConfigControl.characteristicsUpdate(characteristic); else //otherwise is a feature characteristics updateFeature(characteristic); }
Example 10
Source File: HRDemoActivity.java From BLEService with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { if(characteristic.equals(mBTValueCharacteristic)) { getAndDisplayHrValue(); } }
Example 11
Source File: BleManagerHandler.java From Android-BLE-Library with BSD 3-Clause "New" or "Revised" License | 4 votes |
final void onCharacteristicWriteRequest(@NonNull final BluetoothGattServer server, @NonNull final BluetoothDevice device, final int requestId, @NonNull final BluetoothGattCharacteristic characteristic, final boolean preparedWrite, final boolean responseNeeded, final int offset, @NonNull final byte[] value) { log(Log.DEBUG, "[Server callback] Write " + (responseNeeded ? "request" : "command") + " to characteristic " + characteristic.getUuid() + " (requestId=" + requestId + ", prepareWrite=" + preparedWrite + ", responseNeeded=" + responseNeeded + ", offset: " + offset + ", value=" + ParserUtils.parseDebug(value) + ")"); if (offset == 0) { final String type = responseNeeded ? "WRITE REQUEST" : "WRITE COMMAND"; final String option = preparedWrite ? "Prepare " : ""; log(Log.INFO, "[Server] " + option + type + " for characteristic " + characteristic.getUuid() + " received, value: " + ParserUtils.parse(value)); } if (responseNeeded) { sendResponse(server, device, BluetoothGatt.GATT_SUCCESS, requestId, offset, value); } // If Prepare Write or Long Write is sent, store the data in a temporary queue until it's executed. if (preparedWrite) { if (preparedValues == null) { preparedValues = new LinkedList<>(); } if (offset == 0) { // Add new value to the operations. preparedValues.offer(new Pair<>(characteristic, value)); } else { // Concatenate the value to the end of previous value, if the previous request was // also for the same characteristic. final Pair<Object, byte[]> last = preparedValues.peekLast(); if (last != null && characteristic.equals(last.first)) { preparedValues.pollLast(); preparedValues.offer(new Pair<>(characteristic, Bytes.concat(last.second, value, offset))); } else { prepareError = BluetoothGatt.GATT_INVALID_OFFSET; } } } else { // Otherwise, save the data immediately. if (assignAndNotify(device, characteristic, value) || checkCondition()) { nextRequest(true); } } }
Example 12
Source File: SensorTagSimpleKeysProfile.java From SensorTag-CC2650 with Apache License 2.0 | 4 votes |
@Override public void didUpdateValueForCharacteristic(BluetoothGattCharacteristic c) { SensorTagSimpleKeysTableRow tmpRow = (SensorTagSimpleKeysTableRow) this.tRow; if (c.equals(this.dataC)){ byte[] value = c.getValue(); switch(value[0]) { case 0x1: tmpRow.leftKeyPressStateImage.setImageResource(R.drawable.leftkeyon_300); tmpRow.rightKeyPressStateImage.setImageResource(R.drawable.rightkeyoff_300); tmpRow.reedStateImage.setImageResource(R.drawable.reedrelayoff_300); break; case 0x2: tmpRow.leftKeyPressStateImage.setImageResource(R.drawable.leftkeyoff_300); tmpRow.rightKeyPressStateImage.setImageResource(R.drawable.rightkeyon_300); tmpRow.reedStateImage.setImageResource(R.drawable.reedrelayoff_300); break; case 0x3: tmpRow.leftKeyPressStateImage.setImageResource(R.drawable.leftkeyon_300); tmpRow.rightKeyPressStateImage.setImageResource(R.drawable.rightkeyon_300); tmpRow.reedStateImage.setImageResource(R.drawable.reedrelayoff_300); break; case 0x4: tmpRow.leftKeyPressStateImage.setImageResource(R.drawable.leftkeyoff_300); tmpRow.rightKeyPressStateImage.setImageResource(R.drawable.rightkeyoff_300); tmpRow.reedStateImage.setImageResource(R.drawable.reedrelayon_300); break; case 0x5: tmpRow.leftKeyPressStateImage.setImageResource(R.drawable.leftkeyon_300); tmpRow.rightKeyPressStateImage.setImageResource(R.drawable.rightkeyoff_300); tmpRow.reedStateImage.setImageResource(R.drawable.reedrelayon_300); break; case 0x6: tmpRow.leftKeyPressStateImage.setImageResource(R.drawable.leftkeyoff_300); tmpRow.rightKeyPressStateImage.setImageResource(R.drawable.rightkeyon_300); tmpRow.reedStateImage.setImageResource(R.drawable.reedrelayon_300); break; case 0x7: tmpRow.leftKeyPressStateImage.setImageResource(R.drawable.leftkeyon_300); tmpRow.rightKeyPressStateImage.setImageResource(R.drawable.rightkeyon_300); tmpRow.reedStateImage.setImageResource(R.drawable.reedrelayon_300); break; default: tmpRow.leftKeyPressStateImage.setImageResource(R.drawable.leftkeyoff_300); tmpRow.rightKeyPressStateImage.setImageResource(R.drawable.rightkeyoff_300); tmpRow.reedStateImage.setImageResource(R.drawable.reedrelayoff_300); break; } tmpRow.lastKeys = value[0]; } }
Example 13
Source File: GenericBluetoothProfile.java From SensorTag-CC2650 with Apache License 2.0 | 4 votes |
public boolean isDataC(BluetoothGattCharacteristic c) { if (this.dataC == null) return false; if (c.equals(this.dataC)) return true; else return false; }
Example 14
Source File: CharacteristicDetailsAdapter.java From BLEService with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void setNotificationEnabledForService(final BluetoothGattCharacteristic ch) { if((!ch.equals(this.mCharacteristic)) || (mNotificationEnabled == true)) return; mNotificationEnabled = true; notifyDataSetChanged(); }