Stylus

来自: http://source.android.com/devices/accessories/stylus.html

 

Stylus

 

Android 6.0 and higher supports a standard data format for Bluetooth stylus connections over Bluetooth (BT), Bluetooth Low Energy (BTLE), or USB. The platform correlates timing between touch input and stylus data then provides stylus data to render MotionEvents to the active application. The following sections provide guidelines for OEM partners, stylus accessory creators, and stylus application developers.

Guidelines for OEM partners


To enable Bluetooth stylus support, OEM partners must support Bluetooth (and should support BTLE for wider compatibility). The platform handles data collection, timing correlation, and rendering to the application for supported stylus events.

At this time, the Android CTS does not include tests to ensure existing APIs for touch events support default behavior. As a workaround, we recommend creating a stylus accessory or emulator that can simulate stylus events.

Guidelines for stylus accessory creators


To implement support on a stylus device, partners must use the Stylus Human Interface Device (HID) Descriptor shown below to describe how stylus data (pressure sensitivity, eraser, side buttons, device ID, etc.) is represented. The stylus device sends the HID information to the Android mobile device, enabling the platform to correlate HID data with touch data from the touchscreen to produce stylus events via MotionEvent. Data can be sent over Bluetooth (BT), Bluetooth Low Energy (BTLE), or USB.

HID descriptor

UsagePage(Digitizer)
Usage(Pen)
Collection(Application)
    Usage(Stylus)
    Collection(Logical)
        Usage(Tip Pressure)
        Logical Minimum(0)
        Logical Maximum(1023)
        Report Count(1)
        Report Size(10)
        Input(Data, Variable, Absolute, No Null)

        Usage(Barrel Switch)
        Usage(Secondary Barrel Switch)
        Usage(Tip Switch)
        Usage(Invert)
        Logical Maximum(1)
        Report Count(4)
        Report Size(1)
        Input(Data, Variable, Absolute, No Null)

        Usage(Transducer Serial Number)
        Report Count(1)
        Report Size(128)
        Feature(Constant, Variable)
    EndCollection
EndCollection

unsigned char HID_DESC[] = {
    0x05, 0x0D, // UsagePage(Digitizer)
    0x09, 0x02, // Usage(Pen)    0xA1, 0x01, // Collection(Application)    0x09, 0x20, // Usage(Stylus)    0xA1, 0x02, // Collection(Logical)    0x09, 0x30, // Usage(Tip Pressure)    0x15, 0x00, // Logical Minimum(0)    0x26, 0xFF, 0x03, // Logical Maximum(1023)    0x95, 0x01, // Report Count(1)    0x75, 0x0A, // Report Size(10)    0x81, 0x02, // Input(Data, Variable, Absolute, No Null)    0x09, 0x44, // Usage(Barrel Switch)    0x09, 0x5A, // Usage(Secondary Barrel Switch)    0x09, 0x42, // Usage(Tip Switch)    0x09, 0x3C, // Usage(Invert)    0x25, 0x01, // Logical Maximum(1)    0x95, 0x04, // Report Count(4)    0x75, 0x01, // Report Size(1)    0x81, 0x02, // Input(Data, Variable, Absolute, No Null)    0x09, 0x5B, // Usage(Transducer Serial Number)    0x95, 0x01, // Report Count(1)    0x75, 0x80, // Report Size(128)    0xB1, 0x03, // Feature(Constant, Variable)    0xC0, // End Collection    0xC0, // End Collection}

Guidelines for stylus application developers


The Android 6.0 platform automatically handles pairing and event correlation, so both existing and new applications running on Android 6.0 support Bluetooth stylus by default. For details on Bluetooth stylus APIs, refer to developer.android.com.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值