GCSControlGadget::GCSControlGadget(QString classId, GCSControlGadgetWidget *widget, QWidget *parent, QObject *plugin) :
    IUAVGadget(classId, parent),
    m_widget(widget)
{
    connect(getManualControlCommand(), SIGNAL(objectUpdated(UAVObject *)), this, SLOT(manualControlCommandUpdated(UAVObject *)));
    connect(widget, SIGNAL(sticksChanged(double, double, double, double)), this, SLOT(sticksChangedLocally(double, double, double, double)));
    connect(this, SIGNAL(sticksChangedRemotely(double, double, double, double)), widget, SLOT(updateSticks(double, double, double, double)));

    manualControlCommandUpdated(getManualControlCommand());

    control_sock = new QUdpSocket(this);

    connect(control_sock, SIGNAL(readyRead()), this, SLOT(readUDPCommand()));

    joystickTime.start();
    GCSControlPlugin *pl = dynamic_cast<GCSControlPlugin *>(plugin);
    connect(pl->sdlGamepad, SIGNAL(gamepads(quint8)), this, SLOT(gamepads(quint8)));
    connect(pl->sdlGamepad, SIGNAL(buttonState(ButtonNumber, bool)), this, SLOT(buttonState(ButtonNumber, bool)));
    connect(pl->sdlGamepad, SIGNAL(axesValues(QListInt16)), this, SLOT(axesValues(QListInt16)));
}
예제 #2
0
void NavigatorGamepad::pageVisibilityChanged()
{
    // Inform the embedder whether it needs to provide gamepad data for us.
    bool visible = page()->visibilityState() == PageVisibilityStateVisible;
    if (visible && (m_hasEventListener || m_gamepads))
        startUpdating();
    else
        stopUpdating();

    if (!visible || !m_hasEventListener)
        return;

    // Tell the page what has changed. m_gamepads contains the state before we became hidden.
    // We create a new snapshot and compare them.
    GamepadList* oldGamepads = m_gamepads.release();
    gamepads();
    GamepadList* newGamepads = m_gamepads.get();
    ASSERT(newGamepads);

    for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) {
        Gamepad* oldGamepad = oldGamepads ? oldGamepads->item(i) : 0;
        Gamepad* newGamepad = newGamepads->item(i);
        bool oldWasConnected = oldGamepad && oldGamepad->connected();
        bool newIsConnected = newGamepad && newGamepad->connected();
        bool connectedGamepadChanged = oldWasConnected && newIsConnected && oldGamepad->id() != newGamepad->id();
        if (connectedGamepadChanged || (oldWasConnected && !newIsConnected)) {
            oldGamepad->setConnected(false);
            m_pendingEvents.append(oldGamepad);
        }
        if (connectedGamepadChanged || (!oldWasConnected && newIsConnected)) {
            m_pendingEvents.append(newGamepad);
        }
    }

    if (!m_pendingEvents.isEmpty())
        m_dispatchOneEventRunner.runAsync();
}