示例#1
0
	/** 
	 * Inits connection with the motor
	 */
	bool PhidgetLEDController::init( int serialNumber /*= -1*/)
	{
		// If it has already been init, do nothing
		if ( m_isValid )
		{
			LOG( "PhidgetLEDController::init(). This motor controller was init already --> Doing nothing" );
			return false;
		}

		//create the LED object
		LOG( "Connecting to Phidget LED board" );
		CPhidgetLED_create(&m_LEDControl);

		// Open the connection with the board
		return PhidgetControllerBase::init(serialNumber);
	}
示例#2
0
bool attach(
			CPhidgetLEDHandle &phid,
			int serial_number)
{
    int result;
    const char *err;

    // create the LED object
    CPhidgetLED_create(&phid);

    // Set the handlers to be run when the device is
	// plugged in or opened from software, unplugged or
	// closed from software, or generates an error.
    CPhidget_set_OnAttach_Handler((CPhidgetHandle)phid,
								  AttachHandler, NULL);
    CPhidget_set_OnDetach_Handler((CPhidgetHandle)phid,
								  DetachHandler, NULL);
    CPhidget_set_OnError_Handler((CPhidgetHandle)phid,
								 ErrorHandler, NULL);

    //open the LED for device connections
    CPhidget_open((CPhidgetHandle)phid, -1);

    //get the program to wait for an LED device to be attached
    printf("Waiting for LED to be attached....");
    if ((result =
		 CPhidget_waitForAttachment((CPhidgetHandle)phid,
									10000))) {
        CPhidget_getErrorDescription(result, &err);
        printf("Problem waiting for attachment: %s\n", err);
        return false;
    }
    else {
        return true;
    }
}
int LED_simple()
{
	int result, i;
	const char *err;

	//Declare an LED handle
	CPhidgetLEDHandle led = 0;

	//create the LED object
	CPhidgetLED_create(&led);

	//Set the handlers to be run when the device is plugged in or opened from software, unplugged or closed from software, or generates an error.
	CPhidget_set_OnAttach_Handler((CPhidgetHandle)led, AttachHandler, NULL);
	CPhidget_set_OnDetach_Handler((CPhidgetHandle)led, DetachHandler, NULL);
	CPhidget_set_OnError_Handler((CPhidgetHandle)led, ErrorHandler, NULL);

	//open the LED for device connections
	CPhidget_open((CPhidgetHandle)led, -1);

	//get the program to wait for an LED device to be attached
	printf("Waiting for LED to be attached....");
	if((result = CPhidget_waitForAttachment((CPhidgetHandle)led, 10000)))
	{
		CPhidget_getErrorDescription(result, &err);
		printf("Problem waiting for attachment: %s\n", err);
		return 0;
	}

	//Display the properties of the attached LED device
	display_properties(led);

	printf("Press any key to continue\n");
	getchar();

	//turn on the leds one at a time.
	//This example assumes LED's plugged into locations 0-9
	for(i = 0; i < 10; i++)
	{
		CPhidgetLED_setBrightness(led, i, 100); //maximum brightness is 100, 0 is off.  Can set this value to anything including and inbetween these values.
	}

	printf("Press any key to continue\n");
	getchar();

	//turn off the LEDs one at a a time
	//This example assumes LED's plugged into locations 0-9
	for(i = 0; i < 10; i++)
	{
		CPhidgetLED_setBrightness(led, i, 0); //maximum brightness is 100, 0 is off.  Can set this value to anything including and inbetween these values.
	}

	printf("Press any key to end\n");
	getchar();

	//since user input has been read, this is a signal to terminate the program so we will close the phidget and delete the object we created
	printf("Closing...\n");
	CPhidget_close((CPhidgetHandle)led);
	CPhidget_delete((CPhidgetHandle)led);

	//all done, exit
	return 0;
}