Esempio n. 1
0
int usbmain(){
    int vendor = V_CORSAIR;
    int products[] = { P_K65, P_K70, P_K70_NRGB, P_K95, P_K95_NRGB/*, P_M65*/ };
    // Tell IOService which type of devices we want (IOHIDDevices matching the supported vendor/products)
    CFMutableDictionaryRef match = IOServiceMatching(kIOHIDDeviceKey);
    CFNumberRef cfvendor = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &vendor);
    CFDictionarySetValue(match, CFSTR(kIOHIDVendorIDKey), cfvendor);
    CFRelease(cfvendor);
    CFMutableArrayRef cfproducts = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
    for(uint i = 0; i < sizeof(products) / sizeof(int); i++){
        int product = products[i];
        CFNumberRef cfproduct = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &product);
        CFArrayAppendValue(cfproducts, cfproduct);
        CFRelease(cfproduct);
    }
    CFDictionarySetValue(match, CFSTR(kIOHIDProductIDArrayKey), cfproducts);
    CFRelease(cfproducts);

    notify = IONotificationPortCreate(kIOMasterPortDefault);
    CFRunLoopAddSource(mainloop = CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(notify), kCFRunLoopDefaultMode);
    io_iterator_t iterator;
    IOReturn res = IOServiceAddMatchingNotification(notify, kIOMatchedNotification, match, iterate_devices, 0, &iterator);
    if(res != kIOReturnSuccess){
        ckb_fatal("Failed to list devices: %x\n", res);
        return -1;
    }
    // Iterate existing devices
    iterate_devices(0, iterator);
    // Enter loop to scan/connect new devices
    CFRunLoopRun();
    return 0;
}
Esempio n. 2
0
static PyObject *
S_get_devices(PyObject *self, PyObject *args)
{
    int num;
    PyObject *devices = PyList_New(0);

    num = iterate_devices(_get_devices_callback, (void*)devices);
    if(PyErr_Occurred() != NULL) return NULL;
    if(num == -1)
    {
        PyErr_SetString(PyExc_RuntimeError, "Could not get services.");
        return NULL;
    }
    return devices;
}
Esempio n. 3
0
void							  generate_position()
{
	// Allocates memory for new Iteration and Params_Template structures.
	Iterate* iter = generate_iter();
  iter->params->params = malloc(sizeof(Params_Position));
	// Initializes iter's fields.
	iter->compute_result = &compute_result_position;
	iter->free_params = &free_params_position;
  iter->scan = &scan_position;
  iter->params->result_type = POSITION_DEVICE;
  iter->params->result_model = OTHER;
	// Iterates.
	iterate_devices(iter);
	// Frees allocated ressources.
	free_iter(iter);
}
Esempio n. 4
0
void							generate_vgyro()
{
	// Allocates memory for new Iteration and Params_Vaccel structures.
	Iterate *iter = generate_iter();
  Params_Vgyro *params_ = malloc(sizeof(Params_Vgyro));
  // Create a kalman filter using the data configuration for it.
  Conf *c = load_config_data();
  params_->kf = build_kalman(c);
  free_conf(c);
	// Initializes iter's fields.
	iter->compute_result = &compute_result_vgyro;
	iter->initialize_per_axis = &initialize_per_axis_vgyro;
	iter->free_params = &free_params_vgyro;
  iter->scan = &scan_vgyro;
  iter->params->params = params_;
  iter->params->result_type = GYROSCOPE;
  iter->params->result_model = VIRTUAL;
	// Iterates.
	iterate_devices(iter);
	// Frees allocated ressources.
	free_iter(iter);
}