init
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
// RadioController.cpp
|
||||
#include "RadioController.h"
|
||||
|
||||
void RadioController::setup(int cepin, int cspin) {
|
||||
radio = RF24(cepin, cspin);
|
||||
|
||||
if (!radio.begin()) {
|
||||
Serial.println("Error initializing radio");
|
||||
} else {
|
||||
Serial.println("Succesfully initializing radio");
|
||||
radio.openWritingPipe(writePipe);
|
||||
radio.openReadingPipe(1, readPipe);
|
||||
radio.setPALevel(RF24_PA_MAX);
|
||||
radio.disableDynamicPayloads();
|
||||
radio.setAutoAck(false);
|
||||
radio.setRetries(5, 15);
|
||||
}
|
||||
}
|
||||
|
||||
void RadioController::send(String msg) {
|
||||
radio.stopListening();
|
||||
const char *text = msg.c_str();
|
||||
bool transmissionSuccess = radio.write(text, strlen(text));
|
||||
|
||||
if (transmissionSuccess) {
|
||||
// Serial.println("Transmission successful");
|
||||
} else {
|
||||
Serial.println("Transmission failed");
|
||||
}
|
||||
}
|
||||
|
||||
String RadioController::receive() {
|
||||
radio.startListening();
|
||||
String msg = "";
|
||||
|
||||
if (radio.available()) {
|
||||
char text[32] = "";
|
||||
radio.read(&text, sizeof(text));
|
||||
msg = String(text);
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
Reference in New Issue
Block a user