use PS4
Diff: PS4Serial.cpp
- Revision:
- 2:ebf134f6c2ef
- Parent:
- 1:f953b9de204e
- Child:
- 5:3b887515b46e
--- a/PS4Serial.cpp Mon Aug 20 02:11:23 2018 +0000 +++ b/PS4Serial.cpp Wed Aug 29 04:29:25 2018 +0000 @@ -13,6 +13,7 @@ char data = WirelessSerial.getc(); if(data == 0xff) { rp = 0; + for (int i = 0; i < 8; i++) ControllerData_OLD[i] = ControllerData[i]; } else if(rp > 8) { //nothing } else { @@ -32,7 +33,25 @@ return ControllerData[button - 12]; } } +int PS4Serial::getButtonClick( PS4Button button, bool mode ) +{ + //mode:0 -> Rising + //mode:1 -> Falling -bool PS4Serial::connected(){ + if(button <= 13) { + return mode*(ControllerData[button]*!ControllerData_OLD[button]) + + !mode*(!ControllerData[button]*ControllerData_OLD[button]); + + } else if( (19<=button) && (button<=20) ) { + return mode*((ControllerData[button]>127)*!(ControllerData_OLD[button]>127)) + + !mode*(!(ControllerData[button]>127)*(ControllerData_OLD[button]>127)); + + } else { + return 0; + } +} + +bool PS4Serial::connected() +{ return t.read_ms() < 500; } \ No newline at end of file