Slide 1

Slide 1 text

Promisified BLE Client Masayuki IZUMI - @izumin5210 potatotips #21 https://www.flickr.com/photos/dewittkower/4641701143/

Slide 2

Slide 2 text

 Rekimoto Lab. at the University of Tokyo (2008-2015: Akashi-NCT)  Enginner at Wantedly, Inc. (2014.9-2015.2: Dmetlabel, Inc.) 2

Slide 3

Slide 3 text

2 Ruby JavaScript Android Design pry(main) > izumin.skill_ratio

Slide 4

Slide 4 text

http://konashi.ux-xu.com/ https://github.com/YUKAI/konashi-android-sdk/ https://www.flickr.com/photos/36571434@N03/8524872002

Slide 5

Slide 5 text

\ 前回のラブライブ! / kyobashi.dex

Slide 6

Slide 6 text

https://speakerdeck.com/izumin5210/tsurai-ble-on-android

Slide 7

Slide 7 text

Bluetooth GATT GATT Server Service Service

Slide 8

Slide 8 text

Bluetooth GATT GATT Server Service Service Characteristic

Slide 9

Slide 9 text

BLE on Android Central wants data Peripheral has data

Slide 10

Slide 10 text

BLE on Android Central wants data Peripheral has data write value read value

Slide 11

Slide 11 text

Write characteristic value Central wants data Peripheral has data write value

Slide 12

Slide 12 text

Write characteristic value Central wants data Peripheral has data write value BluetoothGatt#writeCharacteristic()

Slide 13

Slide 13 text

Write characteristic value Central wants data Peripheral has data write value BluetoothGatt#writeCharacteristic() (async)

Slide 14

Slide 14 text

Write characteristic value Central wants data Peripheral has data write value BluetoothGatt#writeCharacteristic() BluetoothGattCallback#onCharacteristicWrite() (async)

Slide 15

Slide 15 text

When is the callback registered ? public BluetoothGatt connectGatt ( Context context, boolean autoConnect, BluetoothGattCallback callback )

Slide 16

Slide 16 text

When is the callback registered ? public BluetoothGatt connectGatt ( Context context, boolean autoConnect, BluetoothGattCallback callback ) We can register only 1 instance...

Slide 17

Slide 17 text

Handle callback public void onCharacteristicWrite ( BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { // check characteristic instance, handling... } else { // error handling... } }

Slide 18

Slide 18 text

Handle callback public void onCharacteristicWrite ( BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { // check characteristic instance, handling... } else { // error handling... } }

Slide 19

Slide 19 text

if BG has promise like api ... gatt.writeCharacteristic(characteristic) .then( // call when the operation successfully ) .fail( // call when the operation failure )

Slide 20

Slide 20 text

Bletia https://github.com/izumin5210/Bletia

Slide 21

Slide 21 text

Download dependencies { compile 'info.izumin.android:bletia:1.2.2' }

Slide 22

Slide 22 text

Instantiate / Connect // Pass application context to constructor. Bletia bletia = new Bletia(context); // BluetoothDevice device bletia.connect(device);

Slide 23

Slide 23 text

Instantiate / Connect bletia.writeCharacteristic(characteristic);

Slide 24

Slide 24 text

Write characteristic bletia.writeCharacteristic(characteristic) .then(new DoneCallback() { @Override public void onDone(BluetoothGattCharacteristic result) { // Call when the request was successfully. } });

Slide 25

Slide 25 text

Write characteristic bletia.writeCharacteristic(characteristic) .then(new DoneCallback() { @Override public void onDone(BluetoothGattCharacteristic result) { // Call when the request was successfully. } });

Slide 26

Slide 26 text

Write characteristic bletia.writeCharacteristic(characteristic) .then(new DoneCallback() { @Override public void onDone(BluetoothGattCharacteristic result) { // Call when the request was successfully. } });

Slide 27

Slide 27 text

Write characteristic bletia.writeCharacteristic(characteristic) .fail(new FailCallback() { @OVerride public void onFail(BletiaException result) { // Call when the request was failure. } });

Slide 28

Slide 28 text

Write characteristic bletia.writeCharacteristic(characteristic) .fail(new FailCallback() { @OVerride public void onFail(BletiaException result) { // Call when the request was failure. } });

Slide 29

Slide 29 text

Write characteristic bletia.writeCharacteristic(characteristic) .fail(new FailCallback() { @OVerride public void onFail(BletiaException result) { // Call when the request was failure. } });

Slide 30

Slide 30 text

Support promisified operations (v1.2.2) * readCharacteristic() / writeCharacteristic() * readDescriptor() / writeDescriptor() * enableNotification() * readRemoteRssi()

Slide 31

Slide 31 text

Conclusion Saiko no Experiense with Promise