Skip to content

Commit

Permalink
Merge pull request #2 from cyberman54/cyberman54-TEMPERATURE
Browse files Browse the repository at this point in the history
Cyberman54 temperature
  • Loading branch information
cyberman54 authored Jul 25, 2021
2 parents 876f39a + c45d63d commit 1fef692
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/lmic/lmic.h
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,8 @@ struct lmic_radio_data_s {
ostime_t txlate_ticks;
// number of tx late launches.
unsigned txlate_count;
// radio chip raw temperature value.
s1_t temperature;
};

/*
Expand Down
2 changes: 1 addition & 1 deletion src/lmic/oslmic.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ int os_init_ex (const void *pPinMap);
void os_runloop (void);
void os_runloop_once (void);
u1_t radio_rssi (void);
s1_t radio_GetRawTemp(void);
s1_t radio_raw_temp(void);
void radio_monitor_rssi(ostime_t n, oslmic_radio_rssi_t *pRssi);

//================================================================================
Expand Down
29 changes: 12 additions & 17 deletions src/lmic/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,12 @@ static void txlora () {
// start transmitter (buf=LMIC.frame, len=LMIC.dataLen)
static void starttx () {
u1_t const rOpMode = readReg(RegOpMode);

// update radio chip raw temperature value
LMIC.radio.temperature = radio_raw_temp();
#if LMIC_DEBUG_LEVEL > 0
LMIC_DEBUG_PRINTF("RegTemp=%d\n", LMIC.radio.temperature);
#endif

// originally, this code ASSERT()ed, but asserts are both bad and
// blunt instruments. If we see that we're not in sleep mode,
Expand Down Expand Up @@ -1177,21 +1183,14 @@ u1_t radio_rssi () {
}

// Reads the raw temperature
// \retval New raw temperature reading in 2's complement format
s1_t radio_GetRawTemp(void) {
// \retval New raw temperature reading
s1_t radio_raw_temp(void) {

#define RF_IMAGECAL_TEMPMONITOR_MASK 0xFE
#define RF_IMAGECAL_TEMPMONITOR_ON 0x00
#define RF_IMAGECAL_TEMPMONITOR_OFF 0x01

s1_t temp = 0;
u1_t previousOpMode, RegTemp;

// Save current Operation Mode
previousOpMode = readReg(RegOpMode);

// Put device in FSK Sleep Mode
opmode(OPMODE_SLEEP);
s1_t RegTemp = 0;

// select FSK modem (from sleep mode)
opmodeFSK();
Expand All @@ -1218,16 +1217,12 @@ s1_t radio_GetRawTemp(void) {
RegTemp = readReg(FSKRegTemp);

if ((RegTemp & 0x80) == 0x80) {
temp = 255 - RegTemp;
RegTemp = 255 - RegTemp;
} else {
temp = RegTemp;
temp *= -1;
RegTemp *= -1;
}

// Reload previous Op Mode
writeReg(RegOpMode, previousOpMode);

return temp;
return RegTemp;
}

/// \brief get the current RSSI on the current channel.
Expand Down

0 comments on commit 1fef692

Please sign in to comment.