diff --git a/modules/server/include/topics/flightcontrollertopic.h b/modules/server/include/topics/flightcontrollertopic.h index 78d74a2df8..fd5647dcbc 100644 --- a/modules/server/include/topics/flightcontrollertopic.h +++ b/modules/server/include/topics/flightcontrollertopic.h @@ -45,8 +45,11 @@ public: void handleJson(const nlohmann::json& json) override; bool isDone() const override; + void toggleAutopilot(); + private: bool _isDone; + bool _autopilotEngaged; nlohmann::json _payload; nlohmann::json _focusNodes; nlohmann::json _allNodes; diff --git a/modules/server/src/topics/flightcontrollertopic.cpp b/modules/server/src/topics/flightcontrollertopic.cpp index 99812b92d9..248e15bc45 100644 --- a/modules/server/src/topics/flightcontrollertopic.cpp +++ b/modules/server/src/topics/flightcontrollertopic.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -52,7 +53,8 @@ namespace { Connect = 0, Disconnect, InputState, - ChangeFocus + ChangeFocus, + Autopilot }; using AxisType = openspace::interaction::WebsocketCameraStates::AxisType; @@ -71,6 +73,9 @@ namespace { // Change focus JSON keys constexpr const char* FocusKey = "focus"; + // Autopilot JSON keys + constexpr const char* AutopilotEngagedKey = "engaged"; + constexpr const char* FlightControllerType = "flightcontroller"; const std::string OrbitX = "orbitX"; @@ -88,6 +93,7 @@ namespace { const std::string Disconnect = "disconnect"; const std::string InputState = "inputState"; const std::string ChangeFocus = "changeFocus"; + const std::string Autopilot = "autopilot"; const static std::unordered_map AxisIndexMap ({ {OrbitX, AxisType::OrbitX}, @@ -106,7 +112,8 @@ namespace { {Connect, Command::Connect}, {Disconnect, Command::Disconnect}, {InputState, Command::InputState}, - {ChangeFocus, Command::ChangeFocus} + {ChangeFocus, Command::ChangeFocus}, + {Autopilot, Command::Autopilot} }); const int Axes = 10; @@ -157,6 +164,9 @@ void FlightControllerTopic::handleJson(const nlohmann::json& json) { case Command::ChangeFocus: changeFocus(json); break; + case Command::Autopilot: + toggleAutopilot(); + break; default: LWARNING(fmt::format("Unrecognized action: {}", it->first)); break; @@ -220,6 +230,14 @@ void FlightControllerTopic::disconnect() { _isDone = true; } +void FlightControllerTopic::toggleAutopilot() { + nlohmann::json j; + j[TypeKey] = Autopilot; + j[Autopilot][AutopilotEngagedKey] = _autopilotEngaged; + + _autopilotEngaged = !_autopilotEngaged; +} + void FlightControllerTopic::processInputState(const nlohmann::json& json) { std::fill(_inputState.axes.begin(), _inputState.axes.end(), 0); diff --git a/src/interaction/inputstate.cpp b/src/interaction/inputstate.cpp index ba011cc03f..45756f110d 100644 --- a/src/interaction/inputstate.cpp +++ b/src/interaction/inputstate.cpp @@ -153,7 +153,7 @@ void InputState::resetWebsockets() { } bool InputState::hasWebsocketStates() const { - return _websocketInputs.size() > 0; + return !_websocketInputs.empty(); } } // namespace openspace::interaction