sensors/hyt271_uorb: support for fixed-point data

support for fixed-point data for hyt271_uorb

Signed-off-by: raiden00pl <raiden00@railab.me>
This commit is contained in:
raiden00pl
2025-12-01 10:06:25 +01:00
committed by Xiang Xiao
parent 5c3c369dbd
commit 25ddf14cf5
+13 -12
View File
@@ -47,12 +47,6 @@
* Pre-processor Definitions
****************************************************************************/
/* Only float data type supported now */
#ifdef CONFIG_SENSORS_USE_B16
# error fixed-point data type not supported yet
#endif
#define HYT271_TEMPDATA_MASK 0x3fff
#define HYT271_HUMIDATA_MASK 0x3fff
@@ -67,9 +61,6 @@
#define HYT271_HUMIRAWEQUAL(x, y) \
(HYT271_HUMIRAWDATA(x) == HYT271_HUMIRAWDATA(y))
#define HYT271_TEMPDATA(x) (HYT271_TEMPRAWDATA(x) * 165.0 / 16383.0 - 40.0)
#define HYT271_HUMIDATA(x) (HYT271_HUMIRAWDATA(x) * 100.0 / 16383.0)
#define HYT271_SENSOR_HUMI 0
#define HYT271_SENSOR_TEMP 1
#define HYT271_SENSOR_MAX 2
@@ -165,8 +156,12 @@ static const struct sensor_ops_s g_hyt271_ops =
static void hyt271_humi_from_rawdata(FAR struct hyt271_sensor_data_s *data,
FAR struct sensor_humi *humi)
{
humi->timestamp = data->timestamp;
humi->humidity = HYT271_HUMIDATA(data->data);
/* hum = HUM_RAW * (100 / 16383) */
humi->timestamp = data->timestamp;
humi->humidity = sensor_data_mul(
sensor_data_itof(HYT271_HUMIRAWDATA(data->data)),
sensor_data_ftof(100.0f / 16383.0f));
}
/****************************************************************************
@@ -183,8 +178,14 @@ static void hyt271_humi_from_rawdata(FAR struct hyt271_sensor_data_s *data,
static void hyt271_temp_from_rawdata(FAR struct hyt271_sensor_data_s *data,
FAR struct sensor_temp *temp)
{
/* temp = TEMP_RAW * (165 / 16383) - 40 */
temp->timestamp = data->timestamp;
temp->temperature = HYT271_TEMPDATA(data->data);
temp->temperature = sensor_data_subi(
sensor_data_mul(
sensor_data_itof(HYT271_TEMPRAWDATA(data->data)),
sensor_data_ftof(165.0f / 16383.0f)),
40);
}
/****************************************************************************