| | 396 | int sensors_read_sysfs_attr(sensors_chip_name name, int feature, double *value) |
| | 397 | { |
| | 398 | const sensors_chip_feature *the_feature; |
| | 399 | int mag; |
| | 400 | char n[NAME_MAX]; |
| | 401 | FILE *f; |
| | 402 | int dummy; |
| | 403 | char check; |
| | 404 | const char *suffix = ""; |
| | 405 | |
| | 406 | if (!(the_feature = sensors_lookup_feature_nr(&name, feature))) |
| | 407 | return -SENSORS_ERR_NO_ENTRY; |
| | 408 | |
| | 409 | /* REVISIT: this is a ugly hack */ |
| | 410 | if (sscanf(the_feature->data.name, "in%d%c", &dummy, &check) == 1 |
| | 411 | || sscanf(the_feature->data.name, "fan%d%c", &dummy, &check) == 1 |
| | 412 | || sscanf(the_feature->data.name, "temp%d%c", &dummy, &check) == 1) |
| | 413 | suffix = "_input"; |
| | 414 | |
| | 415 | snprintf(n, NAME_MAX, "%s/%s%s", name.busname, the_feature->data.name, |
| | 416 | suffix); |
| | 417 | if ((f = fopen(n, "r"))) { |
| | 418 | int res = fscanf(f, "%lf", value); |
| | 419 | fclose(f); |
| | 420 | if (res != 1) |
| | 421 | return -SENSORS_ERR_PROC; |
| | 422 | for (mag = the_feature->scaling; mag > 0; mag --) |
| | 423 | *value /= 10.0; |
| | 424 | } else |
| | 425 | return -SENSORS_ERR_PROC; |
| | 426 | |
| | 427 | return 0; |
| | 428 | } |
| | 429 | |
| | 430 | int sensors_write_sysfs_attr(sensors_chip_name name, int feature, double value) |
| | 431 | { |
| | 432 | const sensors_chip_feature *the_feature; |
| | 433 | int mag; |
| | 434 | char n[NAME_MAX]; |
| | 435 | FILE *f; |
| | 436 | int dummy; |
| | 437 | char check; |
| | 438 | const char *suffix = ""; |
| | 439 | |
| | 440 | if (!(the_feature = sensors_lookup_feature_nr(&name, feature))) |
| | 441 | return -SENSORS_ERR_NO_ENTRY; |
| | 442 | |
| | 443 | /* REVISIT: this is a ugly hack */ |
| | 444 | if (sscanf(the_feature->data.name, "in%d%c", &dummy, &check) == 1 |
| | 445 | || sscanf(the_feature->data.name, "fan%d%c", &dummy, &check) == 1 |
| | 446 | || sscanf(the_feature->data.name, "temp%d%c", &dummy, &check) == 1) |
| | 447 | suffix = "_input"; |
| | 448 | |
| | 449 | snprintf(n, NAME_MAX, "%s/%s%s", name.busname, the_feature->data.name, |
| | 450 | suffix); |
| | 451 | if ((f = fopen(n, "w"))) { |
| | 452 | for (mag = the_feature->scaling; mag > 0; mag --) |
| | 453 | value *= 10.0; |
| | 454 | fprintf(f, "%d", (int) value); |
| | 455 | fclose(f); |
| | 456 | } else |
| | 457 | return -SENSORS_ERR_PROC; |
| | 458 | |
| | 459 | return 0; |
| | 460 | } |