Files
SNES-Gamepad/include/gamepad.h
T
2023-12-10 17:47:41 +01:00

42 lines
891 B
C++

#pragma once
#include <Arduino.h>
#define NUM_KEYS 12
class Gamepad{
public:
enum Button {
B = 0x1,
Y = 0x2,
Select = 0x4,
Start = 0x8,
Up = 0x10,
Down = 0x20,
Left = 0x40,
Right = 0x80,
A = 0x100,
X = 0x200,
LeftShoulder = 0x400,
RightShoulder = 0x800
};
Gamepad(uint8_t latch, uint8_t clock, uint8_t data);
bool isPressed(Button button);
bool isPressedLast(Button button) const;
uint16_t getState();
uint16_t getLastState() const { return this->lastState; }
static bool isPressed(uint16_t input, Button button);
private:
uint16_t readCon();
uint16_t lastState = 0;
uint8_t latch;
uint8_t clock;
uint8_t data;
};