OpenRetroPad/src/gamepad/Radio-Gamepad/RadioGamepad.h

42 lines
819 B
C
Raw Normal View History

2020-12-04 20:34:40 -05:00
#ifndef RADIO_GAMEPAD_H
#define RADIO_GAMEPAD_H
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define GAMEPAD_REPORT_ARRAY_ADD 1
#ifndef GAMEPAD_CLASS
#define GAMEPAD_CLASS RadioGamepad
#endif
2020-12-04 20:34:40 -05:00
#include "../common.h"
2020-12-29 10:58:38 -05:00
#include "../../pins.h"
RF24 radio(OR_PIN_7, OR_PIN_8); // CE, CSN
2020-12-04 20:34:40 -05:00
const byte address[13] = "OpenRetroPad";
class RadioGamepad : public AbstractGamepad {
public:
RadioGamepad() : AbstractGamepad() {
}
virtual void begin(void) {
2020-12-04 20:34:40 -05:00
Serial.println("RadioGamepad.begin");
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
virtual void sendHidReport(const uint8_t cIdx, const void* d, int len) {
2020-12-04 20:34:40 -05:00
Serial.println("RadioGamepad.sync");
gamepadReport[15] = cIdx;
radio.write(d, 16);
2020-12-04 20:34:40 -05:00
}
};
#endif // RADIO_GAMEPAD_H