Skip to content

Commit 26138b7

Browse files
committed
RF69
1 parent 3d2d7db commit 26138b7

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

libraries/MySensors/MyConfig.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
// Choose radio type by enabling one of the following
1414
#define MYSENSORS_RF_NRF24
15+
#define MYSENSORS_RF_RF69
16+
17+
1518

1619

1720

@@ -20,6 +23,11 @@
2023
typedef class MyDriverNRF24 MyDriverClass;
2124
#endif
2225

26+
#ifdef MYSENSORS_RF_RF69
27+
#include "MyDriverRF69.h"
28+
typedef class MyDriverRF69 MyDriverClass;
29+
#endif
30+
2331
/***
2432
* Enable/Disable debug logging
2533
*/

libraries/MySensors/MyDriverRF69.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include "MyDriver.h"
2+
#include "MyDriverRF69.h"
3+
4+
MyDriverRF69::MyDriverRF69() : MyDriver() {
5+
driver = new RH_RF69(RF69_CS_PIN, RF69_INTERRUPT_PIN);
6+
}
7+
8+
void MyDriverRF69::init() {
9+
// Start up the radio library
10+
manager = new RHReliableDatagram(*driver, _address);
11+
driver->setFrequency(RF69_FREQUENCY);
12+
driver->setTxPower(RF69_TRANSMIT_POWER)
13+
14+
}
15+
16+
void MyDriverRF69::setAddress(uint8_t address) {
17+
_address = address;
18+
manager->setThisAddress(_address);
19+
}
20+
21+
uint8_t MyDriverRF69::getAddress() {
22+
return _address;
23+
}
24+
25+
bool MyDriverRF69::send(uint8_t to, const void* data, uint8_t len) {
26+
// Make sure radio has powered up
27+
uint8_t status = manager->sendtoWait((uint8_t *) data, len, to);
28+
if(status==RH_ROUTER_ERROR_NONE) {
29+
return true;
30+
} else {
31+
return false;
32+
}
33+
}
34+
35+
bool MyDriverRF69::available(uint8_t *to) {
36+
return manager->available();
37+
}
38+
39+
uint8_t MyDriverRF69::receive(void* data) {
40+
uint8_t len = 256;
41+
uint8_t from;
42+
manager->recvfromAck((uint8_t *) data, &len, &from);
43+
}
44+
45+
void MyDriverRF69::powerDown() {
46+
driver->sleep();
47+
}

libraries/MySensors/MyDriverRF69.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef MyCommDriver_h
2+
#define MyCommDriver_h
3+
4+
#include "MyConfig.h"
5+
#include "MyDriver.h"
6+
#include <stdint.h>
7+
#include <RH_RF69.h>
8+
#include <RHReliableDatagram.h>
9+
10+
#define RF69_FREQUENCY 868;
11+
#define RF69_TRANSMIT_POWER 14;
12+
#define RF69_MODEM_CONFIG RH_RF69::GFSK_Rb250Fd250;
13+
#define RF69_INTERRUPT_PIN 2;
14+
#define RF69_CS_PIN 10;
15+
16+
class MyDriverRF69 : public MyDriver
17+
{
18+
public:
19+
MyDriverRF69();
20+
void init();
21+
void setAddress(uint8_t address);
22+
uint8_t getAddress();
23+
bool send(uint8_t to, const void* data, uint8_t len);
24+
bool available(uint8_t *to);
25+
uint8_t receive(void* data);
26+
void powerDown();
27+
private:
28+
RH_RF69 *driver = NULL;
29+
RHReliableDatagram *manager = NULL;
30+
uint8_t _address;
31+
};
32+
33+
#endif

0 commit comments

Comments
 (0)