first commit
This commit is contained in:
68
include/drivers/JoystickController.h
Normal file
68
include/drivers/JoystickController.h
Normal file
@@ -0,0 +1,68 @@
|
||||
#ifndef JOYSTICK_H
|
||||
#define JOYSTICK_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
enum JoystickDirection {
|
||||
CENTER,
|
||||
UP,
|
||||
UP_RIGHT,
|
||||
RIGHT,
|
||||
DOWN_RIGHT,
|
||||
DOWN,
|
||||
DOWN_LEFT,
|
||||
LEFT,
|
||||
UP_LEFT
|
||||
};
|
||||
|
||||
class JoystickController {
|
||||
private:
|
||||
uint8_t pinX;
|
||||
uint8_t pinY;
|
||||
uint8_t pinButton;
|
||||
|
||||
int centerX;
|
||||
int centerY;
|
||||
|
||||
int rawX;
|
||||
int rawY;
|
||||
bool buttonState;
|
||||
|
||||
int deadzone;
|
||||
int debounceDelay;
|
||||
unsigned long lastDebounceTime;
|
||||
|
||||
int lastX;
|
||||
int lastY;
|
||||
bool lastButtonState;
|
||||
|
||||
void readRawValues();
|
||||
|
||||
static JoystickController* _instance;
|
||||
|
||||
public:
|
||||
JoystickController(uint8_t xPin, uint8_t yPin, uint8_t buttonPin = 255);
|
||||
~JoystickController();
|
||||
|
||||
void begin();
|
||||
void calibrate();
|
||||
void setDeadzone(int value);
|
||||
void setDebounceDelay(int delayMs);
|
||||
void tick();
|
||||
|
||||
int getRawX();
|
||||
int getRawY();
|
||||
int getX();
|
||||
int getY();
|
||||
int getOffsetX();
|
||||
int getOffsetY();
|
||||
|
||||
bool isPressed();
|
||||
bool isCentered();
|
||||
|
||||
JoystickDirection getDirection();
|
||||
String getDirectionString();
|
||||
int getDistancePercent();
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user