I use 51822 to implement the HID touch device,It can works on android .But Tip Switch up is can't work again. This is my code touch_1012.rar
This is my test tool com.the511plus.MultiTouchTester_1.2_liqucn.com.apk
static uint8_t report_map_data[] =
{
0x05, 0x0D, // USAGE_PAGE(Digitizers)
0x09, 0x04, // USAGE (Touch Screen)
0xA1, 0x01, // COLLECTION(Application)
// define the maximum amount of fingers that the device supports
0x09, 0x55, // USAGE(Contact Count Maximum)//´¥Ãþ×î´óµãÊý
0x25, 0x01, // LOGICAL_MAXIMUM (1) //Ò»¸öµã
0xB1, 0x02, // FEATURE (Data,Var,Abs)
// define the actual amount of fingers that are concurrently touching the screen
0x09, 0x54, // USAGE (Contact count)//´¥µãÊý
0x95, 0x01, // REPORT_COUNT(1)
0x75, 0x08, // REPORT_SIZE (8)
0x81, 0x02, // INPUT (Data,Var,Abs)
// declare a finger collection
0x09, 0x22, // USAGE (Finger)
0xA1, 0x02, // COLLECTION (Logical)
// declare an identifier for the finger
0x09, 0x51, // USAGE (Contact Identifier)//´¥ÃþID
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x01, // REPORT_COUNT (1)
0x81, 0x02, // INPUT (Data,Var,Abs)
// declare Tip Switch and In Range
0x09, 0x42, // USAGE (Tip Switch)
0x09, 0x32, // USAGE (In Range)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x02, // REPORT_COUNT(2)
0x81, 0x02, // INPUT (Data,Var,Abs)
// declare the remaining 6 bits of the first data byte as constant -> the driver will ignore
them
0x95, 0x06, // REPORT_COUNT (6)
0x81, 0x03, // INPUT (Cnst,Ary,Abs)
// define absolute X and Y coordinates of 16 bit each (percent values multiplied with 100)
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x30, // Usage (X)
0x09, 0x31, // Usage (Y)
0x16, 0x00, 0x00, // Logical Minimum (0)
0x26, 0x10, 0x27, // Logical Maximum (10000)
0x36, 0x00, 0x00, // Physical Minimum (0)
0x46, 0x10, 0x27, // Physical Maximum (10000)
0x66, 0x00, 0x00, // UNIT (None)
0x75, 0x10, // Report Size (16),
0x95, 0x02, // Report Count (2),
0x81, 0x02, // Input (Data,Var,Abs)
0xC0, // END_COLLECTION
0xC0 // END_COLLECTION
// With this declaration a data packet must be sent as:
// byte 1 -> "contact count" (always == 1)
// byte 2 -> "contact identifier" (any value)
// byte 3 -> "Tip Switch" state (bit 0 = Tip Switch up/down, bit 1 = In Range)
// byte 4,5 -> absolute X coordinate (0...10000)
// byte 6,7 -> absolute Y coordinate (0...10000)
};
//
static void mouse_moveto_2xy(uint8_t value,uint16_t x_delta,uint16_t y_delta)
{
// With this declaration a data packet must be sent as:
// byte 1 -> "contact count" (always == 1)
// byte 2 -> "contact identifier" (any value)
// byte 3 -> "Tip Switch" state (bit 0 = Tip Switch up/down, bit 1 = In Range)
// byte 4,5 -> absolute X coordinate (0...10000)
// byte 6,7 -> absolute Y coordinate (0...10000)
uint8_t buffer[INPUT_REP_TOUCH_LEN];
uint32_t err_code;
APP_ERROR_CHECK_BOOL(INPUT_REP_TOUCH_LEN == 7);
x_delta = MIN(x_delta, 0x2710);
y_delta = MIN(y_delta, 0x2710);
buffer[0] = 1;
buffer[1] = 1;
buffer[2] = value;
buffer[3] = x_delta & 0x00ff;
buffer[4] = (x_delta>>8)&0x00ff;
buffer[5] = y_delta & 0x00ff;
buffer[6] = (y_delta>>8)&0x00ff;
err_code = ble_hids_inp_rep_send(&m_hids,
INPUT_REP_TOUCH_INDEX,
INPUT_REP_TOUCH_LEN,
buffer);
if ((err_code != NRF_SUCCESS) &&
(err_code != NRF_ERROR_INVALID_STATE) &&
(err_code != BLE_ERROR_NO_TX_BUFFERS) &&
(err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
)
{
APP_ERROR_HANDLER(err_code);
}
}
static void button_meas_timeout_handler(void * p_context)
{
uint8_t key=0;
uint8_t *p_key;
static uint16_t touch_num=5000;
static uint16_t touch_num2=5000;
UNUSED_PARAMETER(p_context);
key=key_scan();
switch (key)
{
case 0:
if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
{
mouse_moveto_2xy(1,touch_num,touch_num);
touch_num-=100;
if(touch_num<100)
touch_num=100;
}
break;
case 1:
if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
{
mouse_moveto_2xy(1,touch_num,touch_num);
touch_num+=100;
if(touch_num>10000)
touch_num=10000;
}
break;
default:
// mouse_moveto_2xy(0,5000,5000); // Tip Switch up
// touch_num=5000;
break;
}
}