BLEでiPadをMacにマウスとして接続する気だった、今は反省している


概要

ZBrushやっててさくさく削りたくなったので、

iPadでキー+マウス操作を行い、Macに送り込むツールを自作することにした。


以前作った、「wifiでディスプレイの一部をiPad上に切り取って筆圧付きペンで部分ペンタブを実現する奴」とは異なり、

・サーバアプリケーション無し

・アスペクト比固定

みたいな省力版が作りたい。


というかやりたいことは快適なモデリングなんだよ。



要件定義、設計

ソフトウェアの要件定義とジェスチャの設計としてはこんな感じ。


Pasted Graphic 3.tiff


Pasted Graphic 2.tiff


Pasted Graphic 1.tiff

Pasted Graphic.tiff

はい、描いた人にしかわかりませんね!



調べるその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

https://developer.apple.com/library/prerelease/ios/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothOverview/CoreBluetoothOverview.html#//apple_ref/doc/uid/TP40013257-CH2-SW1

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 の一覧は無かったので作った。

こんな感じ。


ecbarw.png


1__#$!@%!#__ecbarw.png


2__#$!@%!#__ecbarw.png

dead | alive

3__#$!@%!#__ecbarw.png

Alert Notification Service

org.bluetooth.service.alert_notification

0x1811

ok

Battery Service

org.bluetooth.service.battery_service

0x180F

denied

Blood Pressure

org.bluetooth.service.blood_pressure

0x1810

ok

Current Time Service

org.bluetooth.service.current_time

0x1805

denied

Cycling Power

org.bluetooth.service.cycling_power

0x1818

ok

Cycling Speed and Cadence

org.bluetooth.service.cycling_speed_and_cadence

0x1816

ok

Device Information

org.bluetooth.service.device_information

0x180A

ok

Generic Access

org.bluetooth.service.generic_access

0x1800

denied

Generic Attribute

org.bluetooth.service.generic_attribute

0x1801

denied

Glucose

org.bluetooth.service.glucose

0x1808

ok

Health Thermometer

org.bluetooth.service.health_thermometer

0x1809

ok

Heart Rate

org.bluetooth.service.heart_rate

0x180D

ok

Human Interface Device

org.bluetooth.service.human_interface_device

0x1812

denied

Immediate Alert

org.bluetooth.service.immediate_alert

0x1802

ok

Link Loss

org.bluetooth.service.link_loss

0x1803

ok

Location and Navigation

org.bluetooth.service.location_and_navigation

0x1819

ok

Next DST Change Service

org.bluetooth.service.next_dst_change

0x1807

ok

Phone Alert Status Service

org.bluetooth.service.phone_alert_status

0x180E

ok

Reference Time Update Service

org.bluetooth.service.reference_time_update

0x1806

ok

Running Speed and Cadence

org.bluetooth.service.running_speed_and_cadence

0x1814

ok

Scan Parameters

org.bluetooth.service.scan_parameters

0x1813

ok

Tx Power

org.bluetooth.service.tx_power

0x1804

ok

User Data

org.bluetooth.service.user_data

0x181C

ok



最終的な結論は、「iOSをPeripheralにしてHOGP(とあといくつかのAssignedNumber)を使うのは無理。」



おまけ

Macに限定するならこっちでつくるかなあ、、

Bonjour

http://qiita.com/feb19/items/da07d96619acb933a3c3