Esempio n. 1
0
MainWindow::MainWindow(QWidget *parent) :
    QWidget(parent),
    m_mousePos(0, 0),
    m_mapping(),
    m_points(),
    m_pointsOffset(0),
    m_move(psmove_connect()),
    m_tracker(psmove_tracker_new()),
    m_timer(),
    m_path(),
    m_rect(rect()),
    m_rectOffset(0)
{
    m_points[0] = QPointF(1, 1);
    m_points[1] = QPointF(640, 0);
    m_points[2] = QPointF(640, 480);
    m_points[3] = QPointF(0, 480);
    m_mapping.set(m_points);

    setMouseTracking(true);

    if (m_move) {
        while (psmove_tracker_enable(m_tracker, m_move) != Tracker_CALIBRATED);
    }

    QObject::connect(&m_timer, SIGNAL(timeout()),
                     this, SLOT(timeout()));
    m_timer.start(1);
}
Esempio n. 2
0
int main(int argc, char* argv[])
{
    PSMove *move = psmove_connect();

    if (move == NULL) {
        printf("Could not connect to default Move controller.\n"
               "Please connect one via Bluetooth.\n");
        exit(1);
    }

    csv = fopen("read_performance.csv", "w");
    assert(csv != NULL);
    fprintf(csv, "mode,time,reads,dropped\n");

    printf("\n -- PS Move API Sensor Reading Performance Test -- \n");

    printf("\nTesting STATIC READ performance (non-changing LED setting)\n");
    test_read_performance(move, STATIC_UPDATES);

    printf("\nTesting SMART READ performance (rate-limited LED setting)\n");
    test_read_performance(move, SMART_UPDATES);

    printf("\nTesting BAD READ performance (continous LED setting)\n");
    test_read_performance(move, ALL_UPDATES);

    printf("\nTesting RAW READ performance (no LED setting)\n");
    test_read_performance(move, NO_UPDATES);

    printf("\n");

    fclose(csv);

    return 0;
}
int main(int argc, char* argv[])
{
    PSMove *move;
    
    if (psmove_count_connected() == 0) {
        printf("No controllers connected.\n");
        return 2;
    }

    move = psmove_connect();
    if (move == NULL) {
        printf("Cannot connect to controller.\n");
        return 3;
    }


    printf("Serial: %s\n", psmove_get_serial(move));

    if (psmove_connection_type(move) == Conn_USB) {
        _psmove_get_firmware(move);
    }
    else {
        printf("Please connect the controller via USB.\n");
    }

    psmove_disconnect(move);
    return 0;
}
Esempio n. 4
0
int main(int argc, char* argv[])
{
    PSMove *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);
    }

    printf("\n -- PS Move API Sensor Reading Performance Test -- \n");

    printf("\nTesting STATIC READ performance (non-changing LED setting)\n");
    test_read_performance(move, STATIC_UPDATES);

    printf("\nTesting SMART READ performance (rate-limited LED setting)\n");
    test_read_performance(move, SMART_UPDATES);

    printf("\nTesting BAD READ performance (continous LED setting)\n");
    test_read_performance(move, ALL_UPDATES);

    printf("\nTesting RAW READ performance (no LED setting)\n");
    test_read_performance(move, NO_UPDATES);

    printf("\n");

    return 0;
}
Esempio n. 5
0
int main(int argc, char* argv[])
{
    PSMove *move;
    int i;

    if (psmove_count_connected() == 0) {
        printf("No controllers connected.\n");
        return 1;
    }

    move = psmove_connect();
    if (move == NULL) {
        printf("Cannot connect to controller.\n");
        return 2;
    }

    printf("Connection established.\n");
    printf("Serial: %s\n", psmove_get_serial(move));

    if (psmove_connection_type(move) != Conn_Bluetooth) {
        printf("Controller must be connected via Bluetooth.\n");
        return 3;
    }

    PSMove_Data_AuthChallenge challenge = {
        0x02, 0x00, 0x1D, 0x91, 0xE5, 0x81, 0x30, 0x6A,
        0x22, 0x9A, 0xAB, 0x2E, 0x80, 0xB4, 0xED, 0x2E,
        0xDE, 0x40, 0x0A, 0xF0, 0x02, 0xB0, 0x42, 0x8B,
        0x01, 0x41, 0xB2, 0xA4, 0x3D, 0xE7, 0xD4, 0xBF,
        0x05, 0x92
    };

    challenge[0] = 0;
    send_and_receive(move, &challenge);

    challenge[0] = 1;
    send_and_receive(move, &challenge);

    for (i = 1; i < 0x10; i++) {
        challenge[0] = 0;
		challenge[1] = (unsigned char)i;
        send_and_receive(move, &challenge);
    }

    memset(challenge, 0, sizeof(challenge));
    send_and_receive(move, &challenge);

    psmove_disconnect(move);
    return 0;
}
Esempio n. 6
0
        void run()
        {
            PSMove *move;

            /* 6 values = ax, ay, az, gx, gy, gz (accel + gyro) */
            float gx, gy, gz;

            int i = 0;
            qreal rate = 1.;

            assert((move = psmove_connect()) != NULL);
            assert(psmove_connection_type(move) == Conn_Bluetooth);

            assert(psmove_has_calibration(move));

            while (true) {
                if (psmove_poll(move)) {
                    psmove_get_gyroscope_frame(move, Frame_SecondHalf, &gx, &gy, &gz);

                    /**
                     * Playback rate is calculated based on the RPM of the
                     * controller on the Z axis and the normal
                     * playback rate of the turntable (see above).
                     **/
                    rate = RAD_PER_S_TO_RPM(gz) / TURNTABLE_RPM;

                    /* Rate-limiting the updates of the playback rate */
                    if (i % READ_FRAME_UPDATE_RATE == 0) {
                        /**
                         * On Linux, the rate must not be negative. It might be
                         * possible that on Mac OS X or Windows, the rate can
                         * also be negative (depends on the backend).
                         **/
                        if (rate > 0 && rate != player->playbackRate()) {
                            qint64 pos = player->position();
                            player->setPlaybackRate(rate);
                            player->setPosition(pos);
                        }
                    }

                    i++;
                }
            }

            psmove_disconnect(move);
        }
