/** * @brief tries to open the MSI gaming notebook's SteelSeries keyboard * @returns a corresponding hid_device, null if the keyboard was not detected */ hid_device* open_keyboard() { if (hid_init() == 0) return hid_open(0x1770, 0xff00, 0); else return NULL; }
/* * return appropriate mode for HID descriptor */ const char * hid_mode(prop_data_t desc) { report_desc_t r; hid_data_t d; struct hid_item h; const char *mode; hid_init(NULL); mode = BTDEVauth; /* default */ r = hid_use_report_desc(prop_data_data_nocopy(desc), prop_data_size(desc)); if (r == NULL) err(EXIT_FAILURE, "hid_use_report_desc"); d = hid_start_parse(r, ~0, -1); while (hid_get_item(d, &h) > 0) { if (h.kind == hid_collection && HID_PAGE(h.usage) == HUP_GENERIC_DESKTOP && HID_USAGE(h.usage) == HUG_KEYBOARD) mode = BTDEVencrypt; } hid_end_parse(d); hid_dispose_report_desc(r); return mode; }
int main(int argc, char* argv[]) { // Enumerate and print the HID devices on the system struct hid_device_info *devs, *cur_dev; hid_init(); devs = hid_enumerate(0x0, 0x0); cur_dev = devs; while (cur_dev) { printf("Device Found\n"); printf(" VID PID: %04hx %04hx\n", cur_dev->vendor_id, cur_dev->product_id); printf(" Page/Usage: 0x%x/0x%x (%d/%d)\n", cur_dev->usage_page, cur_dev->usage, cur_dev->usage_page, cur_dev->usage); printf("\n"); printf(" Manufacturer: %ls\n", cur_dev->manufacturer_string); printf(" Product: %ls\n", cur_dev->product_string); printf(" Device path: %s%s%s\n", QUOTE, cur_dev->path, QUOTE); printf("\n"); cur_dev = cur_dev->next; } hid_free_enumeration(devs); hid_exit(); return 0; }
int doScan() { struct hid_device_info *devs, *cur_dev; if (hid_init()) { return -1; }; devs = hid_enumerate(0x0, 0x0); for (cur_dev = devs ; cur_dev; cur_dev = cur_dev->next) { printf("====>\n"); printf("\tvendor_id: %04hx\n", cur_dev->vendor_id); printf("\tproduct_id: %04hx\n", cur_dev->product_id); printf("\tpath: %s\n", cur_dev->path); printf("\tserial_number: %ls\n", cur_dev->serial_number); printf("\tmanufacturer string: %ls\n", cur_dev->manufacturer_string); printf("\tproduct string: %ls\n", cur_dev->product_string); printf("\trelease number: %hx\n", cur_dev->release_number); printf("\tinterface number%d\n", cur_dev->interface_number); if (cur_dev->vendor_id == RELAY_VENDOR_ID || cur_dev->product_id == RELAY_PRODUCT_ID) { // will not work with more than one realy per card unsigned int state = relay_get_state(cur_dev->path); switch (state) { case 0: printf("\tstate off\n"); break; case 1: printf("\tstate on\n"); break; default: printf("\tstate unknown\n"); break; } } printf("\n"); } hid_free_enumeration(devs); hid_exit(); return 0; }
//----------------------------------------------------------------------------- int dbg_enumerate(debugger_t *debuggers, int size) { struct hid_device_info *devs, *cur_dev; int rsize = 0; if (hid_init()) return 0; devs = hid_enumerate(0, 0); cur_dev = devs; for (cur_dev = devs; cur_dev && rsize < size; cur_dev = cur_dev->next) { debuggers[rsize].path = strdup(cur_dev->path); debuggers[rsize].serial = cur_dev->serial_number ? wcstombsdup(cur_dev->serial_number) : "<unknown>"; debuggers[rsize].wserial = cur_dev->serial_number ? wcsdup(cur_dev->serial_number) : NULL; debuggers[rsize].manufacturer = cur_dev->manufacturer_string ? wcstombsdup(cur_dev->manufacturer_string) : "<unknown>"; debuggers[rsize].product = cur_dev->product_string ? wcstombsdup(cur_dev->product_string) : "<unknown>"; debuggers[rsize].vid = cur_dev->vendor_id; debuggers[rsize].pid = cur_dev->product_id; if (strstr(debuggers[rsize].product, "CMSIS-DAP")) rsize++; } hid_free_enumeration(devs); return rsize; }
int open_usb_device() { hid_return ret; HIDInterfaceMatcher matcher = { VENDOR_ID, PRODUCT_ID, NULL, NULL, 0 }; hid_set_debug(HID_DEBUG_NONE); hid_set_debug_stream(stderr); hid_set_usb_debug(0); ret = hid_init(); if (ret != HID_RET_SUCCESS) { fprintf(stderr, "hid_init failed with return code %d\n", ret); return -1; } hid = hid_new_HIDInterface(); if (hid == 0) { fprintf(stderr, "hid_new_HIDInterface() failed, out of memory?\n"); return -1; } ret = hid_force_open(hid, IFACE_CONTROL, &matcher, 3); if (ret != HID_RET_SUCCESS) { fprintf(stderr, "hid_force_open failed with return code %d\n", ret); return -1; } ret = hid_os_force_claim(hid, 0, &matcher, 3); if (ret != HID_RET_SUCCESS) { fprintf(stderr, "hid_os_force_claim failed with return code %d\n", ret); return -1; } hid->interface = 1; return 0; }
bool RawHID::open(OpenMode mode) { QMutexLocker locker(m_mutex); int res; hid_device *handle; // Initialize the hidapi library (safe to call multiple times) res = hid_init(); // Open the device using the VID, PID handle = hid_open(m_deviceInfo->getVendorID(), m_deviceInfo->getProductID(), NULL); if (handle) { m_handle = handle; m_writeThread = new RawHIDWriteThread(this); m_readThread = new RawHIDReadThread(this); m_readThread->start(); m_writeThread->start(); } else { qDebug() << "Failed to open USB device"; } return QIODevice::open(mode); }
int main(void){ HIDInterface* hid; hid_return ret; HIDInterfaceMatcher matcher = { VENDOR, PRODUCT, NULL, NULL, 0 }; char packet[PACKET_LEN]; hid_set_debug(HID_DEBUG_NONE); hid_set_debug_stream(stderr); hid_set_usb_debug(0); hid_init(); hid = hid_new_HIDInterface(); ret = hid_force_open(hid, 0, &matcher, 3); if (ret == HID_RET_FAIL_DETACH_DRIVER) { printf("Failed to detach Driver for Device %04x:%04x; Permission?\n", VENDOR, PRODUCT); return 1; } if (ret != HID_RET_SUCCESS) { printf("Could not open HID device %04x:%04x (ret was %d)\n", VENDOR, PRODUCT, ret); return 1; } // printf("hid_force_open ret=%d\n", ret); // hid_set_idle(hid,0,0); // Discard till first '\n' do { memset(packet,0,sizeof(packet)); ret = hid_interrupt_read(hid,0x81,packet,PACKET_LEN,1000); } while (getTheChar(packet[1]) != '\n'); while (1) { memset(packet,0,sizeof(packet)); ret = hid_interrupt_read(hid,0x81,packet,PACKET_LEN,1000); /* if (ret == HID_RET_FAIL_INT_READ) { printf("Fail hid_interrupt_read\n"); } else { printf("hid_interrupt_read ret=%d\n", ret); } */ if( ret == HID_RET_SUCCESS ) { //printPacket(packet,PACKET_LEN); showTemperature(packet); } } hid_close(hid); hid_delete_HIDInterface(&hid); hid_cleanup(); return 0; }
int hid_change_skin(const char *filename) { int ret1, ret2; ret1 = hid_exit(); ret2 = hid_init(); return ret1 | ret2; }
HID_API_EXPORT hid_device* HID_API_CALL hid_open_path(const char *path) { hid_device *dev; HIDP_CAPS caps; PHIDP_PREPARSED_DATA pp_data = NULL; BOOLEAN res; NTSTATUS nt_res; if (hid_init() < 0) { return NULL; } dev = new_hid_device(); /* Open a handle to the device */ dev->device_handle = open_device(path, FALSE); /* Check validity of write_handle. */ if (dev->device_handle == INVALID_HANDLE_VALUE) { /* Unable to open the device. */ register_error(dev, "CreateFile"); goto err; } /* Set the Input Report buffer size to 64 reports. */ res = HidD_SetNumInputBuffers(dev->device_handle, 64); if (!res) { register_error(dev, "HidD_SetNumInputBuffers"); goto err; } /* Get the Input Report length for the device. */ res = HidD_GetPreparsedData(dev->device_handle, &pp_data); if (!res) { register_error(dev, "HidD_GetPreparsedData"); goto err; } nt_res = HidP_GetCaps(pp_data, &caps); if (nt_res != HIDP_STATUS_SUCCESS) { register_error(dev, "HidP_GetCaps"); goto err_pp_data; } dev->output_report_length = caps.OutputReportByteLength; dev->input_report_length = caps.InputReportByteLength; HidD_FreePreparsedData(pp_data); dev->read_buf = (char*) malloc(dev->input_report_length); return dev; err_pp_data: HidD_FreePreparsedData(pp_data); err: free_hid_device(dev); return NULL; }
static bool switch_joypad_init(void *data) { hid_init(); switch_joypad_autodetect_add(0); switch_joypad_autodetect_add(1); return true; }
REALTOUCH_DECLSPEC struct realtouch* realtouch_create() { struct realtouch* s = (struct realtouch*)malloc(sizeof(struct realtouch)); s->_is_open = 0; s->_is_inited = 0; hid_init(); s->_is_inited = 1; return s; }
int main(int argc, char* argv[]) { int res; int i; // Initialize the hidapi library printf("Starting to initialize HID library...\n"); res = hid_init(); printf("Initialized HID library.\n"); // Open the device using the VID, PID, // and optionally the Serial number. printf("Trying to open device...\n"); handle = hid_open(0x04d8, 0x003f, NULL); if(handle != NULL) { printf("Opened device successfully.\n"); } else { printf("Could not open device.\n"); exit(EXIT_FAILURE); } read_device_info(); toggle_led1(); printf("Button is %spressed.\n", get_push1_state() ? "" : "not "); printf("The decimal result is %d\n", get_pot1_val()); // Register signal handler if (signal(SIGINT, sig_handler) == SIG_ERR) { printf("\nCan't catch SIGINT\n"); exit(EXIT_FAILURE); } // Enter ncurses mode initialize_display(); // Main loop while(1) { int a; a = (int)((100 / 1023.0) * get_pot1_val()); print_percent_bar(2, a); refresh(); sleep(0.1); } // Leave ncurses mode end_display(); // Unregister signal handler signal(SIGINT, SIG_DFL); // Finalize the hidapi library res = hid_exit(); return 0; }
int main(int argc, char* argv[]) { int res; unsigned char buf[RELAY_COMMAND_SIZE]; hid_device *handle; unsigned char command; if (argc != 2) { fprintf(stderr, "usage: %s [on|off]\n", argv[0]); exit(1); } if (strcmp(argv[1], "on") == 0) { command = RELAY_STATE_ON; } else if (strcmp(argv[1], "off") == 0) { command = RELAY_STAT_OFF; } else if (strcmp(argv[1], "scan") == 0) { return doScan(); } else { fprintf(stderr, "usage: %s [on|off]\n", argv[0]); exit(1); } if (hid_init()) { fprintf(stderr, "can't init hid lib\n"); exit(1); } // Set up the command buffer. memset(buf,0x00,sizeof(buf)); buf[1] = command; buf[2] = RELAY_NUMBER; // Open the device using the VID, PID, // and optionally the Serial number. ////handle = hid_open(0x4d8, 0x3f, L"12345"); handle = hid_open(RELAY_VENDOR_ID, RELAY_PRODUCT_ID, NULL); if (!handle) { printf("unable to open device\n"); return 1; } res = hid_write(handle, buf, sizeof(buf)); if (res < 0) { printf("Unable to send command\n"); } hid_close(handle); /* Free static HIDAPI objects. */ hid_exit(); exit(0); }
void init_pid(unsigned short vid, unsigned short pid) { #ifdef OSX hid_init(); dev = hid_open(vid, pid, NULL); #else struct hid_device_info *info = NULL, *ptr = NULL; hid_init(); info = hid_enumerate(vid, pid); ptr = info; while (ptr != NULL) { if (ptr->interface_number == 1) { dev = hid_open_path(ptr->path); break; } ptr = ptr->next; } hid_free_enumeration(info); #endif }
int SC_HID_APIManager::initialize_hidapi(){ m_running = false; if (hid_init()){ post( "Unable to initialize hidapi\n"); return errFailed; } m_running = true; return errNone; }
Program::Program() { hid_init(); addCommand(make_shared<ListCommand>()); addCommand(make_shared<GetCommand>()); addCommand(make_shared<SetCommand>()); addCommand(make_shared<ConfigureCommand>()); addCommand(make_shared<DescribeCommand>()); addCommand(make_shared<GetEepromCommand>()); addCommand(make_shared<SetEepromCommand>()); addCommand(make_shared<HelpCommand>(this)); }
/** Initialize the HID TEMPer types. */ bool tempered_type_hid_init( char **error ) { if ( hid_init() != 0 ) { if ( error != NULL ) { *error = strdup( "Could not initialize the HID API." ); } return false; } return true; }
static t_int init_libhid(t_usbhid *x) { if (! hid_is_initialised() ) { x->x_hid_return = hid_init(); if(x->x_hid_return != HID_RET_SUCCESS) { error("[usbhid] hid_init failed with return code %d\n", x->x_hid_return); } } return(x->x_hid_return); }
int hid_switch_normal_view(void) { if(options.view != VIEW_NORMAL) { set_scale(options.view = VIEW_NORMAL); hid_exit(); hid_init(); //gdk_window_unfullscreen(main_wnd->window); } return 0; }
int hid_switch_fullscreen(void) { if(options.view != VIEW_FULL) { set_scale(options.view = VIEW_FULL); hid_exit(); hid_init(); gdk_window_fullscreen(main_wnd->window); } return 0; }
int hid_switch_large_view(void) { if(options.view != VIEW_LARGE) { set_scale(options.view = VIEW_LARGE); hid_exit(); hid_init(); //gdk_window_unfullscreen(main_wnd->window); } return 0; }
HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path) { hid_device *dev; HIDP_CAPS caps; HIDP_PREPARSED_DATA *pp_data = NULL; BOOLEAN res; NTSTATUS nt_res; if (hid_init() < 0) { return NULL; } dev = new_hid_device(); // Open a handle to the device dev->device_handle = open_device(path); // Check validity of write_handle. if (dev->device_handle == INVALID_HANDLE_VALUE) { // Unable to open the device. register_error(dev, "CreateFile"); goto err; } // Get the Input Report length for the device. res = HidD_GetPreparsedData(dev->device_handle, &pp_data); if (!res) { register_error(dev, "HidD_GetPreparsedData"); goto err; } nt_res = HidP_GetCaps(pp_data, &caps); if (nt_res != HIDP_STATUS_SUCCESS) { register_error(dev, "HidP_GetCaps"); goto err_pp_data; } dev->input_report_length = caps.InputReportByteLength; HidD_FreePreparsedData(pp_data); dev->read_buf = (char*) malloc(dev->input_report_length); return dev; err_pp_data: HidD_FreePreparsedData(pp_data); err: CloseHandle(dev->device_handle); free(dev); return NULL; }
int main(int argc, char *argv[]) { bdaddr_t bdaddr; int opt; hid_init(NULL); memcpy(&bdaddr, NG_HCI_BDADDR_ANY, sizeof(bdaddr)); while ((opt = getopt(argc, argv, "a:c:H:hv")) != -1) { switch (opt) { case 'a': /* bdaddr */ if (!bt_aton(optarg, &bdaddr)) { struct hostent *he = NULL; if ((he = bt_gethostbyname(optarg)) == NULL) errx(1, "%s: %s", optarg, hstrerror(h_errno)); memcpy(&bdaddr, he->h_addr, sizeof(bdaddr)); } break; case 'c': /* config file */ config_file = optarg; break; case 'H': /* HIDs file */ hids_file = optarg; break; case 'v': /* verbose */ verbose++; break; case 'h': default: usage(); /* NOT REACHED */ } } argc -= optind; argv += optind; if (*argv == NULL) usage(); return (do_bthid_command(&bdaddr, argc, argv)); } /* main */
hid_device * HID_API_EXPORT hid_open_path(const char *path) { hid_device *dev = NULL; hid_init(); dev = new_hid_device(); if (kernel_version == 0) { struct utsname name; int major, minor, release; int ret; uname(&name); ret = sscanf(name.release, "%d.%d.%d", &major, &minor, &release); if (ret == 3) { kernel_version = major << 16 | minor << 8 | release; //printf("Kernel Version: %d\n", kernel_version); } else { printf("Couldn't sscanf() version string %s\n", name.release); } } // OPEN HERE // dev->device_handle = open(path, O_RDWR); // If we have a good handle, return it. if (dev->device_handle > 0) { /* Get the report descriptor */ int res; struct hidraw_report_descriptor rpt_desc; res = get_report_descriptor(dev->device_handle, &rpt_desc); if (res >= 0) { /* Determine if this device uses numbered reports. */ dev->uses_numbered_reports = uses_numbered_reports(rpt_desc.value, rpt_desc.size); } return dev; } else { // Unable to open any devices. free(dev); return NULL; } }
int initializeUSB1208(){ ret = hid_init(); if (ret < 0) { fprintf(stderr, "hid_init failed with return code %d\n", ret); return -1; } if ((hid = hid_open(MCC_VID, USB1208LS_PID, NULL)) > 0) { //printf("USB-1208LS Device is found!\n"); } else { fprintf(stderr, "USB-1208LS not found.\n"); exit(1); } return 0; }
hid_device * HID_API_EXPORT hid_open_path(const char *path) { hid_device *dev = NULL; hid_init(); dev = new_hid_device(); /* OPEN HERE */ dev->device_handle = open(path, O_RDWR); /* If we have a good handle, return it. */ /* test test shoud be >= 0 even if it is not so likely (I guess) */ if (dev->device_handle > 0) { /* Get the report descriptor */ int res, desc_size = 0; struct hidraw_report_descriptor rpt_desc; memset(&rpt_desc, 0x0, sizeof(rpt_desc)); /* Get Report Descriptor Size */ res = ioctl(dev->device_handle, HIDIOCGRDESCSIZE, &desc_size); if (res < 0) perror("HIDIOCGRDESCSIZE"); /* Get Report Descriptor */ rpt_desc.size = desc_size; res = ioctl(dev->device_handle, HIDIOCGRDESC, &rpt_desc); if (res < 0) { perror("HIDIOCGRDESC"); } else { /* Determine if this device uses numbered reports. */ dev->uses_numbered_reports = uses_numbered_reports(rpt_desc.value, rpt_desc.size); } return dev; } else { /* Unable to open any devices. */ free(dev); return NULL; } }
int main() { hid_init(); struct hid_device_info *hid_dev = hid_enumerate(0, 0); while (hid_dev) { std::printf("HID device: VID=%x PID=%x Path=%s Product string: \"%S\"\n", hid_dev->vendor_id, hid_dev->product_id, hid_dev->path, hid_dev->product_string); hid_dev = hid_dev->next; } hid_exit(); return 0; }
static void run(bool verbose, bool diagnostic, bool proxy_log) { hid_init(); zsys_set_logsender(LOG_PUB_ENDPOINT); // zsys_set_logsystem(true); twps_server_t *self = twps_new(verbose, proxy_log); assert(self); self->diagnostic = diagnostic; zpoller_t *poller = zpoller_new(self->printer_store_sub, NULL); while (!zctx_interrupted) { void *which = zpoller_wait(poller, 200); if (which == self->printer_store_sub) { s_loop_handle_printer_store_sub(self); } } zpoller_destroy(&poller); twps_destroy(&self); hid_exit(); }
int LedDeviceLightpackHidapi::open(const std::string & serialNumber) { // initialize the usb context int error = hid_init(); if (error != 0) { Error(_log, "Error while initializing the hidapi context"); return -1; } Info("Hidapi initialized"); // retrieve the list of usb devices hid_device_info * deviceList = hid_enumerate(0x0, 0x0); // iterate the list of devices for (hid_device_info * deviceInfo = deviceList; deviceInfo != nullptr; deviceInfo = deviceInfo->next) { // try to open and initialize the device error = testAndOpen(deviceInfo, serialNumber); if (error == 0) { // a device was sucessfully opened. break from list break; } } // free the device list hid_free_enumeration(deviceList); if (_deviceHandle == nullptr) { if (_serialNumber.empty()) { Error(_log, "No Lightpack device has been found"); } else { Error(_log, "No Lightpack device has been found with serial %s", _serialNumber); } } return _deviceHandle == nullptr ? -1 : 0; }