int main(void) {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	Pressure p;
	pressure_create(&p, 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

	// Get current pressure (unit is Pa)
	int32_t pressure;
	if(pressure_get_pressure(&p, &pressure) < 0) {
		fprintf(stderr, "Could not get pressure, probably timeout\n");
		return 1;
	}

	printf("Pressure: %f kPa\n", pressure/1000.0);

	printf("Press key to exit\n");
	getchar();
	pressure_destroy(&p);
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
	return 0;
}
int main() {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	Barometer b;
	barometer_create(&b, UID, &ipcon);

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

	// Get threshold callbacks with a debounce time of 10 seconds (10000ms)
	barometer_set_debounce_period(&b, 10000);

	// Register threshold reached callback to function cb_reached
	barometer_register_callback(&b,
	                            BAROMETER_CALLBACK_AIR_PRESSURE_REACHED,
	                            (void *)cb_reached,
	                            NULL);

	// Configure threshold for "greater than 1025 mbar" (unit is mbar/1000)
	barometer_set_air_pressure_callback_threshold(&b, '>', 1025*1000, 0);

	printf("Press key to exit\n");
	getchar();
	ipcon_destroy(&ipcon);
}
Пример #3
0
int main(void) {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	SoundIntensity si;
	sound_intensity_create(&si, 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 intensity callback to function cb_intensity
	sound_intensity_register_callback(&si,
	                                  SOUND_INTENSITY_CALLBACK_INTENSITY,
	                                  (void *)cb_intensity,
	                                  NULL);

	// Set period for intensity callback to 0.05s (50ms)
	// Note: The intensity callback is only called every 0.05 seconds
	//       if the intensity has changed since the last call!
	sound_intensity_set_intensity_callback_period(&si, 50);

	printf("Press key to exit\n");
	getchar();
	sound_intensity_destroy(&si);
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
	return 0;
}
Пример #4
0
int main(void) {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	Tilt t;
	tilt_create(&t, 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

	// Enable tilt state callback
	tilt_enable_tilt_state_callback(&t);

	// Register tilt state callback to function cb_tilt_state
	tilt_register_callback(&t,
	                       TILT_CALLBACK_TILT_STATE,
	                       (void *)cb_tilt_state,
	                       NULL);

	printf("Press key to exit\n");
	getchar();
	tilt_destroy(&t);
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
	return 0;
}
Пример #5
0
int main(void) {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	Moisture m;
	moisture_create(&m, 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

	// Get current moisture value
	uint16_t moisture;
	if(moisture_get_moisture_value(&m, &moisture) < 0) {
		fprintf(stderr, "Could not get moisture value, probably timeout\n");
		return 1;
	}

	printf("Moisture Value: %d\n", moisture);

	printf("Press key to exit\n");
	getchar();
	moisture_destroy(&m);
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
	return 0;
}
int main(void) {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	Humidity h;
	humidity_create(&h, 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

	// Get threshold callbacks with a debounce time of 10 seconds (10000ms)
	humidity_set_debounce_period(&h, 10000);

	// Register humidity reached callback to function cb_humidity_reached
	humidity_register_callback(&h,
	                           HUMIDITY_CALLBACK_HUMIDITY_REACHED,
	                           (void *)cb_humidity_reached,
	                           NULL);

	// Configure threshold for humidity "outside of 30 to 60 %RH"
	humidity_set_humidity_callback_threshold(&h, 'o', 30*10, 60*10);

	printf("Press key to exit\n");
	getchar();
	humidity_destroy(&h);
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
	return 0;
}
int main(void) {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	LCD20x4 lcd;
	lcd_20x4_create(&lcd, 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

	// Turn backlight on
	lcd_20x4_backlight_on(&lcd);

	// Write "Hello World"
	lcd_20x4_write_line(&lcd, 0, 0, "Hello World");

	printf("Press key to exit\n");
	getchar();
	lcd_20x4_destroy(&lcd);
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
	return 0;
}
int main(void) {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	Pressure p;
	pressure_create(&p, 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

	// Get threshold callbacks with a debounce time of 10 seconds (10000ms)
	pressure_set_debounce_period(&p, 10000);

	// Register pressure reached callback to function cb_pressure_reached
	pressure_register_callback(&p,
	                           PRESSURE_CALLBACK_PRESSURE_REACHED,
	                           (void *)cb_pressure_reached,
	                           NULL);

	// Configure threshold for pressure "greater than 10 kPa" (unit is Pa)
	pressure_set_pressure_callback_threshold(&p, '>', 10*1000, 0);

	printf("Press key to exit\n");
	getchar();
	pressure_destroy(&p);
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
	return 0;
}
Пример #9
0
int main(void) {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	PTC ptc;
	ptc_create(&ptc, 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

	// Get threshold callbacks with a debounce time of 10 seconds (10000ms)
	ptc_set_debounce_period(&ptc, 10000);

	// Register temperature reached callback to function cb_temperature_reached
	ptc_register_callback(&ptc,
	                      PTC_CALLBACK_TEMPERATURE_REACHED,
	                      (void *)cb_temperature_reached,
	                      NULL);

	// Configure threshold for temperature "greater than 30 °C"
	ptc_set_temperature_callback_threshold(&ptc, '>', 30*100, 0);

	printf("Press key to exit\n");
	getchar();
	ptc_destroy(&ptc);
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
	return 0;
}
Пример #10
0
int main(void) {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	GPS gps;
	gps_create(&gps, 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 coordinates callback to function cb_coordinates
	gps_register_callback(&gps,
	                      GPS_CALLBACK_COORDINATES,
	                      (void *)cb_coordinates,
	                      NULL);

	// Set period for coordinates callback to 1s (1000ms)
	// Note: The coordinates callback is only called every second
	//       if the coordinates has changed since the last call!
	gps_set_coordinates_callback_period(&gps, 1000);

	printf("Press key to exit\n");
	getchar();
	gps_destroy(&gps);
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
	return 0;
}
int main(void) {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	SegmentDisplay4x7 sd;
	segment_display_4x7_create(&sd, 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

	// Write "4223" to the display with full brightness without colon
	uint8_t segments[4] = {digits[4], digits[2], digits[2], digits[3]};
	segment_display_4x7_set_segments(&sd, segments, 7, false);

	printf("Press key to exit\n");
	getchar();
	segment_display_4x7_destroy(&sd);
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
	return 0;
}
Пример #12
0
int main() {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	IndustrialDigitalIn4 idi4;
	industrial_digital_in_4_create(&idi4, UID, &ipcon); 

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

	// Read out values as bitmask
	uint16_t value;
	industrial_digital_in_4_get_value(&idi4, &value);
	printf("Value: %d\n", value);

	printf("Press key to exit\n");
	getchar();
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
}
int main(void) {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	PiezoBuzzer pb;
	piezo_buzzer_create(&pb, 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

	// Morse SOS
	piezo_buzzer_morse_code(&pb, "... --- ...");

	printf("Press key to exit\n");
	getchar();
	piezo_buzzer_destroy(&pb);
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
	return 0;
}
Пример #14
0
int main(void) {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	IndustrialDual020mA id020;
	industrial_dual_0_20ma_create(&id020, 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

	// Get threshold callbacks with a debounce time of 10 seconds (10000ms)
	industrial_dual_0_20ma_set_debounce_period(&id020, 10000);

	// Register current reached callback to function cb_current_reached
	industrial_dual_0_20ma_register_callback(&id020,
	                                         INDUSTRIAL_DUAL_0_20MA_CALLBACK_CURRENT_REACHED,
	                                         (void *)cb_current_reached,
	                                         NULL);

	// Configure threshold for current (sensor 1) "greater than 10 mA" (unit is nA)
	industrial_dual_0_20ma_set_current_callback_threshold(&id020, 1, '>', 10*1000000, 0);

	printf("Press key to exit\n");
	getchar();
	industrial_dual_0_20ma_destroy(&id020);
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
	return 0;
}
int main() {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	AmbientLight al;
	ambient_light_create(&al, UID, &ipcon); 

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

	// Set Period for illuminance callback to 1s (1000ms)
	// Note: The illuminance callback is only called every second if the 
	//       illuminance has changed since the last call!
	ambient_light_set_illuminance_callback_period(&al, 1000);

	// Register illuminance callback to function cb_illuminance
	ambient_light_register_callback(&al,
	                                AMBIENT_LIGHT_CALLBACK_ILLUMINANCE,
	                                (void *)cb_illuminance,
	                                NULL);

	printf("Press key to exit\n");
	getchar();
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
}
Пример #16
0
int main(void) {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	IO4 io;
	io4_create(&io, 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

	// Get current value as bitmask
	uint8_t value_mask;
	if(io4_get_value(&io, &value_mask) < 0) {
		fprintf(stderr, "Could not get value as bitmask, probably timeout\n");
		return 1;
	}

	printf("Value Mask: %d\n", value_mask);

	printf("Press key to exit\n");
	getchar();
	io4_destroy(&io);
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
	return 0;
}
Пример #17
0
int main() {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	IndustrialDigitalIn4 idi4;
	industrial_digital_in_4_create(&idi4, UID, &ipcon); 

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

	// Register callback for interrupts
	industrial_digital_in_4_register_callback(&idi4,
	                                          INDUSTRIAL_DIGITAL_IN_4_CALLBACK_INTERRUPT,
	                                          (void *)cb_interrupt,
	                                          NULL);

	// Enable interrupt on pin 0
	industrial_digital_in_4_set_interrupt(&idi4, 1 << 0);

	printf("Press key to exit\n");
	getchar();
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
}
Пример #18
0
int main(void) {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	Color c;
	color_create(&c, 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

	// Get threshold callbacks with a debounce time of 10 seconds (10000ms)
	color_set_debounce_period(&c, 10000);

	// Register color reached callback to function cb_color_reached
	color_register_callback(&c,
	                        COLOR_CALLBACK_COLOR_REACHED,
	                        (void *)cb_color_reached,
	                        NULL);

	// Configure threshold for color "greater than 100, 200, 300, 400"
	color_set_color_callback_threshold(&c, '>', 100, 0, 200, 0, 300, 0, 400, 0);

	printf("Press key to exit\n");
	getchar();
	color_destroy(&c);
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
	return 0;
}
Пример #19
0
int main(void) {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	DistanceIR dir;
	distance_ir_create(&dir, 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

	// Get current distance (unit is mm)
	uint16_t distance;
	if(distance_ir_get_distance(&dir, &distance) < 0) {
		fprintf(stderr, "Could not get distance, probably timeout\n");
		return 1;
	}

	printf("Distance: %f cm\n", distance/10.0);

	printf("Press key to exit\n");
	getchar();
	distance_ir_destroy(&dir);
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
	return 0;
}
Пример #20
0
int LaserTransform::init()
{
  // create IP connection
  ipcon_create(&ipcon);

  // connect to brickd
  if(ipcon_connect(&ipcon, HOST, PORT) < 0) {
    std::cout << "could not connect to brickd!" << std::endl;
    return false;
  }

  // register connected callback to "cb_connected"
  ipcon_register_callback(&ipcon,
    IPCON_CALLBACK_CONNECTED,
    (void*)callbackConnected,
    this);

  // register enumeration callback to "cb_enumerate"
  ipcon_register_callback(&ipcon,
    IPCON_CALLBACK_ENUMERATE,
    (void*)callbackEnumerate,
    this);

  return 0;
}
Пример #21
0
int main() {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	Stepper stepper;
	stepper_create(&stepper, UID, &ipcon); 

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

	stepper_set_motor_current(&stepper, 800); // 800mA
	stepper_set_step_mode(&stepper, 8); // 1/8 step mode
	stepper_set_max_velocity(&stepper, 2000); // Velocity 2000 steps/s

	// Slow acceleration (500 steps/s^2), 
	// Fast deacceleration (5000 steps/s^2)
	stepper_set_speed_ramping(&stepper, 500, 5000);

	stepper_enable(&stepper);
	stepper_set_steps(&stepper, 60000); // Drive 60000 steps forward

	printf("Press key to exit\n");
	getchar();
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
}
Пример #22
0
int main(void) {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	Ozone o;
	ozone_create(&o, 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 ozone concentration callback to function cb_ozone_concentration
	ozone_register_callback(&o,
	                        OZONE_CALLBACK_OZONE_CONCENTRATION,
	                        (void *)cb_ozone_concentration,
	                        NULL);

	// Set period for ozone concentration callback to 1s (1000ms)
	// Note: The ozone concentration callback is only called every second
	//       if the ozone concentration has changed since the last call!
	ozone_set_ozone_concentration_callback_period(&o, 1000);

	printf("Press key to exit\n");
	getchar();
	ozone_destroy(&o);
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
	return 0;
}
Пример #23
0
int main(void) {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	Voltage v;
	voltage_create(&v, 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

	// Get threshold callbacks with a debounce time of 10 seconds (10000ms)
	voltage_set_debounce_period(&v, 10000);

	// Register voltage reached callback to function cb_voltage_reached
	voltage_register_callback(&v,
	                          VOLTAGE_CALLBACK_VOLTAGE_REACHED,
	                          (void *)cb_voltage_reached,
	                          NULL);

	// Configure threshold for voltage "greater than 5 V" (unit is mV)
	voltage_set_voltage_callback_threshold(&v, '>', 5*1000, 0);

	printf("Press key to exit\n");
	getchar();
	voltage_destroy(&v);
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
	return 0;
}
int main(void) {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	RotaryEncoder re;
	rotary_encoder_create(&re, 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 count callback to function cb_count
	rotary_encoder_register_callback(&re,
	                                 ROTARY_ENCODER_CALLBACK_COUNT,
	                                 (void *)cb_count,
	                                 NULL);

	// Set period for count callback to 0.05s (50ms)
	// Note: The count callback is only called every 0.05 seconds
	//       if the count has changed since the last call!
	rotary_encoder_set_count_callback_period(&re, 50);

	printf("Press key to exit\n");
	getchar();
	rotary_encoder_destroy(&re);
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
	return 0;
}
Пример #25
0
int main() {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	Temperature t;
	temperature_create(&t, UID, &ipcon); 

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

	// Get current temperature (unit is °C/100)
	int16_t temperature;
	if(temperature_get_temperature(&t, &temperature) < 0) {
		fprintf(stderr, "Could not get value, probably timeout\n");
		exit(1);
	}

	printf("Temperature: %f °C\n", temperature/100.0);

	printf("Press key to exit\n");
	getchar();
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
}
Пример #26
0
int main(void) {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	Voltage v;
	voltage_create(&v, 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

	// Get current voltage
	uint16_t voltage;
	if(voltage_get_voltage(&v, &voltage) < 0) {
		fprintf(stderr, "Could not get voltage, probably timeout\n");
		return 1;
	}

	printf("Voltage: %f V\n", voltage/1000.0);

	printf("Press key to exit\n");
	getchar();
	voltage_destroy(&v);
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
	return 0;
}
Пример #27
0
int main() {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	Joystick js;
	joystick_create(&js, UID, &ipcon); 

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

	// Register callbacks for pressed and released events
	joystick_register_callback(&js, 
	                           JOYSTICK_CALLBACK_PRESSED, 
	                           (void *)cb_pressed,
	                           NULL);

	joystick_register_callback(&js, 
	                           JOYSTICK_CALLBACK_RELEASED, 
	                           (void *)cb_released,
	                           NULL);

	printf("Press key to exit\n");
	getchar();
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
}
Пример #28
0
int main(void) {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	IO16 io;
	io16_create(&io, 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

	// Set pin 0 on port A to output low
	io16_set_port_configuration(&io, 'a', 1 << 0, 'o', false);

	// Set pin 0 and 7 on port B to output high
	io16_set_port_configuration(&io, 'b', (1 << 0) | (1 << 7), 'o', true);

	printf("Press key to exit\n");
	getchar();
	io16_destroy(&io);
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
	return 0;
}
int TinkerforgeSensors::init()
{
  // create IP connection
  ipcon_create(&ipcon);

  // connect to brickd
  if(ipcon_connect(&ipcon, this->host.c_str(), this->port) < 0) {
    std::cout << "could not connect to brickd!" << std::endl;
    return false;
  }

  // register connected callback to "cb_connected"
  ipcon_register_callback(&ipcon,
    IPCON_CALLBACK_CONNECTED,
    (void*)callbackConnected,
    this);

  // register enumeration callback to "cb_enumerate"
  ipcon_register_callback(&ipcon,
    IPCON_CALLBACK_ENUMERATE,
    (void*)callbackEnumerate,
    this);

  return 0;
}
Пример #30
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;
}