22
iOS BLE 簡単プロトタイピング with Swift BLE-Serial mbed 山本 恭大 Takahiro YAMAMOTO 株式会社ニコンシステム 1

I os*ble簡単プロトタイピング

Embed Size (px)

Citation preview

Page 1: I os*ble簡単プロトタイピング

iOS ✖️ BLE 簡単プロトタイピング

with Swift ✖️ BLE-Serial ✖️ mbed

山本 恭大Takahiro YAMAMOTO

株式会社ニコンシステム

1

Page 2: I os*ble簡単プロトタイピング

自己紹介

• 山本 恭大

• お仕事

• 株式会社ニコンシステム

• カメラ用アプリのMac版の開発

2

今日の発表は業務とは 関係なし

Page 3: I os*ble簡単プロトタイピング

背景スマホエンジニア枠で参加したハッカソン

このアイデア、 なんかデバイス作った方が盛り上がるよね?

OK! じゃあ、俺作るわ(ドヤ顔)

Page 4: I os*ble簡単プロトタイピング

完成度が低いっす。 プレゼンで誤魔化して

でも、結局

どんまい

とか

Page 5: I os*ble簡単プロトタイピング

周辺デバイスも作れないかな?

いや、 今回はアプリだけで勝負しよう

最初から諦めてたり。。。

Page 6: I os*ble簡単プロトタイピング

くやしい!!

Page 7: I os*ble簡単プロトタイピング

https://www.apple.com/watch/ http://ja.wikipedia.org/wiki/Google_Glass

プロトタイプしたいもの

7

ウェアラブルデバイスとか、

スマホから周辺デバイス制御したり、 センサのデータ取り出したい

Page 8: I os*ble簡単プロトタイピング

mbed

iPhone

BLE

http://ja.wikipedia.org/wiki/IPhone

http://www.robotsfx.com/robot/BLESerial.html

http://ja.wikipedia.org/wiki/Mbed

Page 9: I os*ble簡単プロトタイピング

BLE意外と大変

9

Page 10: I os*ble簡単プロトタイピング

10

mbed

iPhone

http://ja.wikipedia.org/wiki/IPhoneGATTATTL2CAP

GAP

BLEプロトコルスタック

link layerLE physical

Bluetooth SIG

英語,200pくらいの資料

http://ja.wikipedia.org/wiki/Mbed

Page 11: I os*ble簡単プロトタイピング

大変!!

なら、そこは作らない

Page 12: I os*ble簡単プロトタイピング

mbed

iPhone

12

ライブラリ

BLE-Serial

BLEプロトコル

ブラックボックス

UART

http://ja.wikipedia.org/wiki/Mbed

http://ja.wikipedia.org/wiki/IPhone

Page 13: I os*ble簡単プロトタイピング

BLE-Serial

http://www.robotsfx.com/robot/BLESerial.html

・UARTで読み書きするだけでBLE通信

・BLEの知識不要

・BLEの大変な部分は全てモジュール側が担当

・¥4200(税込)

13

Page 14: I os*ble簡単プロトタイピング

ライブラリ

・coreBluetoothラッパーライブラリ

14

coreBluetooth

・有名どころ   ・YmsCoreBluetooth   ・LGBluetooth

英語、objective-c

ラッパーライブラリ

BLESerial用ライブラリ

Page 15: I os*ble簡単プロトタイピング

ライブラリ

https://github.com/TakahiroYamamoto/BLE-Serial

swift日本語で作ってみた

15

Page 16: I os*ble簡単プロトタイピング

ライブラリ• API

• connect

• disconnect

• readBlock

• write以上!!

16

Page 17: I os*ble簡単プロトタイピング

デモ

Page 18: I os*ble簡単プロトタイピング
Page 19: I os*ble簡単プロトタイピング

コード(iOS側)

19

@IBAction func prev(sender:AnyObject) //前進ボタン { var communicator : BLECommunicator = BLECommunicator.sharedInstance communicator.write("a") } @IBAction func back(sender:AnyObject) //後退ボタン { var communicator : BLECommunicator = BLECommunicator.sharedInstance communicator.write("z") } @IBAction func rotate(sender:AnyObject) //回転ボタン { var communicator : BLECommunicator = BLECommunicator.sharedInstance communicator.write("r") } @IBAction func stop(sender:AnyObject) //停止ボタン { var communicator : BLECommunicator = BLECommunicator.sharedInstance communicator.write("o") }

Page 20: I os*ble簡単プロトタイピング

if(SciByteRx(&data) > 0){{

if(data == ‘a’)//前進処理{

//前進}else if(data == ‘z’)//後退{

//後退}else if(data == ‘r’)//回転{

//回転}else{ //停止}

}}

コード デバイス側

Page 21: I os*ble簡単プロトタイピング

コード

GetEncoder(&right_b,&left_b); char str[256]; sprintf(str,"r:%d,l:%d",right_b - right , left_b - left);

communicator.readBlock = {string in }

iOS側

デバイス側

Page 22: I os*ble簡単プロトタイピング

まとめ• iOSと周辺デバイスをBLEの知識なしで繋げます!

• ライブラリ使ってもらえたら嬉しいです

• プルリクとかもらえたらもっと嬉しいです

• 温泉ハッカソン誰か一緒に出ませんか?

• http://spajam.jp/2015/