Initial ability to send a packet from RFPowerView
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
RFPowerView::RFPowerView(uint8_t cePin, uint8_t csPin, uint8_t irqPin, uint16_t rfID) :
|
||||
radio(cePin, csPin),
|
||||
packetReceiver(&radio),
|
||||
bufferFiller(0x00, 0x00, 0x05),
|
||||
irqPin(irqPin),
|
||||
rfID{static_cast<uint8_t>(rfID & 0xFF), static_cast<uint8_t>(rfID >> 8)},
|
||||
packetCallback(nullptr) {}
|
||||
@@ -16,6 +17,18 @@ bool RFPowerView::begin() {
|
||||
packetReceiver.setBufferCallback([this](const uint8_t* buffer) { this->processBuffer(buffer); });
|
||||
packetReceiver.setInvalidBufferCallback([this](const uint8_t* buffer) { this->processInvalidBuffer(buffer); });
|
||||
|
||||
pinMode(irqPin, INPUT);
|
||||
|
||||
attachInterrupt(digitalPinToInterrupt(irqPin), std::bind(&RFPowerView::interruptHandler, this), FALLING);
|
||||
|
||||
radio.setChannel(DEFAULT_RF_CHANNEL);
|
||||
radio.setDataRate(DEFAULT_RF_DATARATE);
|
||||
radio.setAutoAck(false);
|
||||
radio.disableCRC();
|
||||
radio.setRetries(0, 0);
|
||||
radio.setPayloadSize(32);
|
||||
radio.setAddressWidth(2);
|
||||
|
||||
startListening();
|
||||
|
||||
return true;
|
||||
@@ -26,25 +39,22 @@ void RFPowerView::loop() {
|
||||
}
|
||||
|
||||
void RFPowerView::startListening() {
|
||||
radio.setChannel(DEFAULT_RF_CHANNEL);
|
||||
radio.setDataRate(DEFAULT_RF_DATARATE);
|
||||
radio.setAutoAck(false);
|
||||
radio.disableCRC();
|
||||
radio.setPayloadSize(32);
|
||||
|
||||
// TODO: Verify that putting this in begin() instead of startListening() works
|
||||
pinMode(irqPin, INPUT);
|
||||
|
||||
radio.setAddressWidth(2);
|
||||
radio.openReadingPipe(0, rfID);
|
||||
|
||||
radio.startListening();
|
||||
Serial.println("Listening");
|
||||
// TODO: Verify that putting this in being() instead of startListening() works
|
||||
attachInterrupt(digitalPinToInterrupt(irqPin), std::bind(&RFPowerView::interruptHandler, this), FALLING);
|
||||
|
||||
interrupts();
|
||||
}
|
||||
|
||||
void RFPowerView::startTransmitting() {
|
||||
radio.stopListening();
|
||||
|
||||
radio.setPALevel(RF24_PA_HIGH, true);
|
||||
|
||||
radio.openWritingPipe(rfID);
|
||||
radio.powerUp();
|
||||
}
|
||||
|
||||
void RFPowerView::interruptHandler() {
|
||||
packetReceiver.read();
|
||||
}
|
||||
@@ -65,4 +75,23 @@ void RFPowerView::processInvalidBuffer(const uint8_t *buffer) {
|
||||
|
||||
void RFPowerView::setPacketCallback(std::function<void(const Packet*)> callback) {
|
||||
packetCallback = callback;
|
||||
}
|
||||
|
||||
void RFPowerView::sendPacket(const Packet* packet) {
|
||||
if (bufferFiller.fill(sendBuffer, packet)) {
|
||||
startTransmitting();
|
||||
|
||||
uint8_t bytecount = sendBuffer[1] + 4;
|
||||
for (int j = 1; j < 5; j++) {
|
||||
radio.openWritingPipe(rfID);
|
||||
for (int i = 1; i < 200; i++) {
|
||||
radio.writeFast(sendBuffer, bytecount);
|
||||
}
|
||||
delay(100);
|
||||
radio.flush_tx();
|
||||
radio.txStandBy();
|
||||
}
|
||||
|
||||
startListening();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user