Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | sensors.c: read sensors from sys/thermal, also fix read_sensors_hwmon to read both from /sys/class/hwmon and /sys/class/hwmon/device. |
---|---|
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: | e53cf0fadd559e0cc6fbfb4d9b9b357cf64b5f63 |
User & Date: | jamesbond 2015-02-19 07:18:01 |
Context
2015-02-19
| ||
11:42 | quote lsusb -v output so it is safe for hardinfo. check-in: 215d179605 user: jamesbond tags: trunk | |
07:18 | sensors.c: read sensors from sys/thermal, also fix read_sensors_hwmon to read both from /sys/class/hwmon and /sys/class/hwmon/device. check-in: e53cf0fadd user: jamesbond tags: trunk | |
2015-02-13
| ||
04:33 | update sensors.c to work with kernel 3.18.x check-in: b699f12863 user: jamesbond tags: trunk | |
Changes
Changes to modules/devices/sensors.c.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 ... 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 ... 304 305 306 307 308 309 310 311 312 313 314 315 316 317 ... 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
postfix = g_hash_table_lookup(sensor_compute, name); if (!postfix) return value; return math_postfix_eval(postfix, value); } static char *get_sensor_path(int number) { char *path, *last_slash; path = g_strdup_printf("/sys/class/hwmon/hwmon%d", number); if (g_file_test(path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { return path; } /* we start at the top of hwmon, this fallback is not needed anymore if ((last_slash = strrchr(path, '/'))) { *last_slash = '\0'; return path; ................................................................................ static const struct HwmonSensor hwmon_sensors[] = { { "Cooling Fans", "%s/fan%d_input", "fan%d", "%s (%s)=%.0fRPM\n", 1.0, 1 }, { "Temperature", "%s/temp%d_input", "temp%d", "%s (%s)=%.2f\302\260C\n", 1000.0, 1 }, { "Voltage Values", "%s/in%d_input", "in%d", "%s (%s)=%.3fV\n", 1000.0, 0 }, { NULL, NULL, NULL, NULL, 0.0, 0 }, }; static void read_sensors_hwmon(void) { int hwmon, count; gchar *path_hwmon, *path_sensor, *tmp, *driver, *name, *mon; hwmon = 0; path_hwmon = get_sensor_path(hwmon); while (path_hwmon && g_file_test(path_hwmon, G_FILE_TEST_EXISTS)) { const struct HwmonSensor *sensor; driver = determine_driver_for_hwmon_path(path_hwmon); DEBUG("hwmon%d has driver=%s", hwmon, driver); if (!sensor_labels) { read_sensor_labels(driver); } for (sensor = hwmon_sensors; sensor->friendly_name; sensor++) { char *output = NULL; DEBUG("current sensor type=%s", sensor->friendly_name); for (count = sensor->begin_at;; count++) { path_sensor = g_strdup_printf(sensor->path_format, path_hwmon, count); DEBUG("should be reading from %s", path_sensor); if (!g_file_get_contents(path_sensor, &tmp, NULL, NULL)) { g_free(path_sensor); break; } mon = g_strdup_printf(sensor->key_format, count); name = get_sensor_label(mon); if (!g_str_equal(name, "ignore")) { output = h_strdup_cprintf(sensor->value_format, output, name, driver, adjust_sensor(mon, atof(tmp) / sensor->adjust_ratio)); } g_free(tmp); g_free(mon); g_free(name); g_free(path_sensor); } if (output) { sensors = g_strconcat(sensors, "[", sensor->friendly_name, "]\n", output, "\n", NULL); g_free(output); } } g_free(path_hwmon); g_free(driver); path_hwmon = get_sensor_path(++hwmon); } g_free(path_hwmon); } static void read_sensors_acpi(void) { const gchar *path_tz = "/proc/acpi/thermal_zone"; if (g_file_test(path_tz, G_FILE_TEST_EXISTS)) { ................................................................................ } if (*temp != '\0') sensors = h_strdup_cprintf("\n[ACPI Thermal Zone]\n%s", sensors, temp); g_dir_close(tz); } } } static void read_sensors_omnibook(void) ................................................................................ { g_free(sensors); sensors = g_strdup(""); read_sensors_hwmon(); read_sensors_acpi(); read_sensors_omnibook(); read_sensors_hddtemp(); /* FIXME: Add support for ibm acpi and more sensors */ } void sensors_init(void) |
| | > > < > | > > > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 ... 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 ... 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 ... 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 |
postfix = g_hash_table_lookup(sensor_compute, name); if (!postfix) return value; return math_postfix_eval(postfix, value); } static char *get_sensor_path(int number, char *prefix) { char *path, *last_slash; path = g_strdup_printf("/sys/class/hwmon/hwmon%d/%s", number, prefix); if (g_file_test(path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { return path; } /* we start at the top of hwmon, this fallback is not needed anymore if ((last_slash = strrchr(path, '/'))) { *last_slash = '\0'; return path; ................................................................................ static const struct HwmonSensor hwmon_sensors[] = { { "Cooling Fans", "%s/fan%d_input", "fan%d", "%s (%s)=%.0fRPM\n", 1.0, 1 }, { "Temperature", "%s/temp%d_input", "temp%d", "%s (%s)=%.2f\302\260C\n", 1000.0, 1 }, { "Voltage Values", "%s/in%d_input", "in%d", "%s (%s)=%.3fV\n", 1000.0, 0 }, { NULL, NULL, NULL, NULL, 0.0, 0 }, }; const char *hwmon_prefix[] = { "device", "", NULL }; static void read_sensors_hwmon(void) { int hwmon, count; gchar *path_hwmon, *path_sensor, *tmp, *driver, *name, *mon; char **prefix; for (prefix = hwmon_prefix; *prefix; prefix++) { hwmon = 0; path_hwmon = get_sensor_path(hwmon, *prefix); while (path_hwmon && g_file_test(path_hwmon, G_FILE_TEST_EXISTS)) { const struct HwmonSensor *sensor; driver = determine_driver_for_hwmon_path(path_hwmon); DEBUG("hwmon%d has driver=%s", hwmon, driver); if (!sensor_labels) { read_sensor_labels(driver); } for (sensor = hwmon_sensors; sensor->friendly_name; sensor++) { char *output = NULL; DEBUG("current sensor type=%s", sensor->friendly_name); for (count = sensor->begin_at;; count++) { path_sensor = g_strdup_printf(sensor->path_format, path_hwmon, count); DEBUG("should be reading from %s", path_sensor); if (!g_file_get_contents(path_sensor, &tmp, NULL, NULL)) { g_free(path_sensor); break; } mon = g_strdup_printf(sensor->key_format, count); name = get_sensor_label(mon); if (!g_str_equal(name, "ignore")) { output = h_strdup_cprintf(sensor->value_format, output, name, driver, adjust_sensor(mon, atof(tmp) / sensor->adjust_ratio)); } g_free(tmp); g_free(mon); g_free(name); g_free(path_sensor); } if (output) { sensors = g_strconcat(sensors, "[", sensor->friendly_name, "]\n", output, "\n", NULL); g_free(output); } } g_free(path_hwmon); g_free(driver); path_hwmon = get_sensor_path(++hwmon, *prefix); } g_free(path_hwmon); } } static void read_sensors_acpi(void) { const gchar *path_tz = "/proc/acpi/thermal_zone"; if (g_file_test(path_tz, G_FILE_TEST_EXISTS)) { ................................................................................ } if (*temp != '\0') sensors = h_strdup_cprintf("\n[ACPI Thermal Zone]\n%s", sensors, temp); g_dir_close(tz); } } } static void read_sensors_sys_thermal(void) { const gchar *path_tz = "/sys/class/thermal"; if (g_file_test(path_tz, G_FILE_TEST_EXISTS)) { GDir *tz; if ((tz = g_dir_open(path_tz, 0, NULL))) { const gchar *entry; gchar *temp = g_strdup(""); while ((entry = g_dir_read_name(tz))) { gchar *path = g_strdup_printf("%s/%s/temp", path_tz, entry); gchar *contents; if (g_file_get_contents(path, &contents, NULL, NULL)) { int temperature; sscanf(contents, "temperature: %d C", &temperature); temp = h_strdup_cprintf("\n%s=%d\302\260C\n", temp, entry, temperature); g_free(contents); } } if (*temp != '\0') sensors = h_strdup_cprintf("\n[ACPI Thermal Zone (sysfs)]\n%s", sensors, temp); g_dir_close(tz); } } } static void read_sensors_omnibook(void) ................................................................................ { g_free(sensors); sensors = g_strdup(""); read_sensors_hwmon(); read_sensors_acpi(); read_sensors_sys_thermal(); read_sensors_omnibook(); read_sensors_hddtemp(); /* FIXME: Add support for ibm acpi and more sensors */ } void sensors_init(void) |