Upload
takahiro-yamamoto
View
59
Download
6
Embed Size (px)
Citation preview
iOS ✖️ BLE 簡単プロトタイピング
with Swift ✖️ BLE-Serial ✖️ mbed
山本 恭大Takahiro YAMAMOTO
株式会社ニコンシステム
1
自己紹介
• 山本 恭大
• お仕事
• 株式会社ニコンシステム
• カメラ用アプリのMac版の開発
2
今日の発表は業務とは 関係なし
背景スマホエンジニア枠で参加したハッカソン
このアイデア、 なんかデバイス作った方が盛り上がるよね?
OK! じゃあ、俺作るわ(ドヤ顔)
完成度が低いっす。 プレゼンで誤魔化して
でも、結局
どんまい
とか
周辺デバイスも作れないかな?
いや、 今回はアプリだけで勝負しよう
最初から諦めてたり。。。
くやしい!!
https://www.apple.com/watch/ http://ja.wikipedia.org/wiki/Google_Glass
プロトタイプしたいもの
7
ウェアラブルデバイスとか、
スマホから周辺デバイス制御したり、 センサのデータ取り出したい
mbed
iPhone
BLE
http://ja.wikipedia.org/wiki/IPhone
http://www.robotsfx.com/robot/BLESerial.html
http://ja.wikipedia.org/wiki/Mbed
BLE意外と大変
9
10
mbed
iPhone
http://ja.wikipedia.org/wiki/IPhoneGATTATTL2CAP
GAP
BLEプロトコルスタック
link layerLE physical
Bluetooth SIG
英語,200pくらいの資料
http://ja.wikipedia.org/wiki/Mbed
大変!!
なら、そこは作らない
mbed
iPhone
12
ライブラリ
BLE-Serial
BLEプロトコル
ブラックボックス
UART
http://ja.wikipedia.org/wiki/Mbed
http://ja.wikipedia.org/wiki/IPhone
BLE-Serial
http://www.robotsfx.com/robot/BLESerial.html
・UARTで読み書きするだけでBLE通信
・BLEの知識不要
・BLEの大変な部分は全てモジュール側が担当
・¥4200(税込)
13
ライブラリ
・coreBluetoothラッパーライブラリ
14
coreBluetooth
・有名どころ ・YmsCoreBluetooth ・LGBluetooth
英語、objective-c
ラッパーライブラリ
BLESerial用ライブラリ
ライブラリ
https://github.com/TakahiroYamamoto/BLE-Serial
swift日本語で作ってみた
15
ライブラリ• API
• connect
• disconnect
• readBlock
• write以上!!
16
デモ
コード(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") }
if(SciByteRx(&data) > 0){{
if(data == ‘a’)//前進処理{
//前進}else if(data == ‘z’)//後退{
//後退}else if(data == ‘r’)//回転{
//回転}else{ //停止}
}}
コード デバイス側
コード
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側
デバイス側
まとめ• iOSと周辺デバイスをBLEの知識なしで繋げます!
• ライブラリ使ってもらえたら嬉しいです
• プルリクとかもらえたらもっと嬉しいです
• 温泉ハッカソン誰か一緒に出ませんか?
• http://spajam.jp/2015/