Esempio n. 7
0
int main( void )
{
	// get number of attached controllers
	int count = psmove_count_connected();
	if( count < 1 )
	{
		printf( "No controller connected.\n" );
		return 0;
	}

	printf( "Number of connected controllers: %d\n", count );

	// connect to the controller
	PSMove* move = psmove_connect();
	if( ! move )
	{
		printf( "Cannot connect to controller.\n" );
		return 0;
	}

	// print the connection type
	printf( "Connection type: " );
	switch( psmove_connection_type( move ) )
	{
		case Conn_Bluetooth:
			printf( "Bluetooth" );
			break;

		case Conn_USB:
			printf( "USB" );
			break;

		default:
			printf( "Unknown" );
	}
	printf( "\n" );

	// send and receive some different Feature Reports
	test_send_auth( move );
	test_send_led( move, 255, 255, 0 );
	test_read_auth( move );

	psmove_disconnect( move );

	return 0;
}
int main(int argc, char* argv[])
{
    
    if (!psmove_init(PSMOVE_CURRENT_VERSION)) {
        fprintf(stderr, "PS Move API init failed (wrong version?)\n");
        exit(1);
    }
    
    PSMove *move = psmove_connect();

    if (move == NULL) {
        printf("Could not connect to default Move controller.\n"
               "Please connect one via Bluetooth.\n");
        exit(1);
    }

    csv = psmove_file_open("read_performance.csv", "w");
    assert(csv != NULL);
    fprintf(csv, "mode,time,reads,dropped\n");

    printf("\n -- PS Move API Sensor Reading Performance Test -- \n");

    printf("\nTesting STATIC READ performance (non-changing LED setting)\n");
    test_read_performance(move, STATIC_UPDATES);

    printf("\nTesting SMART READ performance (rate-limited LED setting)\n");
    test_read_performance(move, SMART_UPDATES);

    printf("\nTesting BAD READ performance (continous LED setting)\n");
    test_read_performance(move, ALL_UPDATES);

    printf("\nTesting RAW READ performance (no LED setting)\n");
    test_read_performance(move, NO_UPDATES);

    printf("\n");

    psmove_file_close(csv);
    
    psmove_shutdown();
    
    return 0;
}
Esempio n. 9
0
int
main(int argc, char* argv[])
{
    PSMove *move;

	if (!psmove_init(PSMOVE_CURRENT_VERSION)) {
		fprintf(stderr, "PS Move API init failed (wrong version?)\n");
		exit(1);
	}

    move = psmove_connect();

    if (move == NULL) {
        fprintf(stderr, "Could not connect to controller.\n");
        return EXIT_FAILURE;
    }

    assert(psmove_has_calibration(move));

    if (psmove_connection_type(move) == Conn_Bluetooth) {
        float ax, ay, az, gx, gy, gz;

        while (1) {
            int res = psmove_poll(move);
            if (res) {
                psmove_get_accelerometer_frame(move, Frame_SecondHalf,
                        &ax, &ay, &az);
                psmove_get_gyroscope_frame(move, Frame_SecondHalf,
                        &gx, &gy, &gz);

                printf("A: %5.2f %5.2f %5.2f ", ax, ay, az);
                printf("G: %6.2f %6.2f %6.2f ", gx, gy, gz);
                printf("\n");
            }
        }
    }

    psmove_disconnect(move);
	psmove_shutdown();

    return EXIT_SUCCESS;
}
Esempio n. 10
0
int main(int argc, char* argv[])
{
    PSMove *move = psmove_connect();
    int i;

    if (move == NULL) {
        printf("Could not connect to default Move controller.\n"
               "Please connect one via USB or Bluetooth.\n");
        exit(1);
    }

    INFO("Rate limiting is disabled by default");
    test_succeeds(move);

    INFO("Enabling rate limiting");
    psmove_set_rate_limiting(move, 1);

    BEGIN_TEST("psmove_update_leds ignores updates (rate limiting enabled)");
    for (i=0; i<10; i++) {
        psmove_set_leds(move, i, i, i);
        assert(psmove_update_leds(move) == Update_Ignored);
    }
    END_TEST();

    INFO("Disabling rate limiting");
    psmove_set_rate_limiting(move, 0);

    BEGIN_TEST("psmove_update_leds ignores updates (unchanged values)");
    psmove_set_leds(move, 1, 1, 1);
    assert(psmove_update_leds(move) == Update_Success);
    for (i=0; i<10; i++) {
        assert(psmove_update_leds(move) == Update_Ignored);
    }
    END_TEST();

    test_succeeds(move);

    psmove_disconnect(move);

    return 0;
}
int main(int argc, char *argv[])
{
    if (!psmove_init(PSMOVE_CURRENT_VERSION)) {
        fprintf(stderr, "PS Move API init failed (wrong version?)\n");
        exit(1);
    }

    /* Check if at least one controller is attached */
    if (psmove_count_connected() < 1) {
        printf("No Move controller attached.\n");
        exit(1);
    }

    PSMove *move = psmove_connect();
    if(move == NULL) {
        printf("Could not connect to default Move controller.\n");
        exit(1);
    }

    /* Make sure we are connected via Bluetooth */
    if (psmove_connection_type(move) != Conn_Bluetooth) {
        printf("Controller must be connected via Bluetooth.\n");
        psmove_disconnect(move);
        exit(1);
    }

    unsigned int freq_idx = 0;

    while (!(psmove_get_buttons(move) & Btn_PS)) {
        if (!psmove_poll(move)) {
            continue;
        }

        unsigned int pressed_buttons;
        psmove_get_button_events(move, &pressed_buttons, NULL);

        unsigned long frequency = freqs[freq_idx];

        /* Cycle through the list of frequencies */
        if (pressed_buttons & Btn_CROSS) {
            freq_idx = (freq_idx + 1) % NUM_FREQS;
            frequency = freqs[freq_idx];
            printf("Selecting frequency %lu Hz. Press SQUARE to apply.\n", frequency);
        }

        /* Apply the currently selected frequency as new PWM frequency */
        if (pressed_buttons & Btn_SQUARE) {
            printf("Setting LED PWM frequency to %lu Hz.\n", frequency);

            /*
               Switch off the LEDs. If we do not do this, changing the PWM
               frequency will switch off the LEDs and keep them off until
               the Bluetooth connection has been teared down (at least
               once) and then reestablished.
            */
            psmove_set_leds(move, 0, 0, 0);
            psmove_update_leds(move);

            /*
               TODO:
               How can we make sure the LEDs are really off before changing
               the PWM frequency? It seems to work in all tests so far, but
               a proper verification would be nice.
            */
            if (!psmove_set_led_pwm_frequency(move, frequency)) {
                printf("Failed to set LED PWM frequency.\n");
            }
        }

        /* Keep fixed color for visual feedback */
        psmove_set_leds(move, 0, 0, 63);
        psmove_update_leds(move);
    }

    psmove_disconnect(move);
	psmove_shutdown();

    return 0;
}
Esempio n. 12
0
int main(int argc, char *argv[])
{
    if (!psmove_init(PSMOVE_CURRENT_VERSION)) {
        fprintf(stderr, "PS Move API init failed (wrong version?)\n");
        exit(1);
    }

    /* check if at least one controller is attached */
    if (psmove_count_connected() < 1) {
        printf("No Move controller attached.\n");
        exit(1);
    }

    PSMove *move = psmove_connect();
    if(move == NULL) {
        printf("Could not connect to default Move controller.\n");
        exit(1);
    }

    /* make sure we are connected via Bluetooth */
    if (psmove_connection_type(move) != Conn_Bluetooth) {
        printf("Controller must be connected via Bluetooth.\n");
        psmove_disconnect(move);
        exit(1);
    }

    int ext_connected = 0;
    enum Extension_Device ext_device = Ext_Unknown;

    while (!(psmove_get_buttons(move) & Btn_PS)) {
        if (!psmove_poll(move)) {
            continue;
        }

        if(psmove_is_ext_connected(move)) {
            /* if the extension device was not connected before, report connect */
            if (!ext_connected) {
                PSMove_Ext_Device_Info ext;
                enum PSMove_Bool success = psmove_get_ext_device_info(move, &ext);

                if (success) {
                    switch (ext.dev_id) {
                        case EXT_DEVICE_ID_SHARP_SHOOTER:
                            ext_device = Ext_Sharp_Shooter;
                            printf("Sharp Shooter extension connected!\n");
                            break;
                        case EXT_DEVICE_ID_RACING_WHEEL:
                            ext_device = Ext_Racing_Wheel;
                            printf("Racing Wheel extension connected!\n");
                            break;
                        default:
                            ext_device = Ext_Unknown;
                            printf("Unknown extension device (id 0x%04X) connected!\n", ext.dev_id);
                            break;
                    }
                }
                else {
                    printf("Unknown extension device connected! Failed to get device info.\n");
                }
            }

            ext_connected = 1;

            /* handle button presses etc. for a known extension device only */
            PSMove_Ext_Data data;
            if (psmove_get_ext_data(move, &data)) {
                unsigned int move_buttons = psmove_get_buttons(move);

                switch (ext_device) {
                    case Ext_Sharp_Shooter:
                        handle_sharp_shooter(&data, move_buttons);
                        break;
                    case Ext_Racing_Wheel:
                        handle_racing_wheel(move, &data, move_buttons);
                        break;
                    default:
                        break;
                }
            }
        } else {
            /* if the extension device was connected before, report disconnect */
            if (ext_connected) {
                printf("Extension device disconnected!\n");
            }

            ext_connected = 0;
        }
    }

    psmove_disconnect(move);

    return 0;
}
Esempio n. 13
0
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 arg, char** args)
{
    measurement measurements[MEASUREMENTS];
    float distance = MEASUREMENTS_CM_START;
    int pos = 0;

    PSMove *move = psmove_connect();

    if (move == NULL) {
        printf("Could not connect to the default controller.\n");
        return 1;
    }

    PSMoveTracker* tracker = psmove_tracker_new();

    if (tracker == NULL) {
        printf("Could not create tracker.\n");
        return 2;
    }

    printf("Calibrating controller...\n");
    while (psmove_tracker_enable(tracker, move) != Tracker_CALIBRATED);

    while (cvWaitKey(1) != 27 && pos < MEASUREMENTS) {
        psmove_tracker_update_image(tracker);
        psmove_tracker_update(tracker, NULL);
        printf("Distance: %.2f cm\n", distance);

        void *frame = psmove_tracker_get_image(tracker);
        cvShowImage("Camera", frame);

        unsigned char r, g, b;
        psmove_tracker_get_color(tracker, move, &r, &g, &b);
        psmove_set_leds(move, r, g, b);
        psmove_update_leds(move);

        float x, y, radius;
        psmove_tracker_get_position(tracker, move, &x, &y, &radius);

        unsigned int pressed, released;
        while (psmove_poll(move));
        psmove_get_button_events(move, &pressed, &released);
        if (pressed & Btn_CROSS) {
            // Save current measurement
            save(frame, (int)distance);
            measurements[pos].distance_cm = distance;
            measurements[pos].radius_px = radius;
            distance += MEASUREMENTS_CM_STEP;
            pos++;
        } else if (pressed & Btn_CIRCLE && pos > 0) {
            // Go back and retry previous measurement
            distance -= MEASUREMENTS_CM_STEP;
            pos--;
        }
    }

    int i;
    FILE *fp = fopen("distance.csv", "w");
    fprintf(fp, "distance,radius\n");
    for (i=0; i<pos; i++) {
        fprintf(fp, "%.5f,%.5f\n",
                measurements[i].distance_cm,
                measurements[i].radius_px);
    }
    fclose(fp);

    psmove_tracker_free(tracker);
    psmove_disconnect(move);

    return 0;
}
Esempio n. 15
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;
}