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

Cyberman54 temperature #2

Merged
merged 4 commits into from
Jul 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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