From 464da85686a35ae62b37c9bd75bbb33a0b06bfdb Mon Sep 17 00:00:00 2001 From: Robert Stanley Judka Date: Sat, 25 Apr 2020 23:49:33 -0500 Subject: [PATCH] add interface to allow for night mode control (#2) --- .../f1x/openauto/autoapp/Service/SensorService.hpp | 4 +++- .../f1x/openauto/autoapp/Service/ServiceFactory.hpp | 6 +++++- src/autoapp/Service/SensorService.cpp | 11 +++++++++-- src/autoapp/Service/ServiceFactory.cpp | 12 ++++++++++-- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/include/f1x/openauto/autoapp/Service/SensorService.hpp b/include/f1x/openauto/autoapp/Service/SensorService.hpp index 5dfd8e5..8006065 100644 --- a/include/f1x/openauto/autoapp/Service/SensorService.hpp +++ b/include/f1x/openauto/autoapp/Service/SensorService.hpp @@ -33,7 +33,7 @@ namespace service class SensorService: public aasdk::channel::sensor::ISensorServiceChannelEventHandler, public IService, public std::enable_shared_from_this { public: - SensorService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger); + SensorService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, bool nightMode = false); void start() override; void stop() override; @@ -41,6 +41,7 @@ public: void onChannelOpenRequest(const aasdk::proto::messages::ChannelOpenRequest& request) override; void onSensorStartRequest(const aasdk::proto::messages::SensorStartRequestMessage& request) override; void onChannelError(const aasdk::error::Error& e) override; + void setNightMode(bool nightMode); private: using std::enable_shared_from_this::shared_from_this; @@ -49,6 +50,7 @@ private: boost::asio::io_service::strand strand_; aasdk::channel::sensor::SensorServiceChannel::Pointer channel_; + bool nightMode_; }; } diff --git a/include/f1x/openauto/autoapp/Service/ServiceFactory.hpp b/include/f1x/openauto/autoapp/Service/ServiceFactory.hpp index 61d2223..9d79b84 100644 --- a/include/f1x/openauto/autoapp/Service/ServiceFactory.hpp +++ b/include/f1x/openauto/autoapp/Service/ServiceFactory.hpp @@ -23,6 +23,7 @@ #include #include #include +#include namespace f1x { @@ -36,10 +37,11 @@ namespace service class ServiceFactory: public IServiceFactory { public: - ServiceFactory(boost::asio::io_service& ioService, configuration::IConfiguration::Pointer configuration, QWidget* activeArea=nullptr, std::function activeCallback=nullptr); + ServiceFactory(boost::asio::io_service& ioService, configuration::IConfiguration::Pointer configuration, QWidget* activeArea=nullptr, std::function activeCallback=nullptr, bool nightMode = false); ServiceList create(aasdk::messenger::IMessenger::Pointer messenger) override; void setOpacity(unsigned int alpha); void resize(); + void setNightMode(bool nightMode); static QRect mapActiveAreaToGlobal(QWidget* activeArea); #ifdef USE_OMX static projection::DestRect QRectToDestRect(QRect rect); @@ -62,6 +64,8 @@ private: #else projection::QtVideoOutput *qtVideoOutput_; #endif + bool nightMode_; + std::shared_ptr sensorService_; }; } diff --git a/src/autoapp/Service/SensorService.cpp b/src/autoapp/Service/SensorService.cpp index f6c05ef..c2b4ada 100644 --- a/src/autoapp/Service/SensorService.cpp +++ b/src/autoapp/Service/SensorService.cpp @@ -29,9 +29,10 @@ namespace autoapp namespace service { -SensorService::SensorService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger) +SensorService::SensorService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, bool nightMode) : strand_(ioService) , channel_(std::make_shared(strand_, std::move(messenger))) + , nightMode_(nightMode) { } @@ -121,7 +122,7 @@ void SensorService::sendDrivingStatusUnrestricted() void SensorService::sendNightData() { aasdk::proto::messages::SensorEventIndication indication; - indication.add_night_mode()->set_is_night(false); + indication.add_night_mode()->set_is_night(nightMode_); auto promise = aasdk::channel::SendPromise::defer(strand_); promise->then([]() {}, std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1)); @@ -133,6 +134,12 @@ void SensorService::onChannelError(const aasdk::error::Error& e) OPENAUTO_LOG(error) << "[SensorService] channel error: " << e.what(); } +void SensorService::setNightMode(bool nightMode) +{ + nightMode_ = nightMode; + this->sendNightData(); +} + } } } diff --git a/src/autoapp/Service/ServiceFactory.cpp b/src/autoapp/Service/ServiceFactory.cpp index dca6f65..461751f 100644 --- a/src/autoapp/Service/ServiceFactory.cpp +++ b/src/autoapp/Service/ServiceFactory.cpp @@ -49,7 +49,7 @@ namespace autoapp namespace service { -ServiceFactory::ServiceFactory(boost::asio::io_service& ioService, configuration::IConfiguration::Pointer configuration, QWidget *activeArea, std::function activeCallback) +ServiceFactory::ServiceFactory(boost::asio::io_service& ioService, configuration::IConfiguration::Pointer configuration, QWidget *activeArea, std::function activeCallback, bool nightMode) : ioService_(ioService) , configuration_(std::move(configuration)) , activeArea_(activeArea) @@ -58,6 +58,7 @@ ServiceFactory::ServiceFactory(boost::asio::io_service& ioService, configuration #ifdef USE_OMX , omxVideoOutput_(std::make_shared(configuration_, this->QRectToDestRect(screenGeometry_), activeCallback_)) #endif + , nightMode_(nightMode) { } @@ -69,7 +70,8 @@ ServiceList ServiceFactory::create(aasdk::messenger::IMessenger::Pointer messeng projection::IAudioInput::Pointer audioInput(new projection::QtAudioInput(1, 16, 16000), std::bind(&QObject::deleteLater, std::placeholders::_1)); serviceList.emplace_back(std::make_shared(ioService_, messenger, std::move(audioInput))); this->createAudioServices(serviceList, messenger); - serviceList.emplace_back(std::make_shared(ioService_, messenger)); + sensorService_ = std::make_shared(ioService_, messenger, nightMode_); + serviceList.emplace_back(sensorService_); serviceList.emplace_back(this->createVideoService(messenger)); serviceList.emplace_back(this->createBluetoothService(messenger)); serviceList.emplace_back(this->createInputService(messenger)); @@ -182,6 +184,12 @@ void ServiceFactory::resize() #endif } +void ServiceFactory::setNightMode(bool nightMode) +{ + nightMode_ = nightMode; + if (sensorService_ != nullptr) sensorService_->setNightMode(nightMode_); +} + QRect ServiceFactory::mapActiveAreaToGlobal(QWidget* activeArea) { if (activeArea == nullptr)