Files
hexapod-robot/2026-current/robot/Comms.cpp
T

28 lines
697 B
C++
Raw Normal View History

#include "Comms.h"
#include "Config.h"
#include <RF24.h>
#include <SPI.h>
static RF24 radio(RADIO_CE_PIN, RADIO_CSN_PIN);
bool Comms::begin() {
radio_present_ = radio.begin();
if (radio_present_) {
radio.openReadingPipe(1, RADIO_ADDRESS);
radio.setPALevel(RF24_PA_LOW);
radio.setDataRate(RF24_250KBPS);
radio.setChannel(96); // pick one clear of your local Wi-Fi
radio.startListening();
}
return radio_present_;
}
void Comms::update() {
if (radio_present_) {
while (radio.available()) {
radio.read(&packet_, sizeof(packet_));
last_rx_ms_ = millis();
}
}
link_ok_ = (millis() - last_rx_ms_) < (uint32_t)(LINK_TIMEOUT_SEC * 1000);
}