This is an automated email from the ASF dual-hosted git repository.
linguini1 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 1757b28b1f1 drivers/sensors: Use sensor_data_t for the electrical
quantities.
1757b28b1f1 is described below
commit 1757b28b1f13bd98dcf68f622b56dce5ea9aba1a
Author: Justin Hammond <[email protected]>
AuthorDate: Sun Sep 20 16:01:54 2026 +0800
drivers/sensors: Use sensor_data_t for the electrical quantities.
The voltage, current, power, resistance and conductivity messages
declare their measurement as float, where every other message in
uorb.h declares it as sensor_data_t. That type is b16_t under
CONFIG_SENSORS_USE_B16 and float otherwise, so on a fixed point
configuration these five are the only sensors still producing floats.
A driver that computes in sensor_data_t, as the helpers in fixedmath.h
encourage, then assigns a b16_t to a float field: the raw fixed point
integer is stored as a float and the reading is wrong by 65536 with no
diagnostic.
The accumulators keep int64_t. Energy in uJ and charge in uC are
counts of micro units rather than measurements, and neither is
affected by the fixed point option.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Justin Hammond <[email protected]>
---
include/nuttx/uorb.h | 33 ++++++++++++++++++---------------
1 file changed, 18 insertions(+), 15 deletions(-)
diff --git a/include/nuttx/uorb.h b/include/nuttx/uorb.h
index fc102fb782e..c67f88b99cb 100644
--- a/include/nuttx/uorb.h
+++ b/include/nuttx/uorb.h
@@ -1091,34 +1091,37 @@ struct sensor_eng /* Type: ENG */
uint32_t stat; /* Status. bit3:0 - value 3:0 is valid or not */
};
-struct sensor_voltage /* Type: Voltage */
+struct sensor_voltage /* Type: Voltage */
{
- uint64_t timestamp; /* Unit is microseconds */
- float voltage; /* in SI units V */
+ uint64_t timestamp; /* Unit is microseconds */
+ sensor_data_t voltage; /* in SI units V */
};
-struct sensor_current /* Type: Current */
+struct sensor_current /* Type: Current */
{
- uint64_t timestamp; /* Unit is microseconds */
- float current; /* in SI units A, signed */
+ uint64_t timestamp; /* Unit is microseconds */
+ sensor_data_t current; /* in SI units A, signed */
};
-struct sensor_power /* Type: Power */
+struct sensor_power /* Type: Power */
{
- uint64_t timestamp; /* Unit is microseconds */
- float power; /* Instantaneous active power in SI units W */
+ uint64_t timestamp; /* Unit is microseconds */
+ sensor_data_t power; /* Instantaneous active power, SI units W */
};
-struct sensor_resistance /* Type: Resistance */
+struct sensor_resistance /* Type: Resistance */
{
- uint64_t timestamp; /* Unit is microseconds */
- float resistance; /* in SI units Ohm(Ω) */
+ uint64_t timestamp; /* Unit is microseconds */
+ sensor_data_t resistance; /* in SI units Ohm(Ω) */
};
-struct sensor_conductivity /* Type: Electrical conductivity */
+struct sensor_conductivity /* Type: Electrical conductivity */
{
- uint64_t timestamp; /* Unit is microseconds */
- float conductivity; /* in SI units S/m, 1 S/m = 1e4 uS/cm */
+ uint64_t timestamp; /* Unit is microseconds */
+
+ /* In SI units S/m, where 1 S/m is 1e4 uS/cm */
+
+ sensor_data_t conductivity;
};
struct sensor_energy /* Type: Energy */