#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <jni.h>
#include <android/log.h>
#include "hidapi.h"
void hid_read_test(hid_device *handle)
{
pthread_detach( pthread_self());
int res = 0;
unsigned char buf[65] = {0};
int i;
while(1)
{
//printf("USB READ ....\n");
buf[0] = 0x41; // First byte is report number
buf[1] = 0x00;
res = hid_send_feature_report(handle, buf, 2);
buf[1] = 0x01;
res = hid_send_feature_report(handle, buf, 2);
buf[0] = 25;
// Read requested state
res = hid_read(handle, buf,26);
if (res < 0){
printf("Unable to read() res=%d \n", res);
sleep(1);
continue;
//return ;
}
else if(res == 0)
{
continue;
//return;
}
printf(" read() res=%d \n", res);
// Print out the returned buffer.
for (i = 0; i < res; i++)
printf("buf[%d]: %02X\n", i, buf[i]);
printf("\n\n");
}
//pthread_exit(0);
return 0;
}
int setBRate(hid_device *handle)
{
unsigned char buf[65];
int res = 0;
int i = 0;
buf[0] = 0x50; // First byte is report number
#if 0
buf[1] = 0x00;//brate 38400
buf[2] = 0x01;
buf[3] = 0xc2;
buf[4] = 0x00;
#endif
buf[1] = 0x00;//brate 38400
buf[2] = 0x00;
buf[3] = 0x96;
buf[4] = 0x00;
buf[5] = 0x00;
buf[6] = 0x00;
buf[7] = 0x03;
buf[8] = 0x00;
res = hid_send_feature_report(handle, buf, 9);
printf("res=%d \n", res);
memset(buf, 0, sizeof(buf));
buf[0] = 0x50;
res = hid_get_feature_report(handle, buf,10);
printf("get report: %d \n", res);
for (i = 0; i < res; i++)
printf("buf[%d]: %02X\n", i, buf[i]);
printf("\n\n");
}
int hid_set_reset(hid_device *handle)
{
unsigned char buf[65];
int res = 0;
int i = 0;
buf[0] = 0x40;
buf[1] = 0x00;
res = hid_send_feature_report(handle, buf,2);
printf("res: %d \n", res);
for (i = 0; i < res; i++)
printf("buf[%d]: %02X\n", i, buf[i]);
printf("\n\n");
}
void GET_UART_STATUS(hid_device *handle)
{
unsigned char buf[65] = {0};
int res = 0;
int i = 0;
buf[0] = 0x42;
res = hid_get_feature_report(handle, buf,17);
printf("GET_UART_STATUS res: %d \n", res);
for (i = 0; i < res; i++)
printf("buf[%d]: %02X\n", i, buf[i]);
printf("\n\n");
}
void SET_TRANSFER_MODE(hid_device *handle)
{
unsigned char buf[65] = {0};
int res = 0;
int i = 0;
buf[0] = 0x48;
buf[1] = 0x0;
buf[2] = 0x0;
res = hid_send_feature_report(handle, buf,3);
res = hid_get_feature_report(handle, buf,17);
printf("GET_TRANSFER_MODE res: %d \n", res);
for (i = 0; i < res; i++)
printf("buf[%d]: %02X\n", i, buf[i]);
printf("\n\n");
}
void SET_SUSPEND_OUTPUT_CONFIG(hid_device *handle)
{
unsigned char buf[65] = {0};
int res = 0;
int i = 0;
buf[0] = 0x4a;
buf[1] = 0x80;
buf[2] = 0x00;
buf[1] = 0x80;
buf[2] = 0x00;
//res = hid_send_feature_report(handle, buf,5);
memset(buf, 0, sizeof(buf));
buf[0] = 0x4a;
res = hid_get_feature_report(handle, buf,17);
printf("SET_SUSPEND_OUTPUT_CONFIG res: %d \n", res);
for (i = 0; i < res; i++)
printf("buf[%d]: %02X\n", i, buf[i]);
printf("\n\n");
return;
}
#include <stdlib.h>
#include <pthread.h>
#include <jni.h>
#include <android/log.h>
#include "hidapi.h"
void hid_read_test(hid_device *handle)
{
pthread_detach( pthread_self());
int res = 0;
unsigned char buf[65] = {0};
int i;
while(1)
{
//printf("USB READ ....\n");
buf[0] = 0x41; // First byte is report number
buf[1] = 0x00;
res = hid_send_feature_report(handle, buf, 2);
buf[1] = 0x01;
res = hid_send_feature_report(handle, buf, 2);
buf[0] = 25;
// Read requested state
res = hid_read(handle, buf,26);
if (res < 0){
printf("Unable to read() res=%d \n", res);
sleep(1);
continue;
//return ;
}
else if(res == 0)
{
continue;
//return;
}
printf(" read() res=%d \n", res);
// Print out the returned buffer.
for (i = 0; i < res; i++)
printf("buf[%d]: %02X\n", i, buf[i]);
printf("\n\n");
}
//pthread_exit(0);
return 0;
}
int setBRate(hid_device *handle)
{
unsigned char buf[65];
int res = 0;
int i = 0;
buf[0] = 0x50; // First byte is report number
#if 0
buf[1] = 0x00;//brate 38400
buf[2] = 0x01;
buf[3] = 0xc2;
buf[4] = 0x00;
#endif
buf[1] = 0x00;//brate 38400
buf[2] = 0x00;
buf[3] = 0x96;
buf[4] = 0x00;
buf[5] = 0x00;
buf[6] = 0x00;
buf[7] = 0x03;
buf[8] = 0x00;
res = hid_send_feature_report(handle, buf, 9);
printf("res=%d \n", res);
memset(buf, 0, sizeof(buf));
buf[0] = 0x50;
res = hid_get_feature_report(handle, buf,10);
printf("get report: %d \n", res);
for (i = 0; i < res; i++)
printf("buf[%d]: %02X\n", i, buf[i]);
printf("\n\n");
}
int hid_set_reset(hid_device *handle)
{
unsigned char buf[65];
int res = 0;
int i = 0;
buf[0] = 0x40;
buf[1] = 0x00;
res = hid_send_feature_report(handle, buf,2);
printf("res: %d \n", res);
for (i = 0; i < res; i++)
printf("buf[%d]: %02X\n", i, buf[i]);
printf("\n\n");
}
void GET_UART_STATUS(hid_device *handle)
{
unsigned char buf[65] = {0};
int res = 0;
int i = 0;
buf[0] = 0x42;
res = hid_get_feature_report(handle, buf,17);
printf("GET_UART_STATUS res: %d \n", res);
for (i = 0; i < res; i++)
printf("buf[%d]: %02X\n", i, buf[i]);
printf("\n\n");
}
void SET_TRANSFER_MODE(hid_device *handle)
{
unsigned char buf[65] = {0};
int res = 0;
int i = 0;
buf[0] = 0x48;
buf[1] = 0x0;
buf[2] = 0x0;
res = hid_send_feature_report(handle, buf,3);
res = hid_get_feature_report(handle, buf,17);
printf("GET_TRANSFER_MODE res: %d \n", res);
for (i = 0; i < res; i++)
printf("buf[%d]: %02X\n", i, buf[i]);
printf("\n\n");
}
void SET_SUSPEND_OUTPUT_CONFIG(hid_device *handle)
{
unsigned char buf[65] = {0};
int res = 0;
int i = 0;
buf[0] = 0x4a;
buf[1] = 0x80;
buf[2] = 0x00;
buf[1] = 0x80;
buf[2] = 0x00;
//res = hid_send_feature_report(handle, buf,5);
memset(buf, 0, sizeof(buf));
buf[0] = 0x4a;
res = hid_get_feature_report(handle, buf,17);
printf("SET_SUSPEND_OUTPUT_CONFIG res: %d \n", res);
for (i = 0; i < res; i++)
printf("buf[%d]: %02X\n", i, buf[i]);
printf("\n\n");
return;
}