Question
According to the Tizen native application sensor API documentation (https://developer.tizen.org/development/guides/native-application/system/sensor), the HRM (Heart Rate Monitor) sensor measurement values should return as int type. However, when implementing the following code:
dlog_print(DLOG_INFO, TAG, "%d", event->values[0]);
The output values are not correct. Interestingly, when changing the format specifier to float type:
dlog_print(DLOG_INFO, TAG, "%f", event->values[0]);
The values are displayed correctly within the expected range (between Min and Max). This suggests that the HRM sensor documentation should be updated to specify float instead of int for the return type.
Answer
Problem Understanding
The issue occurs when trying to read HRM sensor values using the documented int type format specifier (%d), which produces incorrect readings. The values only display correctly when using a float type format specifier (%f).
Solution Methods
- Use
floattype format specifier (%f) when printing HRM sensor values - Update your code to handle the values as floating-point numbers
- Be aware that this discrepancy exists in the current documentation
Code Examples
// Correct way to print HRM sensor values
dlog_print(DLOG_INFO, TAG, "Heart Rate: %f", event->values[0]);
// Alternative way to store the value
float heart_rate = event->values[0];
dlog_print(DLOG_INFO, TAG, "Heart Rate: %.1f", heart_rate);
Additional Tips
- This behavior has been confirmed on both emulator and physical devices (like Gear S2)
- While waiting for official documentation updates, always use
floattype for HRM sensor values - Consider checking for sensor availability and proper initialization before reading values