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

Fix Error in converting EddystoneTLM negative temperatures to float #677

Merged
merged 1 commit into from
Jun 8, 2024

Conversation

Max93
Copy link
Contributor

@Max93 Max93 commented Jun 6, 2024

In NimBLEEddystoneTLM.cpp, there is an issue when receiving negative numbers for temperature readings and when setting the temperature.

For example, a temperature of -0.1°C is incorrectly converted to approximately 256°C.

To address this issue, we made the following changes:

/**
 * @brief Set the temperature to advertise.
 * @param [in] temp The temperature value.
 */
void NimBLEEddystoneTLM::setTemp(float temp) {
-  m_eddystoneData.temp = (uint16_t)temp;
+  m_eddystoneData.temp = ENDIAN_CHANGE_U16((int16_t)(temp * 256.0f));
} // setTemp

/**
 * @brief Get the temperature being advertised.
 * @return The temperature value.
 */
float NimBLEEddystoneTLM::getTemp() {
-  return ENDIAN_CHANGE_U16(m_eddystoneData.temp) / 256.0f;
+  return (int16_t)ENDIAN_CHANGE_U16(m_eddystoneData.temp) / 256.0f;
} // getTemp

I am a colleague of Giovanni, who opened the issue #675

Thank you for considering this fix.

@h2zero h2zero merged commit 6d8eb8a into h2zero:release/1.4 Jun 8, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants