Merge pull request #93 from Guglio95/master

[CC1101] Added setOOK(bool enableOOK)
pull/96/head
Jan Gromeš 2019-12-20 20:20:36 +01:00 zatwierdzone przez GitHub
commit 444800ea08
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 53 dodań i 2 usunięć

Wyświetl plik

@ -4,6 +4,7 @@ CC1101::CC1101(Module* module) : PhysicalLayer(CC1101_CRYSTAL_FREQ, CC1101_DIV_E
_mod = module;
_packetLengthQueried = false;
_packetLengthConfig = CC1101_LENGTH_CONFIG_VARIABLE;
_modulation = CC1101_MOD_FORMAT_2_FSK;
_syncWordLength = 2;
}
@ -449,8 +450,20 @@ int16_t CC1101::setOutputPower(int8_t power) {
return(ERR_INVALID_OUTPUT_POWER);
}
// write raw power setting
return(SPIsetRegValue(CC1101_REG_PATABLE, powerRaw));
if (_modulation == CC1101_MOD_FORMAT_ASK_OOK){
// Amplitude modulation:
// PA_TABLE[0] is the power to be used when transmitting a 0 (no power)
// PA_TABLE[1] is the power to be used when transmitting a 1 (full power)
byte paValues[2] = {0x00, powerRaw};
SPIwriteRegisterBurst(CC1101_REG_PATABLE, paValues, 2);
return ERR_NONE;
}else{
// Freq modulation:
// PA_TABLE[0] is the power to be used when transmitting.
return(SPIsetRegValue(CC1101_REG_PATABLE, powerRaw));
}
}
int16_t CC1101::setSyncWord(uint8_t* syncWord, uint8_t len, uint8_t maxErrBits) {
@ -548,6 +561,34 @@ int16_t CC1101::disableAddressFiltering() {
return(SPIsetRegValue(CC1101_REG_ADDR, 0x00));
}
int16_t CC1101::setOOK(bool enableOOK) {
// Change modulation
if (enableOOK) {
_modulation = CC1101_MOD_FORMAT_ASK_OOK;
}else{
_modulation = CC1101_MOD_FORMAT_2_FSK;
}
uint8_t state = SPIsetRegValue(CC1101_REG_MDMCFG2, _modulation, 6, 4);
// Change Front End TX Configuration
if (enableOOK){
// PA_TABLE[0] is (by default) the power value used when transmitting a "0L".
// Set PA_TABLE[1] to be used when transmitting a "1L".
state |= SPIsetRegValue(CC1101_REG_FREND0, 1, 2, 0);
}else{
// Reset FREND0 to default value.
state |= SPIsetRegValue(CC1101_REG_FREND0, 0, 2, 0);
}
if (state != ERR_NONE)
return state;
// Update PA_TABLE values according to the new _modulation.
return setOutputPower(_power);
}
float CC1101::getRSSI() {
float rssi;
if(_rawRSSI >= 128) {

Wyświetl plik

@ -742,6 +742,15 @@ class CC1101: public PhysicalLayer {
*/
int16_t disableAddressFiltering();
/*!
\brief Enables/disables OOK modulation instead of FSK.
\param enableOOK Enable (true) or disable (false) OOK.
\returns \ref status_codes
*/
int16_t setOOK(bool enableOOK);
/*!
\brief Gets RSSI (Recorded Signal Strength Indicator) of the last received packet.
@ -825,6 +834,7 @@ class CC1101: public PhysicalLayer {
float _freq;
uint8_t _rawRSSI;
uint8_t _rawLQI;
uint8_t _modulation;
size_t _packetLength;
bool _packetLengthQueried;