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

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

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

	printf("Press key to exit\n");
	getchar();
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
	return 0;
}