diff --git a/autoapp/autoapp.cpp b/autoapp/autoapp.cpp index 949ad42..9fd63b9 100644 --- a/autoapp/autoapp.cpp +++ b/autoapp/autoapp.cpp @@ -158,7 +158,7 @@ int main(int argc, char *argv[]) qDebug() << "[WebSocket] Disconnected. Will retry..."; reconnectTimer.start(3000); }); - QObject::connect(&webSocket, &QWebSocket::textMessageReceived, [&mainWindow, &connectDialog](const QString &message) + QObject::connect(&webSocket, &QWebSocket::textMessageReceived, [&mainWindow, &connectDialog, &serviceFactory](const QString &message) { QJsonParseError error; QJsonDocument doc = QJsonDocument::fromJson(message.toUtf8(), &error); @@ -172,7 +172,10 @@ int main(int argc, char *argv[]) connectDialog.connectToAddress(ipAddr); } else if (rootObj.contains("button")) { - + QJsonObject btnObj = rootObj["button"].toObject(); + QString btn = btnObj["btn"].toString(); + int state = btnObj["state"].toInt(); + serviceFactory.sendButtonPressFromString(btn.toStdString(), state); } else{ mainWindow.handleIncomingMessage(rootObj); diff --git a/include/openauto/Service/ServiceFactory.hpp b/include/openauto/Service/ServiceFactory.hpp index aaede04..135e68d 100644 --- a/include/openauto/Service/ServiceFactory.hpp +++ b/include/openauto/Service/ServiceFactory.hpp @@ -46,6 +46,7 @@ public: void sendButtonPress(aasdk::proto::enums::ButtonCode::Enum buttonCode, projection::WheelDirection wheelDirection = projection::WheelDirection::NONE, projection::ButtonEventType buttonEventType = projection::ButtonEventType::NONE); void sendKeyEvent(QKeyEvent* event); void setAndroidAutoInterface(IAndroidAutoInterface* aa_interface); + void sendButtonPressFromString(const std::string& btn, const int state); static QRect mapActiveAreaToGlobal(QWidget* activeArea); #ifdef USE_OMX static projection::DestRect QRectToDestRect(QRect rect); diff --git a/openauto/Configuration/Configuration.cpp b/openauto/Configuration/Configuration.cpp index acaabcc..6cedcfe 100644 --- a/openauto/Configuration/Configuration.cpp +++ b/openauto/Configuration/Configuration.cpp @@ -257,7 +257,7 @@ bool Configuration::getWhitescreenWorkaround() const bool Configuration::getTouchscreenEnabled() const { - return enableTouchscreen_; + return false; } void Configuration::setTouchscreenEnabled(bool value) diff --git a/openauto/Service/ServiceFactory.cpp b/openauto/Service/ServiceFactory.cpp index 71e811a..65e531f 100644 --- a/openauto/Service/ServiceFactory.cpp +++ b/openauto/Service/ServiceFactory.cpp @@ -262,6 +262,52 @@ void ServiceFactory::setNightMode(bool nightMode) } } +void ServiceFactory::sendButtonPressFromString(const std::string& btn, const int state) +{ + aasdk::proto::enums::ButtonCode::Enum buttonCode; + projection::WheelDirection wheelDirection = projection::WheelDirection::NONE; + projection::ButtonEventType buttonEventType = state == 0 ? projection::ButtonEventType::PRESS : projection::ButtonEventType::RELEASE; + + if (btn == "ENTER") { + buttonCode = aasdk::proto::enums::ButtonCode::ENTER; + } else if (btn == "LEFT") { + buttonCode = aasdk::proto::enums::ButtonCode::LEFT; + } else if (btn == "RIGHT") { + buttonCode = aasdk::proto::enums::ButtonCode::RIGHT; + } else if (btn == "UP") { + buttonCode = aasdk::proto::enums::ButtonCode::UP; + } else if (btn == "DOWN") { + buttonCode = aasdk::proto::enums::ButtonCode::DOWN; + } else if (btn == "BACK") { + buttonCode = aasdk::proto::enums::ButtonCode::BACK; + } else if (btn == "HOME") { + buttonCode = aasdk::proto::enums::ButtonCode::HOME; + } else if (btn == "PHONE") { + buttonCode = aasdk::proto::enums::ButtonCode::PHONE; + } else if (btn == "CALL_END") { + buttonCode = aasdk::proto::enums::ButtonCode::CALL_END; + } else if (btn == "PLAY") { + buttonCode = aasdk::proto::enums::ButtonCode::PLAY; + } else if (btn == "PAUSE") { + buttonCode = aasdk::proto::enums::ButtonCode::PAUSE; + } else if (btn == "PREV_TRACK") { + buttonCode = aasdk::proto::enums::ButtonCode::PREV; + } else if (btn == "NEXT_TRACK") { + buttonCode = aasdk::proto::enums::ButtonCode::NEXT; + } else if (btn == "TOGGLE_PLAY") { + buttonCode = aasdk::proto::enums::ButtonCode::TOGGLE_PLAY; + } else if (btn == "VOICE") { + buttonCode = aasdk::proto::enums::ButtonCode::MICROPHONE_1; + } else if (btn == "WHEEL_LEFT" || btn == "WHEEL_RIGHT") { + buttonCode = aasdk::proto::enums::ButtonCode::SCROLL_WHEEL; + wheelDirection = btn == "WHEEL_LEFT" ? projection::WheelDirection::LEFT : projection::WheelDirection::RIGHT; + } else { + return; + } + + sendButtonPress(buttonCode, wheelDirection, buttonEventType); +} + void ServiceFactory::sendButtonPress(aasdk::proto::enums::ButtonCode::Enum buttonCode, projection::WheelDirection wheelDirection, projection::ButtonEventType buttonEventType) { if(std::shared_ptr inputService = inputService_.lock())