#pragma once // #include #include class Controller { public: class Digital { public: Digital( std::function isPressedEvalFunc, std::function onPressedFunc = []() {}, std::function onReleasedFunc = []() {}) : m_isPressedEvalFunc(isPressedEvalFunc) { } bool isPressed() { bool isPressed = m_isPressedEvalFunc(); m_wasChangedThisUpdate = m_pressedLastUpdate != m_pressed; m_pressed = isPressed; return m_pressed; } bool wasPressedThisUpdate() const { return m_wasChangedThisUpdate && m_pressed; } private: std::function m_isPressedEvalFunc; bool m_pressed = false; bool m_pressedLastUpdate = false; bool m_wasChangedThisUpdate = false; }; struct Output { // Analog float leftJoystickX = {}; float leftJoystickY = {}; float rightJoystickX = {}; float rightJoystickY = {}; float l2 = {}; float r2 = {}; // Digital bool triangle = {}; // Interpreted float throttle = {}; float steering = {}; }; Controller() = delete; Controller(const char* macAddress); // Controller(std::string macAddress); void setup(); void setup(const char* mac); Output loop(); private: // std::string m_macAddress; const char* m_macAddress; Digital m_triangle; };