Ejemplo n.º 1
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;
}