Skip to content

Commit

Permalink
Complete RadioStream initialization in begin func
Browse files Browse the repository at this point in the history
  • Loading branch information
alexozer committed Feb 15, 2017
1 parent 4e22374 commit 49bc54a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
20 changes: 12 additions & 8 deletions radio/radio_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
#include <string.h>
#include "radio_stream.h"

RadioStream::RadioStream(
uint8_t csPin, uint8_t irqPin, int irqn, uint8_t rstPin,
int freq, int nodeId, int receiverId, int networkId, int power, bool haveRFM69HCW):
m_radio{csPin, irqPin, irqn, rstPin},
m_receiverId{receiverId},
RadioStream::RadioStream(uint8_t csPin, uint8_t irqPin, bool haveRFM69HCW):
m_radio{csPin, irqPin, haveRFM69HCW, (uint8_t)digitalPinToInterrupt(irqPin)},
m_recvBegin{0},
m_recvEnd{0}
{
m_recvEnd{0},
m_sendEnd{0} {}

void RadioStream::begin(int freq, int nodeId, int receiverId, int networkId, uint8_t rstPin, int power) {
m_receiverId = receiverId;

// Hard reset
pinMode(rstPin, OUTPUT);
digitalWrite(rstPin, HIGH);
Expand All @@ -18,7 +19,6 @@ RadioStream::RadioStream(
delay(100);

m_radio.initialize(freq, nodeId, networkId);
if (haveRFM69HCW) m_radio.setHighPower();
m_radio.setPowerLevel(power);
}

Expand Down Expand Up @@ -80,3 +80,7 @@ void RadioStream::flush() {
m_sendEnd = 0;
m_radio.receiveDone();
}

RFM69& RadioStream::rfm69() {
return m_radio;
}
11 changes: 7 additions & 4 deletions radio/radio_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

class RadioStream : public Stream {
public:
RadioStream(
uint8_t csPin, uint8_t irqPin, int irqn, uint8_t rstPin,
int freq, int nodeId, int receiverId, int networkId, int power, bool haveRFM69HCW);
RadioStream(uint8_t csPin, uint8_t irqPin, bool haveRFM69HCW);

// Arguments not needed to construct RFM69 object passed here
void begin(int freq, int nodeId, int receiverId, int networkId, uint8_t rstPin, int power);

int available() override;
int read() override;
Expand All @@ -17,10 +18,12 @@ class RadioStream : public Stream {
size_t write(const uint8_t* buffer, size_t size) override;
void flush() override;

RFM69& rfm69();

private:
RFM69 m_radio;
int m_receiverId;
uint8_t m_recvBegin, m_recvEnd;
size_t m_recvBegin, m_recvEnd;

uint8_t m_sendBuf[RF69_MAX_DATA_LEN];
size_t m_sendEnd;
Expand Down

0 comments on commit 49bc54a

Please sign in to comment.