Skip to content

Commit 633521b

Browse files
committed
sensors/adxl362_uorb: support for fixed-point data
support for fixed-point data for adxl362_uorb Signed-off-by: raiden00pl <[email protected]>
1 parent 5777357 commit 633521b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

drivers/sensors/adxl362_uorb.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ struct adxl362_sensor_s
112112
struct sensor_lowerhalf_s lower;
113113
FAR struct spi_dev_s *spi;
114114
int devno;
115-
float scale;
115+
sensor_data_t scale;
116116
#ifdef CONFIG_SENSORS_ADXL362_POLL
117117
bool enabled;
118118
uint32_t interval;
@@ -488,10 +488,12 @@ static int adxl362_fetch(FAR struct sensor_lowerhalf_s *lower,
488488
adxl362_getregs(priv, ADXL362_XDATA_L, (FAR uint8_t *)data, 8);
489489

490490
accel.timestamp = sensor_get_timestamp();
491-
accel.x = (float)adxl362_data(&data[0]) * priv->scale;
492-
accel.y = (float)adxl362_data(&data[2]) * priv->scale;
493-
accel.z = (float)adxl362_data(&data[4]) * priv->scale;
494-
accel.temperature = (float)adxl362_data(&data[6]) * ADXL362_TEMP_SCALE;
491+
492+
accel.x = sensor_data_muli(priv->scale, adxl362_data(&data[0]));
493+
accel.y = sensor_data_muli(priv->scale, adxl362_data(&data[2]));
494+
accel.z = sensor_data_muli(priv->scale, adxl362_data(&data[4]));
495+
accel.temperature = sensor_data_muli(
496+
sensor_data_ftof(ADXL362_TEMP_SCALE), adxl362_data(&data[6]));
495497

496498
memcpy(buffer, &accel, sizeof(accel));
497499

@@ -608,7 +610,7 @@ int adxl362_register(int devno, FAR struct spi_dev_s *spi)
608610
priv->lower.ops = &g_adxl362_accel_ops;
609611
priv->lower.type = SENSOR_TYPE_ACCELEROMETER;
610612
priv->lower.nbuffer = 1;
611-
priv->scale = (CONSTANTS_ONE_G / 1000.0f);
613+
priv->scale = sensor_data_ftof(CONSTANTS_ONE_G / 1000.0f);
612614
priv->devno = devno;
613615
#ifdef CONFIG_SENSORS_ADXL362_POLL
614616
priv->enabled = false;

0 commit comments

Comments
 (0)