drivers/sensors: add voltage, current and power sensor types

uORB has no type for electrical quantities, so power monitors can only use
the legacy character drivers, which are deprecated and report their values
in three incompatible unit systems.  Add SENSOR_TYPE_VOLTAGE,
SENSOR_TYPE_CURRENT and SENSOR_TYPE_POWER with their message structs in SI
units (V, A, W).

Signed-off-by: likun17 <likun17@xiaomi.com>
This commit is contained in:
likun17 2026-09-09 20:12:19 +08:00 committed by Xiang Xiao
parent ad176ac47f
commit cd225a0e56
2 changed files with 46 additions and 1 deletions

View file

@ -590,11 +590,35 @@
#define SENSOR_TYPE_ENG 58
/* Voltage
* A sensor of this type returns the measured voltage between two points.
* The value is in SI units volt(V).
*/
#define SENSOR_TYPE_VOLTAGE 59
/* Current
* A sensor of this type returns the measured current flowing through a
* path. The value is in SI units ampere(A) and is signed: a negative value
* indicates that the current flows in the opposite direction.
*/
#define SENSOR_TYPE_CURRENT 60
/* Power
* A sensor of this type returns the measured instantaneous active power.
* The value is in SI units watt(W). The accumulated energy and the AC
* power components (reactive, apparent and power factor) are not covered
* by this type.
*/
#define SENSOR_TYPE_POWER 61
/* The total number of sensor
* please increase it if you added a new sensor type!
*/
#define SENSOR_TYPE_COUNT 59
#define SENSOR_TYPE_COUNT 62
/* The additional sensor open flags */
@ -1033,6 +1057,24 @@ struct sensor_eng /* Type: ENG */
uint32_t stat; /* Status. bit3:0 - value 3:0 is valid or not */
};
struct sensor_voltage /* Type: Voltage */
{
uint64_t timestamp; /* Unit is microseconds */
float voltage; /* in SI units V */
};
struct sensor_current /* Type: Current */
{
uint64_t timestamp; /* Unit is microseconds */
float current; /* in SI units A, signed */
};
struct sensor_power /* Type: Power */
{
uint64_t timestamp; /* Unit is microseconds */
float power; /* Instantaneous active power in SI units W */
};
struct sensor_gnss /* Type: GNSS */
{
uint64_t timestamp; /* Time since system start, Units is microseconds */