Ejemplo n.º 1
0
int main(void) {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	DualButton db;
	dual_button_create(&db, UID, &ipcon);

	// Connect to brickd
	if(ipcon_connect(&ipcon, HOST, PORT) < 0) {
		fprintf(stderr, "Could not connect\n");
		return 1;
	}
	// Don't use device before ipcon is connected

	// Register state changed callback to function cb_state_changed
	dual_button_register_callback(&db,
	                              DUAL_BUTTON_CALLBACK_STATE_CHANGED,
	                              (void *)cb_state_changed,
	                              NULL);

	printf("Press key to exit\n");
	getchar();
	dual_button_destroy(&db);
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
	return 0;
}
TinkerforgeSensors::~TinkerforgeSensors()
{
  bool is_ipcon = false;
  // clean up tf devices
  while(!sensors.empty())
  {
    SensorDevice *dev = sensors.front();
    switch (dev->getType())
    {
      case AMBIENT_LIGHT_DEVICE_IDENTIFIER:
        ambient_light_destroy((AmbientLight*)dev->getDev());
      break;
      case AMBIENT_LIGHT_V2_DEVICE_IDENTIFIER:
        ambient_light_v2_destroy((AmbientLightV2*)dev->getDev());
      break;
      case DISTANCE_IR_DEVICE_IDENTIFIER:
        distance_ir_destroy((DistanceIR*)dev->getDev());
      break;
      case DISTANCE_US_DEVICE_IDENTIFIER:
        distance_us_destroy((DistanceUS*)dev->getDev());
      break;
      case DUAL_BUTTON_DEVICE_IDENTIFIER:
        dual_button_destroy((DualButton*)dev->getDev());
      break;
      case GPS_DEVICE_IDENTIFIER:
        gps_destroy((GPS*)dev->getDev());
      break;
      case IMU_DEVICE_IDENTIFIER:
        imu_leds_off((IMU*)dev->getDev());
        imu_destroy((IMU*)dev->getDev());
      break;
      case IMU_V2_DEVICE_IDENTIFIER:
        imu_v2_leds_off((IMUV2*)dev->getDev());
        imu_v2_destroy((IMUV2*)dev->getDev());
      break;
      case TEMPERATURE_DEVICE_IDENTIFIER:
        temperature_destroy((Temperature*)dev->getDev());
      break;
    }
    delete dev;
    sensors.pop_front();
    is_ipcon = true;
  }
  if (is_ipcon)
  {
    ipcon_destroy(&ipcon);
  }
}