Updated to follow new header define scheme.

This commit is contained in:
jakeg00dwin 2024-09-26 17:10:41 -07:00
parent 5634999429
commit b49645e82c
1 changed files with 15 additions and 12 deletions

View File

@ -20,7 +20,7 @@ Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST); // Initialize d
CRGB leds[NUM_LEDS]; // Array to hold LED colors CRGB leds[NUM_LEDS]; // Array to hold LED colors
SoftwareSerial gpsSerial(GPS_RX_PIN, GPS_TX_PIN); // Software serial for GPS SoftwareSerial gpsSerial(GPS_RX_PIN, GPS_TX_PIN); // Software serial for GPS
TinyGPSPlus gps; // TinyGPS++ object to process GPS data TinyGPSPlus gps; // TinyGPS++ object to process GPS data
RH_RF95 rf95(RFM95_CS, RMF95_INT); // Radio instance. RH_RF95 rf95(RFM9X_CS, RMF9X_INT); // Radio instance.
typedef struct Msg{ typedef struct Msg{
@ -39,36 +39,36 @@ NodeId node = {
id = 0; id = 0;
name = "name"; name = "name";
}; };
uint8_t reciver_buffer[RF95_BUF_SZ]; uint8_t reciver_buffer[RF9X_BUF_SZ];
void Radio_setup(void) { void Radio_setup(void) {
pinMode(RFM95_RST, OUTPUT); pinMode(RFM9X_RST, OUTPUT);
digitalWrite(RFM95_RST, HIGH); digitalWrite(RFM9X_RST, HIGH);
while(!rf95.init()){} while(!rf95.init()){}
Serial.println("radio: Initialized"); Serial.println("radio: Initialized");
if(rf95.setFrequency(RF95_FREQ)) { if(rf95.setFrequency(RF9X_FREQ)) {
Serial.println("radio: Error could not set frequency"); Serial.println("radio: Error could not set frequency");
while(true){} //Loop forever while(true){} //Loop forever
} }
Serial.print("radio: Frequency = "); Serial.print("radio: Frequency = ");
Serial.println(RF95_FREQ); Serial.println(RF9X_FREQ);
rf95.setTxPower(RF95_MIN_DB, false); rf95.setTxPower(RF9X_MIN_DB, false);
} }
void Radio_reset(void) { void Radio_reset(void) {
digitalWrite(RFM95_RST, LOW); digitalWrite(RFM9X_RST, LOW);
delay(10); delay(10);
digitalWrite(RFM95_RST, HIGH); digitalWrite(RFM9X_RST, HIGH);
delay(10); delay(10);
} }
int Radio_SendData() { int Radio_SendData() {
int8_t tx_power = RF95_MIN_DB; int8_t tx_power = RF9X_MIN_DB;
uint8_t received_id = 0; uint8_t received_id = 0;
//Set the radio output to lowest power. //Set the radio output to lowest power.
@ -78,21 +78,24 @@ int Radio_SendData() {
rf95.setModeTx(); rf95.setModeTx();
//Try transmitting data //Try transmitting data
Serial.println("Radio: Sending data...");
rf95.send(node.id, 1); rf95.send(node.id, 1);
rf95.waitPacketSent(); rf95.waitPacketSent();
//Wait for ACK or Radio Msg. (Timeout Should be included). //Wait for ACK or Radio Msg. (Timeout Should be included).
//On timeout increase the transmit power and re-attempt. //On timeout increase the transmit power and re-attempt.
if(!rf95.waitAvailbleTimeout(RF95_TIMEOUT)) { if(!rf95.waitAvailbleTimeout(RF9X_TIMEOUT)) {
if(rf95.recv(reciver_buffer, RF95_BUF_SZ)) { if(rf95.recv(reciver_buffer, RF9X_BUF_SZ)) {
} }
else { else {
//Failed to receive the message. //Failed to receive the message.
Serial.println("Radio: Error failed to receive msg.");
} }
} }
else { else {
//No reply of any kind. //No reply of any kind.
Serial.println("Radio: Error no reply.");
} }
//Set the radio mode to idle. //Set the radio mode to idle.