コード例 #1
0
    void testQOfonoCallVolume()
    {
        QSignalSpy mutedChanged(m, SIGNAL(mutedChanged(bool)));
        QSignalSpy speakerVolumeChanged(m, SIGNAL(speakerVolumeChanged(quint8)));
        QSignalSpy microphoneVolumeChanged(m, SIGNAL(microphoneVolumeChanged(quint8)));

        m->setMuted(true);
        QTRY_COMPARE(mutedChanged.count(), 1);
        QVERIFY(mutedChanged.takeFirst().at(0).toBool()==bool(true));
        QVERIFY(m->muted()==bool(true));

        m->setMuted(false);
        QTRY_COMPARE(mutedChanged.count(), 1);
        QVERIFY(mutedChanged.takeFirst().at(0).toBool()==bool(false));
        QVERIFY(m->muted()==bool(false));

        m->setSpeakerVolume(quint8(15));
        QTRY_COMPARE(speakerVolumeChanged.count(), 1);
        QCOMPARE(quint8(speakerVolumeChanged.takeFirst().at(0).toUInt()), quint8(15));
        QCOMPARE(m->speakerVolume(),quint8(15));

        m->setSpeakerVolume(quint8(250));
        m->setMicrophoneVolume(quint8(10));
        QTest::qWait(REASONABLE_TIMEOUT);
        QCOMPARE(speakerVolumeChanged.count(), 0);
        QCOMPARE(microphoneVolumeChanged.count(), 0);
    }
コード例 #2
0
/*!
    This method is the concrete implementation of the
    QBluetoothAudioGateway interface method of the same name.
    It is called from the QBluetoothHandsfreeAudioGatewayServer
    class, which acts as a forwarding agent.

    Instructs the Bluetooth device to set the speaker volume to
    \a volume.

    \sa QBluetoothHandsfreeAudioGatewayServer
*/
void QBluetoothHeadsetService::setSpeakerVolume(int volume)
{
    qLog(Bluetooth) << "setSpeakerVolume:" << volume;

    if (!m_data->m_client)
        return;

    if (m_data->m_client->state() != QBluetoothRfcommSocket::ConnectedState) {
        return;
    }

    if (m_data->m_scofd == -1) // Don't send when audio not connected
        return;

    if (volume == m_data->m_speakerVolume)
        return;

    char data[64];
    int len = sprintf(data, "\r\n+VGS=%d\r\n", volume);
    qLog(Bluetooth) << "Writing" << data << "(len =" << volume << "bytes) to the headset";
    m_data->m_client->write(data, len);

    m_data->m_speakerVolume = volume;
    m_data->m_interface->setValue("SpeakerVolume", volume);
    emit speakerVolumeChanged();
}
コード例 #3
0
/*!
    Constructs a new Headset Interface group.  The audio
    device to use is given by \a audioDev.  The implementation
    object is given by \a parent.
*/
QBluetoothHeadsetCommInterface::QBluetoothHeadsetCommInterface(const QByteArray &audioDev, QBluetoothHeadsetService *parent)
    : QAbstractIpcInterfaceGroup(parent->name(), parent),
      m_data(new QBluetoothHeadsetCommInterfacePrivate)
{
    m_data->m_service = parent;
    m_data->m_gatewayServer = new QBluetoothHeadsetAudioGatewayServer(this, audioDev,
            parent->name());

    QObject::connect(parent, SIGNAL(connectResult(bool,QString)),
                     SIGNAL(connectResult(bool,QString)));
    QObject::connect(parent, SIGNAL(newConnection(QBluetoothAddress)),
                     SIGNAL(newConnection(QBluetoothAddress)));
    QObject::connect(parent, SIGNAL(disconnected()),
                     SIGNAL(disconnected()));
    QObject::connect(parent, SIGNAL(speakerVolumeChanged()),
                     SIGNAL(speakerVolumeChanged()));
    QObject::connect(parent, SIGNAL(microphoneVolumeChanged()),
                     SIGNAL(microphoneVolumeChanged()));
    QObject::connect(parent, SIGNAL(audioStateChanged()),
                     SIGNAL(audioStateChanged()));
}
コード例 #4
0
/*!
    \internal
*/
void QBluetoothHeadsetService::readyRead()
{
    char buf[512];

    int size = m_data->m_client->read(buf, 512);
    buf[size] = '\0';
    int volume = 0;

    if (m_data->m_connectInProgress) {
        if (!strncmp("AT+CKPD=200\r", buf, 512)) {
            m_data->m_client->write("\r\nOK\r\n");
            emit connectResult(true, QString());
            m_data->m_connectInProgress = false;
            m_data->m_interface->setValue("IsConnected", true);
            m_data->m_interface->setValue("RemotePeer",
                                          QVariant::fromValue(m_data->m_client->remoteAddress()));
        }
        else {
            m_data->m_client->write("\r\nERROR\r\n");
        }
        return;
    }

    if (!strncmp("AT+CKPD=200\r", buf, 512)) {
        qLog(Bluetooth) << "QBluetoothHeadsetService::readyRead: Got an AT+CKPD=200";
        // Audio not connected
        if (m_data->m_scofd == -1) {
            qLog(Bluetooth) << "QBluetoothHeadsetService::readyRead: No audio.";
            if (doConnectAudio()) {
                m_data->m_client->write("\r\nOK\r\n");
            }
            else {
                m_data->m_client->write("\r\nERROR\r\n");
            }
        }
        else {
            qLog(Bluetooth) << "QBluetoothHeadsetService::readyRead: Releasing audio.";
            releaseAudio();
            m_data->m_client->write("\r\nOK\r\n");
        }
    }
    else if (sscanf(buf, "AT+VGS=%d", &volume) == 1) {
        qLog(Bluetooth) << "QBluetoothHeadsetService::readyRead: Got a SpeakerVolume change.";
        if (m_data->m_speakerVolume != volume) {
            m_data->m_speakerVolume = volume;
            m_data->m_interface->setValue("SpeakerVolume", volume);
            emit speakerVolumeChanged();
        }

        m_data->m_client->write("\r\nOK\r\n");
    }
    else if (sscanf(buf, "AT+VGM=%d", &volume) == 1) {
        qLog(Bluetooth) << "QBluetoothHeadsetService::readyRead: Got a MicrophoneVolume change.";
        if (m_data->m_microphoneVolume != volume) {
            m_data->m_microphoneVolume = volume;
            m_data->m_interface->setValue("MicrophoneVolume", volume);
            emit microphoneVolumeChanged();
        }

        m_data->m_client->write("\r\nOK\r\n");
    }
}