RF69
This commit is contained in:
@@ -12,6 +12,9 @@
|
||||
|
||||
// Choose radio type by enabling one of the following
|
||||
#define MYSENSORS_RF_NRF24
|
||||
#define MYSENSORS_RF_RF69
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -20,6 +23,11 @@
|
||||
typedef class MyDriverNRF24 MyDriverClass;
|
||||
#endif
|
||||
|
||||
#ifdef MYSENSORS_RF_RF69
|
||||
#include "MyDriverRF69.h"
|
||||
typedef class MyDriverRF69 MyDriverClass;
|
||||
#endif
|
||||
|
||||
/***
|
||||
* Enable/Disable debug logging
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
#include "MyDriver.h"
|
||||
#include "MyDriverRF69.h"
|
||||
|
||||
MyDriverRF69::MyDriverRF69() : MyDriver() {
|
||||
driver = new RH_RF69(RF69_CS_PIN, RF69_INTERRUPT_PIN);
|
||||
}
|
||||
|
||||
void MyDriverRF69::init() {
|
||||
// Start up the radio library
|
||||
manager = new RHReliableDatagram(*driver, _address);
|
||||
driver->setFrequency(RF69_FREQUENCY);
|
||||
driver->setTxPower(RF69_TRANSMIT_POWER)
|
||||
|
||||
}
|
||||
|
||||
void MyDriverRF69::setAddress(uint8_t address) {
|
||||
_address = address;
|
||||
manager->setThisAddress(_address);
|
||||
}
|
||||
|
||||
uint8_t MyDriverRF69::getAddress() {
|
||||
return _address;
|
||||
}
|
||||
|
||||
bool MyDriverRF69::send(uint8_t to, const void* data, uint8_t len) {
|
||||
// Make sure radio has powered up
|
||||
uint8_t status = manager->sendtoWait((uint8_t *) data, len, to);
|
||||
if(status==RH_ROUTER_ERROR_NONE) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool MyDriverRF69::available(uint8_t *to) {
|
||||
return manager->available();
|
||||
}
|
||||
|
||||
uint8_t MyDriverRF69::receive(void* data) {
|
||||
uint8_t len = 256;
|
||||
uint8_t from;
|
||||
manager->recvfromAck((uint8_t *) data, &len, &from);
|
||||
}
|
||||
|
||||
void MyDriverRF69::powerDown() {
|
||||
driver->sleep();
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef MyCommDriver_h
|
||||
#define MyCommDriver_h
|
||||
|
||||
#include "MyConfig.h"
|
||||
#include "MyDriver.h"
|
||||
#include <stdint.h>
|
||||
#include <RH_RF69.h>
|
||||
#include <RHReliableDatagram.h>
|
||||
|
||||
#define RF69_FREQUENCY 868;
|
||||
#define RF69_TRANSMIT_POWER 14;
|
||||
#define RF69_MODEM_CONFIG RH_RF69::GFSK_Rb250Fd250;
|
||||
#define RF69_INTERRUPT_PIN 2;
|
||||
#define RF69_CS_PIN 10;
|
||||
|
||||
class MyDriverRF69 : public MyDriver
|
||||
{
|
||||
public:
|
||||
MyDriverRF69();
|
||||
void init();
|
||||
void setAddress(uint8_t address);
|
||||
uint8_t getAddress();
|
||||
bool send(uint8_t to, const void* data, uint8_t len);
|
||||
bool available(uint8_t *to);
|
||||
uint8_t receive(void* data);
|
||||
void powerDown();
|
||||
private:
|
||||
RH_RF69 *driver = NULL;
|
||||
RHReliableDatagram *manager = NULL;
|
||||
uint8_t _address;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user