Skip to content

Commit

Permalink
reformat RFM transmission
Browse files Browse the repository at this point in the history
  • Loading branch information
cameron-goddard committed Jan 21, 2024
1 parent 8ee2718 commit 1f19e89
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
31 changes: 12 additions & 19 deletions src/rfm/rfm.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "rfm.hpp"

volatile bool transmitted = false;
volatile bool awaiting = true;

void RFM::set_flag() {
transmitted = true;
awaiting = true;
}

bool RFM::begin() {
Expand All @@ -21,41 +21,34 @@ bool RFM::begin() {
state = radio.begin();
if (state != RADIOLIB_ERR_NONE) {
#ifdef VERBOSE
printf("RFM: Init failed, code %d\n", state);
printf("RFM Error: Init failed, code %d\n", state);
#endif
return false;
}

radio.setPacketSentAction(set_flag);

state = radio.startTransmit("first");
return true;
}

bool RFM::transmit() {
if (transmitted) {
transmitted = false;
if (awaiting) {
awaiting = false;

if (state == RADIOLIB_ERR_NONE) {
#ifdef VERBOSE
printf("RFM: Transmit success\n");
#endif
} else {
printf("RFM: Transmit failed, code %d\n", state);
#ifdef VERBOSE
printf("RFM Error: Transmit failed, code %d\n", state);
return false;
}
#endif
radio.finishTransmit();

state = radio.startTransmit("test");
return true;
}
return true;
//state = radio.transmit("test");

// if (state == RADIOLIB_ERR_NONE) {
// #ifdef VERBOSE
// printf("RFM: Transmit success\n");
// #endif
// return true;
// }
// #ifdef VERBOSE
// printf("RFM: Transmit failed, code %d\n", state);
// #endif
return false;
}
10 changes: 8 additions & 2 deletions src/rfm/rfm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ struct RFM {
*/
bool transmit();

/**
* Callback function for when a transmission is finished.
*/
static void set_flag();

int state = RADIOLIB_ERR_NONE;

/**
* A RadioLib hardware abstraction layer.
*/
Expand All @@ -34,6 +35,11 @@ struct RFM {
* A RadioLib radio object representation.
*/
SX1276 radio = new Module(hal, RFM_CS, RFM_DIO0, RADIOLIB_NC, RFM_DIO1);

/**
* Radio return state.
*/
int state = RADIOLIB_ERR_NONE;
};

#endif // RFM_HPP_

0 comments on commit 1f19e89

Please sign in to comment.