[SX127x] add getTempRaw method
Signed-off-by: gozu42 <tvguho-tbmh42-tct.76b2756e@hashmail.org>
This commit is contained in:
parent
f068a15029
commit
f534185cfb
3 changed files with 62 additions and 2 deletions
|
@ -126,6 +126,7 @@ setRSSIConfig KEYWORD2
|
||||||
setEncoding KEYWORD2
|
setEncoding KEYWORD2
|
||||||
getIRQFlags KEYWORD2
|
getIRQFlags KEYWORD2
|
||||||
getModemStatus KEYWORD2
|
getModemStatus KEYWORD2
|
||||||
|
getTempRaw KEYWORD2
|
||||||
|
|
||||||
# RF69-specific
|
# RF69-specific
|
||||||
setAESKey KEYWORD2
|
setAESKey KEYWORD2
|
||||||
|
|
|
@ -934,6 +934,58 @@ uint8_t SX127x::getModemStatus() {
|
||||||
return(_mod->SPIreadRegister(SX127X_REG_MODEM_STAT));
|
return(_mod->SPIreadRegister(SX127X_REG_MODEM_STAT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int8_t SX127x::getTempRaw() {
|
||||||
|
int8_t temp = 0;
|
||||||
|
uint8_t previousOpMode;
|
||||||
|
uint8_t ival;
|
||||||
|
|
||||||
|
// save current Op Mode
|
||||||
|
previousOpMode = _mod->SPIgetRegValue(SX127X_REG_OP_MODE);
|
||||||
|
|
||||||
|
// check if we need to step out of LoRa mode first
|
||||||
|
if ((previousOpMode & SX127X_LORA) == SX127X_LORA) {
|
||||||
|
_mod->SPIsetRegValue(SX127X_REG_OP_MODE, (SX127X_LORA | SX127X_SLEEP));
|
||||||
|
}
|
||||||
|
|
||||||
|
// put device in FSK sleep
|
||||||
|
_mod->SPIsetRegValue(SX127X_REG_OP_MODE, (SX127X_FSK_OOK | SX127X_SLEEP));
|
||||||
|
|
||||||
|
// put device in FSK RxSynth
|
||||||
|
_mod->SPIsetRegValue(SX127X_REG_OP_MODE, (SX127X_FSK_OOK | SX127X_FSRX));
|
||||||
|
|
||||||
|
// enable temperature reading
|
||||||
|
_mod->SPIsetRegValue(SX127X_REG_IMAGE_CAL, SX127X_TEMP_MONITOR_ON, 0, 0);
|
||||||
|
|
||||||
|
// wait
|
||||||
|
delayMicroseconds(200);
|
||||||
|
|
||||||
|
// disable temperature reading
|
||||||
|
_mod->SPIsetRegValue(SX127X_REG_IMAGE_CAL, SX127X_TEMP_MONITOR_OFF, 0, 0);
|
||||||
|
|
||||||
|
// put device in FSK sleep
|
||||||
|
_mod->SPIsetRegValue(SX127X_REG_OP_MODE, (SX127X_FSK_OOK | SX127X_SLEEP));
|
||||||
|
|
||||||
|
// read temperature
|
||||||
|
ival = _mod->SPIgetRegValue(SX127X_REG_TEMP);
|
||||||
|
|
||||||
|
// convert very raw value
|
||||||
|
if ((ival & 0x80) == 0x80) {
|
||||||
|
temp = 255 - ival;
|
||||||
|
} else {
|
||||||
|
temp = -1 * ival;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if we need to step back into LoRa mode
|
||||||
|
if ((previousOpMode & SX127X_LORA) == SX127X_LORA) {
|
||||||
|
_mod->SPIsetRegValue(SX127X_REG_OP_MODE, (SX127X_LORA | SX127X_SLEEP));
|
||||||
|
}
|
||||||
|
|
||||||
|
// reload previous Op Mode
|
||||||
|
_mod->SPIsetRegValue(SX127X_REG_OP_MODE, previousOpMode);
|
||||||
|
|
||||||
|
return(temp);
|
||||||
|
}
|
||||||
|
|
||||||
int16_t SX127x::config() {
|
int16_t SX127x::config() {
|
||||||
// turn off frequency hopping
|
// turn off frequency hopping
|
||||||
int16_t state = _mod->SPIsetRegValue(SX127X_REG_HOP_PERIOD, SX127X_HOP_PERIOD_OFF);
|
int16_t state = _mod->SPIsetRegValue(SX127X_REG_HOP_PERIOD, SX127X_HOP_PERIOD_OFF);
|
||||||
|
|
|
@ -459,8 +459,8 @@
|
||||||
#define SX127X_TEMP_THRESHOLD_10_DEG_C 0b00000010 // 2 1 10 deg. C (default)
|
#define SX127X_TEMP_THRESHOLD_10_DEG_C 0b00000010 // 2 1 10 deg. C (default)
|
||||||
#define SX127X_TEMP_THRESHOLD_15_DEG_C 0b00000100 // 2 1 15 deg. C
|
#define SX127X_TEMP_THRESHOLD_15_DEG_C 0b00000100 // 2 1 15 deg. C
|
||||||
#define SX127X_TEMP_THRESHOLD_20_DEG_C 0b00000110 // 2 1 20 deg. C
|
#define SX127X_TEMP_THRESHOLD_20_DEG_C 0b00000110 // 2 1 20 deg. C
|
||||||
#define SX127X_TEMP_MONITOR_OFF 0b00000000 // 0 0 temperature monitoring disabled (default)
|
#define SX127X_TEMP_MONITOR_ON 0b00000000 // 0 0 temperature monitoring enabled (default)
|
||||||
#define SX127X_TEMP_MONITOR_ON 0b00000001 // 0 0 temperature monitoring enabled
|
#define SX127X_TEMP_MONITOR_OFF 0b00000001 // 0 0 temperature monitoring disabled
|
||||||
|
|
||||||
// SX127X_REG_LOW_BAT
|
// SX127X_REG_LOW_BAT
|
||||||
#define SX127X_LOW_BAT_OFF 0b00000000 // 3 3 low battery detector disabled
|
#define SX127X_LOW_BAT_OFF 0b00000000 // 3 3 low battery detector disabled
|
||||||
|
@ -913,6 +913,13 @@ class SX127x: public PhysicalLayer {
|
||||||
*/
|
*/
|
||||||
uint8_t getModemStatus();
|
uint8_t getModemStatus();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Reads uncalibrated temperature value.
|
||||||
|
|
||||||
|
\returns Uncalibrated temperature sensor reading.
|
||||||
|
*/
|
||||||
|
int8_t getTempRaw();
|
||||||
|
|
||||||
#ifdef RADIOLIB_DEBUG
|
#ifdef RADIOLIB_DEBUG
|
||||||
void regDump();
|
void regDump();
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue