예제 #1
0
bool HIDDevice::GetFeatureReport(UByte* data, UInt32 length)
{
    if (!Device)
        return false;
    
    CFIndex bufferLength = length;
    
    // Report id is in first byte of the buffer.
	IOReturn result = IOHIDDeviceGetReport(Device, kIOHIDReportTypeFeature, data[0], data, &bufferLength);
	
    return (result == kIOReturnSuccess);
}
예제 #2
0
파일: usb_mac.c 프로젝트: julianliaw/ckb
int _usbinput(usbdevice* kb, uchar* message, const char* file, int line){
    if(!IS_ACTIVE(kb))
        return -1;
    CFIndex length = MSG_SIZE;
    IOReturn res = IOHIDDeviceGetReport(kb->handle, kIOHIDReportTypeFeature, 0, message, &length);
    if(res != kIOReturnSuccess){
        printf("Error: usbinput (%s:%d): Got return value %d\n", file, line, res);
        return 0;
    }
    if(length != MSG_SIZE)
        printf("Warning: usbinput (%s:%d): Read %d bytes (expected %d)\n", file, line, (int)length, MSG_SIZE);
    return length;
}
예제 #3
0
파일: usb_mac.c 프로젝트: jsnel/ckb
int _usbinput(usbdevice* kb, uchar* message, const char* file, int line){
    if(!IS_CONNECTED(kb) || !HAS_FEATURES(kb, FEAT_RGB))
        return -1;
    CFIndex length = MSG_SIZE;
    IOReturn res = IOHIDDeviceGetReport(kb->handle, kIOHIDReportTypeFeature, 0, message, &length);
    kb->lastError = res;
    if(res != kIOReturnSuccess && res != 0xe0004051){
        printf("usbinput (%s:%d): Got return value 0x%x\n", file, line, res);
        return 0;
    }
    if(length != MSG_SIZE)
        printf("usbinput (%s:%d): Read %d bytes (expected %d)\n", file, line, (int)length, MSG_SIZE);
    return length;
}
int HID_API_EXPORT hid_get_feature_report(hid_device *dev, unsigned char *data, size_t length)
{
	CFIndex len = length;
	IOReturn res;

	res = IOHIDDeviceGetReport(dev->device_handle,
	                           kIOHIDReportTypeFeature,
	                           data[0], /* Report ID */
	                           data, &len);
	if (res == kIOReturnSuccess)
		return len;
	else
		return -1;
}
예제 #5
0
파일: hid.c 프로젝트: ndrake/blink1
int HID_API_EXPORT hid_get_feature_report(hid_device *dev, unsigned char *data, size_t length)
{
    CFIndex len = length;
    IOReturn res;

    /* Return if the device has been unplugged. */
    if (dev->disconnected)
        return -1;

    res = IOHIDDeviceGetReport(dev->device_handle,
                               kIOHIDReportTypeFeature,
                               data[0], /* Report ID */
                               data, &len);
    if (res == kIOReturnSuccess)
        return (int)len;
    else
        return -1;
}
예제 #6
0
int _ykusb_read(void *dev, int report_type, int report_number,
		char *buffer, int size)
{
	CFIndex sizecf = (CFIndex)size;

	if (report_type != REPORT_TYPE_FEATURE)
	{
		yk_errno = YK_ENOTYETIMPL;
		return 0;
	}

	_ykusb_IOReturn = IOHIDDeviceGetReport( dev, kIOHIDReportTypeFeature, report_number, (uint8_t *)buffer, (CFIndex *) &sizecf );

	if ( _ykusb_IOReturn != kIOReturnSuccess )
	{
		yk_errno = YK_EUSBERR;
		return 0;
	}

	return (int)sizecf;
}
/*
 * @return number of bytes read if function succeeds otherwise -1 if an error occurs.
 * @throws SerialComException if any JNI function, system call or C function fails.
 */
jint mac_get_feature_report(JNIEnv *env, jlong fd, jbyte reportID, jbyteArray report, jint length) {
	IOReturn ret = -1;
	int num_bytes_to_read = 0;
	int report_id = -1;
	jbyte* buffer = NULL;

	if(reportID < 0) {
		buffer = (jbyte *) calloc(length, sizeof(unsigned char));
		if(buffer == NULL) {
			throw_serialcom_exception(env, 3, 0, E_CALLOCSTR);
			return -1;
		}
		(*env)->GetByteArrayRegion(env, report, 0, length, &buffer[0]);
		num_bytes_to_read = length;
		report_id = 0x00;
	}else {
		buffer = (jbyte *) calloc((length + 1), sizeof(unsigned char));
		if(buffer == NULL) {
			throw_serialcom_exception(env, 3, 0, E_CALLOCSTR);
			return -1;
		}
		buffer[0] = reportID;
		(*env)->GetByteArrayRegion(env, report, 0, length, &buffer[1]);
		num_bytes_to_read = length + 1;
		report_id = reportID;
	}
	if((*env)->ExceptionOccurred(env) != NULL) {
		throw_serialcom_exception(env, 3, 0, E_GETBYTEARRREGIONSTR);
		return -1;
	}

	/* after completion num_bytes_to_read will contain number of bytes read. */
	ret = IOHIDDeviceGetReport(fd, kIOHIDReportTypeFeature, report_id, buffer, &num_bytes_to_read);
	if(ret != kIOReturnSuccess) {
		/* to error throw_serialcom_exception(env, 1, errno, NULL);*/
		return -1;
	}

	return num_bytes_to_read;
}
예제 #8
0
static void __timerCallback(CFRunLoopTimerRef timer, void *info)
{
    IOHIDDeviceRef  device = (IOHIDDeviceRef)info;
    
    CFNumberRef     number      = NULL;
    CFIndex         reportSize  = 0;
    IOReturn        result;
    
    number = IOHIDDeviceGetProperty(device, CFSTR(kIOHIDMaxInputReportSizeKey));
    if ( !number )
        return;
    
    CFNumberGetValue(number, kCFNumberCFIndexType, &reportSize);
    
    uint8_t report[reportSize];
    
    bzero(report, reportSize);
    
    result = IOHIDDeviceGetReport(device, kIOHIDReportTypeInput, 0, report, &reportSize);
    
    __deviceReportCallback(NULL, result, device, kIOHIDReportTypeInput, 0, report, reportSize);
}
예제 #9
0
 void GetReport(Connection* aConnection, bool aFeature, uint8_t aID, uint8_t* aData, uint16_t aSize)
 {
     CFIndex size = aSize - 1;
     IOHIDDeviceGetReport(aConnection->device, aFeature ? kIOHIDReportTypeFeature : kIOHIDReportTypeInput,
                          aID, aData + 1, &size);
 }