mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-02-06 20:33:00 -05:00
Added button on AllDevices window, and handling for it. Added needed messages for communication with service bluetooth. Feature is now complete on application settings side. Further integration in service bluetooth is needed.
60 lines
1.8 KiB
C++
60 lines
1.8 KiB
C++
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
|
|
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
|
|
|
|
#include "AddDeviceWindow.hpp"
|
|
#include "application-settings-new/ApplicationSettings.hpp"
|
|
#include "application-settings-new/data/DeviceData.hpp"
|
|
|
|
#include "OptionSetting.hpp"
|
|
|
|
extern "C"
|
|
{
|
|
#include <module-bluetooth/lib/btstack/src/btstack_util.h>
|
|
}
|
|
|
|
namespace gui
|
|
{
|
|
|
|
AddDeviceWindow::AddDeviceWindow(app::Application *app) : BaseSettingsWindow(app, window::name::add_device)
|
|
{
|
|
bluetoothSettingsModel = std::make_unique<BluetoothSettingsModel>(application);
|
|
}
|
|
|
|
void AddDeviceWindow::onBeforeShow(ShowMode /*mode*/, SwitchData *data)
|
|
{
|
|
const auto newData = dynamic_cast<DeviceData *>(data);
|
|
if (newData != nullptr) {
|
|
devices = newData->getDevices();
|
|
}
|
|
refreshOptionsList();
|
|
}
|
|
|
|
void AddDeviceWindow::onClose()
|
|
{
|
|
bluetoothSettingsModel->stopScan();
|
|
}
|
|
|
|
auto AddDeviceWindow::buildOptionsList() -> std::list<gui::Option>
|
|
{
|
|
std::list<gui::Option> optionsList;
|
|
|
|
for (const auto &device : devices) {
|
|
optionsList.emplace_back(std::make_unique<gui::option::OptionSettings>(
|
|
device.name,
|
|
[=](gui::Item & /*unused*/) {
|
|
LOG_DEBUG("Device: %s", device.name.c_str());
|
|
bluetoothSettingsModel->requestDevicePair(bd_addr_to_str(device.address));
|
|
application->switchWindow(gui::window::name::all_devices);
|
|
return true;
|
|
},
|
|
nullptr,
|
|
nullptr,
|
|
gui::option::SettingRightItem::Bt));
|
|
}
|
|
|
|
bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get(style::strings::common::add));
|
|
|
|
return optionsList;
|
|
}
|
|
} // namespace gui
|