Beispiel #1
0
static int set_report(hid_device *dev, IOHIDReportType type, const unsigned char *data, size_t length)
{
    const unsigned char *data_to_send;
    size_t length_to_send;
    IOReturn res;

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

    if (data[0] == 0x0) {
        /* Not using numbered Reports.
           Don't send the report number. */
        data_to_send = data+1;
        length_to_send = length-1;
    }
    else {
        /* Using numbered Reports.
           Send the Report Number */
        data_to_send = data;
        length_to_send = length;
    }

    if (!dev->disconnected) {
        res = IOHIDDeviceSetReport(dev->device_handle,
                                   type,
                                   data[0], /* Report ID*/
                                   data_to_send, length_to_send);

        if (res == kIOReturnSuccess) {
            return length;
        }
        else
            return -1;
    }

    return -1;
}
Beispiel #2
0
static void output_thread(void *arg)
{
	teensy_t *t = (teensy_t *)arg;
	struct timeval tv;
	struct timespec ts;
	uint8_t buf[64];
	int r;

	printf("output_thread begin\n");
	while (1) {
		//printf("output_thread\n");
		if (t->online == 0) break;
		if (TeensyControls_output_fetch(t, buf) && t->online) {
			//printf("output_thread: send\n");
			IOHIDDeviceSetReport(t->usb.dev,
				kIOHIDReportTypeOutput,
				0, buf, 64);
		} else {
			pthread_mutex_lock(&t->output_mutex);
			if (t->output_head == t->output_tail) {
				t->output_thread_waiting = 1;
				//clock_gettime(CLOCK_REALTIME, &ts);
				gettimeofday(&tv, NULL);
				ts.tv_sec = tv.tv_sec;
				ts.tv_nsec = tv.tv_usec*1000;
				ts.tv_sec += 1;
				r = pthread_cond_timedwait(&t->output_event,
					&t->output_mutex, &ts);
				t->output_thread_waiting = 0;
				//printf("output_thread, r: %d, errno: %d\n", r, errno);
			}
			pthread_mutex_unlock(&t->output_mutex);
			// wait for event signal, 1 sec timeout
		}
	}
	t->output_thread_quit = 1;
	printf("output_thread end\n");
}
Beispiel #3
0
bool HIDDevice::SetFeatureReport(UByte* data, UInt32 length)
{
    
    if (!Device)
        return false;
    
    UByte reportID = data[0];

    if (reportID == 0)
    {
        // Not using reports so remove from data packet.
        data++;
        length--;
    }
    
	IOReturn result = IOHIDDeviceSetReport( Device,
                                            kIOHIDReportTypeFeature,
                                            reportID,
                                            data,
                                            length);
    
    return (result == kIOReturnSuccess);
}
int yyySignalOutPkt(yInterfaceSt *iface, char *errmsg)
{
    int res =YAPI_SUCCESS;
    pktItem *pktitem;

    yPktQueuePopH2D(iface, &pktitem);
    while (pktitem!=NULL){
        if(iface->devref==NULL){
            yFree(pktitem);
            return YERR(YAPI_IO_ERROR);
        }
        res = IOHIDDeviceSetReport(iface->devref,
                                   kIOHIDReportTypeOutput,
                                   0, /* Report ID*/
                                   (u8*)&pktitem->pkt, sizeof(USB_Packet));
        yFree(pktitem);
        if (res != kIOReturnSuccess) {
            dbglog("IOHIDDeviceSetReport failed with 0x%x\n", res);
            return YERRMSG(YAPI_IO_ERROR,"IOHIDDeviceSetReport failed");;
        }
        yPktQueuePopH2D(iface, &pktitem);
    }
	return YAPI_SUCCESS;
}
int main( int argc, const char * argv[] )
{
	Boolean initialized = FALSE;
	
	if (( argc != 4 ) && ( argc != 5 ))  {
		printf ( "usage: Dream Cheeky Notifier R G B [A]\n\tRGB values should be 0-31.  A is an optional parameter on whether to do the LED activation sequence.  Anything larger than 0 is YES, default is 0 (activate).\n\n");
		exit ( -1 );
	}
	
	char r = (int)strtol ( argv[1], NULL, 10 );
	char g = (int)strtol ( argv[2], NULL, 10 );
	char b = (int)strtol ( argv[3], NULL, 10 );
	if ( argc == 5 ) {
		initialized = TRUE;
	}
	
	if ((r < 0) || (r > 31) || (g < 0) || (g > 31) || (b < 0) || (b > 31)) {
		printf("RGB values must be within 0-31.");
		exit -1;
	}
	
	// create a IO HID Manager reference
	IOHIDManagerRef tIOHIDManagerRef = IOHIDManagerCreate( kCFAllocatorDefault, kIOHIDOptionsTypeNone );
	// Create a device matching dictionary
	CFDictionaryRef matchingCFDictRef = hu_CreateMatchingDictionaryUsagePageUsage( TRUE,
																				  kHIDPage_GenericDesktop,
																				  0x10 );
	// set the HID device matching dictionary
	IOHIDManagerSetDeviceMatching( tIOHIDManagerRef, matchingCFDictRef );
	if ( matchingCFDictRef ) {
		CFRelease( matchingCFDictRef );
	}
	
	// Now open the IO HID Manager reference
	IOReturn tIOReturn = IOHIDManagerOpen( tIOHIDManagerRef, kIOHIDOptionsTypeNone );
	
	// and copy out its devices
	CFSetRef deviceCFSetRef = IOHIDManagerCopyDevices( tIOHIDManagerRef );
	
	// how many devices in the set?
	CFIndex deviceIndex, deviceCount = CFSetGetCount( deviceCFSetRef );
	
	// allocate a block of memory to extact the device ref's from the set into
	IOHIDDeviceRef * tIOHIDDeviceRefs = malloc( sizeof( IOHIDDeviceRef ) * deviceCount );
	
	// now extract the device ref's from the set
	CFSetGetValues( deviceCFSetRef, (const void **) tIOHIDDeviceRefs );
	
	// before we get into the device loop we'll setup our element matching dictionary (Note: we don't do element matching anymore)
	matchingCFDictRef = hu_CreateMatchingDictionaryUsagePageUsage( FALSE, 0, 0 );
	
	for ( deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++ ) {
		
		// if this isn't the notifier device...  TODO: let's detect via vendor/product ids instead
		long vendor_id = 0;
		IOHIDDevice_GetLongProperty(tIOHIDDeviceRefs[deviceIndex], CFSTR(kIOHIDVendorIDKey), &vendor_id);
		long product_id = 0;
		IOHIDDevice_GetLongProperty(tIOHIDDeviceRefs[deviceIndex], CFSTR(kIOHIDProductIDKey), &product_id);
		if ((vendor_id != 0x1D34 ) || (product_id != 0x0004 )) {
			printf("	skipping device %p.\n", tIOHIDDeviceRefs[deviceIndex] );
			continue;	// ...skip it
		}
		
		printf( "	 device = %p.\n", tIOHIDDeviceRefs[deviceIndex] );
		
		unsigned char report[8];
		if (initialized == FALSE) {
			report[0] = 0x1F; // turn on LEDs
			report[1] = 0x02;
			report[2] = 0x00;
			report[3] = 0x5F;
			report[4] = 0x00;
			report[5] = 0x00;
			report[6] = 0x1A;
			report[7] = 0x03;
			
            // Note: We don't use the returned value here, so the compiler might throw a warning.
			IOReturn  tIOReturn = IOHIDDeviceSetReport(
													   tIOHIDDeviceRefs[deviceIndex],          // IOHIDDeviceRef for the HID device
													   kIOHIDReportTypeInput,   // IOHIDReportType for the report (input, output, feature)
													   0,           // CFIndex for the report ID
													   report,             // address of report buffer
													   8);      // length of the report
			initialized = TRUE;
		}
		
		report[0] = r; // set brightness on LEDs to r, g, & b
		report[1] = g;
		report[2] = b;
		report[3] = 0x00;
		report[4] = 0x00;
		report[5] = 0x00;
		report[6] = 0x1A;
		report[7] = 0x05;
		
		tIOReturn = IOHIDDeviceSetReport(
										 tIOHIDDeviceRefs[deviceIndex],          // IOHIDDeviceRef for the HID device
										 kIOHIDReportTypeInput,   // IOHIDReportType for the report (input, output, feature)
										 0,           // CFIndex for the report ID
										 report,             // address of report buffer
										 8);      // length of the report
		
	next_device: ;
		continue;
	}
	
	
	if ( tIOHIDManagerRef ) {
		CFRelease( tIOHIDManagerRef );
	}
	
	if ( matchingCFDictRef ) {
		CFRelease( matchingCFDictRef );
	}
Oops:	;
	return -1;
} /* main */
Beispiel #6
0
 void run() {
     ret = IOHIDDeviceSetReport(dev, kIOHIDReportTypeOutput, 2, buf, len);
     result = (ret == kIOReturnSuccess) ? len : -1;
 }
 void SetReport(Connection* aConnection, bool aFeature, uint8_t aID, uint8_t* aData, uint16_t aSize)
 {
     IOHIDDeviceSetReport(aConnection->device, aFeature ? kIOHIDReportTypeFeature : kIOHIDReportTypeOutput,
                          aID, aData + 1, aSize - 1);
 }
Beispiel #8
0
void apple_pad_send_control(struct apple_pad_connection* connection, uint8_t* data, size_t size)
{
   IOHIDDeviceSetReport(connection->device, kIOHIDReportTypeOutput, 0x01, data + 1, size - 1);
}