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;
}
PhidgetManager::~PhidgetManager()
{
	// Close the manager    
	CPhidgetManager_close((CPhidgetManagerHandle) _manHandle);
	CPhidgetManager_delete((CPhidgetManagerHandle) _manHandle);

	sleep(0.5);
}
Beispiel #3
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;
}
JNIEXPORT void JNICALL
Java_com_phidgets_Manager_nativeClose(JNIEnv *env, jobject obj)
{
	int error;
	
	CPhidgetManagerHandle h = (CPhidgetManagerHandle)(uintptr_t)
	    (*env)->GetLongField(env, obj, manager_handle_fid);

	if ((error = CPhidgetManager_close(h)))
		PH_THROW(error);
}
PhidgetManager::~PhidgetManager()
{
	Lock();

	PhidgetsInfo* item;
	while (NULL!=(item=m_phidget_list))
	{
		m_phidget_list = m_phidget_list->m_next_phidget;
		delete item;
	}

  CPhidgetManager_close(m_manager);
  CPhidgetManager_delete(m_manager);

	Unlock();
	pthread_mutex_destroy(&m_phidget_mutex);
}
Beispiel #6
0
int main() 
{
  CPhidgetManagerHandle phidm;
	
  //CPhidget_enableLogging(PHIDGET_LOG_VERBOSE, NULL);
	
  CPhidgetManager_create(&phidm);
  CPhidgetManager_set_OnAttach_Handler(phidm, gotAttach, NULL);
  CPhidgetManager_set_OnDetach_Handler(phidm, gotDetach, NULL);
  CPhidgetManager_open(phidm);
  //CPhidgetManager_openRemote(phidm, NULL, NULL);

  signal (SIGTERM, sighandler);
  signal (SIGINT, sighandler);

while(!exitMan)
  sleep(5);

  printf ("Removing resources.\n");
	 CPhidgetManager_close(phidm);
	 CPhidgetManager_delete(phidm);
  return 0;
}
PhidgetsDeviceManager::~PhidgetsDeviceManager()
{
    CPhidgetManager_close(manager);
    CPhidgetManager_delete(manager);

}