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
This commit is contained in:
Cole Brinsfield 2021-07-15 16:11:59 -07:00 committed by GitHub
parent e940b8036e
commit 658005da61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 6 deletions

View File

@ -38,6 +38,7 @@ class InputService:
public: public:
InputService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, projection::IInputDevice::Pointer inputDevice); 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 start() override;
void stop() override; void stop() override;
void fillFeatures(aasdk::proto::messages::ServiceDiscoveryResponse& response) override; void fillFeatures(aasdk::proto::messages::ServiceDiscoveryResponse& response) override;
@ -53,6 +54,7 @@ private:
boost::asio::io_service::strand strand_; boost::asio::io_service::strand strand_;
aasdk::channel::input::InputServiceChannel::Pointer channel_; aasdk::channel::input::InputServiceChannel::Pointer channel_;
projection::IInputDevice::Pointer inputDevice_; projection::IInputDevice::Pointer inputDevice_;
bool serviceActive = false;
}; };
} }

View File

@ -25,6 +25,7 @@
#include "openauto/Projection/GSTVideoOutput.hpp" #include "openauto/Projection/GSTVideoOutput.hpp"
#include "openauto/Projection/QtVideoOutput.hpp" #include "openauto/Projection/QtVideoOutput.hpp"
#include "openauto/Service/SensorService.hpp" #include "openauto/Service/SensorService.hpp"
#include "openauto/Service/InputService.hpp"
#include "btservice/btservice.hpp" #include "btservice/btservice.hpp"
namespace openauto namespace openauto
@ -40,6 +41,7 @@ public:
void setOpacity(unsigned int alpha); void setOpacity(unsigned int alpha);
void resize(); void resize();
void setNightMode(bool nightMode); void setNightMode(bool nightMode);
void sendButtonPress(aasdk::proto::enums::ButtonCode::Enum buttonCode);
void sendKeyEvent(QKeyEvent* event); void sendKeyEvent(QKeyEvent* event);
static QRect mapActiveAreaToGlobal(QWidget* activeArea); static QRect mapActiveAreaToGlobal(QWidget* activeArea);
#ifdef USE_OMX #ifdef USE_OMX
@ -49,7 +51,7 @@ public:
private: private:
IService::Pointer createVideoService(aasdk::messenger::IMessenger::Pointer messenger); IService::Pointer createVideoService(aasdk::messenger::IMessenger::Pointer messenger);
IService::Pointer createBluetoothService(aasdk::messenger::IMessenger::Pointer messenger); IService::Pointer createBluetoothService(aasdk::messenger::IMessenger::Pointer messenger);
IService::Pointer createInputService(aasdk::messenger::IMessenger::Pointer messenger); std::shared_ptr<InputService> createInputService(aasdk::messenger::IMessenger::Pointer messenger);
void createAudioServices(ServiceList& serviceList, aasdk::messenger::IMessenger::Pointer messenger); void createAudioServices(ServiceList& serviceList, aasdk::messenger::IMessenger::Pointer messenger);
boost::asio::io_service& ioService_; boost::asio::io_service& ioService_;
@ -68,6 +70,7 @@ private:
btservice::btservice btservice_; btservice::btservice btservice_;
bool nightMode_; bool nightMode_;
std::weak_ptr<SensorService> sensorService_; std::weak_ptr<SensorService> sensorService_;
std::weak_ptr<InputService> inputService_;
}; };
} }

View File

@ -30,7 +30,7 @@ InputService::InputService(boost::asio::io_service& ioService, aasdk::messenger:
, channel_(std::make_shared<aasdk::channel::input::InputServiceChannel>(strand_, std::move(messenger))) , channel_(std::make_shared<aasdk::channel::input::InputServiceChannel>(strand_, std::move(messenger)))
, inputDevice_(std::move(inputDevice)) , inputDevice_(std::move(inputDevice))
{ {
OPENAUTO_LOG(info) << "[InputService] Created";
} }
void InputService::start() void InputService::start()
@ -39,6 +39,7 @@ void InputService::start()
OPENAUTO_LOG(info) << "[InputService] start."; OPENAUTO_LOG(info) << "[InputService] start.";
channel_->receive(this->shared_from_this()); channel_->receive(this->shared_from_this());
}); });
serviceActive = true;
} }
void InputService::stop() void InputService::stop()
@ -47,6 +48,7 @@ void InputService::stop()
OPENAUTO_LOG(info) << "[InputService] stop."; OPENAUTO_LOG(info) << "[InputService] stop.";
inputDevice_->stop(); inputDevice_->stop();
}); });
serviceActive = false;
} }
void InputService::fillFeatures(aasdk::proto::messages::ServiceDiscoveryResponse& response) 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) 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) void InputService::onButtonEvent(const projection::ButtonEvent& event)
{ {
if(!serviceActive) return;
auto timestamp = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()); auto timestamp = std::chrono::duration_cast<std::chrono::microseconds>(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)]() { 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) void InputService::onTouchEvent(const projection::TouchEvent& event)
{ {
auto timestamp = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()); auto timestamp = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now().time_since_epoch());

View File

@ -79,8 +79,9 @@ ServiceList ServiceFactory::create(aasdk::messenger::IMessenger::Pointer messeng
serviceList.emplace_back(this->createVideoService(messenger)); serviceList.emplace_back(this->createVideoService(messenger));
serviceList.emplace_back(this->createBluetoothService(messenger)); serviceList.emplace_back(this->createBluetoothService(messenger));
serviceList.emplace_back(this->createInputService(messenger)); std::shared_ptr<InputService> inputService = this->createInputService(messenger);
inputService_ = inputService;
serviceList.emplace_back(inputService);
return serviceList; return serviceList;
} }
@ -127,7 +128,7 @@ IService::Pointer ServiceFactory::createBluetoothService(aasdk::messenger::IMess
return std::make_shared<BluetoothService>(ioService_, messenger, std::move(bluetoothDevice)); return std::make_shared<BluetoothService>(ioService_, messenger, std::move(bluetoothDevice));
} }
IService::Pointer ServiceFactory::createInputService(aasdk::messenger::IMessenger::Pointer messenger) std::shared_ptr<InputService> ServiceFactory::createInputService(aasdk::messenger::IMessenger::Pointer messenger)
{ {
QRect videoGeometry; QRect videoGeometry;
switch(configuration_->getVideoResolution()) 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 = inputService_.lock())
{
inputService->sendButtonPress(buttonCode);
}
}
void ServiceFactory::sendKeyEvent(QKeyEvent* event) void ServiceFactory::sendKeyEvent(QKeyEvent* event)
{ {
if(inputDevice_ != nullptr) if(inputDevice_ != nullptr)