mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-10-26 12:24:33 +00:00
quantity: Add enumeration type
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
This commit is contained in:
1 parent
502ce051fe
commit
3bbd975860
4 files changed
+73
-37
No files matched your search
+3
-1
@@ -16,7 +16,9 @@ global:
|
||||
sensors_set_value;
|
||||
sensors_snprintf_chip_name;
|
||||
sensors_temp_type_name;
|
||||
sensors_get_quantity;
|
||||
sensors_get_subfeature_quantity;
|
||||
sensors_get_quantity_name;
|
||||
sensors_get_quantity_unit;
|
||||
sensors_strerror;
|
||||
sensors_parse_error;
|
||||
sensors_parse_error_wfn;
|
||||
|
||||
+18
-4
@@ -269,12 +269,26 @@ typedef enum sensors_subfeature_type {
|
||||
SENSORS_SUBFEATURE_UNKNOWN = INT_MAX,
|
||||
} sensors_subfeature_type;
|
||||
|
||||
typedef struct sensors_quantity {
|
||||
const char * quantity;
|
||||
const char * unit;
|
||||
typedef enum sensors_quantity {
|
||||
SENSORS_QUANTITY_UNKNOWN,
|
||||
SENSORS_QUANTITY_NONE,
|
||||
SENSORS_QUANTITY_BOOL,
|
||||
SENSORS_QUANTITY_VOLTAGE,
|
||||
SENSORS_QUANTITY_RPM,
|
||||
SENSORS_QUANTITY_TEMP,
|
||||
SENSORS_QUANTITY_POWER,
|
||||
SENSORS_QUANTITY_INTERVAL,
|
||||
SENSORS_QUANTITY_ENERGY,
|
||||
SENSORS_QUANTITY_CURRENT,
|
||||
SENSORS_QUANTITY_HUMIDITY,
|
||||
SENSORS_QUANTITY_PWM,
|
||||
SENSORS_QUANTITY_FREQ,
|
||||
SENSORS_QUANTITY_MAX = SENSORS_QUANTITY_FREQ,
|
||||
} sensors_quantity;
|
||||
|
||||
const sensors_quantity *sensors_get_quantity(sensors_subfeature_type) __attribute__ ((const));
|
||||
sensors_quantity sensors_get_subfeature_quantity(sensors_subfeature_type) __attribute__ ((const));
|
||||
const char * sensors_get_quantity_name(sensors_quantity) __attribute__ ((const));
|
||||
const char * sensors_get_quantity_unit(sensors_quantity) __attribute__ ((const));
|
||||
|
||||
typedef enum sensors_temp_type {
|
||||
SENSORS_TEMP_DISABLED,
|
||||
|
||||
+48
-28
@@ -169,20 +169,7 @@ int get_type_scaling(sensors_subfeature_type type)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static sensors_quantity none = {"", ""};
|
||||
static sensors_quantity bool = {"boolean", ""};
|
||||
static sensors_quantity voltage = {"voltage", "V"};
|
||||
static sensors_quantity rpm = {"rotation speed", "RPM"};
|
||||
static sensors_quantity temperature = {"temperature", "°C"};
|
||||
static sensors_quantity power = {"power", "W"};
|
||||
static sensors_quantity interval = {"time interval", "s"};
|
||||
static sensors_quantity energy = {"energy", "J"};
|
||||
static sensors_quantity current = {"electric current", "A"};
|
||||
static sensors_quantity humidity = {"humidity", "%RH"};
|
||||
static sensors_quantity pwm = {"pwm", "%"};
|
||||
static sensors_quantity freq = {"frequency", "Hz"};
|
||||
|
||||
const sensors_quantity* sensors_get_quantity(sensors_subfeature_type type)
|
||||
sensors_quantity sensors_get_subfeature_quantity(sensors_subfeature_type type)
|
||||
{
|
||||
/* Second class subfeatures
|
||||
that need their own handling */
|
||||
@@ -192,11 +179,11 @@ const sensors_quantity* sensors_get_quantity(sensors_subfeature_type type)
|
||||
case SENSORS_SUBFEATURE_TEMP_TYPE:
|
||||
case SENSORS_SUBFEATURE_TEMP_OFFSET:
|
||||
case SENSORS_SUBFEATURE_PWM_MODE:
|
||||
return &none;
|
||||
return SENSORS_QUANTITY_NONE;
|
||||
case SENSORS_SUBFEATURE_POWER_AVERAGE_INTERVAL:
|
||||
return &interval;
|
||||
return SENSORS_QUANTITY_INTERVAL;
|
||||
case SENSORS_SUBFEATURE_PWM_FREQ:
|
||||
return &freq;
|
||||
return SENSORS_QUANTITY_FREQ;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -211,29 +198,62 @@ const sensors_quantity* sensors_get_quantity(sensors_subfeature_type type)
|
||||
case SENSORS_SUBFEATURE_PWM_ENABLE:
|
||||
case SENSORS_SUBFEATURE_INTRUSION_ALARM:
|
||||
case SENSORS_SUBFEATURE_BEEP_ENABLE:
|
||||
return &bool;
|
||||
return SENSORS_QUANTITY_BOOL;
|
||||
case SENSORS_SUBFEATURE_VID: /* reported in mV and scaled */
|
||||
case SENSORS_SUBFEATURE_IN_INPUT:
|
||||
return &voltage;
|
||||
return SENSORS_QUANTITY_VOLTAGE;
|
||||
case SENSORS_SUBFEATURE_FAN_INPUT:
|
||||
return &rpm;
|
||||
return SENSORS_QUANTITY_RPM;
|
||||
case SENSORS_SUBFEATURE_TEMP_INPUT:
|
||||
return &temperature;
|
||||
return SENSORS_QUANTITY_TEMP;
|
||||
case SENSORS_SUBFEATURE_POWER_AVERAGE:
|
||||
return &power;
|
||||
return SENSORS_QUANTITY_POWER;
|
||||
case SENSORS_SUBFEATURE_ENERGY_INPUT:
|
||||
return &energy;
|
||||
return SENSORS_QUANTITY_ENERGY;
|
||||
case SENSORS_SUBFEATURE_CURR_INPUT:
|
||||
return ¤t;
|
||||
return SENSORS_QUANTITY_CURRENT;
|
||||
case SENSORS_SUBFEATURE_HUMIDITY_INPUT:
|
||||
return &humidity;
|
||||
return SENSORS_QUANTITY_VOLTAGE;
|
||||
case SENSORS_SUBFEATURE_PWM_IO:
|
||||
return &pwm;
|
||||
return SENSORS_QUANTITY_PWM;
|
||||
case SENSORS_SUBFEATURE_FREQ_INPUT:
|
||||
return &freq;
|
||||
return SENSORS_QUANTITY_FREQ;
|
||||
}
|
||||
|
||||
return &none;
|
||||
return SENSORS_QUANTITY_UNKNOWN;
|
||||
}
|
||||
|
||||
static struct {
|
||||
const char * name;
|
||||
const char * unit;
|
||||
} quantity_names[SENSORS_QUANTITY_MAX + 1] = {
|
||||
{"", ""},
|
||||
{"", ""},
|
||||
{"boolean", ""},
|
||||
{"voltage", "V"},
|
||||
{"rotation speed", "RPM"},
|
||||
{"temperature", "°C"},
|
||||
{"power", "W"},
|
||||
{"time interval", "s"},
|
||||
{"energy", "J"},
|
||||
{"electric current", "A"},
|
||||
{"humidity", "%RH"},
|
||||
{"pwm", "%"},
|
||||
{"frequency", "Hz"},
|
||||
};
|
||||
|
||||
const char *sensors_get_quantity_name(sensors_quantity quant)
|
||||
{
|
||||
if (quant > SENSORS_QUANTITY_MAX)
|
||||
return NULL;
|
||||
return quantity_names[quant].name;
|
||||
}
|
||||
|
||||
const char *sensors_get_quantity_unit(sensors_quantity quant)
|
||||
{
|
||||
if (quant > SENSORS_QUANTITY_MAX)
|
||||
return NULL;
|
||||
return quantity_names[quant].unit;
|
||||
}
|
||||
|
||||
static
|
||||
|
||||
@@ -60,7 +60,7 @@ void print_chip_raw(const sensors_chip_name *name)
|
||||
b = 0;
|
||||
while ((sub = sensors_get_all_subfeatures(name, feature, &b))) {
|
||||
if (sub->flags & SENSORS_MODE_R) {
|
||||
is_temp = !strcmp("°C", sensors_get_quantity(sub->type)->unit);
|
||||
is_temp = sensors_get_subfeature_quantity(sub->type) == SENSORS_QUANTITY_TEMP;
|
||||
|
||||
if ((err = sensors_get_value(name, sub->number,
|
||||
&val)))
|
||||
@@ -121,7 +121,7 @@ void print_chip_json(const sensors_chip_name *name)
|
||||
}
|
||||
}
|
||||
if (sub->flags & SENSORS_MODE_R) {
|
||||
is_temp = !strcmp("°C", sensors_get_quantity(sub->type)->unit);
|
||||
is_temp = sensors_get_subfeature_quantity(sub->type) == SENSORS_QUANTITY_TEMP;
|
||||
|
||||
if ((err = sensors_get_value(name, sub->number,
|
||||
&val))) {
|
||||
@@ -135,8 +135,8 @@ void print_chip_json(const sensors_chip_name *name)
|
||||
if (is_temp && fahrenheit)
|
||||
val = deg_ctof(val);
|
||||
if (new_json) {
|
||||
const char *unit = sensors_get_quantity(sub->type)->unit;
|
||||
const char *quantity = sensors_get_quantity(sub->type)->quantity;
|
||||
const char *unit = sensors_get_quantity_unit(sensors_get_subfeature_quantity(sub->type));
|
||||
const char *quantity = sensors_get_quantity_name(sensors_get_subfeature_quantity(sub->type));
|
||||
int quaCnt = 0;
|
||||
|
||||
printf("\"%s\":{", fname);
|
||||
|
||||
Reference in new issue
Block a user