From adeba6b981c4dd9830caf01113209a4c15f98018 Mon Sep 17 00:00:00 2001 From: PA4WDH Date: Sun, 28 Jul 2024 15:57:46 +0200 Subject: Check driver names in autodetection --- cputemp.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'cputemp.c') diff --git a/cputemp.c b/cputemp.c index 559056f..0960662 100644 --- a/cputemp.c +++ b/cputemp.c @@ -87,6 +87,42 @@ void cputemp_read_hwmon(char *hwmon,char *sensor_name,struct s_sensor *sensor) hwmon_dirent=readdir(hwmon_dir); } closedir(hwmon_dir); + +// Some drivers do note have labels, so check the driver too if we didn't find anything so far + if (sensor->valid==0) + { + DEBUG2_CPUTEMP("Checking driver name\n"); + sprintf(sysfs_file,"%s/name",hwmon); + +// Read the name to see if it matches what we're looking for + datalen=sysfs_read_str(sysfs_file,buf,sizeof(buf)); + + if (datalen<0) + { + DEBUG2_CPUTEMP("Failed to driver name\n"); + } else { + DEBUG1_CPUTEMP("Name is: %s\n",buf); + if (strncasecmp(buf,sensor_name,255)==0) { + DEBUG2_CPUTEMP("Label machtes our search criteria\n"); + + sprintf(sysfs_file,"%s/temp1_input",hwmon); + DEBUG1_CPUTEMP("Input filename: %s\n",sysfs_file); + +// Validate the sensor by reading it + testdata=sysfs_read_long_int(sysfs_file); + DEBUG2_CPUTEMP("Input value: %ld\n",testdata); + if ((testdata>=VALID_TEMP_MIN) && (testdata<=VALID_TEMP_MAX)) + { + DEBUG1_CPUTEMP("Input data is valid, marking sensor as valid\n"); + sensor->valid=1; + strncpy(sensor->name,buf,sizeof(buf)); + strncpy(sensor->filename,sysfs_file,sizeof(sysfs_file)); + } else { + DEBUG1_CPUTEMP("Input data is invalid, ignoring sensor\n"); + } + } + } + } } // Find all entries under /sys/class/hwmon and check them with -- cgit v1.2.3