Sends broadcast of time messages.
This commit is contained in:
95
src/main.cpp
95
src/main.cpp
@@ -1,31 +1,47 @@
|
||||
#include <Arduino.h>
|
||||
#include <SPI.h>
|
||||
#include <RH_NRF24.h>
|
||||
#include <RHDatagram.h>
|
||||
#ifdef FCRF_RadioHead
|
||||
#include <RH_NRF24.h>
|
||||
#include <RHDatagram.h>
|
||||
#endif
|
||||
#ifdef FCRF_RF24
|
||||
#include <RF24.h>
|
||||
#endif
|
||||
#include "config.h"
|
||||
#include "clockMsg.h"
|
||||
#include "master.h"
|
||||
#include "client.h"
|
||||
|
||||
#if WITH_DISPLAY
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
|
||||
#define OLED_RESET /*4*/
|
||||
Adafruit_SSD1306 display(OLED_RESET);
|
||||
#define OLED_RESET /*4*/
|
||||
Adafruit_SSD1306 display(OLED_RESET);
|
||||
#endif
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_NRF24 nrf24(PIN_NRF24_CSN, PIN_NRF24_CE);
|
||||
#ifdef FCRF_RadioHead
|
||||
// Singleton instance of the radio driver
|
||||
RH_NRF24 nrf24(PIN_NRF24_CSN, PIN_NRF24_CE);
|
||||
// Address RH_BROADCAST_ADDRESS can be used for broadcasts as destination
|
||||
RHDatagram Datagram(nrf24, THIS_ADRESS);
|
||||
#endif
|
||||
|
||||
// Address RH_BROADCAST_ADDRESS can be used for broadcasts as destination
|
||||
RHDatagram Datagram(nrf24, THIS_ADRESS);
|
||||
#ifdef FCRF_RF24
|
||||
RF24 radio(PIN_NRF24_CE, PIN_NRF24_CSN);
|
||||
// const uint64_t pipes[2] = { 0xABCDABCD71LL, 0x544d52687CLL };
|
||||
const byte *addresses[] = {"1Mstr","2Mstr"};
|
||||
byte data[32];
|
||||
unsigned long sendFailedCounter=0, rxTimer; //Counter and timer for keeping track transfer info
|
||||
unsigned long receivedCounter=0;
|
||||
unsigned long startTime, stopTime, pauseTime;
|
||||
#endif
|
||||
|
||||
int masterConfigPin = PIN_MASTER_CLIENT_SELECT;
|
||||
static boolean isMaster = true;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.begin(115200);
|
||||
while (!Serial)
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
|
||||
@@ -42,8 +58,33 @@ void setup() {
|
||||
Serial.println("In Client-Mode");
|
||||
}
|
||||
|
||||
#ifdef FCRF_RadioHead
|
||||
if (!Datagram.init())
|
||||
Serial.println("Init datagram with nrf24 failed");
|
||||
#endif
|
||||
|
||||
#ifdef FCRF_RF24
|
||||
radio.begin();
|
||||
if (radio.isChipConnected()) { Serial.println("*** RF chip found"); }
|
||||
else { Serial.println("*** ERROR: RF chip not found!"); }
|
||||
radio.setChannel(1);
|
||||
radio.setPALevel(RF24_PA_MAX);
|
||||
radio.setDataRate(RF24_2MBPS);
|
||||
radio.setAutoAck(0);
|
||||
//radio.setRetries(2,15); // Optionally, increase the delay between retries & # of retries
|
||||
radio.setCRCLength(RF24_CRC_8);
|
||||
radio.openWritingPipe(addresses[0]);
|
||||
radio.openReadingPipe(1,addresses[1]);
|
||||
radio.startListening();
|
||||
radio.printDetails();
|
||||
// @TODO: real random seed!
|
||||
randomSeed(analogRead(0));
|
||||
//randomSeed(22);
|
||||
radio.powerUp();
|
||||
Serial.print("*** RF payload size="); Serial.print(radio.getPayloadSize()); Serial.println(" bytes");
|
||||
if (radio.testCarrier() || radio.testRPD()) { Serial.println("*** Carrier/RPD seen on radio"); }
|
||||
if (radio.failureDetected) { Serial.println("*** Radio error detected!"); }
|
||||
#endif
|
||||
|
||||
#if WITH_DISPLAY
|
||||
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
|
||||
@@ -69,13 +110,27 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (isMaster) {
|
||||
masterLoop(Datagram);
|
||||
} else {
|
||||
#if WITH_DISPLAY
|
||||
clientLoop(Datagram, display);
|
||||
#else
|
||||
clientLoop(Datagram);
|
||||
#endif
|
||||
}
|
||||
#ifdef FCRF_RadioHead
|
||||
if (isMaster) {
|
||||
masterLoop(Datagram);
|
||||
} else {
|
||||
#if WITH_DISPLAY
|
||||
clientLoop(Datagram, display);
|
||||
#else
|
||||
clientLoop(Datagram);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef FCRF_RF24
|
||||
if (isMaster) {
|
||||
masterLoop(radio);
|
||||
} else {
|
||||
#if WITH_DISPLAY
|
||||
clientLoop(radio, display);
|
||||
#else
|
||||
clientLoop(radio);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user