示例#1
0
文件: window.cpp 项目: sntx/psmoveosc
Window::Window(QWidget* parent)
    : QWidget(parent)
{
    QGridLayout* grid = new QGridLayout;
    grid->addWidget(createAccelerometerGroup(), 0, 0);
    grid->addWidget(createGyroscopeGroup(), 0, 1);
    grid->addWidget(createMagnetometerGroup(), 1, 0);
    grid->addWidget(createButtonsGroup(), 1, 1);

    setLayout(grid);
    setWindowTitle(tr("psmoveosc"));
    resize(480, 320);

    psm = new PSMoveQt(0);
    psm->setColor(Qt::red);
    psm->setEnabled(true);

    connect(psm, SIGNAL(accelerometerChanged()),
            this, SLOT(readAccelerometer()));

    connect(psm, SIGNAL(gyroChanged()),
            this, SLOT(readGyro()));

    connect(psm, SIGNAL(magnetometerChanged()),
            this, SLOT(readMagnetometer()));

    connect(psm, SIGNAL(triggerChanged()),
            this, SLOT(setTrigger()));

    connect(psm, SIGNAL(buttonPressed(int)),
            this, SLOT(onButton(int)));

    connect(psm, SIGNAL(buttonReleased(int)),
            this, SLOT(onButton(int)));

}
示例#2
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);
            }
        }
    }
}