BLEでiPadをMacにマウスとして接続する気だった、今は反省している
概要
ZBrushやっててさくさく削りたくなったので、
iPadでキー+マウス操作を行い、Macに送り込むツールを自作することにした。
以前作った、「wifiでディスプレイの一部をiPad上に切り取って筆圧付きペンで部分ペンタブを実現する奴」とは異なり、
・サーバアプリケーション無し
・アスペクト比固定
みたいな省力版が作りたい。
というかやりたいことは快適なモデリングなんだよ。
要件定義、設計
ソフトウェアの要件定義とジェスチャの設計としてはこんな感じ。
はい、描いた人にしかわかりませんね!
調べるその1 サンプル
サンプルを探す。
安定のgithub検索
https://github.com/search?utf8=✓&q=iOS+ble&type=Repositories&ref=searchresults
以下がそのまま動かせた。
https://github.com/khr128/BTPeripheralIPhone
んで、Peripheralって何って話が始まる。
以下が参考になった。
http://reinforce-lab.github.io/blog/2013/01/21/ios-ble-introduction/
調べるその2 規格と仕様について
やりたいこととしては、
BLE使って、iPadをMacにマウスとして認識させる
なので、以下のような話が始まる。
・まずBTマウスはどうやってMacにつながってるのか
→BTLEマウスがあるんなら調べなくてよさそう
・BTLEマウスってあるのか
→あった
・Macでドングル無しでつかえんの?
→使えた。キャリブレーションめっちゃ怪しい。
・iOSをマウスとして接続できるのか
→MacをCentral、iOS側をPeripheralにできる!
→既存でできてるマウスがあるんだしできるのでは?
→というわけであとは試してみることに。
実装
死霊++
Bluetooth のプロファイルについて調べたことのまとめ
http://d.hatena.ne.jp/shu223/touch/20140109/1389216052
CoreBluetooth
Eng
Jp
https://developer.apple.com/jp/devcenter/ios/library/documentation/CoreBluetoothPG.pdf
で、HID over GATT Profile (HOGP)について、以下のサービスが必要。
Hunan Interface Device Service (0x1812)
https://devzone.nordicsemi.com/documentation/nrf51/4.1.0/html/group__ble__sdk__srv__hids.html
と、
Device Information Service (0x180A)
https://devzone.nordicsemi.com/documentation/nrf51/4.1.0/html/group__ble__sdk__srv__dis.html
と、
Battery Service (0x180F)
https://devzone.nordicsemi.com/documentation/nrf51/4.1.0/html/group__ble__sdk__srv__bas.html
1812とか、それぞれのAssignedNumberは、下記に書いてあった。
https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx
→Macへの接続状況をしらべてみたところで、ServiceのIDを1812系に変えたら、
Serviceのadd時に
The specified UUID is not allowed for this operation.
というエラーがでた。なるほど使っちゃ駄目と。
詳しく書くと以下の箇所でエラーが出る。
- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral {
switch (peripheral.state) {
case CBPeripheralManagerStatePoweredOn:{
CBUUID *serviceId = [CBUUID UUIDWithString:@"00001812-0000-1000-8000-00805F9B34FB"];
cbService = [[CBMutableService alloc] initWithType:serviceId primary:YES];
[cBPManager addService:cbService];// <- このあとでおこ The specified UUID is not allowed for this operation.
break;
}
default:
NSLog(@"hereComes");
break;
}
}
はい。
駄目だそうです。
ちなみにiOSでCoreBluetoothを使ってPeripheralになろうとして怒られる AssignedNumber の一覧は無かったので作った。
こんな感じ。
|
|
|
dead | alive |
org.bluetooth.service.alert_notification |
0x1811 |
ok |
|
org.bluetooth.service.battery_service |
0x180F |
denied |
|
org.bluetooth.service.blood_pressure |
0x1810 |
ok |
|
org.bluetooth.service.current_time |
0x1805 |
denied |
|
org.bluetooth.service.cycling_power |
0x1818 |
ok |
|
org.bluetooth.service.cycling_speed_and_cadence |
0x1816 |
ok |
|
org.bluetooth.service.device_information |
0x180A |
ok |
|
org.bluetooth.service.generic_access |
0x1800 |
denied |
|
org.bluetooth.service.generic_attribute |
0x1801 |
denied |
|
org.bluetooth.service.glucose |
0x1808 |
ok |
|
org.bluetooth.service.health_thermometer |
0x1809 |
ok |
|
org.bluetooth.service.heart_rate |
0x180D |
ok |
|
org.bluetooth.service.human_interface_device |
0x1812 |
denied |
|
org.bluetooth.service.immediate_alert |
0x1802 |
ok |
|
org.bluetooth.service.link_loss |
0x1803 |
ok |
|
org.bluetooth.service.location_and_navigation |
0x1819 |
ok |
|
org.bluetooth.service.next_dst_change |
0x1807 |
ok |
|
org.bluetooth.service.phone_alert_status |
0x180E |
ok |
|
org.bluetooth.service.reference_time_update |
0x1806 |
ok |
|
org.bluetooth.service.running_speed_and_cadence |
0x1814 |
ok |
|
org.bluetooth.service.scan_parameters |
0x1813 |
ok |
|
org.bluetooth.service.tx_power |
0x1804 |
ok |
|
org.bluetooth.service.user_data |
0x181C |
ok |
最終的な結論は、「iOSをPeripheralにしてHOGP(とあといくつかのAssignedNumber)を使うのは無理。」
おまけ
Macに限定するならこっちでつくるかなあ、、
Bonjour
http://qiita.com/feb19/items/da07d96619acb933a3c3