~aleteoryx/muditaos

da27b16dccd12f589cd56bfa527bf167eef51672 — SP2FET 4 years ago b4b4f3a
[EGD-6100] Add BT device turn off handling

After BT device disconnects (e.g. because of shutdown) Pure is now
aware of this
M module-bluetooth/Bluetooth/interface/profiles/A2DP/A2DP.cpp => module-bluetooth/Bluetooth/interface/profiles/A2DP/A2DP.cpp +6 -2
@@ 1,4 1,4 @@
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

//


@@ 18,6 18,7 @@
#include <service-evtmgr/Constants.hpp>
#include <log/log.hpp>
#include "service-bluetooth/messages/Connect.hpp"
#include "service-bluetooth/Constants.hpp"
extern "C"
{
#include "module-bluetooth/lib/btstack/src/btstack.h"


@@ 539,7 540,7 @@ namespace bluetooth
            stopTimer(&AVRCP::mediaTracker);
            break;

        case A2DP_SUBEVENT_STREAM_RELEASED:
        case A2DP_SUBEVENT_STREAM_RELEASED: {
            AVRCP::playInfo.status = AVRCP_PLAYBACK_STATUS_STOPPED;
            cid                    = a2dp_subevent_stream_released_get_a2dp_cid(packet);
            local_seid             = a2dp_subevent_stream_released_get_local_seid(packet);


@@ 563,12 564,15 @@ namespace bluetooth

            stopTimer(&AVRCP::mediaTracker);
            break;
        }
        case A2DP_SUBEVENT_SIGNALING_CONNECTION_RELEASED:
            cid = a2dp_subevent_signaling_connection_released_get_a2dp_cid(packet);
            if (cid == AVRCP::mediaTracker.a2dp_cid) {
                AVRCP::mediaTracker.avrcp_cid = 0;
                AVRCP::mediaTracker.a2dp_cid  = 0;
                LOG_INFO("A2DP Source: Signaling released.\n\n");
                auto &busProxy = const_cast<sys::Service *>(ownerService)->bus;
                busProxy.sendUnicast(std::make_shared<BluetoothDeviceDisconnectedMessage>(), service::name::bluetooth);
            }
            isConnected = false;
            break;

M module-bsp/board/rt1051/bsp/usb => module-bsp/board/rt1051/bsp/usb +1 -1
@@ 1,1 1,1 @@
Subproject commit 9f9b3f988333f30631caa3b442d57d2b44f7e074
Subproject commit ed8055cf9a7160772ab502b938689088e83f59b1

M module-services/service-bluetooth/ServiceBluetooth.cpp => module-services/service-bluetooth/ServiceBluetooth.cpp +17 -0
@@ 158,6 158,13 @@ sys::ReturnCodes ServiceBluetooth::InitHandler()
        return sys::MessageNone{};
    });

    connect(typeid(BluetoothDeviceDisconnectedMessage), [&](sys::Message *msg) {
        settingsHolder->setValue(bluetooth::Settings::ConnectedDevice, std::string());

        sendDevicesAfterDisconnect();
        return sys::MessageNone{};
    });

    settingsHolder->onStateChange = [this]() {
        auto initialState = std::visit(bluetooth::IntVisitor(), settingsHolder->getValue(bluetooth::Settings::State));
        if (static_cast<BluetoothStatus::State>(initialState) == BluetoothStatus::State::On) {


@@ 279,3 286,13 @@ void ServiceBluetooth::scanStoppedCallback()
        bus.sendUnicast(std::move(message), service::name::service_desktop);
    }
}

void ServiceBluetooth::sendDevicesAfterDisconnect()
{
    auto bondedDevicesStr =
        std::visit(bluetooth::StringVisitor(), this->settingsHolder->getValue(bluetooth::Settings::BondedDevices));

    bus.sendUnicast(std::make_shared<message::bluetooth::ResponseBondedDevices>(
                        SettingsSerializer::fromString(bondedDevicesStr), std::string()),
                    "ApplicationSettingsNew");
}

M module-services/service-bluetooth/service-bluetooth/BluetoothMessage.hpp => module-services/service-bluetooth/service-bluetooth/BluetoothMessage.hpp +21 -7
@@ 42,7 42,8 @@ class BluetoothMessage : public sys::DataMessage
        Disconnect
    };
    enum Request req = Request::None;
    BluetoothMessage(enum Request req = None) : sys::DataMessage(MessageType::BluetoothRequest), req(req){};
    BluetoothMessage(enum Request req = None) : sys::DataMessage(MessageType::BluetoothRequest), req(req)
    {}
    ~BluetoothMessage() override = default;
};



