Skip to content

Commit

Permalink
Merge pull request #1 from tlrobinson/pins-config
Browse files Browse the repository at this point in the history
Add setPins() and setSPIFrequency() + misc other begin() changes
  • Loading branch information
grant_____ authored Jan 14, 2020
2 parents bda9f8d + 365b0bd commit 4fbea99
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/Layer1.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class Layer1Class {
int init();
int send_packet(char* data, int len);

void setPins(int cs, int reset, int dio);
void setSPIFrequency(uint32_t frequency);

private:
uint8_t hex_digit(char ch);
int isHashNew(char incoming[SHA1_LENGTH]);
Expand All @@ -53,6 +56,7 @@ class Layer1Class {
int _csPin;
int _resetPin;
int _DIOPin;
uint32_t _spiFrequency;
};

extern Layer1Class Layer1;
Expand Down
20 changes: 13 additions & 7 deletions src/Layer1_LoRa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Layer1Class::Layer1Class() :

_csPin(LORA_DEFAULT_CS_PIN),
_resetPin(LORA_DEFAULT_RESET_PIN),
_DIOPin(LORA_DEFAULT_DIO0_PIN)
_DIOPin(LORA_DEFAULT_DIO0_PIN),
_spiFrequency(100E3)

{

Expand Down Expand Up @@ -131,24 +132,29 @@ int Layer1Class::DIOPin(){
return _DIOPin;
}

int Layer1Class::init(){ // maybe this should take the pins and spreading factor as inputs?
void Layer1Class::setPins(int cs, int reset, int dio){
_csPin = cs;
_resetPin = reset;
_DIOPin = dio;
}

pinMode(_csPin, OUTPUT);
pinMode(_DIOPin, INPUT);
void Layer1Class::setSPIFrequency(uint32_t frequency){
_spiFrequency = frequency;
}

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
Serial.printf("LoRa init failed. Check your connections.\r\n");
return _loraInitialized;
}

LoRa.setSPIFrequency(100E3);
LoRa.setSpreadingFactor(9); // ranges from 6-12,default 7 see API docs
LoRa.onReceive(onReceive);
LoRa.receive();

Serial.printf("LoRa init succeeded.\r\n");
_loraInitialized = 1;
return _loraInitialized;
}
Expand Down

0 comments on commit 4fbea99

Please sign in to comment.