Browse Source
Merge pull request #2897 from yarda/companion-add-mcu-temp-sensor
Added MCU temp sensor to the companion
pull/2962/head
Liam Cottle
1 week ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
30 additions and
7 deletions
-
examples/companion_radio/MyMesh.cpp
-
src/helpers/NRF52Board.cpp
|
|
|
@ -657,6 +657,11 @@ uint8_t MyMesh::onContactRequest(const ContactInfo &contact, uint32_t sender_tim |
|
|
|
// query other sensors -- target specific
|
|
|
|
sensors.querySensors(permissions, telemetry); |
|
|
|
|
|
|
|
float temperature = board.getMCUTemperature(); |
|
|
|
if(!isnan(temperature)) { // Supported boards with built-in temperature sensor. ESP32-C3 may return NAN
|
|
|
|
telemetry.addTemperature(TELEM_CHANNEL_SELF, temperature); // Built-in MCU Temperature
|
|
|
|
} |
|
|
|
|
|
|
|
memcpy(reply, &sender_timestamp, |
|
|
|
4); // reflect sender_timestamp back in response packet (kind of like a 'tag')
|
|
|
|
|
|
|
|
@ -1640,6 +1645,11 @@ void MyMesh::handleCmdFrame(size_t len) { |
|
|
|
} else if (cmd_frame[0] == CMD_SEND_TELEMETRY_REQ && len == 4) { // 'self' telemetry request
|
|
|
|
telemetry.reset(); |
|
|
|
telemetry.addVoltage(TELEM_CHANNEL_SELF, (float)board.getBattMilliVolts() / 1000.0f); |
|
|
|
float temperature = board.getMCUTemperature(); |
|
|
|
if(!isnan(temperature)) { // Supported boards with built-in temperature sensor. ESP32-C3 may return NAN
|
|
|
|
telemetry.addTemperature(TELEM_CHANNEL_SELF, temperature); // Built-in MCU Temperature
|
|
|
|
} |
|
|
|
|
|
|
|
// query other sensors -- target specific
|
|
|
|
sensors.querySensors(0xFF, telemetry); |
|
|
|
|
|
|
|
|
|
|
|
@ -280,16 +280,29 @@ void NRF52Board::sleep(uint32_t secs) { |
|
|
|
|
|
|
|
// Temperature from NRF52 MCU
|
|
|
|
float NRF52Board::getMCUTemperature() { |
|
|
|
NRF_TEMP->TASKS_START = 1; // Start temperature measurement
|
|
|
|
|
|
|
|
long startTime = millis(); |
|
|
|
while (NRF_TEMP->EVENTS_DATARDY == 0) { // Wait for completion. Should complete in 50us
|
|
|
|
if(millis() - startTime > 5) { // To wait 5ms just in case
|
|
|
|
NRF_TEMP->TASKS_STOP = 1; |
|
|
|
uint8_t sd_enabled = 0; |
|
|
|
sd_softdevice_is_enabled(&sd_enabled); |
|
|
|
if (sd_enabled) { |
|
|
|
uint32_t err_code; |
|
|
|
int32_t temp; |
|
|
|
err_code = sd_temp_get(&temp); |
|
|
|
if (err_code == NRF_SUCCESS) { |
|
|
|
return (float)temp * 0.25f; |
|
|
|
} else { |
|
|
|
return NAN; |
|
|
|
} |
|
|
|
} else { |
|
|
|
NRF_TEMP->TASKS_START = 1; // Start temperature measurement
|
|
|
|
|
|
|
|
long startTime = millis(); |
|
|
|
while (NRF_TEMP->EVENTS_DATARDY == 0) { // Wait for completion. Should complete in 50us
|
|
|
|
if(millis() - startTime > 5) { // To wait 5ms just in case
|
|
|
|
NRF_TEMP->TASKS_STOP = 1; |
|
|
|
return NAN; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
NRF_TEMP->EVENTS_DATARDY = 0; // Clear event flag
|
|
|
|
|
|
|
|
int32_t temp = NRF_TEMP->TEMP; // In 0.25 *C units
|
|
|
|
|