From 658005da61018314dffc11dc414a6c4ad65b7659 Mon Sep 17 00:00:00 2001 From: Cole Brinsfield Date: Thu, 15 Jul 2021 16:11:59 -0700 Subject: [PATCH] input service binding (#22) * Working on proper resizing of AA * allow for custom aspect ratios * A mess of code to support sending input events from dash * Restructuring input injection to be much nicer * Code Cleanup --- include/openauto/Service/InputService.hpp | 2 ++ include/openauto/Service/ServiceFactory.hpp | 5 ++++- openauto/Service/InputService.cpp | 15 +++++++++++++-- openauto/Service/ServiceFactory.cpp | 16 +++++++++++++--- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/include/openauto/Service/InputService.hpp b/include/openauto/Service/InputService.hpp index 3f66e36..1240bed 100644 --- a/include/openauto/Service/InputService.hpp +++ b/include/openauto/Service/InputService.hpp @@ -38,6 +38,7 @@ class InputService: public: InputService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, projection::IInputDevice::Pointer inputDevice); + void sendButtonPress(aasdk::proto::enums::ButtonCode::Enum buttonCode); void start() override; void stop() override; void fillFeatures(aasdk::proto::messages::ServiceDiscoveryResponse& response) override; @@ -53,6 +54,7 @@ private: boost::asio::io_service::strand strand_; aasdk::channel::input::InputServiceChannel::Pointer channel_; projection::IInputDevice::Pointer inputDevice_; + bool serviceActive = false; }; } diff --git a/include/openauto/Service/ServiceFactory.hpp b/include/openauto/Service/ServiceFactory.hpp index 88c6dac..5567099 100644 --- a/include/openauto/Service/ServiceFactory.hpp +++ b/include/openauto/Service/ServiceFactory.hpp @@ -25,6 +25,7 @@ #include "openauto/Projection/GSTVideoOutput.hpp" #include "openauto/Projection/QtVideoOutput.hpp" #include "openauto/Service/SensorService.hpp" +#include "openauto/Service/InputService.hpp" #include "btservice/btservice.hpp" namespace openauto @@ -40,6 +41,7 @@ public: void setOpacity(unsigned int alpha); void resize(); void setNightMode(bool nightMode); + void sendButtonPress(aasdk::proto::enums::ButtonCode::Enum buttonCode); void sendKeyEvent(QKeyEvent* event); static QRect mapActiveAreaToGlobal(QWidget* activeArea); #ifdef USE_OMX @@ -49,7 +51,7 @@ public: private: IService::Pointer createVideoService(aasdk::messenger::IMessenger::Pointer messenger); IService::Pointer createBluetoothService(aasdk::messenger::IMessenger::Pointer messenger); - IService::Pointer createInputService(aasdk::messenger::IMessenger::Pointer messenger); + std::shared_ptr createInputService(aasdk::messenger::IMessenger::Pointer messenger); void createAudioServices(ServiceList& serviceList, aasdk::messenger::IMessenger::Pointer messenger); boost::asio::io_service& ioService_; @@ -68,6 +70,7 @@ private: btservice::btservice btservice_; bool nightMode_; std::weak_ptr sensorService_; + std::weak_ptr inputService_; }; } diff --git a/openauto/Service/InputService.cpp b/openauto/Service/InputService.cpp index 26ff20b..863ed35 100644 --- a/openauto/Service/InputService.cpp +++ b/openauto/Service/InputService.cpp @@ -30,7 +30,7 @@ InputService::InputService(boost::asio::io_service& ioService, aasdk::messenger: , channel_(std::make_shared(strand_, std::move(messenger))) , inputDevice_(std::move(inputDevice)) { - + OPENAUTO_LOG(info) << "[InputService] Created"; } void InputService::start() @@ -39,6 +39,7 @@ void InputService::start() OPENAUTO_LOG(info) << "[InputService] start."; channel_->receive(this->shared_from_this()); }); + serviceActive = true; } void InputService::stop() @@ -47,6 +48,7 @@ void InputService::stop() OPENAUTO_LOG(info) << "[InputService] stop."; inputDevice_->stop(); }); + serviceActive = false; } void InputService::fillFeatures(aasdk::proto::messages::ServiceDiscoveryResponse& response) @@ -128,11 +130,12 @@ void InputService::onBindingRequest(const aasdk::proto::messages::BindingRequest void InputService::onChannelError(const aasdk::error::Error& e) { - OPENAUTO_LOG(error) << "[SensorService] channel error: " << e.what(); + OPENAUTO_LOG(error) << "[InputService] channel error: " << e.what(); } void InputService::onButtonEvent(const projection::ButtonEvent& event) { + if(!serviceActive) return; auto timestamp = std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()); strand_.dispatch([this, self = this->shared_from_this(), event = std::move(event), timestamp = std::move(timestamp)]() { @@ -160,6 +163,14 @@ void InputService::onButtonEvent(const projection::ButtonEvent& event) }); } +void InputService::sendButtonPress(aasdk::proto::enums::ButtonCode::Enum buttonCode) +{ + OPENAUTO_LOG(error) << "[InputService] injecting button press"; + + onButtonEvent({projection::ButtonEventType::PRESS, projection::WheelDirection::NONE, buttonCode}); + onButtonEvent({projection::ButtonEventType::RELEASE, projection::WheelDirection::NONE, buttonCode}); +} + void InputService::onTouchEvent(const projection::TouchEvent& event) { auto timestamp = std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()); diff --git a/openauto/Service/ServiceFactory.cpp b/openauto/Service/ServiceFactory.cpp index 240a7be..bc980a1 100644 --- a/openauto/Service/ServiceFactory.cpp +++ b/openauto/Service/ServiceFactory.cpp @@ -79,8 +79,9 @@ ServiceList ServiceFactory::create(aasdk::messenger::IMessenger::Pointer messeng serviceList.emplace_back(this->createVideoService(messenger)); serviceList.emplace_back(this->createBluetoothService(messenger)); - serviceList.emplace_back(this->createInputService(messenger)); - + std::shared_ptr inputService = this->createInputService(messenger); + inputService_ = inputService; + serviceList.emplace_back(inputService); return serviceList; } @@ -127,7 +128,7 @@ IService::Pointer ServiceFactory::createBluetoothService(aasdk::messenger::IMess return std::make_shared(ioService_, messenger, std::move(bluetoothDevice)); } -IService::Pointer ServiceFactory::createInputService(aasdk::messenger::IMessenger::Pointer messenger) +std::shared_ptr ServiceFactory::createInputService(aasdk::messenger::IMessenger::Pointer messenger) { QRect videoGeometry; switch(configuration_->getVideoResolution()) @@ -227,6 +228,15 @@ void ServiceFactory::setNightMode(bool nightMode) } } +void ServiceFactory::sendButtonPress(aasdk::proto::enums::ButtonCode::Enum buttonCode) +{ + if(std::shared_ptr inputService = inputService_.lock()) + { + + inputService->sendButtonPress(buttonCode); + } +} + void ServiceFactory::sendKeyEvent(QKeyEvent* event) { if(inputDevice_ != nullptr)