SX1231 - reworked status codes

pull/1/head
Jan Gromeš 2018-07-23 12:42:33 +02:00
rodzic 0a90fc42d4
commit 75bb635370
4 zmienionych plików z 46 dodań i 45 usunięć

Wyświetl plik

@ -1,8 +1,8 @@
/*
* KiteLib SX1231 Receive Example
*
* This example receives packets using SX1231 FSK radio module.
*/
KiteLib SX1231 Receive Example
This example receives packets using SX1231 FSK radio module.
*/
// include the library
#include <KiteLib.h>
@ -22,12 +22,12 @@ void setup() {
// output power: 13 dBm
// sync word: 0x2D 0x01
byte state = rf.begin();
if(state == ERR_NONE) {
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code 0x"));
Serial.println(state, HEX);
while(true);
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// you can change the sync word at runtime
@ -38,9 +38,9 @@ void setup() {
// length: 2
// tolerated error bits: 0
state == rf.setSyncWord(syncWord, 2);
if(state == ERR_NONE) {
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else if(state == ERR_INVALID_SYNC_WORD) {
} else if (state == ERR_INVALID_SYNC_WORD) {
Serial.println(F("invalid!"));
}
}
@ -50,29 +50,29 @@ void loop() {
// you can receive data as an Arduino String
String str;
byte state = rf.receive(str);
int state = rf.receive(str);
// you can also receive data as byte array
/*
byte byteArr[8];
byte state = rf.receive(byteArr, 8);
byte byteArr[8];
int state = rf.receive(byteArr, 8);
*/
if(state == ERR_NONE) {
if (state == ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
// print the data of the packet
Serial.print(F("[SX1231] Data:\t\t"));
Serial.println(str);
} else if(state == ERR_RX_TIMEOUT) {
} else if (state == ERR_RX_TIMEOUT) {
// timeout occurred while waiting for a packet
Serial.println(F("timeout!"));
} else if(state == ERR_CRC_MISMATCH) {
} else if (state == ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));
}
}

Wyświetl plik

@ -1,8 +1,8 @@
/*
* KiteLib SX1231 Transmit Example
*
* This example transmits packets using SX1231 FSK radio module.
*/
KiteLib SX1231 Transmit Example
This example transmits packets using SX1231 FSK radio module.
*/
// include the library
#include <KiteLib.h>
@ -21,13 +21,13 @@ void setup() {
// frequency deviation: 50.0 kHz
// output power: 13 dBm
// sync word: 0x2D 0x01
byte state = rf.begin();
if(state == ERR_NONE) {
int state = rf.begin();
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code 0x"));
Serial.println(state, HEX);
while(true);
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// you can change the sync word at runtime
@ -38,9 +38,9 @@ void setup() {
// length: 2
// tolerated error bits: 0
state == rf.setSyncWord(syncWord, 2);
if(state == ERR_NONE) {
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else if(state == ERR_INVALID_SYNC_WORD) {
} else if (state == ERR_INVALID_SYNC_WORD) {
Serial.println(F("invalid!"));
}
}
@ -49,22 +49,22 @@ void loop() {
Serial.print(F("[SX1231] Transmitting packet ... "));
// you can transmit C-string or Arduino string up to 256 characters long
byte state = rf.transmit("Hello World!");
int state = rf.transmit("Hello World!");
// you can also transmit byte array up to 256 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x56, 0x78, 0xAB, 0xCD, 0xEF};
byte state = rf.transmit(byteArr, 8);
byte byteArr[] = {0x01, 0x23, 0x45, 0x56, 0x78, 0xAB, 0xCD, 0xEF};
int state = rf.transmit(byteArr, 8);
*/
if(state == ERR_NONE) {
if (state == ERR_NONE) {
// the packet was successfully transmitted
Serial.println(" success!");
} else if(state == ERR_PACKET_TOO_LONG) {
} else if (state == ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 256 bytes
Serial.println(" too long!");
}
// wait for a second before transmitting again

Wyświetl plik

@ -4,7 +4,7 @@ SX1231::SX1231(Module* mod) : RF69(mod) {
}
uint8_t SX1231::begin(float freq, float br, float rxBw, float freqDev, int8_t power) {
int16_t SX1231::begin(float freq, float br, float rxBw, float freqDev, int8_t power) {
// set module properties
_mod->init(USE_SPI, INT_BOTH);
@ -18,13 +18,14 @@ uint8_t SX1231::begin(float freq, float br, float rxBw, float freqDev, int8_t po
_chipRevision = version;
} else {
#ifdef KITELIB_DEBUG
Serial.print("SX1231 not found! (");
Serial.print(F("SX127x not found! ("));
Serial.print(i + 1);
Serial.print(" of 10 tries) RF69_REG_VERSION == ");
Serial.print(F(" of 10 tries) SX127X_REG_VERSION == "));
char buffHex[5];
sprintf(buffHex, "0x%02X", version);
char buffHex[7];
sprintf(buffHex, "0x%04X", version);
Serial.print(buffHex);
Serial.print(F(", expected 0x0021 / 0x0022 / 0x0023"));
Serial.println();
#endif
delay(1000);
@ -41,7 +42,7 @@ uint8_t SX1231::begin(float freq, float br, float rxBw, float freqDev, int8_t po
}
// configure settings not accessible by API
uint8_t state = config();
int16_t state = config();
if(state != ERR_NONE) {
return(state);
}

Wyświetl plik

@ -21,7 +21,7 @@ class SX1231: public RF69 {
SX1231(Module* mod);
// basic methods
uint8_t begin(float freq = 434.0, float br = 48.0, float rxBw = 125.0, float freqDev = 50.0, int8_t power = 13);
int16_t begin(float freq = 434.0, float br = 48.0, float rxBw = 125.0, float freqDev = 50.0, int8_t power = 13);
private:
uint8_t _chipRevision;