diff --git a/include/gamepad/controller.hpp b/include/gamepad/controller.hpp index e44ae58..86140e9 100644 --- a/include/gamepad/controller.hpp +++ b/include/gamepad/controller.hpp @@ -1,6 +1,7 @@ #pragma once #include "pros/misc.h" +#include #include #include "button.hpp" #include "joystick_modifier.hpp" @@ -78,13 +79,35 @@ class Gamepad { const Button& A() { return m_A; } - float LeftX() { return m_LeftX; } + float LeftX(bool use_curve = true) { + if (use_curve && m_left_transformation) return m_left_transformation->get_value({m_LeftX, m_LeftY}).first; + else return m_LeftX; + } - float LeftY() { return m_LeftY; } + float LeftY(bool use_curve = true) { + if (use_curve && m_left_transformation) return m_left_transformation->get_value({m_LeftX, m_LeftY}).second; + else return m_LeftY; + } - float RightX() { return m_RightX; } + float RightX(bool use_curve = true) { + if (use_curve && m_right_transformation) + return m_right_transformation->get_value({m_RightX, m_RightY}).first; + else return m_RightX; + } - float RightY() { return m_RightY; } + float RightY(bool use_curve = true) { + if (use_curve && m_right_transformation) + return m_right_transformation->get_value({m_RightX, m_RightY}).second; + else return m_RightY; + } + + void set_left_transform(Transformation left_transformation) { + m_left_transformation = std::move(left_transformation); + } + + void set_right_transform(Transformation right_transformation) { + m_right_transformation = std::move(right_transformation); + } /// The master controller, same as @ref gamepad::master static Gamepad master; @@ -98,6 +121,8 @@ class Gamepad { m_A {}; float m_LeftX = 0, m_LeftY = 0, m_RightX = 0, m_RightY = 0; Button Fake {}; + std::optional m_left_transformation {std::nullopt}; + std::optional m_right_transformation {std::nullopt}; /** * @brief Gets a unique name for a listener that will not conflict with user listener names. * diff --git a/include/gamepad/joystick_modifier.hpp b/include/gamepad/joystick_modifier.hpp index 6ccc509..5819917 100644 --- a/include/gamepad/joystick_modifier.hpp +++ b/include/gamepad/joystick_modifier.hpp @@ -64,15 +64,23 @@ class Transformation final { class TransformationBuilder final { public: template T> TransformationBuilder(T first) { - m_transform.m_all_transforms.push_back(std::make_unique(std::move(first))); + m_transform.m_all_transforms.push_back(std::make_unique(std::move(first))); } TransformationBuilder() = delete; template T> TransformationBuilder& and_then(T next) { - m_transform.m_all_transforms.push_back(std::make_unique(std::move(next))); + m_transform.m_all_transforms.push_back(std::make_unique(std::move(next))); return *this; } + + Transformation build() { + return std::move(m_transform); + } + + operator Transformation() { + return std::move(m_transform); + } private: Transformation m_transform {}; }; diff --git a/src/main.cpp b/src/main.cpp index 8d2cc4a..dd04b8d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,7 @@ #include "main.h" #include "gamepad/api.hpp" #include "gamepad/controller.hpp" +#include "gamepad/joystick_modifier.hpp" #include "pros/rtos.hpp" #include #include @@ -52,6 +53,10 @@ void initialize() { gamepad::master.A().onRepeatPress("aRepeatPress", aRepeatPress1); // And we can use lambda's too gamepad::master.X().onShortRelease("xShortRelease1", []() { printf("X Short Release!\n"); }); + + // set up controller curves: + gamepad::master.set_left_transform( + gamepad::TransformationBuilder(gamepad::Deadband(5, 5)).and_then(gamepad::ExpoCurve(2, 2))); } /**