-
Notifications
You must be signed in to change notification settings - Fork 333
Added default temperature for ESP32 and NRF52 repeaters in telemetry #1163
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
Changes from all commits
0c31cd6
1068d9a
d70bbbc
280fdb6
28da9ae
3f0f193
9815e9d
c173a04
3908295
25e5329
4088f66
0271c9b
b870d74
0fa72b6
8fb7f64
fff34bb
2b94ff4
8e276b0
8331e40
841129a
f61811a
2581245
b92f63b
486656a
d9a02b2
8f3150d
6816009
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #if defined(NRF52_PLATFORM) | ||
| #include "NRF52Board.h" | ||
|
|
||
| // 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 > 1) { // To wait 1ms | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: if you're unlucky, millis returns 0 in the first call (while being internally at 0.9999999 ms) and then instantly rolls over to 1 in the next call, without 50us having passed. Additionally, what happens if millis() rolls over (after 49 days)?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @IoTThinks good point on point 2 :) On point 1, I think I should have clarified further: the granularity of millis() is not enough if you want to be guaranteed to wait at least 50us by setting a timeout of 1ms. Another example: if you are at 50000.999999999 ms since boot, the first millis call will return 50000. Before 50us has passed, the next millis call will already return 50001. This could be fixed by changing the timeout to 2 milliseconds instead, that way, you're guaranteed to wait at least 1 full millisecond instead of having no minimal guaranteed timeout. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Point 1 actually wasn't as nitpicky as I though: if you keep the code as-is, you'll see the timeout code trigger before 50us 5% of all calls, on average.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @redfast00 How do you calculate the 5%? 1ms or even 10ms is fine for me. The app is not required to be responsive at ms anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How did I calculate the 5%? At the end of each millisecond real time, the millis() function return value will increase by one. If this happens before 50us of real time has passed, we say the code 'fails' (since it aborts the measurement without 50us having passed). So if the code starts at the end of |
||
| 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 | ||
| NRF_TEMP->TASKS_STOP = 1; | ||
|
|
||
| return temp * 0.25f; // Convert to *C | ||
| } | ||
|
|
||
| #endif | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #pragma once | ||
|
|
||
| #include <MeshCore.h> | ||
| #include <Arduino.h> | ||
|
|
||
| #if defined(NRF52_PLATFORM) | ||
IoTThinks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| class NRF52Board : public mesh::MainBoard { | ||
| public: | ||
| float getMCUTemperature() override; | ||
| }; | ||
|
|
||
| #endif | ||
Uh oh!
There was an error while loading. Please reload this page.