int manager_simple()
{
	//Declare an Manager handle
	CPhidgetManagerHandle man = 0;

	CPhidget_enableLogging(PHIDGET_LOG_VERBOSE, NULL);

	//create the Manager object
	CPhidgetManager_create(&man);

	//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.
	CPhidgetManager_set_OnAttach_Handler(man, AttachHandler, man);
	CPhidgetManager_set_OnDetach_Handler(man, DetachHandler, man);
	CPhidgetManager_set_OnError_Handler(man, ErrorHandler, NULL);

	//open the Manager for device connections
	CPhidgetManager_open(man);
	//end simulation
	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");
	CPhidgetManager_close(man);
	CPhidgetManager_delete(man);

	//all done, exit
	return 0;
}
Example #2
0
int main() {
    
    Compass testCompass;
    InterfaceKit ifKit;
    LCD lcd;
    Motor motor;
    Spatial spatial;

    CPhidgetManagerHandle device = 0;
    LocalErrorCatcher(
        CPhidgetManager_create(&device));
    
    LocalErrorCatcher(
        CPhidgetManager_set_OnAttach_Handler((CPhidgetManagerHandle) device, 
                                         AttachHandler, NULL));
    
    LocalErrorCatcher(
        CPhidgetManager_set_OnDetach_Handler((CPhidgetManagerHandle ) device,
                                         DetachHandler, NULL));
    
    LocalErrorCatcher(
        CPhidgetManager_set_OnError_Handler((CPhidgetManagerHandle) device,
                                        LibraryErrorHandler, NULL));
    printf("Starting Phidget Playground...\n");
    // Most opening and closing would be via a cast to
    // (CPhidgetHandle), however, this manager has its
    // own handle struct to cast to.
	
	LocalErrorCatcher(
        CPhidgetManager_open((CPhidgetManagerHandle) device));
    
    std::stringstream ss;
    lcd.clear();
	
    for(int i=0;i<1000;i++){
        testCompass.refresh();
        ss << std::fixed <<  std::setprecision(1) << "Heading: " << testCompass.getHeading();
        lcd.setText(ss.str(), 0);
        ss.str(std::string());
        
        ss << std::fixed << std::setprecision(2) << spatial.getAcceleration(AXIS_X) << " " << spatial.getAcceleration(AXIS_Y) << " " << spatial.getAcceleration(AXIS_Z);
        lcd.setText(ss.str(), 1);
        ss.str(std::string());
        
        usleep(100000);
    }

    printf("Press Enter to end...\n");
    getchar();

    LocalErrorCatcher(
        CPhidgetManager_close((CPhidgetManagerHandle) device));
    LocalErrorCatcher(
        CPhidgetManager_delete((CPhidgetManagerHandle) device));

    return 0;
}
int PhidgetsDeviceManager::initDevices()
{

      int res = LocalErrorCatcher(CPhidgetManager_create(&manager));

      if(res != 0) return res;


     res =  LocalErrorCatcher(
           CPhidgetManager_set_OnAttach_Handler((CPhidgetManagerHandle) manager,
                                            AttachHandler, this));

     if(res != 0) return res;

     res =  LocalErrorCatcher(
           CPhidgetManager_set_OnDetach_Handler((CPhidgetManagerHandle ) manager,
                                            DetachHandler, this));

     if(res != 0) return res;

     res =  LocalErrorCatcher(
           CPhidgetManager_set_OnError_Handler((CPhidgetManagerHandle) manager,
                                           LibraryErrorHandler, this));

     if(res != 0) return res;

       // Most opening and closing would be via a cast to
       // (CPhidgetHandle), however, this manager has its
       // own handle struct to cast to.
     res=  LocalErrorCatcher(
           CPhidgetManager_open((CPhidgetManagerHandle) manager));



     return res;

}