bool PSNaviController::setHostBluetoothAddress(const std::string &new_host_bt_addr) { bool success= false; unsigned char bts[PSNAVI_BTADDR_SET_SIZE]; memset(bts, 0, sizeof(bts)); bts[0] = PSNavi_Req_SetBTAddr; bts[1] = 0x01; bts[2] = 0x00; unsigned char addr[6]; if (stringToBTAddrUchar(new_host_bt_addr, addr, sizeof(addr))) { int res; /* Copy 6 bytes from addr into bts[3]..bts[8] */ memcpy(&bts[3], addr, sizeof(addr)); /* _WIN32 only has move->handle_addr for getting bluetooth address. */ if (HIDDetails.Handle_addr) { res = hid_send_feature_report(HIDDetails.Handle_addr, bts, sizeof(bts)); } else { res = hid_send_feature_report(HIDDetails.Handle, bts, sizeof(bts)); } if (res == sizeof(bts)) { success= true; } else { char hidapi_err_mbs[256]; bool valid_error_mesg= false; if (HIDDetails.Handle_addr) { valid_error_mesg = hid_error_mbs(HIDDetails.Handle_addr, hidapi_err_mbs, sizeof(hidapi_err_mbs)); } else { valid_error_mesg = hid_error_mbs(HIDDetails.Handle, hidapi_err_mbs, sizeof(hidapi_err_mbs)); } if (valid_error_mesg) { SERVER_LOG_ERROR("PSNaviController::setBTAddress") << "HID ERROR: " << hidapi_err_mbs; } } } else { SERVER_LOG_ERROR("PSNaviController::setBTAddress") << "Malformed address: " << new_host_bt_addr; } return success; }
// ***** Multi Panel Process ****** void process_multi_panel() { process_multi_menu(); // ******* Only do a read if something new to be read ******** hid_set_nonblocking(multihandle, 1); int multi_safety_cntr = 30; do{ multires = hid_read(multihandle, multibuf, sizeof(multibuf)); process_alt_switch(); process_vs_switch(); process_ias_switch(); process_hdg_switch(); process_crs_switch(); process_autothrottle_switch(); process_ap_master_switch(); process_hdg_button(); process_nav_button(); process_ias_button(); process_alt_button(); process_vs_button(); process_apr_button(); process_rev_button(); process_flaps_switch(); process_trim_wheel(); if(multires > 0){ process_multi_flash(); process_multi_blank_display(); process_multi_display(); hid_send_feature_report(multihandle, multiwbuf, sizeof(multiwbuf)); } --multi_safety_cntr; }while((multires > 0) && (multi_safety_cntr > 0)); process_multi_flash(); process_multi_blank_display(); process_multi_display(); // ******* Write on changes or timeout ******** if ((lastmultiseldis != multiseldis) || (lastbtnleds != btnleds) || (multinowrite > 50)) { mulres = hid_send_feature_report(multihandle, multiwbuf, sizeof(multiwbuf)); multinowrite = 1; lastmultiseldis = multiseldis; lastbtnleds = btnleds; }else{ multinowrite++; } return; }
int send_feature_report(hid_device *device, unsigned char const *data, size_t length) { return hid_executor->await([=] { return hid_send_feature_report(device, data, length); }); }
/** * @brief sets the selected color for a specified region * @param dev the hid device * @param color the color value * @param region the region where the color should be set_color * @param brightness the selected brightness * @returns the acutal number of bytes written, -1 on error */ int set_color(hid_device* dev, enum color color, enum region region, enum brightness brightness) { // check for a valid color if (color != none && color != red && color != orange && color != yellow && color != green && color != sky && color != blue && color != purple && color != white) return -1; // check for a valid region if (region != left && region != middle && region != right) return -1; // check for a valid brightness if (brightness != off && brightness != low && brightness != medium && brightness != high) return -1; unsigned char activate[8]; activate[0] = 1; activate[1] = 2; activate[2] = 66; // set activate[3] = (unsigned char)region; activate[4] = (unsigned char)color; activate[5] = (unsigned char)brightness; activate[6] = 0; activate[7] = 236; // EOR (end of request) return hid_send_feature_report(dev, activate, 8); }
int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length) { int res; // int report_number = data[0]; // int skipped_report_id = 0; // // if (report_number == 0x0) { // data++; // length--; // skipped_report_id = 1; // } if (dev->output_endpoint <= 0) { if (data[0] == 0) { length = 256; } else length = 255; if (length == hid_send_feature_report(dev, data, length)) return 255; else return -1; // printf("control transfer\n"); /* No interrput out endpoint. Use the Control Endpoint */ // res = libusb_control_transfer(dev->device_handle, // LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE|LIBUSB_ENDPOINT_OUT, // 0x09/*HID Set_Report*/, // (2/*HID output*/ << 8) | report_number, // dev->interface, // (unsigned char *)data, length, // 1000/*timeout millis*/); // // if (res < 0) // return -1; // // if (skipped_report_id) // length++; // // return length; } else { // printf("interrupt transfer\n"); /* Use the interrupt out endpoint */ int actual_length; res = libusb_interrupt_transfer(dev->device_handle, dev->output_endpoint, (unsigned char*)data, length, &actual_length, 1000); if (res < 0) return -1; // if (skipped_report_id) // actual_length++; return actual_length; } }
int main( int argc, char* argv[] ) { unsigned char buf[2]; hid_device *handle; int res; // Space Navigator: 046d c626 handle = hid_open( 0x046d, 0xc626, NULL ); if ( handle == NULL ) { printf( "spacenav-rezero: Could not open HID device (got sudo?)\n" ); exit( EXIT_FAILURE ); } buf[0] = 0x07; // This proprietary(?) feature report will rezero the device. buf[1] = 0x00; res = hid_send_feature_report( handle, buf, sizeof(buf) ); if ( res != sizeof(buf) ) { printf( "spacenav-rezero: Write failed\n" ); exit( EXIT_FAILURE ); } hid_close( handle ); return EXIT_SUCCESS; }
void RadioPanel::updateDisplay() { static unsigned char buf[23]; if (!handle) { return; } VESSEL *vessel = oapiGetFocusInterface(); // Get current vessel if (vessel!=NULL) // check if pointer is valid { buf[0]=0x00; // parse nav1 parseNavData(vessel, 0, &(buf[1])); // parse nav2 parseNavData(vessel, 1, &(buf[11])); int res = hid_send_feature_report(handle, buf, 23); } }
/*---------------------------------------------------------------------------*/ int t100::sendData(uint8_t* buf, uint8_t len) { int rval; /* Reset the buffer */ memset(tempBuffer,0x00,256); #if WIN /* Dummy report ID */ tempBuffer[0] = 0; tempBuffer[1] = 1; /* Store the data */ for(int i = 0; i < len; ++i) { tempBuffer[i+2] = buf[i]; } /* Send the data */ rval = hid_send_feature_report(this->t100_handle, tempBuffer, len+2); #else /* Dummy report ID */ tempBuffer[0] = 1; /* Store the data */ for(int i = 0; i < len; ++i) { tempBuffer[i+1] = buf[i]; } /* Send the data */ rval = hid_send_feature_report(this->t100_handle, tempBuffer, len+1); #endif if(rval < 0) { this->problem = true; return -1; } return (rval-1); }
int mcp_panel_open() { int res = 0; mcpHandle = hid_open(VENDOR_ID, MCP_PROD_ID, NULL); if (!mcpHandle) { XPLMDebugString("-> CP: mcp_driver.panel_open: unable to open device.\n"); return -1; } wchar_t wstr[MAX_STR]; res = hid_get_manufacturer_string(mcpHandle, wstr, MAX_STR); sprintf(tmp, "-> CP: mcp_driver.panel_open: Manufacturer String %ls\n", wstr); XPLMDebugString(tmp); hid_set_nonblocking(mcpHandle, 1); res = hid_read(mcpHandle, mcp_in_buf, MCP_IN_BUF_SIZE); if (res < 0) { sprintf(tmp, "-> CP: mcp_driver.panel_open: Error: %ls\n", hid_error(mcpHandle)); XPLMDebugString(tmp); } res = hid_send_feature_report(mcpHandle, mcp_all_on_panel, sizeof(mcp_all_on_panel)); res = hid_send_feature_report(mcpHandle, mcp_course_left, sizeof(mcp_course_left)); res = hid_send_feature_report(mcpHandle, mcp_course_right, sizeof(mcp_course_right)); res = hid_send_feature_report(mcpHandle, mcp_ias_mach, sizeof(mcp_ias_mach)); res = hid_send_feature_report(mcpHandle, mcp_heading, sizeof(mcp_heading)); res = hid_send_feature_report(mcpHandle, mcp_altitude, sizeof(mcp_altitude)); res = hid_send_feature_report(mcpHandle, mcp_vert_speed, sizeof(mcp_vert_speed)); if (res < 0) { sprintf(tmp, "-> CP: mcp_driver.panel_open: Error: %ls\n", hid_error(mcpHandle)); XPLMDebugString(tmp); } return 0; }
void HidDevice::sendFeatureReport(uint8_t reportId, const ByteString& data) { ByteString reportBuf = ByteString(1, reportId) + data; int r = hid_send_feature_report(devHandle, reportBuf.data(), reportBuf.size()); if(r<0) { std::string errorString; utf16BufferToUtf8String(errorString, hid_error(devHandle)); throw HidDeviceError(errorString); } }
int cb_panel_write_empty() { int res = 0; unsigned char cb_empty_buf[0]; if (cbHandle) { res = hid_send_feature_report(cbHandle, cb_empty_buf, 0); if (res < 0) { sprintf(tmp, "-> CP: cb_driver.panel_write_empty: Error: %ls\n", hid_error(cbHandle)); printf(tmp); } } return res; }
///////////////////////////////////////////////////////////////////////////////////////////// // Sensor KeepAlive // HID Type: Set Feature // HID Packet Length: 5 ///////////////////////////////////////////////////////////////////////////////////////////// BOOLEAN sendSensorKeepAlive(Device *dev) { UInt8 Buffer[5]; UInt16 CommandId = 0; Buffer[0] = 8; Buffer[1] = CommandId & 0xFF; Buffer[2] = CommandId >> 8; Buffer[3] = dev->keepAliveIntervalMs & 0xFF; Buffer[4] = dev->keepAliveIntervalMs >> 8; return hid_send_feature_report(dev->hidapi_dev, Buffer, 8 ) == 5; }
bool PSDualShock4Controller::setHostBluetoothAddress(const std::string &new_host_bt_addr) { bool success = false; unsigned char bts[PSDS4_BTADDR_SET_SIZE]; memset(bts, 0, sizeof(bts)); bts[0] = PSDualShock4_USBReport_SetBTAddr; unsigned char addr[6]; if (ServerUtility::bluetooth_string_address_to_bytes(new_host_bt_addr, addr, sizeof(addr))) { int res; // Copy 6 bytes from addr into bts[1]..bts[6] memcpy(&bts[1], addr, sizeof(addr)); // Copy the bluetooth link key index backwards into the bluetooth report for (size_t key_byte_index = 0; key_byte_index < k_ps4_bluetooth_link_key_length; ++key_byte_index) { bts[7 + key_byte_index] = k_ps4_bluetooth_link_key[k_ps4_bluetooth_link_key_length - key_byte_index - 1]; } /* _WIN32 only has move->handle_addr for getting bluetooth address. */ res = hid_send_feature_report(HIDDetails.Handle, bts, sizeof(bts)); if (res == sizeof(bts)) { success = true; } else { char hidapi_err_mbs[256]; bool valid_error_mesg = false; valid_error_mesg = hid_error_mbs(HIDDetails.Handle, hidapi_err_mbs, sizeof(hidapi_err_mbs)); if (valid_error_mesg) { SERVER_LOG_ERROR("PSDualShock4Controller::setBTAddress") << "HID ERROR: " << hidapi_err_mbs; } } } else { SERVER_LOG_ERROR("PSDualShock4Controller::setBTAddress") << "Malformed address: " << new_host_bt_addr; } return success; }
int mcp_panel_close() { int res = 0; if (mcpHandle) { res = hid_send_feature_report(mcpHandle, mcp_blank_panel, sizeof(mcp_blank_panel)); if (res < 0) { sprintf(tmp, "-> CP: mcp_driver.panel_close: Error: %ls\n", hid_error(mcpHandle)); XPLMDebugString(tmp); } hid_close(mcpHandle); XPLMDebugString("-> CP: mcp_driver.panel_close: panel closed.\n"); mcpHandle = NULL; } return res; }
///////////////////////////////////////////////////////////////////////////////////////////// // Sensor Config // HID Type: Set Feature // HID Packet Length: 7 ///////////////////////////////////////////////////////////////////////////////////////////// BOOLEAN sendSensorConfig(Device *dev, UInt8 flags, UInt8 packetInterval, UInt16 keepAliveIntervalMs) { UInt8 Buffer[7]; UInt16 CommandId = 0; Buffer[0] = 2; Buffer[1] = CommandId & 0xFF; Buffer[2] = CommandId >> 8; Buffer[3] = flags; Buffer[4] = packetInterval; Buffer[5] = keepAliveIntervalMs & 0xFF; Buffer[6] = keepAliveIntervalMs >> 8; return hid_send_feature_report(dev->hidapi_dev, Buffer, 8 ) == 7; }
int LedDeviceLightpackHidapi::writeBytes(uint8_t *data, int size) { // std::cout << "Writing " << size << " bytes: "; // for (int i = 0; i < size ; ++i) printf("%02x ", data[i]); // std::cout << std::endl; int error = hid_send_feature_report(_deviceHandle, data, size); if (error == size) { return 0; } Error(_log, "Unable to write %d bytes to Lightpack device(%d)", size, error); return error; }
USING_PTYPES /** * */ void rp_init(hid_device* hid) { LPRINTF("Saitek ProPanels Plugin: rp_init\n"); uint8_t buf[4]; hid_set_nonblocking(hid, (int)true); hid_read(hid, buf, sizeof(buf)); hid_send_feature_report(hid, rp_blank_panel, sizeof(rp_blank_panel)); hid_set_nonblocking(hid, (int)false); }
///////////////////////////////////////////////////////////////////////////////////////////// // Sensor Scale Range // HID Type: Set Feature // HID Packet Length: 7 -- TODO Really 8? Check ///////////////////////////////////////////////////////////////////////////////////////////// BOOLEAN sendSensorScaleRange( Device *dev, const struct SensorScaleRange *r) { UInt8 Buffer[8]; UInt16 CommandId = 0; Buffer[0] = 4; Buffer[1] = CommandId & 0xFF; Buffer[2] = CommandId >> 8; Buffer[3] = r->AccelScale; Buffer[4] = r->GyroScale & 0xFF; Buffer[5] = r->GyroScale >> 8; Buffer[6] = r->MagScale & 0xFF; Buffer[7] = r->MagScale >> 8; return hid_send_feature_report(dev->hidapi_dev, Buffer, 8 ) == 8; }
void SwitchPanel::clearDisplay() { static unsigned char buf[2]; if (!handle) { return; } buf[0]=0x00; buf[1]=0x00; int res = hid_send_feature_report(handle, buf, 2); }
void vrpn_HidInterface::send_feature_report(size_t bytes, const vrpn_uint8 *buffer) { if (!_working) { fprintf(stderr,"vrpn_HidInterface::send_feature_report(): Interface not currently working\n"); return; } int ret = hid_send_feature_report(_device, buffer, bytes); if (ret == -1) { fprintf(stderr, "vrpn_HidInterface::send_feature_report(): failed to send feature report\n"); const wchar_t * errmsg = hid_error(_device); if (errmsg) { fprintf(stderr, "vrpn_HidInterface::send_feature_report(): error message: %ls\n", errmsg); } } else { //fprintf(stderr, "vrpn_HidInterface::send_feature_report(): sent feature report, %d bytes\n", static_cast<int>(bytes)); } }
int mcp_panel_write(unsigned char buf[]) { int res = 0; int i = 0; unsigned char tmpBuffer[MCP_OUT_BUF_SIZE]; for (i = 0; i < MCP_OUT_BUF_SIZE; i++) { tmpBuffer[i] = buf[i]; } if (mcpHandle) { res = hid_send_feature_report(mcpHandle, tmpBuffer, sizeof(tmpBuffer)); if (res < 0) { sprintf(tmp, "-> CP: mcp_driver.panel_write: Error: %ls\n", hid_error(mcpHandle)); XPLMDebugString(tmp); } } return res; }
void Keyboard::setMode(Mode mode) { if(!m_dev) return; unsigned char buf[BUFSIZE] = {0}; buf[0] = 1; buf[1] = 2; buf[2] = 65; buf[3] = static_cast<unsigned int>(mode); buf[4] = 0; buf[5] = 0; buf[6] = 0; buf[7] = 236; hid_send_feature_report(m_dev, buf, BUFSIZE); }
void Keyboard::setColor(Region region, Color color, Intensity intensity) { if(!m_dev) return; unsigned char buf[BUFSIZE] = {0}; buf[0] = 1; buf[1] = 2; buf[2] = 66; buf[3] = static_cast<unsigned int>(region); buf[4] = static_cast<unsigned int>(color); buf[5] = static_cast<unsigned int>(intensity); buf[6] = 0; buf[7] = 236; hid_send_feature_report(m_dev, buf, BUFSIZE); }
void RadioPanel::clearDisplay() { static unsigned char buf[23] = { 0x00, 0x0f,0x0f,0x0f,0x0f,0x0f, 0x0f,0x0f,0x0f,0x0f,0x0f, 0x0f,0x0f,0x0f,0x0f,0x0f, 0x0f,0x0f,0x0f,0x0f,0x0f, 0x00,0x00 }; if (!handle) { return; } int res = hid_send_feature_report(handle, buf, 23); }
//-------------------------------------------------------------- void ofxPowerMate::setBrillo(int brillo){ // valor entre 0 - 255 ¿?¿ //hid_set_nonblocking(handle, 1); unsigned char bufBrillo[8]; bufBrillo[0] = 0x41; bufBrillo[1] = 0x01; bufBrillo[2] = 0x01; bufBrillo[3] = 0x00; // command type bufBrillo[4] = brillo; // select table bufBrillo[5] = 0x00; bufBrillo[6] = 0x00; bufBrillo[7] = 0x00; res = hid_send_feature_report(handle, bufBrillo, sizeof(bufBrillo)); //res = hid_write(handle, buf, bufbuf); }
/** * @brief sets the selected mode * @param dev the hid device * @param mode the selected mode * @returns the acutal number of bytes written, -1 on error */ int set_mode(hid_device* dev, enum mode mode) { // check for a valid value, otherwise use normal mode if (mode != normal && mode != gaming && mode != breathe && mode != demo && mode != wave) return -1; unsigned char commit[8]; commit[0] = 1; commit[1] = 2; commit[2] = 65; // commit commit[3] = (unsigned char)mode; // set hardware mode commit[4] = 0; commit[5] = 0; commit[6] = 0; commit[7] = 236; // EOR (end of request) return hid_send_feature_report(dev, commit, 8); }
int touchmouse_set_device_mode(touchmouse_device *dev, touchmouse_mode mode) { // We need to set two bits in a particular Feature report. We first fetch // the current state of the feature report, set the interesting bits, and // write that feature report back to the device. TM_SPEW("touchmouse_set_device_mode: Reading current config flags\n"); unsigned char data[27] = {0x22}; int transferred = 0; transferred = hid_get_feature_report(dev->dev, data, 27); if (transferred > 0) { TM_SPEW("%d bytes received:\n", transferred); int i; for(i = 0; i < transferred; i++) { TM_SPEW("%02X ", data[i]); } TM_SPEW("\n"); } if (transferred != 0x1B) { TM_ERROR("touchmouse_set_device_mode: Failed to read Feature 0x22 correctly; expected 27 bytes, got %d\n", transferred); return -1; } // This particular byte/setting appears to control the // "send all the raw input" flag. switch (mode) { case TOUCHMOUSE_DEFAULT: data[4] = 0x00; TM_DEBUG("touchmouse_set_device_mode: Trying to disable full touch updates...\n"); break; case TOUCHMOUSE_RAW_IMAGE: data[4] = 0x06; TM_DEBUG("touchmouse_set_device_mode: Trying to enable full touch updates...\n"); break; } transferred = hid_send_feature_report(dev->dev, data, 27); TM_SPEW("Wrote %d bytes\n", transferred); if (transferred == 0x1B) { TM_DEBUG("touchmouse_set_device_mode: Successfully set device mode.\n"); return 0; } TM_ERROR("touchmouse_set_device_mode: Failed to set device mode.\n"); return -1; }
bool CDevice::SramTransfer(uint32_t slot) { int ret; hidbuf[0] = ID_SPI_SRAM_TRANSFER; hidbuf[1] = (uint8_t)(slot); hidbuf[2] = (uint8_t)(slot >> 8); if (hid_send_feature_report(handle, hidbuf, 4) >= 0) { } while (1) { hidbuf[0] = ID_SPI_SRAM_TRANSFER_STATUS; ret = hid_get_feature_report(handle, hidbuf, 2); if (hidbuf[1] == 0) break; } return(true); }
bool CDevice::Selftest() { int ret; hidbuf[0] = ID_SELFTEST; hidbuf[1] = 0; ret = hid_send_feature_report(handle, hidbuf, 2); if (ret == -1) { wprintf(L"error: %s\n", hid_error(handle)); } uint32_t start = getTicks(); do { } while ((getTicks() - start) < 1000); hidbuf[1] = 0xFF; ret = hid_get_feature_report(handle, hidbuf, 2); printf("self-test code $%02X\n", hidbuf[1]); return(hidbuf[1] == 0 ? true : false); }
/** * Commits the lights with the modes */ void commit(hid_device *handle, unsigned char mode) { //CONFIRMATION. This needs to be sent for confirmate all the led operations unsigned char data[8]; data[0] = 0x01; data[1] = 0x02; data[2] = 0x41; // commit byte data[3] = mode; // current mode data[4] = 0x00; data[5] = 0x00; data[6] = 0x00; data[7] = 0xec; if (hid_send_feature_report(handle, data, 9) < 0) { printf("Unable to send a feature report.\n"); } }