Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Random function #395

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
12 changes: 6 additions & 6 deletions examples/LoRandom/LoRandom.ino
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ void setup() {
void loop() {
byte randomBytes[256];
// We'll build a stock of random bytes for use in code
uint8_t randomIndex = 0;
uint16_t i;
int randomIndex = 0;
unsigned int i;
for (i = 0; i < 256; i++) {
uint8_t x = LoRa.random();
int x = LoRa.random();
randomBytes[i] = x;
}
randomIndex = 0;
hexDump(randomBytes, 256);
delay(2000);
}

void hexDump(unsigned char *buf, uint16_t len) {
void hexDump(unsigned char *buf, unsigned int len) {
String s = "|", t = "| |";
Serial.println(F(" |.0 .1 .2 .3 .4 .5 .6 .7 .8 .9 .a .b .c .d .e .f |"));
Serial.println(F(" +------------------------------------------------+ +----------------+"));
for (uint16_t i = 0; i < len; i += 16) {
for (uint8_t j = 0; j < 16; j++) {
for ( unsigned int i = 0; i < len; i += 16) {
for (int j = 0; j < 16; j++) {
if (i + j >= len) {
s = s + " "; t = t + " ";
} else {
Expand Down
12 changes: 9 additions & 3 deletions src/LoRa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,11 @@ void LoRaClass::sleep()
writeRegister(REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_SLEEP);
}

void LoRaClass::continuosMode()
sabas1080 marked this conversation as resolved.
Show resolved Hide resolved
{
writeRegister(REG_OP_MODE, 0x72);
}

void LoRaClass::setTxPower(int level, int outputPin)
{
if (PA_OUTPUT_RFO_PIN == outputPin) {
Expand Down Expand Up @@ -608,9 +613,10 @@ void LoRaClass::setOCP(uint8_t mA)
}

void LoRaClass::beginRandom() {
writeRegister(REG_OP_MODE, 0x72);
writeRegister(REG_MODEM_CONFIG_1, 0x72);
writeRegister(REG_MODEM_CONFIG_2, 0x70);
continuosMode();
setSignalBandwidth(125E3);
setCodingRate4(5);
setSpreadingFactor(7);
}

byte LoRaClass::random()
Expand Down
1 change: 1 addition & 0 deletions src/LoRa.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class LoRaClass : public Stream {
#endif
void idle();
void sleep();
void continuosMode();

void setTxPower(int level, int outputPin = PA_OUTPUT_PA_BOOST_PIN);
void setFrequency(long frequency);
Expand Down