예제 #1
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
}
예제 #2
0
int main(void) {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	Joystick j;
	joystick_create(&j, 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 position
	int16_t x, y;
	if(joystick_get_position(&j, &x, &y) < 0) {
		fprintf(stderr, "Could not get position, probably timeout\n");
		return 1;
	}

	printf("Position[X]: %d\n", x);
	printf("Position[Y]: %d\n", y);

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