@@ 51,7 52,8 @@ class BluetoothScanResultMessage : public sys::DataMessage
  public:
    std::vector<Devicei> devices;
    BluetoothScanResultMessage(std::vector<Devicei> devices)
        : sys::DataMessage(MessageType::BluetoothScanResult), devices(std::move(devices)){};
        : sys::DataMessage(MessageType::BluetoothScanResult), devices(std::move(devices))
    {}
    ~BluetoothScanResultMessage() override = default;
};



@@ 81,7 83,8 @@ class BluetoothScanMessage : public sys::DataMessage
  public:
    std::vector<Devicei> devices;
    BluetoothScanMessage(std::vector<Devicei> devices)
        : sys::DataMessage(MessageType::BluetoothScanResult), devices(std::move(devices)){};
        : sys::DataMessage(MessageType::BluetoothScanResult), devices(std::move(devices))
    {}
    ~BluetoothScanMessage() override = default;
};



@@ 108,7 111,8 @@ class BluetoothAudioRegisterMessage : public sys::DataMessage
    QueueHandle_t audioSinkQueue;
    BluetoothAudioRegisterMessage(QueueHandle_t audioSourceQueue, QueueHandle_t audioSinkQueue)
        : sys::DataMessage(MessageType::BluetoothAudioRegister), audioSourceQueue(audioSourceQueue),
          audioSinkQueue(audioSinkQueue){};
          audioSinkQueue(audioSinkQueue)
    {}
    ~BluetoothAudioRegisterMessage() override = default;
};



@@ 117,14 121,16 @@ class BluetoothDeviceMetadataMessage : public sys::DataMessage
  public:
    DeviceMetadata_t metadata;
    BluetoothDeviceMetadataMessage(DeviceMetadata_t metadata)
        : DataMessage(MessageType::BluetoothDeviceMetadata), metadata(std::move(metadata)){};
        : DataMessage(MessageType::BluetoothDeviceMetadata), metadata(std::move(metadata))
    {}
    ~BluetoothDeviceMetadataMessage() override = default;
};

class BluetoothRequestStreamMessage : public sys::DataMessage
{
  public:
    BluetoothRequestStreamMessage() : DataMessage(MessageType::BluetoothRequestStream){};
    BluetoothRequestStreamMessage() : DataMessage(MessageType::BluetoothRequestStream)
    {}
    ~BluetoothRequestStreamMessage() override = default;
};



@@ 132,7 138,8 @@ class BluetoothRequestStreamResultMessage : public sys::DataMessage
{
  public:
    BluetoothRequestStreamResultMessage(std::shared_ptr<BluetoothStreamData> data)
        : DataMessage(MessageType::BluetoothRequestStream), data(data){};
        : DataMessage(MessageType::BluetoothRequestStream), data(data)
    {}
    ~BluetoothRequestStreamResultMessage() override = default;

    std::shared_ptr<BluetoothStreamData> getData()


@@ 143,3 150,10 @@ class BluetoothRequestStreamResultMessage : public sys::DataMessage
  private:
    std::shared_ptr<BluetoothStreamData> data;
};

class BluetoothDeviceDisconnectedMessage : public sys::DataMessage
{
  public:
    BluetoothDeviceDisconnectedMessage() : DataMessage(MessageType::BluetoothDeviceDisconnected)
    {}
};

M module-services/service-bluetooth/service-bluetooth/ServiceBluetooth.hpp => module-services/service-bluetooth/service-bluetooth/ServiceBluetooth.hpp +1 -0
@@ 46,6 46,7 @@ class ServiceBluetooth : public sys::Service
    std::unique_ptr<BluetoothWorker> worker;
    std::shared_ptr<sys::CpuSentinel> cpuSentinel;
    bool enabledFromHarness = false;
    void sendDevicesAfterDisconnect();
};

namespace sys

M source/MessageType.hpp => source/MessageType.hpp +1 -0
@@ 196,6 196,7 @@ enum class MessageType
    BluetoothAudioRegister,
    BluetoothDeviceMetadata,
    BluetoothRequestStream,
    BluetoothDeviceDisconnected,

    // bluetooth proxy
    BluetoothProxyStart,

M test/harness => test/harness +1 -1
@@ 1,1 1,1 @@
Subproject commit 630bd58022e56e5b58db3f762cccd3bdc040c608
Subproject commit 5e89897197e210f9fec418b0765d6234275d4069