Merge pull request 'Pwm' (#363) from Wer-Wolf/pwm into master

Reviewed-on: http://localhost:8888/hramrach/lm-sensors/pulls/363
This commit is contained in:
hramrach committed 2023-12-24 12:06:18 +01:00
commit e7ecb0b92f
5 files changed
+92 -3

No files matched your search

+1
View File
@@ -2,6 +2,7 @@ lm-sensors CHANGES file
-----------------------
git HEAD
Add PWM sensor support
3.6.0 (2019-10-18)
configs: Added a number of new configuration files
+3
View File
@@ -6,6 +6,9 @@ over time. This document summarizes these evolutions so that application
authors can quickly figure out how to test for the availability of a
given new feature.
0x501
* Added support for pwm sensors
0x500 lm-sensors 3.5.0
* Added support for power min, lcrit, min_alarm and lcrit_alarm
enum sensors_subfeature_type SENSORS_SUBFEATURE_POWER_MIN
+7 -1
View File
@@ -31,7 +31,7 @@
when the API or ABI breaks), the third digit is incremented to track small
API additions like new flags / enum values. The second digit is for tracking
larger additions like new methods. */
#define SENSORS_API_VERSION 0x500
#define SENSORS_API_VERSION 0x501
#define SENSORS_CHIP_NAME_PREFIX_ANY NULL
#define SENSORS_CHIP_NAME_ADDR_ANY (-1)
@@ -144,6 +144,7 @@ typedef enum sensors_feature_type {
SENSORS_FEATURE_ENERGY = 0x04,
SENSORS_FEATURE_CURR = 0x05,
SENSORS_FEATURE_HUMIDITY = 0x06,
SENSORS_FEATURE_PWM = 0x07,
SENSORS_FEATURE_MAX_MAIN,
SENSORS_FEATURE_VID = 0x10,
SENSORS_FEATURE_INTRUSION = 0x11,
@@ -245,6 +246,11 @@ typedef enum sensors_subfeature_type {
SENSORS_SUBFEATURE_HUMIDITY_INPUT = SENSORS_FEATURE_HUMIDITY << 8,
SENSORS_SUBFEATURE_PWM_IO = SENSORS_FEATURE_PWM << 8,
SENSORS_SUBFEATURE_PWM_FREQ,
SENSORS_SUBFEATURE_PWM_ENABLE = (SENSORS_FEATURE_PWM << 8) | 0x80,
SENSORS_SUBFEATURE_PWM_MODE,
SENSORS_SUBFEATURE_VID = SENSORS_FEATURE_VID << 8,
SENSORS_SUBFEATURE_INTRUSION_ALARM = SENSORS_FEATURE_INTRUSION << 8,
+25 -2
View File
@@ -149,6 +149,7 @@ int get_type_scaling(sensors_subfeature_type type)
case SENSORS_SUBFEATURE_HUMIDITY_INPUT:
return 1000;
case SENSORS_SUBFEATURE_FAN_INPUT:
case SENSORS_SUBFEATURE_PWM_IO:
return 1;
case SENSORS_SUBFEATURE_POWER_AVERAGE:
case SENSORS_SUBFEATURE_ENERGY_INPUT:
@@ -186,6 +187,13 @@ char *get_feature_name(sensors_feature_type ftype, char *sfname)
if (!name)
sensors_fatal_error(__func__, "Out of memory");
break;
case SENSORS_FEATURE_PWM:
/* Not all pwm subfeatures have a underscore in there name */
name = strndup(sfname, 4);
if (!name)
sensors_fatal_error(__func__, "Out of memory");
break;
default:
name = strdup(sfname);
@@ -319,6 +327,13 @@ static const struct subfeature_type_match humidity_matches[] = {
{ NULL, 0 }
};
static const struct subfeature_type_match pwm_matches[] = {
{ "enable", SENSORS_SUBFEATURE_PWM_ENABLE },
{ "mode", SENSORS_SUBFEATURE_PWM_MODE },
{ "freq", SENSORS_SUBFEATURE_PWM_FREQ },
{ NULL, 0 }
};
static const struct subfeature_type_match cpu_matches[] = {
{ "vid", SENSORS_SUBFEATURE_VID },
{ NULL, 0 }
@@ -339,6 +354,7 @@ static struct feature_type_match matches[] = {
{ "energy%d%c", energy_matches },
{ "intrusion%d%c", intrusion_matches },
{ "humidity%d%c", humidity_matches },
{ "pwm%d%c", pwm_matches },
};
/* Return the subfeature type and channel number based on the subfeature
@@ -356,9 +372,15 @@ sensors_subfeature_type sensors_subfeature_get_type(const char *name, int *nr)
return SENSORS_SUBFEATURE_BEEP_ENABLE;
}
for (i = 0; i < ARRAY_SIZE(matches); i++)
if ((count = sscanf(name, matches[i].name, nr, &c)))
for (i = 0; i < ARRAY_SIZE(matches); i++) {
if ((count = sscanf(name, matches[i].name, nr, &c))) {
/* Needed for matching pwm[1-*] */
if (count == 1 && matches[i].submatches == pwm_matches)
return SENSORS_SUBFEATURE_PWM_IO;
break;
}
}
if (i == ARRAY_SIZE(matches) || count != 2 || c != '_')
return SENSORS_SUBFEATURE_UNKNOWN; /* no match */
@@ -468,6 +490,7 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
case SENSORS_FEATURE_ENERGY:
case SENSORS_FEATURE_CURR:
case SENSORS_FEATURE_HUMIDITY:
case SENSORS_FEATURE_PWM:
nr--;
break;
default:
+56
View File
@@ -754,6 +754,59 @@ static void print_chip_humidity(const sensors_chip_name *name,
free(label);
}
static void print_chip_pwm(const sensors_chip_name *name,
const sensors_feature *feature,
int label_size)
{
const sensors_subfeature *sfio, *sffreq, *sfenable, *sfmode;
char *label;
double val;
if (!(label = sensors_get_label(name, feature))) {
fprintf(stderr, "ERROR: Can't get label of feature %s!\n",
feature->name);
return;
}
print_label(label, label_size);
free(label);
sfio = sensors_get_subfeature(name, feature,
SENSORS_SUBFEATURE_PWM_IO);
if (sfio && !get_input_value(name, sfio, &val))
printf(" %3.0f%%", val / 2.55);
else
printf(" N/A");
sffreq = sensors_get_subfeature(name, feature,
SENSORS_SUBFEATURE_PWM_FREQ);
sfmode = sensors_get_subfeature(name, feature,
SENSORS_SUBFEATURE_PWM_MODE);
if (sffreq || sfmode) {
printf(" (");
if (sffreq)
printf("freq = %.0f Hz", get_value(name, sffreq));
if (sfmode) {
if (!get_input_value(name, sfmode, &val))
printf("%smode = %s", sffreq ? ", " : "",
(int) val ? "pwm" : "dc");
else
printf("%smode = N/A", sffreq ? ", " : "");
}
printf(")");
}
sfenable = sensors_get_subfeature(name, feature,
SENSORS_SUBFEATURE_PWM_ENABLE);
if (sfenable && !get_input_value(name, sfenable, &val) &&
(int) val == 1)
printf(" MANUAL CONTROL");
printf("\n");
}
static void print_chip_beep_enable(const sensors_chip_name *name,
const sensors_feature *feature,
int label_size)
@@ -894,6 +947,9 @@ void print_chip(const sensors_chip_name *name)
case SENSORS_FEATURE_HUMIDITY:
print_chip_humidity(name, feature, label_size);
break;
case SENSORS_FEATURE_PWM:
print_chip_pwm(name, feature, label_size);
break;
default:
continue;
}