35 int8_t PS4Parser::getButtonIndexPS4(
ButtonEnum b) {
57 const int8_t index = getButtonIndexPS4(b);
if (index < 0)
return 0;
65 const int8_t index = getButtonIndexPS4(b);
if (index < 0)
return 0;
67 bool click = buttonClickState.
val & mask;
68 buttonClickState.
val &= ~mask;
73 const int8_t index = getButtonIndexPS4(b);
if (index < 0)
return 0;
89 for (uint8_t i = 0; i < len; i++) {
90 D_PrintHex<uint8_t > (buf[i], 0x80);
96 memcpy(&ps4Data, buf + 1, min((uint8_t)(len - 1),
MFK_CASTUINT8T sizeof(ps4Data)));
97 else if (buf[0] == 0x11) {
100 Notify(
PSTR(
"\r\nReport is too short: "), 0x80);
101 D_PrintHex<uint8_t > (len, 0x80);
105 memcpy(&ps4Data, buf + 3, min((uint8_t)(len - 3),
MFK_CASTUINT8T sizeof(ps4Data)));
107 #ifdef DEBUG_USB_HOST
108 Notify(
PSTR(
"\r\nUnknown report id: "), 0x80);
109 D_PrintHex<uint8_t > (buf[0], 0x80);
114 if (ps4Data.
btn.
val != oldButtonState.
val) {
115 buttonClickState.
val = ps4Data.
btn.
val & ~oldButtonState.
val;
122 if (checkDpad(
RIGHT))
123 newDpad |= 1 <<
RIGHT;
125 newDpad |= 1 <<
DOWN;
127 newDpad |= 1 <<
LEFT;
128 if (newDpad != oldDpad) {
129 buttonClickState.
dpad = newDpad & ~oldDpad;
141 for (i = 0; i <
sizeof(ps4Data.
hatValue); i++)
144 oldButtonState.
val = 0;
145 for (i = 0; i <
sizeof(ps4Data.
trigger); i++)
147 for (i = 0; i <
sizeof(ps4Data.
xy)/
sizeof(ps4Data.
xy[0]); i++) {
148 for (uint8_t j = 0; j <
sizeof(ps4Data.
xy[0].
finger)/
sizeof(ps4Data.
xy[0].
finger[0]); j++)
154 buttonClickState.
dpad = 0;
158 ps4Output.
r = ps4Output.
g = ps4Output.
b = 0;
const uint8_t PS4_BUTTONS[]
void Parse(uint8_t len, uint8_t *buf)
uint8_t getAnalogButton(ButtonEnum b)
virtual void sendOutputReport(PS4Output *output)=0
bool getButtonClick(ButtonEnum b)
uint8_t getAnalogHat(AnalogHatEnum a)
bool getButtonPress(ButtonEnum b)
constexpr int8_t ButtonIndex(ButtonEnum key)
struct touchpadXY::@28 finger[2]
#define pgm_read_byte(addr)