From d13b6c3228ea3e8b4a905518c0a1ceb628e9a5d3 Mon Sep 17 00:00:00 2001 From: ackimixs Date: Thu, 16 May 2024 10:12:09 +0200 Subject: [PATCH] dynamic range --- GameControllerHandler.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/GameControllerHandler.h b/GameControllerHandler.h index 0bf59e0..df06616 100644 --- a/GameControllerHandler.h +++ b/GameControllerHandler.h @@ -38,6 +38,12 @@ public: void handleMessage(const std::string &message) override { std::vector tokens = Utils::split(message, ";"); + if (tokens[1] == "all" || tokens[1] == "lidar") { + if (tokens[2] == "set range") { + this->lidarDectectionDistance = stod(tokens[3]); + } + } + if (tokens[1] == "all" || tokens[1] == "gc") { if (tokens[2] == "stop proximity") { std::vector args = Utils::split(tokens[3], ","); @@ -47,7 +53,7 @@ public: if (distance <= 100) { strength = 0xFFFF; } else if (distance <= 500) { - double factor = 1 - Utils::mapValue(distance, 100.0, 750.0, 0.0, 1.0); + double factor = 1 - Utils::mapValue(distance, 100.0, this->lidarDectectionDistance, 0.0, 1.0); strength = static_cast(factor * 0xFFFF); } else { strength = 0; @@ -131,4 +137,6 @@ public: private: SDL_GameController* controller; + + double lidarDectectionDistance = 0; };