/* -------------------------------------------------------------------------- */ static void usbhid_set(t_usbhid *x, t_symbol *s, int argc, t_atom *argv) { if(x->debug_level) post("usbhid_set"); char *packet; if ( !hid_is_opened(x->x_hidinterface) ) { error("[usbhid] device not open, can't set data"); return; } packet = make_hid_packet(argc, argv); x->x_hid_return = hid_set_output_report(x->x_hidinterface, x->x_write_paths, x->x_write_path_count, packet, argc); if (x->x_hid_return != HID_RET_SUCCESS) { error("[usbhid] hid_get_input_report failed with return code %d\n", x->x_hid_return); reset_output(x); add_float_to_output(x, x->x_hid_return); outlet_anything(x->x_status_outlet, gensym("set_error"), x->output_count, x->output); } }
/* * set cmd len is 8 * */ int send_device_command(unsigned char *cmd) { hid_return ret; ret = hid_set_output_report(hid, PATH_IN, PATHLEN, cmd, 8); if (ret != HID_RET_SUCCESS) { fprintf(stderr, "hid_set_output_report failed with return code %d\n", ret); } return ret; }
/* -------------------------------------------------------------------------- */ static void usbhid_write(t_usbhid *x, t_symbol *s, int argc, t_atom *argv) { if(x->debug_level) post("usbhid_write"); int i; // const int path[] = {0x000c0001, 0x000c0001}; // int path[] = {0x00010005, 0x00010036}; int path[] = {0xffa00001, 0xffa00005}; // int *path; unsigned int const depth = 2; // number of 32bit chunks in the path unsigned char const SEND_PACKET_LEN = 1; // number of bytes in packet char const PACKET[] = { 0xff, 0xff }; // the data to write // char const PACKET[] = { 0x00, 0x00 }; // the data to write // char PACKET[] = { 0x00, 0x00 }; // the data to write if ( !hid_is_opened(x->x_hidinterface) ) { error("[usbhid] device not open, can't set data"); return; } /* path = getbytes(sizeof(int) * (argc - 1)); depth = (argc - 1) / 2; for(i = 0; i < argc - 1; ++i) { path[(i+1)/2] = (strtol(atom_getsymbol(argv + i)->s_name, NULL, 16) << 16) + (strtol(atom_getsymbol(argv + i + 1)->s_name, NULL, 16) & 0x0000ffff); ++i; } SEND_PACKET_LEN = 2; PACKET[1] = (unsigned short) atom_getfloat(argv + argc - 1); */ post("depth: %d SEND_PACKET_LEN: %d PACKET[0]: %d PACKET[1]: %d", depth, SEND_PACKET_LEN, PACKET[0], PACKET[1]); for(i = 0; i < (argc - 1) / 2; ++i) { post("path %d: 0x%08x", i, path[i]); } x->x_hid_return = hid_set_output_report(x->x_hidinterface, path, depth, PACKET, SEND_PACKET_LEN); if (x->x_hid_return != HID_RET_SUCCESS) { error("[usbhid] hid_set_output_report failed with return code %d", x->x_hid_return); reset_output(x); add_float_to_output(x, x->x_hid_return); outlet_anything(x->x_status_outlet, gensym("get_error"), x->output_count, x->output); } post("wrote"); }
bool PSDualShock4Controller::writeDataOut() { bool bSuccess= true; if (bWriteStateDirty) { const bool bLedIsOn = LedR != 0 || LedG != 0 || LedB != 0; const bool bIsRumbleOn = RumbleRight != 0 || RumbleLeft != 0; // Light bar color OutData->led_r = LedR; OutData->led_g = LedG; OutData->led_b = LedB; // Set off interval to 0% and the on interval to 100%. // There are no discos in PSMoveService. OutData->led_flash_on = bLedIsOn ? 0xff : 0x00; OutData->led_flash_off = 0x00; // a.k.a Soft Rumble Motor OutData->rumble_right = RumbleRight; // a.k.a Hard Rumble Motor OutData->rumble_left = RumbleLeft; // Keep writing state out until the desired LED and Rumble are 0 bWriteStateDirty = bLedIsOn || bIsRumbleOn; // Unfortunately in windows simply writing to the HID device, via WriteFile() internally, // doesn't appear to actually set the data on the controller (despite returning successfully). // In the DS4 implementation they use the HidD_SetOutputReport() Win32 API call instead. // Unfortunately HIDAPI doesn't have any equivalent call, so we have to make our own. #ifdef _WIN32 int res = hid_set_output_report(HIDDetails.Handle, (unsigned char*)OutData, sizeof(PSDualShock4DataOutput)); #else int res = hid_write(HIDDetails.Handle, (unsigned char*)OutData, sizeof(PSDualShock4DataOutput)); #endif bSuccess = res > 0; if (!bSuccess) { char szErrorMessage[256]; if (hid_error_mbs(HIDDetails.Handle, szErrorMessage, sizeof(szErrorMessage))) { SERVER_LOG_ERROR("PSDualShock4Controller::writeDataOut") << "HID ERROR: " << szErrorMessage; } } } return bSuccess; }
static void RFIDCommunication(hid_return ret, HIDInterface** const hid) { int const PATH_IN[] = { PATHIN }; unsigned int SEND_PACKET_LEN1 = 3; unsigned int REPLY_PACKET_LENGTH1 = 3; printf("\n/* * * * * * * * BEGIN COMMUNICATION WITH RFID DEVICE * * * * * * * */"); // SET ANTENNA POWER char PACKET1[] = { 0xC0, 0x03, 0x12 }; ret = hid_set_output_report(*hid, PATH_IN, PATHLEN, PACKET1, SEND_PACKET_LEN1); if (ret != HID_RET_SUCCESS) { fprintf(stderr, "hid_set_output_report failed with return code %d\n", ret); } else { printf("\n\n----->First sent: \n"); printHex(PACKET1, SEND_PACKET_LEN1); } char reply1[REPLY_PACKET_LENGTH1+1]; ret = hid_interrupt_read(*hid, EP_INTERRUPT_IN, reply1, REPLY_PACKET_LENGTH1, 100); if (ret != HID_RET_SUCCESS) { fprintf(stderr, "interrupt read failed with return code %d\n", ret); } else { printf("\n\n----->First reply:\n"); printHex(reply1, REPLY_PACKET_LENGTH1); } // TAG INVENTORY OPERATION // XXX: returns EPC Data unsigned int SEND_PACKET_LEN2 = 3; unsigned int REPLY_PACKET_LENGTH2 = 64; char PACKET2[] = { 0x31, 0x03, 0x01 }; ret = hid_set_output_report(*hid, PATH_IN, PATHLEN, PACKET2, SEND_PACKET_LEN2); if (ret != HID_RET_SUCCESS) { fprintf(stderr, "hid_set_output_report failed with return code %d\n", ret); } else { printf("\n\n----->Second sent:\n"); printHex(PACKET2, SEND_PACKET_LEN2); } char reply2[REPLY_PACKET_LENGTH2+1]; ret = hid_interrupt_read(*hid, EP_INTERRUPT_IN, reply2, REPLY_PACKET_LENGTH2, 100); if (ret != HID_RET_SUCCESS) { fprintf(stderr, "interrupt read failed with return code %d\n", ret); } else { printf("\n\n----->Second reply:\n"); printHex(reply2, REPLY_PACKET_LENGTH2); } // NEXT TAG //unsigned int SEND_PACKET_LEN3 = 3; //unsigned int REPLY_PACKET_LENGTH3 = 64; //char PACKET3[] = { 0x31, 0x03, 0x02 }; //ret = hid_set_output_report(*hid, PATH_IN, PATHLEN, PACKET3, SEND_PACKET_LEN3); //if (ret != HID_RET_SUCCESS) { // fprintf(stderr, "hid_set_output_report failed with return code %d\n", ret); //} else { // printf("\n\n----->Third sent: \n"); // printHex(PACKET3, SEND_PACKET_LEN3); //} //char reply3[REPLY_PACKET_LENGTH3+1]; //ret = hid_interrupt_read(*hid, EP_INTERRUPT_IN, reply3, REPLY_PACKET_LENGTH3, 100); //if (ret != HID_RET_SUCCESS) { // fprintf(stderr, "interrupt read failed with return code %d\n", ret); //} else { // printf("\n\n----->Third reply: \n", reply3); // printHex(reply3, REPLY_PACKET_LENGTH3); //} // TAG SELECT OPERATION unsigned int SEND_PACKET_LEN4 = 15; unsigned int REPLY_PACKET_LENGTH4 = 3; char PACKET4[] = { 0x33, 0x0F, 0x0C, 0xCF, 0xFA, 0x04, 0x9C, 0x53, 0xE0, 0xC9, 0x7E, 0x13, 0x77, 0xFB, 0x97 }; ret = hid_set_output_report(*hid, PATH_IN, PATHLEN, PACKET4, SEND_PACKET_LEN4); if (ret != HID_RET_SUCCESS) { fprintf(stderr, "hid_set_output_report failed with return code %d\n", ret); } else { printf("\n\n----->Fourth sent: \n"); printHex(PACKET4, SEND_PACKET_LEN4); } char reply4[REPLY_PACKET_LENGTH4+1]; ret = hid_interrupt_read(*hid, EP_INTERRUPT_IN, reply4, REPLY_PACKET_LENGTH4, 100); if (ret != HID_RET_SUCCESS) { fprintf(stderr, "interrupt read failed with return code %d\n", ret); } else { printf("\n\n----->Fourth reply: \n", reply4); printHex(reply4, REPLY_PACKET_LENGTH4); } // TAG READ EPC MEMORY OPERATION unsigned int SEND_PACKET_LEN5 = 9; unsigned int REPLY_PACKET_LENGTH5 = 64; char PACKET5[] = { 0x37, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04 }; ret = hid_set_output_report(*hid, PATH_IN, PATHLEN, PACKET5, SEND_PACKET_LEN5); if (ret != HID_RET_SUCCESS) { fprintf(stderr, "hid_set_output_report failed with return code %d\n", ret); } else { printf("\n\n----->Fifth sent: \n"); printHex(PACKET5, SEND_PACKET_LEN5); } char reply5[REPLY_PACKET_LENGTH5+1]; ret = hid_interrupt_read(*hid, EP_INTERRUPT_IN, reply5, REPLY_PACKET_LENGTH5, 100); if (ret != HID_RET_SUCCESS) { fprintf(stderr, "interrupt read failed with return code %d\n", ret); } else { printf("\n\n----->Fifth reply: \n", reply5); printHex(reply5, REPLY_PACKET_LENGTH5); } }