int main(int argc, char* argv[]) { PSMove *moves[MAX_CONTROLLERS]; int controllers = psmove_count_connected(); int i; int quit = 0; for (i=0; i<controllers; i++) { moves[i] = psmove_connect_by_id(i); if (moves[i] == NULL) { fprintf(stderr, "Could not connect to controller #%d.\n", i); return EXIT_FAILURE; } } while (!quit) { for (i=0; i<controllers; i++) { int x, y, z; int seq = psmove_poll(moves[i]); if (seq) { int which; if (psmove_get_buttons(moves[i]) & Btn_PS) { quit = 1; break; } seq -= 1; for (which=0; which<2; which++) { printf("%d %s PSMOVE seq=%-2d", i, psmove_get_serial(moves[i]), seq*2+which); psmove_get_half_frame(moves[i], Sensor_Accelerometer, which, &x, &y, &z); printf(" aX=%-6d aY=%-6d aZ=%-6d", x, y, z); psmove_get_half_frame(moves[i], Sensor_Gyroscope, which, &x, &y, &z); printf(" gX=%-6d gY=%-6d gZ=%-6d", x, y, z); psmove_get_magnetometer(moves[i], &x, &y, &z); /* The y value of the magnetometer is inverted in linmctool */ printf(" mX=%-5d mY=%-5d mZ=%-5d", x, -y, z); printf("\n"); } } } } for (i=0; i<controllers; i++) { psmove_disconnect(moves[i]); } return 0; }
void PSMoveQt::onTimeout() { int ax, ay, az, gx, gy, gz, mx, my, mz, buttons, battery; while (psmove_poll(_move)) { setTrigger(psmove_get_trigger(_move)); psmove_get_gyroscope(_move, &gx, &gy, &gz); if (gx != _gx || gy != _gy || gz != _gz) { _gx = gx; _gy = gy; _gz = gz; emit gyroChanged(); } psmove_get_accelerometer(_move, &ax, &ay, &az); if (ax != _ax || ay != _ay || az != _az) { _ax = ax; _ay = ay; _az = az; emit accelerometerChanged(); } psmove_get_magnetometer(_move, &mx, &my, &mz); if (mx != _mx || my != _my || mz != _mz) { _mx = mx; _my = my; _mz = mz; emit magnetometerChanged(); } buttons = psmove_get_buttons(_move); if (buttons != _buttons) { unsigned int pressed, released; psmove_get_button_events(_move, &pressed, &released); for (int i=1; i<=PSMoveQt::T; i <<= 1) { if (pressed & i) { emit buttonPressed(i); } else if (released & i) { emit buttonReleased(i); } } _buttons = buttons; } battery = psmove_get_battery(_move); if (battery != _battery) { bool charging = (battery == Batt_CHARGING || _battery == Batt_CHARGING); _battery = battery; if (charging) { emit chargingChanged(); } else if (_battery != Batt_CHARGING) { emit batteryChanged(_battery); } } } }
int main(int argc, char* argv[]) { PSMove *move; enum PSMove_Connection_Type ctype; int i; i = psmove_count_connected(); printf("Connected controllers: %d\n", i); move = psmove_connect(); if (move == NULL) { printf("Could not connect to default Move controller.\n" "Please connect one via USB or Bluetooth.\n"); exit(1); } ctype = psmove_connection_type(move); switch (ctype) { case Conn_USB: printf("Connected via USB.\n"); break; case Conn_Bluetooth: printf("Connected via Bluetooth.\n"); break; case Conn_Unknown: printf("Unknown connection type.\n"); break; } if (ctype == Conn_USB) { PSMove_Data_BTAddr addr; psmove_read_btaddrs(move, &addr, NULL); printf("Current BT Host: "); for (i=0; i<6; i++) { printf("%02x ", addr[i]); } printf("\n"); #if 0 /* This is the easy method (pair to this host): */ if (psmove_pair(move)) { printf("Paired. Press the PS Button now :)\n"); } else { printf("psmove_pair() failed :/\n"); } /* This is the advanced method: */ /* Example BT Address: 01:23:45:67:89:ab */ const PSMove_Data_BTAddr newhost = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, }; if (!psmove_set_btaddr(move, &newhost)) { printf("Could not set BT address!\n"); } #endif } for (i=0; i<10; i++) { psmove_set_leds(move, 0, 255*(i%3==0), 0); psmove_set_rumble(move, 255*(i%2)); psmove_update_leds(move); usleep(10000*(i%10)); } for (i=250; i>=0; i-=5) { psmove_set_leds(move, i, i, 0); psmove_set_rumble(move, 0); psmove_update_leds(move); } /* Enable rate limiting for LED updates */ psmove_set_rate_limiting(move, 1); psmove_set_leds(move, 0, 0, 0); psmove_set_rumble(move, 0); psmove_update_leds(move); while (!(psmove_get_buttons(move) & Btn_PS)) { int res = psmove_poll(move); if (res) { if (psmove_get_buttons(move) & Btn_TRIANGLE) { printf("Triangle pressed, with trigger value: %d\n", psmove_get_trigger(move)); psmove_set_rumble(move, psmove_get_trigger(move)); } else { psmove_set_rumble(move, 0x00); } psmove_set_leds(move, 0, 0, psmove_get_trigger(move)); int x, y, z; psmove_get_accelerometer(move, &x, &y, &z); printf("accel: %5d %5d %5d\n", x, y, z); psmove_get_gyroscope(move, &x, &y, &z); printf("gyro: %5d %5d %5d\n", x, y, z); psmove_get_magnetometer(move, &x, &y, &z); printf("magnetometer: %5d %5d %5d\n", x, y, z); printf("buttons: %x\n", psmove_get_buttons(move)); int battery = psmove_get_battery(move); if (battery == Batt_CHARGING) { printf("battery charging\n"); } else if (battery >= Batt_MIN && battery <= Batt_MAX) { printf("battery level: %d / %d\n", battery, Batt_MAX); } else { printf("battery level: unknown (%x)\n", battery); } printf("temperature: %d\n", psmove_get_temperature(move)); psmove_update_leds(move); } } psmove_disconnect(move); return 0; }
int main(int argc, char* argv[]) { PSMove *move; enum PSMove_Connection_Type ctype; int i; if (!psmove_init(PSMOVE_CURRENT_VERSION)) { fprintf(stderr, "PS Move API init failed (wrong version?)\n"); exit(1); } i = psmove_count_connected(); printf("Connected controllers: %d\n", i); move = psmove_connect(); if (move == NULL) { printf("Could not connect to default Move controller.\n" "Please connect one via USB or Bluetooth.\n"); exit(1); } char *serial = psmove_get_serial(move); printf("Serial: %s\n", serial); free(serial); ctype = psmove_connection_type(move); switch (ctype) { case Conn_USB: printf("Connected via USB.\n"); break; case Conn_Bluetooth: printf("Connected via Bluetooth.\n"); break; case Conn_Unknown: printf("Unknown connection type.\n"); break; } for (i=0; i<10; i++) { psmove_set_leds(move, 0, 255*(i%3==0), 0); psmove_set_rumble(move, 255*(i%2)); psmove_update_leds(move); psmove_usleep(10000 * (i % 10)); } for (i=250; i>=0; i-=5) { psmove_set_leds(move, i, i, 0); psmove_set_rumble(move, 0); psmove_update_leds(move); } /* Enable rate limiting for LED updates */ psmove_set_rate_limiting(move, 1); psmove_set_leds(move, 0, 0, 0); psmove_set_rumble(move, 0); psmove_update_leds(move); while (ctype != Conn_USB && !(psmove_get_buttons(move) & Btn_PS)) { int res = psmove_poll(move); if (res) { if (psmove_get_buttons(move) & Btn_TRIANGLE) { printf("Triangle pressed, with trigger value: %d\n", psmove_get_trigger(move)); psmove_set_rumble(move, psmove_get_trigger(move)); } else { psmove_set_rumble(move, 0x00); } psmove_set_leds(move, 0, 0, psmove_get_trigger(move)); int x, y, z; psmove_get_accelerometer(move, &x, &y, &z); printf("accel: %5d %5d %5d\n", x, y, z); psmove_get_gyroscope(move, &x, &y, &z); printf("gyro: %5d %5d %5d\n", x, y, z); psmove_get_magnetometer(move, &x, &y, &z); printf("magnetometer: %5d %5d %5d\n", x, y, z); printf("buttons: %x\n", psmove_get_buttons(move)); int battery = psmove_get_battery(move); if (battery == Batt_CHARGING) { printf("battery charging\n"); } else if (battery == Batt_CHARGING_DONE) { printf("battery fully charged (on charger)\n"); } else if (battery >= Batt_MIN && battery <= Batt_MAX) { printf("battery level: %d / %d\n", battery, Batt_MAX); } else { printf("battery level: unknown (%x)\n", battery); } printf("raw temperature: %d\n", psmove_get_temperature(move)); printf("celsius temperature: %f\n", psmove_get_temperature_in_celsius(move)); psmove_update_leds(move); } } psmove_disconnect(move); psmove_shutdown(); return 0; }