本文整理匯總了Java中android.bluetooth.BluetoothGattCharacteristic.setWriteType方法的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothGattCharacteristic.setWriteType方法的具體用法?Java BluetoothGattCharacteristic.setWriteType怎麽用?Java BluetoothGattCharacteristic.setWriteType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.bluetooth.BluetoothGattCharacteristic
的用法示例。
在下文中一共展示了BluetoothGattCharacteristic.setWriteType方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setLights
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
public void setLights(BluetoothUtil bluetoothUtil,int state) {
lightMode.set(state);
BluetoothGattCharacteristic lc = null;
ByteBuffer v = ByteBuffer.allocate(2);
lc = bluetoothUtil.getCharacteristic(OWDevice.OnewheelCharacteristicLightingMode);
v.putShort((short) state);
if (lc != null) {
lc.setValue(v.array());
lc.setWriteType(2);
bluetoothUtil.writeCharacteristic(lc);
EventBus.getDefault().post(new DeviceStatusEvent("LIGHTS SET TO STATE:" + state));
}
}
示例2: setRideMode
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
public void setRideMode(BluetoothUtil bluetoothUtil, int ridemode) {
Log.d(TAG,"setRideMode() called for gatt:" + ridemode);
BluetoothGattCharacteristic lc = bluetoothUtil.getCharacteristic(OWDevice.OnewheelCharacteristicRidingMode);
if (lc != null) {
ByteBuffer var2 = ByteBuffer.allocate(2);
var2.putShort((short) ridemode);
lc.setValue(var2.array());
lc.setWriteType(2);
bluetoothUtil.writeCharacteristic(lc);
//setDeviceCharacteristicDisplay("ride_mode","ridemode: " + ridemode);
}
}
示例3: setCharacteristicValue
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
public void setCharacteristicValue(BluetoothGattService gattService, BluetoothGatt gatt, String k, int v) {
DeviceCharacteristic dc = getDeviceCharacteristicByKey(k);
if (dc != null) {
BluetoothGattCharacteristic lc = null;
lc = gattService.getCharacteristic(UUID.fromString(dc.uuid.get()));
if (lc != null) {
ByteBuffer var2 = ByteBuffer.allocate(2);
var2.putShort((short) v);
lc.setValue(var2.array());
lc.setWriteType(2);
gatt.writeCharacteristic(lc);
EventBus.getDefault().post(new DeviceStatusEvent("SET " + k + " TO " + v));
}
}
}
示例4: writeImageSize
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
/**
* Writes the image size to the characteristic. This method is SYNCHRONOUS and wait until the {@link android.bluetooth.BluetoothGattCallback#onCharacteristicWrite(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic, int)}
* will be called or the connection state will change from {@link #STATE_CONNECTED_AND_READY}. If connection state will change, or an error will occur, an exception will be thrown.
*
* @param gatt the GATT device
* @param characteristic the characteristic to write to. Should be the DFU PACKET
* @param imageSize the image size in bytes
* @throws DeviceDisconnectedException
* @throws DfuException
* @throws UploadAbortedException
*/
private void writeImageSize(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic, final int imageSize) throws DeviceDisconnectedException, DfuException,
UploadAbortedException {
mReceivedData = null;
mError = 0;
mImageSizeSent = false;
characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
characteristic.setValue(new byte[4]);
characteristic.setValue(imageSize, BluetoothGattCharacteristic.FORMAT_UINT32, 0);
sendLogBroadcast(LOG_LEVEL_VERBOSE, "Writing to characteristic " + characteristic.getUuid());
sendLogBroadcast(LOG_LEVEL_DEBUG, "gatt.writeCharacteristic(" + characteristic.getUuid() + ")");
gatt.writeCharacteristic(characteristic);
// We have to wait for confirmation
try {
synchronized (mLock) {
while ((!mImageSizeSent && mConnectionState == STATE_CONNECTED_AND_READY && mError == 0 && !mAborted) || mPaused)
mLock.wait();
}
} catch (final InterruptedException e) {
loge("Sleeping interrupted", e);
}
if (mAborted)
throw new UploadAbortedException();
if (mError != 0)
throw new DfuException("Unable to write Image Size", mError);
if (mConnectionState != STATE_CONNECTED_AND_READY)
throw new DeviceDisconnectedException("Unable to write Image Size", mConnectionState);
}
示例5: writeInitPacket
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
/**
* Writes the Init packet to the characteristic. This method is SYNCHRONOUS and wait until the {@link android.bluetooth.BluetoothGattCallback#onCharacteristicWrite(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic, int)}
* will be called or the connection state will change from {@link #STATE_CONNECTED_AND_READY}. If connection state will change, or an error will occur, an exception will be thrown.
*
* @param gatt the GATT device
* @param characteristic the characteristic to write to. Should be the DFU PACKET
* @param buffer the init packet as a byte array. This must be shorter or equal to 20 bytes (TODO check this restriction).
* @param size the init packet size
* @throws DeviceDisconnectedException
* @throws DfuException
* @throws UploadAbortedException
*/
private void writeInitPacket(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic, final byte[] buffer, final int size) throws DeviceDisconnectedException, DfuException,
UploadAbortedException {
byte[] locBuffer = buffer;
if (buffer.length != size) {
locBuffer = new byte[size];
System.arraycopy(buffer, 0, locBuffer, 0, size);
}
mReceivedData = null;
mError = 0;
mInitPacketSent = false;
characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
characteristic.setValue(locBuffer);
logi("Sending init packet (Value = " + parse(locBuffer) + ")");
sendLogBroadcast(LOG_LEVEL_VERBOSE, "Writing to characteristic " + characteristic.getUuid());
sendLogBroadcast(LOG_LEVEL_DEBUG, "gatt.writeCharacteristic(" + characteristic.getUuid() + ")");
gatt.writeCharacteristic(characteristic);
// We have to wait for confirmation
try {
synchronized (mLock) {
while ((!mInitPacketSent && mConnectionState == STATE_CONNECTED_AND_READY && mError == 0 && !mAborted) || mPaused)
mLock.wait();
}
} catch (final InterruptedException e) {
loge("Sleeping interrupted", e);
}
if (mAborted)
throw new UploadAbortedException();
if (mError != 0)
throw new DfuException("Unable to write Init DFU Parameters", mError);
if (mConnectionState != STATE_CONNECTED_AND_READY)
throw new DeviceDisconnectedException("Unable to write Init DFU Parameters", mConnectionState);
}