switch from rf24 to espnow
This commit is contained in:
@@ -11,34 +11,8 @@
|
||||
|
||||
#include "controlPad.h"
|
||||
|
||||
ControlPad::ControlPad(SPIClass *spiPort, uint8_t cePin, uint8_t csnPin) {
|
||||
this->radio = new RF24(cePin, csnPin);
|
||||
ControlPad::ControlPad() {
|
||||
|
||||
std::cout << "ControlPad::ControlPad: sizeof ControlPadInput in byte: " << sizeof(ControlPadInput) << std::endl;
|
||||
|
||||
|
||||
if (!this->radio->begin(spiPort)) {
|
||||
std::cout << "ControlPad::ControlPad: Error radio->begin!" << std::endl;
|
||||
while(true);
|
||||
}
|
||||
|
||||
// this->radio->setAddressWidth(5);
|
||||
// this->radio->setChannel(7);
|
||||
// this->radio->setDataRate(RF24_1MBPS);
|
||||
// this->radio->setAutoAck(true);
|
||||
// this->radio->enableDynamicPayloads();
|
||||
// this->radio->enableAckPayload();
|
||||
// this->radio->setCRCLength(RF24_CRC_16);
|
||||
|
||||
this->radio->setPALevel(RF24_PA_LOW);
|
||||
|
||||
// this->radio->openWritingPipe(this->address[1]);
|
||||
this->radio->openReadingPipe(0, this->address[0]);
|
||||
|
||||
this->radio->startListening();
|
||||
|
||||
// this->radio->printPrettyDetails();
|
||||
this->radio->printPrettyDetails();
|
||||
}
|
||||
|
||||
bool ControlPad::loop() {
|
||||
@@ -78,6 +52,16 @@ bool ControlPad::loop() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void ControlPad::insertData(const uint8_t *data) {
|
||||
uint8_t lastCount = this->controlInput.counter + 1;
|
||||
memcpy(&(this->controlInput), data, sizeof(this->controlInput));
|
||||
if (lastCount != this->controlInput.counter)
|
||||
std::cout << "ControlPad::insertData counter wrong value" << std::endl;
|
||||
|
||||
this->lastMessageReceive = millis();
|
||||
std::cout << "data: " << (int) this->controlInput.counter << std::endl;
|
||||
}
|
||||
|
||||
const ControlPadInput * ControlPad::getControlPadDataPtr(uint16_t maxElapsedTime) const {
|
||||
if (maxElapsedTime && millis() - this->lastMessageReceive > maxElapsedTime)
|
||||
return nullptr;
|
||||
@@ -85,10 +69,5 @@ const ControlPadInput * ControlPad::getControlPadDataPtr(uint16_t maxElapsedTime
|
||||
}
|
||||
|
||||
void ControlPad::receiveData() {
|
||||
this->radio->startListening();
|
||||
if (this->radio->available()) {
|
||||
ControlPadInput lastInput = this->controlInput;
|
||||
this->radio->read(&this->controlInput, sizeof(ControlPadInput));
|
||||
std::cout << "Data RF24: " << this->controlInput.counter << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,19 +12,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <menuControl.h>
|
||||
#include <nRF24L01.h>
|
||||
#include <RF24.h>
|
||||
#include <SPI.h>
|
||||
// #include <printf.h>
|
||||
|
||||
#include "controlPadInput.h"
|
||||
|
||||
class ControlPad {
|
||||
public:
|
||||
ControlPad(SPIClass *spiPort, uint8_t cePin, uint8_t csnPin);
|
||||
ControlPad();
|
||||
|
||||
bool loop();
|
||||
|
||||
void insertData(const uint8_t *data);
|
||||
|
||||
void setMenuControl(MenuControl* menuControl) { this->menuControl = menuControl; }
|
||||
|
||||
const ControlPadInput * getControlPadDataPtr(uint16_t maxElapsedTime = 0) const;
|
||||
@@ -33,7 +31,6 @@ class ControlPad {
|
||||
|
||||
private:
|
||||
MenuControl* menuControl = nullptr;
|
||||
RF24* radio;
|
||||
ControlPadInput controlInput;
|
||||
|
||||
void receiveData();
|
||||
|
||||
Reference in New Issue
Block a user