PS4 controller with IM315
Diff: IM315PS4.cpp
- Revision:
- 2:83f5186d950c
- Parent:
- 0:9577e971f55b
--- a/IM315PS4.cpp Sat Aug 06 07:24:24 2022 +0000 +++ b/IM315PS4.cpp Wed Oct 12 09:35:15 2022 +0000 @@ -2,6 +2,7 @@ IM315PS4::IM315PS4(PinName TX, PinName RX){ i = 0; + flag = false; len = 17; val = ':'; data = new uint8_t[len]; @@ -16,6 +17,7 @@ IM315PS4::IM315PS4(PinName TX, PinName RX, int baud){ i = 0; + flag = false; len = 17; val = ':'; data = new uint8_t[len]; @@ -45,6 +47,7 @@ } if(i >= len){ if(data[0] == val){ + flag = !flag; DATA[0] = ASCII(data[1], data[2]); DATA[1] = ASCII(data[3], data[4]); DATA[2] = ASCII(data[5], data[6]); @@ -99,6 +102,10 @@ } void IM315PS4::data_print(){_pc -> printf("%2x %2x %2x %2x %2x %2x %2x %2x\n", DATA[0], DATA[1], DATA[2], DATA[3], DATA[4], DATA[5], DATA[6], DATA[7]);} +bool IM315PS4::available(){ + return flag; +} + bool IM315PS4::up(){return DATA[1] & UP ? 1 : 0;} bool IM315PS4::right(){return DATA[1] & RIGHT ? 1 : 0;}