From 8509821d2a04b5edccaaaab7a6ef3260aa7b2cba Mon Sep 17 00:00:00 2001
From: paidforby <ggallo102@gmail.com>
Date: Mon, 20 Jan 2020 10:01:34 -0500
Subject: [PATCH] expose LoRaFrequency and spreadingFactor in public functions,
 related to https://github.com/sudomesh/disaster-radio/issues/43

---
 README.md           | 24 +++++++++++++++++++++++-
 src/Layer1.h        |  4 ++++
 src/Layer1_LoRa.cpp | 16 +++++++++++++---
 3 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md
index dd5f460..0e8e48a 100644
--- a/README.md
+++ b/README.md
@@ -26,7 +26,29 @@ This library consists of two closely related classes. The Layer1 class and the L
 
 ### Layer1
 
-Initialize your Layer 1 interface,
+Prior to initializing your Layer1 interface, you can choose to set the following values,  
+```
+Layer1.setPins(int cs, int reset, int dio);
+```
+Corresponds to the GPIO pins of your ESP32 board that are conencted to chip select, reset and DIO0 pins of the LoRa transceiver. Defaults to cs = 18, reset = 23, dio = 26.  
+
+```
+Layer1.setSPIFrequency(uint32_t frequency);
+```
+Sets the frequency of the SPI bus connected to the LoRa transceiver. Defaults to 100E3.  
+
+```
+Layer1.setLoRaFrequency(uint32_t frequency);
+```
+Sets the frequency at which the LoRa transceiver transmits. Typically 915E6 for NA/SA/AU/NZ or 866E6 for EU, 433E6 is also an option. Defaults to 915E6.   
+
+```
+Layer1.setSpreadingFactor(uint8_t spreadingFactor);
+```
+Sets the spreading factor for the LoRa transceiver. Defaults to 9.  
+
+
+To initialize your Layer 1 interface,  
 ```
 Layer1.init();
 ```
diff --git a/src/Layer1.h b/src/Layer1.h
index 528f2bf..ccc5b93 100644
--- a/src/Layer1.h
+++ b/src/Layer1.h
@@ -42,6 +42,8 @@ class Layer1Class {
 
     void setPins(int cs, int reset, int dio);
     void setSPIFrequency(uint32_t frequency);
+    void setLoRaFrequency(uint32_t frequency);
+    void setSpreadingFactor(uint8_t spreadingFactor);
 
 private:
     uint8_t hex_digit(char ch);
@@ -57,6 +59,8 @@ class Layer1Class {
     int _resetPin;
     int _DIOPin;
     uint32_t _spiFrequency;
+    uint32_t _loraFrequency;
+    uint8_t _spreadingFactor;
 };
 
 extern Layer1Class Layer1;
diff --git a/src/Layer1_LoRa.cpp b/src/Layer1_LoRa.cpp
index 15cea68..4c6b150 100644
--- a/src/Layer1_LoRa.cpp
+++ b/src/Layer1_LoRa.cpp
@@ -14,7 +14,9 @@ Layer1Class::Layer1Class() :
     _csPin(L1_DEFAULT_CS_PIN),
     _resetPin(L1_DEFAULT_RESET_PIN),
     _DIOPin(L1_DEFAULT_DIO0_PIN),
-    _spiFrequency(100E3)
+    _spiFrequency(100E3),
+    _loraFrequency(915E6),
+    _spreadingFactor(9)
 
 {
 
@@ -142,16 +144,24 @@ void Layer1Class::setSPIFrequency(uint32_t frequency){
     _spiFrequency = frequency;
 }
 
+void Layer1Class::setLoRaFrequency(uint32_t frequency){
+    _loraFrequency = frequency;
+}
+
+void Layer1Class::setSpreadingFactor(uint8_t spreadingFactor){
+    _spreadingFactor = spreadingFactor;
+}
+
 int Layer1Class::init(){ // maybe this should take the pins and spreading factor as inputs?
 
     LoRa.setPins(_csPin, _resetPin, _DIOPin); // set CS, reset, DIO pin
     LoRa.setSPIFrequency(_spiFrequency);
 
-    if (!LoRa.begin(915E6)) {             // initialize ratio at 915 MHz
+    if (!LoRa.begin(_loraFrequency)) {             // initialize ratio at 915 MHz
         return _loraInitialized;
     }
 
-    LoRa.setSpreadingFactor(9);           // ranges from 6-12,default 7 see API docs
+    LoRa.setSpreadingFactor(_spreadingFactor);           // ranges from 6-12,default 7 see API docs
     LoRa.onReceive(onReceive);
     LoRa.receive();