From 799ed557ec67a7da856a6a8fa8e80e7e33d02eba Mon Sep 17 00:00:00 2001 From: "michal.szwaj" Date: Wed, 14 Mar 2018 17:20:59 +0100 Subject: [PATCH 1/5] Implement and use configuration of video margins --- .../autoapp/Configuration/Configuration.hpp | 5 +++++ .../autoapp/Configuration/IConfiguration.hpp | 3 +++ .../openauto/autoapp/Projection/IVideoOutput.hpp | 2 ++ .../openauto/autoapp/Projection/VideoOutput.hpp | 1 + src/autoapp/Configuration/Configuration.cpp | 16 ++++++++++++++++ src/autoapp/Projection/VideoOutput.cpp | 5 +++++ src/autoapp/Projection/VideoService.cpp | 6 ++++-- 7 files changed, 36 insertions(+), 2 deletions(-) diff --git a/include/f1x/openauto/autoapp/Configuration/Configuration.hpp b/include/f1x/openauto/autoapp/Configuration/Configuration.hpp index 2498977..93d44b3 100644 --- a/include/f1x/openauto/autoapp/Configuration/Configuration.hpp +++ b/include/f1x/openauto/autoapp/Configuration/Configuration.hpp @@ -52,6 +52,8 @@ public: void setScreenDPI(size_t value) override; void setOMXLayerIndex(int32_t value) override; int32_t getOMXLayerIndex() const override; + void setVideoMargins(QRect value) override; + QRect getVideoMargins() const override; bool getTouchscreenEnabled() const override; void setTouchscreenEnabled(bool value) override; @@ -79,6 +81,7 @@ private: aasdk::proto::enums::VideoResolution::Enum videoResolution_; size_t screenDPI_; int32_t omxLayerIndex_; + QRect videoMargins_; bool enableTouchscreen_; ButtonCodes buttonCodes_; BluetoothAdapterType bluetoothAdapterType_; @@ -95,6 +98,8 @@ private: static const std::string cVideoResolutionKey; static const std::string cVideoScreenDPIKey; static const std::string cVideoOMXLayerIndexKey; + static const std::string cVideoMarginWidth; + static const std::string cVideoMarginHeight; static const std::string cAudioMusicAudioChannelEnabled; static const std::string cAudioSpeechAudioChannelEnabled; diff --git a/include/f1x/openauto/autoapp/Configuration/IConfiguration.hpp b/include/f1x/openauto/autoapp/Configuration/IConfiguration.hpp index 48437f6..2f086cd 100644 --- a/include/f1x/openauto/autoapp/Configuration/IConfiguration.hpp +++ b/include/f1x/openauto/autoapp/Configuration/IConfiguration.hpp @@ -19,6 +19,7 @@ #pragma once #include +#include #include #include #include @@ -59,6 +60,8 @@ public: virtual void setScreenDPI(size_t value) = 0; virtual void setOMXLayerIndex(int32_t value) = 0; virtual int32_t getOMXLayerIndex() const = 0; + virtual void setVideoMargins(QRect value) = 0; + virtual QRect getVideoMargins() const = 0; virtual bool getTouchscreenEnabled() const = 0; virtual void setTouchscreenEnabled(bool value) = 0; diff --git a/include/f1x/openauto/autoapp/Projection/IVideoOutput.hpp b/include/f1x/openauto/autoapp/Projection/IVideoOutput.hpp index c1ada0d..1c483bc 100644 --- a/include/f1x/openauto/autoapp/Projection/IVideoOutput.hpp +++ b/include/f1x/openauto/autoapp/Projection/IVideoOutput.hpp @@ -19,6 +19,7 @@ #pragma once #include +#include #include #include #include @@ -47,6 +48,7 @@ public: virtual aasdk::proto::enums::VideoFPS::Enum getVideoFPS() const = 0; virtual aasdk::proto::enums::VideoResolution::Enum getVideoResolution() const = 0; virtual size_t getScreenDPI() const = 0; + virtual QRect getVideoMargins() const = 0; }; } diff --git a/include/f1x/openauto/autoapp/Projection/VideoOutput.hpp b/include/f1x/openauto/autoapp/Projection/VideoOutput.hpp index 7cfac93..3c67cf6 100644 --- a/include/f1x/openauto/autoapp/Projection/VideoOutput.hpp +++ b/include/f1x/openauto/autoapp/Projection/VideoOutput.hpp @@ -38,6 +38,7 @@ public: aasdk::proto::enums::VideoFPS::Enum getVideoFPS() const override; aasdk::proto::enums::VideoResolution::Enum getVideoResolution() const override; size_t getScreenDPI() const override; + QRect getVideoMargins() const override; protected: configuration::IConfiguration::Pointer configuration_; diff --git a/src/autoapp/Configuration/Configuration.cpp b/src/autoapp/Configuration/Configuration.cpp index c1c4229..72e51e1 100644 --- a/src/autoapp/Configuration/Configuration.cpp +++ b/src/autoapp/Configuration/Configuration.cpp @@ -37,6 +37,8 @@ const std::string Configuration::cVideoFPSKey = "Video.FPS"; const std::string Configuration::cVideoResolutionKey = "Video.Resolution"; const std::string Configuration::cVideoScreenDPIKey = "Video.ScreenDPI"; const std::string Configuration::cVideoOMXLayerIndexKey = "Video.OMXLayerIndex"; +const std::string Configuration::cVideoMarginWidth = "Video.MarginWidth"; +const std::string Configuration::cVideoMarginHeight = "Video.MarginHeight"; const std::string Configuration::cAudioMusicAudioChannelEnabled = "Audio.MusicAudioChannelEnabled"; const std::string Configuration::cAudioSpeechAudioChannelEnabled = "Audio.SpeechAudioChannelEnabled"; @@ -87,6 +89,7 @@ void Configuration::load() screenDPI_ = iniConfig.get(cVideoScreenDPIKey, 140); omxLayerIndex_ = iniConfig.get(cVideoOMXLayerIndexKey, 1); + videoMargins_ = QRect(0, 0, iniConfig.get(cVideoMarginWidth, 0), iniConfig.get(cVideoMarginHeight, 0)); enableTouchscreen_ = iniConfig.get(cInputEnableTouchscreenKey, true); this->readButtonCodes(iniConfig); @@ -116,6 +119,7 @@ void Configuration::reset() videoResolution_ = aasdk::proto::enums::VideoResolution::_480p; screenDPI_ = 140; omxLayerIndex_ = 1; + videoMargins_ = QRect(0, 0, 0, 0); enableTouchscreen_ = true; buttonCodes_.clear(); bluetoothAdapterType_ = BluetoothAdapterType::NONE; @@ -134,6 +138,8 @@ void Configuration::save() iniConfig.put(cVideoResolutionKey, static_cast(videoResolution_)); iniConfig.put(cVideoScreenDPIKey, screenDPI_); iniConfig.put(cVideoOMXLayerIndexKey, omxLayerIndex_); + iniConfig.put(cVideoMarginWidth, videoMargins_.width()); + iniConfig.put(cVideoMarginHeight, videoMargins_.height()); iniConfig.put(cInputEnableTouchscreenKey, enableTouchscreen_); this->writeButtonCodes(iniConfig); @@ -206,6 +212,16 @@ int32_t Configuration::getOMXLayerIndex() const return omxLayerIndex_; } +void Configuration::setVideoMargins(QRect value) +{ + videoMargins_ = value; +} + +QRect Configuration::getVideoMargins() const +{ + return videoMargins_; +} + bool Configuration::getTouchscreenEnabled() const { return enableTouchscreen_; diff --git a/src/autoapp/Projection/VideoOutput.cpp b/src/autoapp/Projection/VideoOutput.cpp index 1b0c4e4..dca398d 100644 --- a/src/autoapp/Projection/VideoOutput.cpp +++ b/src/autoapp/Projection/VideoOutput.cpp @@ -48,6 +48,11 @@ size_t VideoOutput::getScreenDPI() const return configuration_->getScreenDPI(); } +QRect VideoOutput::getVideoMargins() const +{ + return configuration_->getVideoMargins(); +} + } } } diff --git a/src/autoapp/Projection/VideoService.cpp b/src/autoapp/Projection/VideoService.cpp index 251e037..b419d4a 100644 --- a/src/autoapp/Projection/VideoService.cpp +++ b/src/autoapp/Projection/VideoService.cpp @@ -144,8 +144,10 @@ void VideoService::fillFeatures(aasdk::proto::messages::ServiceDiscoveryResponse auto* videoConfig1 = videoChannel->add_video_configs(); videoConfig1->set_video_resolution(videoOutput_->getVideoResolution()); videoConfig1->set_video_fps(videoOutput_->getVideoFPS()); - videoConfig1->set_margin_height(0); - videoConfig1->set_margin_width(0); + + const auto& videoMargins = videoOutput_->getVideoMargins(); + videoConfig1->set_margin_height(videoMargins.height()); + videoConfig1->set_margin_width(videoMargins.width()); videoConfig1->set_dpi(videoOutput_->getScreenDPI()); } From d483040d764822d4d23285dbe10a2e025761ac57 Mon Sep 17 00:00:00 2001 From: "michal.szwaj" Date: Wed, 14 Mar 2018 17:33:28 +0100 Subject: [PATCH 2/5] Add fields to set margin values --- src/autoapp/UI/settingswindow.ui | 134 +++++++++++++++++++++---------- 1 file changed, 91 insertions(+), 43 deletions(-) diff --git a/src/autoapp/UI/settingswindow.ui b/src/autoapp/UI/settingswindow.ui index 11e6ad4..e476b55 100644 --- a/src/autoapp/UI/settingswindow.ui +++ b/src/autoapp/UI/settingswindow.ui @@ -260,48 +260,6 @@ color: rgb(238, 238, 236); - - - - 20 - 390 - 531 - 31 - - - - 400 - - - Qt::Horizontal - - - - - - 20 - 360 - 91 - 17 - - - - Screen DPI - - - - - - 570 - 380 - 41 - 51 - - - - 400 - - @@ -312,7 +270,7 @@ color: rgb(238, 238, 236); - OMX Layer index + Display @@ -363,6 +321,94 @@ color: rgb(238, 238, 236); + + + + 200 + 40 + 101 + 21 + + + + Margin width: + + + + + + 310 + 30 + 71 + 41 + + + + + + + 410 + 40 + 111 + 21 + + + + Margin height: + + + + + + 520 + 30 + 71 + 41 + + + + + + + + 0 + 360 + 621 + 81 + + + + Screen DPI + + + + + 570 + 40 + 41 + 31 + + + + 400 + + + + + + 20 + 40 + 531 + 31 + + + + 400 + + + Qt::Horizontal + + @@ -912,6 +958,8 @@ color: rgb(238, 238, 236); radioButton720p radioButton1080p spinBoxOmxLayerIndex + spinBoxVideoMarginWidth + spinBoxVideoMarginHeight horizontalSliderScreenDPI checkBoxMusicAudioChannel checkBoxSpeechAudioChannel From 3c1e65792fede9826d36cc34e5dc69acf219edb0 Mon Sep 17 00:00:00 2001 From: "michal.szwaj" Date: Wed, 14 Mar 2018 17:45:03 +0100 Subject: [PATCH 3/5] Set margin values on ui controls --- src/autoapp/UI/SettingsWindow.cpp | 8 ++++++++ src/autoapp/UI/settingswindow.ui | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/src/autoapp/UI/SettingsWindow.cpp b/src/autoapp/UI/SettingsWindow.cpp index dd55a57..3117cf3 100644 --- a/src/autoapp/UI/SettingsWindow.cpp +++ b/src/autoapp/UI/SettingsWindow.cpp @@ -73,6 +73,10 @@ void SettingsWindow::onSave() configuration_->setScreenDPI(static_cast(ui_->horizontalSliderScreenDPI->value())); configuration_->setOMXLayerIndex(ui_->spinBoxOmxLayerIndex->value()); + + QRect videoMargins(0, 0, ui_->spinBoxVideoMarginWidth->value(), ui_->spinBoxVideoMarginHeight->value()); + configuration_->setVideoMargins(std::move(videoMargins)); + configuration_->setTouchscreenEnabled(ui_->checkBoxEnableTouchscreen->isChecked()); this->saveButtonCheckBoxes(); @@ -130,6 +134,10 @@ void SettingsWindow::load() ui_->horizontalSliderScreenDPI->setValue(static_cast(configuration_->getScreenDPI())); ui_->spinBoxOmxLayerIndex->setValue(configuration_->getOMXLayerIndex()); + const auto& videoMargins = configuration_->getVideoMargins(); + ui_->spinBoxVideoMarginWidth->setValue(videoMargins.width()); + ui_->spinBoxVideoMarginHeight->setValue(videoMargins.height()); + ui_->checkBoxEnableTouchscreen->setChecked(configuration_->getTouchscreenEnabled()); this->loadButtonCheckBoxes(); diff --git a/src/autoapp/UI/settingswindow.ui b/src/autoapp/UI/settingswindow.ui index e476b55..63ad7a2 100644 --- a/src/autoapp/UI/settingswindow.ui +++ b/src/autoapp/UI/settingswindow.ui @@ -343,6 +343,9 @@ color: rgb(238, 238, 236); 41 + + 99999 + @@ -366,6 +369,9 @@ color: rgb(238, 238, 236); 41 + + 99999 + From 28cff9c53bc3a625af78c9f042a2f0a49c521119 Mon Sep 17 00:00:00 2001 From: "michal.szwaj" Date: Sat, 17 Mar 2018 01:20:48 +0100 Subject: [PATCH 4/5] Enumerate connected devices with AOAP capabilities --- include/f1x/openauto/autoapp/USB/USBApp.hpp | 6 +++++- src/autoapp/USB/USBApp.cpp | 18 +++++++++++++++++- src/autoapp/USB/USBMain.cpp | 8 ++++++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/include/f1x/openauto/autoapp/USB/USBApp.hpp b/include/f1x/openauto/autoapp/USB/USBApp.hpp index 76c6955..6b0a81b 100644 --- a/include/f1x/openauto/autoapp/USB/USBApp.hpp +++ b/include/f1x/openauto/autoapp/USB/USBApp.hpp @@ -19,6 +19,7 @@ #pragma once #include +#include #include #include @@ -36,7 +37,8 @@ class USBApp: public projection::IAndroidAutoEntityEventHandler, public std::ena public: typedef std::shared_ptr Pointer; - USBApp(boost::asio::io_service& ioService, projection::IAndroidAutoEntityFactory& androidAutoEntityFactory, aasdk::usb::IUSBHub::Pointer usbHub); + USBApp(boost::asio::io_service& ioService, projection::IAndroidAutoEntityFactory& androidAutoEntityFactory, + aasdk::usb::IUSBHub::Pointer usbHub, aasdk::usb::IConnectedAccessoriesEnumerator::Pointer connectedAccessoriesEnumerator); void start(); void stop(); @@ -45,6 +47,7 @@ public: private: using std::enable_shared_from_this::shared_from_this; + void enumerateDevices(); void waitForDevice(); void aoapDeviceHandler(aasdk::usb::DeviceHandle deviceHandle); void onUSBHubError(const aasdk::error::Error& error); @@ -53,6 +56,7 @@ private: boost::asio::io_service::strand strand_; projection::IAndroidAutoEntityFactory& androidAutoEntityFactory_; aasdk::usb::IUSBHub::Pointer usbHub_; + aasdk::usb::IConnectedAccessoriesEnumerator::Pointer connectedAccessoriesEnumerator_; projection::IAndroidAutoEntity::Pointer androidAutoEntity_; bool isStopped_; }; diff --git a/src/autoapp/USB/USBApp.cpp b/src/autoapp/USB/USBApp.cpp index 7f1af9a..d535ccf 100644 --- a/src/autoapp/USB/USBApp.cpp +++ b/src/autoapp/USB/USBApp.cpp @@ -29,11 +29,13 @@ namespace autoapp namespace usb { -USBApp::USBApp(boost::asio::io_service& ioService, projection::IAndroidAutoEntityFactory& androidAutoEntityFactory, aasdk::usb::IUSBHub::Pointer usbHub) +USBApp::USBApp(boost::asio::io_service& ioService, projection::IAndroidAutoEntityFactory& androidAutoEntityFactory, + aasdk::usb::IUSBHub::Pointer usbHub, aasdk::usb::IConnectedAccessoriesEnumerator::Pointer connectedAccessoriesEnumerator) : ioService_(ioService) , strand_(ioService_) , androidAutoEntityFactory_(androidAutoEntityFactory) , usbHub_(std::move(usbHub)) + , connectedAccessoriesEnumerator_(std::move(connectedAccessoriesEnumerator)) , isStopped_(false) { @@ -43,6 +45,7 @@ void USBApp::start() { strand_.dispatch([this, self = this->shared_from_this()]() { this->waitForDevice(); + this->enumerateDevices(); }); } @@ -84,6 +87,19 @@ void USBApp::aoapDeviceHandler(aasdk::usb::DeviceHandle deviceHandle) } } +void USBApp::enumerateDevices() +{ + auto promise = aasdk::usb::IConnectedAccessoriesEnumerator::Promise::defer(strand_); + promise->then([this, self = this->shared_from_this()](auto result) { + OPENAUTO_LOG(info) << "[USBApp] Devices enumeration result: " << result; + }, + [this, self = this->shared_from_this()](auto e) { + OPENAUTO_LOG(error) << "[USBApp] Devices enumeration failed: " << e.what(); + }); + + connectedAccessoriesEnumerator_->enumerate(std::move(promise)); +} + void USBApp::waitForDevice() { OPENAUTO_LOG(info) << "[USBApp] Waiting for device..."; diff --git a/src/autoapp/USB/USBMain.cpp b/src/autoapp/USB/USBMain.cpp index 4242920..6c3602f 100644 --- a/src/autoapp/USB/USBMain.cpp +++ b/src/autoapp/USB/USBMain.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -42,8 +43,11 @@ USBMain::USBMain(libusb_context* context) , serviceFactory_(ioService_, configuration_) , androidAutoEntityFactory_(usbWrapper_, ioService_, configuration_, serviceFactory_) { - aasdk::usb::IUSBHub::Pointer usbHub(std::make_shared(usbWrapper_, ioService_, queryChainFactory_)); - usbApp_ = std::make_shared(ioService_, androidAutoEntityFactory_, std::move(usbHub)); + auto usbHub(std::make_shared(usbWrapper_, ioService_, queryChainFactory_)); + auto ConnectedAccessoriesEnumerator(std::make_shared(usbWrapper_, ioService_, queryChainFactory_)); + + usbApp_ = std::make_shared(ioService_, androidAutoEntityFactory_, + std::move(usbHub), std::move(ConnectedAccessoriesEnumerator)); } int USBMain::exec(int argc, char* argv[]) From c4e4192cf82eb5b9ae1e8c6a96b6ecd249e4d083 Mon Sep 17 00:00:00 2001 From: "michal.szwaj" Date: Sat, 17 Mar 2018 02:00:06 +0100 Subject: [PATCH 5/5] Cancel device enumeration when app is stopped --- src/autoapp/USB/USBApp.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/autoapp/USB/USBApp.cpp b/src/autoapp/USB/USBApp.cpp index d535ccf..fe4064b 100644 --- a/src/autoapp/USB/USBApp.cpp +++ b/src/autoapp/USB/USBApp.cpp @@ -53,6 +53,7 @@ void USBApp::stop() { strand_.dispatch([this, self = this->shared_from_this()]() { isStopped_ = true; + connectedAccessoriesEnumerator_->cancel(); usbHub_->cancel(); if(androidAutoEntity_ != nullptr)