Beispiel #1
0
int main(int argc, char *argv[]) 
{
  cwiid_wiimote_t *wiimote;	/* wiimote handle */
  //struct cwiid_state state;	/* wiimote state */
  bdaddr_t bdaddr;	/* bluetooth device address */
  //unsigned char mesg = 0;
  //unsigned char led_state = 0;
  unsigned char rpt_mode = 0;
  //unsigned char rumble = 0;

  /* Make stdout unbuffered, which is useful for piping the output of
   * this program into a timestamping utility, such as tai64n(1) */
  setvbuf(stdout, NULL, _IOLBF, 0);

  cwiid_set_err(err);

  /* Connect to address given on command-line, if present */
  if (argc > 1) {
    str2ba(argv[1], &bdaddr);
  }
  else {
    bdaddr = *BDADDR_ANY;
  }

  printf("Put Wiimote in discoverable mode now (press 1+2)...\n");
  if (!(wiimote = cwiid_open(&bdaddr, 0))) {
    fprintf(stderr, "Unable to connect to wiimote\n");
    exit(1);
  }
  if (cwiid_set_mesg_callback(wiimote, cwiid_callback)) {
    fprintf(stderr, "Unable to set message callback\n");
    exit(1);
  }

  toggle_bit(rpt_mode, CWIID_RPT_ACC);
  toggle_bit(rpt_mode, CWIID_RPT_BTN);
  set_rpt_mode(wiimote, rpt_mode);


  if (cwiid_enable(wiimote, CWIID_FLAG_MESG_IFC)) {
    fprintf(stderr, "Unable to set message flag\n");
    exit(1);
  }


  while(1) {
    sleep(1);
  }
}
// Creadora del device
TPFC_device_wiimote::TPFC_device_wiimote(int ident, string bta):TPFC_device(ident){
  // creamos el bufer de datos
  data = new TrackingPFC_data(TrackingPFC_data::TPFCDATA2D);
  // sobreescribimos el mensaje de error por defecto con el nuestro, para evitar spam
  cwiid_set_err(err);

  // comprobamos si tenemos una direccion asignada
  if (bta.compare("")==0){
    // conectarse al primer wiimote que se encuentre
    bdaddr = *BDADDR_ANY;// bluetooth device address
  }else{
    // conectarse al wiimote con direccion == bta
    str2ba(bta.c_str(), &bdaddr);
  }

  // Conectar los wiimotes
  printf("Pon el wiimote en modo discoverable (pulsa 1+2)...\n");
  wiimote=NULL;
  while (!wiimote){
    if ( !(wiimote = cwiid_open(&bdaddr, 0)) ){
	    printf("Esperando al wiimote (pulsa 1+2)...\n");
    }
  }

  // registramos el wiimote para poder identificar despues los callbacks 
  registerwiimote(wiimote, this);
  
  // registramos nuestro callback con el wiimote
  if (cwiid_set_mesg_callback(wiimote, callback)) {
	  fprintf(stderr, "No se ha podido registrar el callback\n");
  }
  // activamos el paso de mensajes desde el wiimote
  if (cwiid_enable(wiimote, CWIID_FLAG_MESG_IFC)) {
	  fprintf(stderr, "Error activando los mensajes\n");
  }
  // configuramos el report mode
  unsigned char rpt_mode = 0;
  toggle_bit(rpt_mode, CWIID_RPT_IR);
  set_rpt_mode(wiimote, rpt_mode);

  printf("Wiimote conectado!\n");

}
Beispiel #3
0
int main(int argc, char *argv[])
{
	cwiid_wiimote_t *wiimote;	/* wiimote handle */
	struct cwiid_state state;	/* wiimote state */
	bdaddr_t bdaddr;	/* bluetooth device address */
	unsigned char mesg = 0;
	unsigned char led_state = 0;
	unsigned char rpt_mode = 0;
	unsigned char rumble = 0;
	int exit = 0;

	cwiid_set_err(err);

	/* Connect to address given on command-line, if present */
	if (argc > 1) {
		str2ba(argv[1], &bdaddr);
	}
	else {
		bdaddr = *BDADDR_ANY;
	}

	/* Connect to the wiimote */
	printf("Put Wiimote in discoverable mode now (press 1+2)...\n");
	if (!(wiimote = cwiid_open(&bdaddr, 0))) {
		fprintf(stderr, "Unable to connect to wiimote\n");
		return -1;
	}
	if (cwiid_set_mesg_callback(wiimote, cwiid_callback)) {
		fprintf(stderr, "Unable to set message callback\n");
	}

	printf("Note: To demonstrate the new API interfaces, wmdemo no longer "
	       "enables messages by default.\n"
		   "Output can be gathered through the new state-based interface (s), "
	       "or by enabling the messages interface (c).\n");

	/* Menu */
	printf("%s", MENU);

	while (!exit) {
		switch (getchar()) {
		case '1':
			toggle_bit(led_state, CWIID_LED1_ON);
			set_led_state(wiimote, led_state);
			break;
		case '2':
			toggle_bit(led_state, CWIID_LED2_ON);
			set_led_state(wiimote, led_state);
			break;
		case '3':
			toggle_bit(led_state, CWIID_LED3_ON);
			set_led_state(wiimote, led_state);
			break;
		case '4':
			toggle_bit(led_state, CWIID_LED4_ON);
			set_led_state(wiimote, led_state);
			break;
		case '5':
			toggle_bit(rumble, 1);
			if (cwiid_set_rumble(wiimote, rumble)) {
				fprintf(stderr, "Error setting rumble\n");
			}
			break;
		case 'a':
			toggle_bit(rpt_mode, CWIID_RPT_ACC);
			set_rpt_mode(wiimote, rpt_mode);
			break;
		case 'b':
			toggle_bit(rpt_mode, CWIID_RPT_BTN);
			set_rpt_mode(wiimote, rpt_mode);
			break;
		case 'e':
			/* CWIID_RPT_EXT is actually
			 * CWIID_RPT_NUNCHUK | CWIID_RPT_CLASSIC */
			toggle_bit(rpt_mode, CWIID_RPT_EXT);
			set_rpt_mode(wiimote, rpt_mode);
			break;
		case 'i':
			/* libwiimote picks the highest quality IR mode available with the
			 * other options selected (not including as-yet-undeciphered
			 * interleaved mode */
			toggle_bit(rpt_mode, CWIID_RPT_IR);
			set_rpt_mode(wiimote, rpt_mode);
			break;
		case 'm':
			if (!mesg) {
				if (cwiid_enable(wiimote, CWIID_FLAG_MESG_IFC)) {
					fprintf(stderr, "Error enabling messages\n");
				}
				else {
					mesg = 1;
				}
			}
			else {
				if (cwiid_disable(wiimote, CWIID_FLAG_MESG_IFC)) {
					fprintf(stderr, "Error disabling message\n");
				}
				else {
					mesg = 0;
				}
			}
			break;
		case 'p':
			printf("%s", MENU);
			break;
		case 'r':
			if (cwiid_request_status(wiimote)) {
				fprintf(stderr, "Error requesting status message\n");
			}
			break;
		case 's':
			if (cwiid_get_state(wiimote, &state)) {
				fprintf(stderr, "Error getting state\n");
			}
			print_state(&state);
			break;
		case 't':
			toggle_bit(rpt_mode, CWIID_RPT_STATUS);
			set_rpt_mode(wiimote, rpt_mode);
			break;
		case 'x':
			exit = -1;
			break;
		case '\n':
			break;
		default:
			fprintf(stderr, "invalid option\n");
		}
	}

	if (cwiid_close(wiimote)) {
		fprintf(stderr, "Error on wiimote disconnect\n");
		return -1;
	}

	return 0;
}
Beispiel #4
0
int main(int argc, char *argv[]) 
{
  if (argc != 2) {
    printf("Usage: %s 3, where 3 is the number of gestures to recognize\n", argv[0]);
    exit(1);
  }
  n_gestures = atoi(argv[1]);
  hmms = malloc(n_gestures * sizeof(HmmStateRef));

  int n_states = n_gestures+3;
  int n_obs = 17;

  for(int i = 0; i < n_gestures; i++) {
    hmms[i] = hmm_new(n_states, n_obs);
  }

  cwiid_wiimote_t *wiimote;	/* wiimote handle */
  //struct cwiid_state state;	/* wiimote state */
  bdaddr_t bdaddr;	/* bluetooth device address */
  //unsigned char mesg = 0;
  //unsigned char led_state = 0;
  unsigned char rpt_mode = 0;
  //unsigned char rumble = 0;

  /* Make stdout unbuffered, which is useful for piping the output of
   * this program into a timestamping utility, such as tai64n(1) */
  setvbuf(stdout, NULL, _IOLBF, 0);

  cwiid_set_err(err);

#if WE_ACTUALLY_CARE_ABOUT_BLUETOOTH
  /* Connect to address given on command-line, if present */
  if (argc > 1) {
    str2ba(argv[1], &bdaddr);
  }
  else {
#endif
    bdaddr = *BDADDR_ANY;
#if WE_ACTUALLY_CARE_ABOUT_BLUETOOTH
  }
#endif

  printf("Put Wiimote in discoverable mode now (press 1+2)...\n");
  if (!(wiimote = cwiid_open(&bdaddr, 0))) {
    fprintf(stderr, "Unable to connect to wiimote\n");
    exit(1);
  }
  if (cwiid_set_mesg_callback(wiimote, cwiid_callback)) {
    fprintf(stderr, "Unable to set message callback\n");
    exit(1);
  }

  toggle_bit(rpt_mode, CWIID_RPT_ACC);
  toggle_bit(rpt_mode, CWIID_RPT_BTN);
  set_rpt_mode(wiimote, rpt_mode);


  if (cwiid_enable(wiimote, CWIID_FLAG_MESG_IFC)) {
    fprintf(stderr, "Unable to set message flag\n");
    exit(1);
  }


  while(1) {
    sleep(1);
  }
}
Beispiel #5
0
int main(int argc, char *argv[])
{
	cwiid_wiimote_t *wiimote;	/* wiimote handle */
	struct cwiid_state state;	/* wiimote state */
	bdaddr_t bdaddr;	/* bluetooth device address */
	unsigned char mesg = 0;
	unsigned char led_state = 0;
	unsigned char rpt_mode = 0;
	unsigned char rumble = 0;
	int exit = 0;

	deviceState.numButtons = NUM_BUTTONS;
	deviceState.numAxis = NUM_AXIS;
	deviceState.numSensors = NUM_SENSORS;
	deviceState.axisValues = NULL;
	deviceState.buttonValues = NULL;
	deviceState.sensorValues = new SensorData[NUM_SENSORS];

	cwiid_set_err(err);

	if (argc < 2) {
		fprintf(stderr, "Usage: %s HOSTNAME\n\n", argv[0]);
		return 1;
	} // if

// TODO: parse data from config file!!!
	/* Connect to address given on command-line, if present */
	if (argc > 2) {
		str2ba(argv[2], &bdaddr);
	}
	else {
		bdaddr = *BDADDR_ANY;
	}

	/* Connect to the wiimote */
	printf("Put Wiimote in discoverable mode now (press 1+2)...\n");
	if (!(wiimote = cwiid_open(&bdaddr, 0))) {
		fprintf(stderr, "Unable to connect to wiimote\n");
		return -1;
	}
	if (cwiid_set_mesg_callback(wiimote, cwiid_callback)) {
		fprintf(stderr, "Unable to set message callback\n");
	}

	toggle_bit(led_state, CWIID_LED1_ON);
	set_led_state(wiimote, led_state);
	if (cwiid_get_state(wiimote, &state)) {
		fprintf(stderr, "Error getting state\n");
	}
	print_state(&state);
	toggle_bit(rpt_mode, CWIID_RPT_IR);
	toggle_bit(rpt_mode, CWIID_RPT_BTN);
//	toggle_bit(rpt_mode, CWIID_RPT_ACC);
	set_rpt_mode(wiimote, rpt_mode);
	if (cwiid_enable(wiimote, CWIID_FLAG_MESG_IFC)) {
	    fprintf(stderr, "Error enabling messages\n");
	} else {
	    mesg = 1;
	}

	if (initNetwork(argv[1], CLIENTPORT)) {
		fprintf(stderr, "Error at network initialization\n");
		return -1;
	} // if

	bool running = true;

	while (running) {sleep(1);}

	if (cwiid_close(wiimote)) {
		fprintf(stderr, "Error on wiimote disconnect\n");
		return -1;
	}

	return 0;
}