72 lines
1.5 KiB
C++
72 lines
1.5 KiB
C++
#pragma once
|
|
|
|
// #include <string>
|
|
#include <functional>
|
|
|
|
class Controller
|
|
{
|
|
public:
|
|
class Digital
|
|
{
|
|
public:
|
|
Digital(
|
|
std::function<bool()> isPressedEvalFunc,
|
|
std::function<void()> onPressedFunc = []() {},
|
|
std::function<void()> 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<bool()> 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;
|
|
}; |