-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfan.c
58 lines (47 loc) · 1.86 KB
/
fan.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#include <errno.h>
#include "util.h"
#include "fan.h"
void stub_set_fan_mode(__attribute__((unused)) const fan_mode_t mode) { return; }
unsigned char stub_get_fan_speed(void) { return 255; }
void stub_set_fan_speed(__attribute__((unused)) const unsigned char speed) { return; }
static void _set_fan_mode(const char* const path, const fan_mode_t mode) {
int ret = file_write_uint(path, mode);
if (ret <= 0) {
fprintf(stderr, "ubnt-fan-speed: [ERR] Failed to write %s = %u (errno = %d, ret = %d)\n", path, mode, errno, ret);
}
}
void legacy_set_fan_mode(const fan_mode_t mode) {
_set_fan_mode("/sys/class/hwmon/hwmon0/pwm1_enable", mode);
}
void set_fan_mode(const fan_mode_t mode) {
_set_fan_mode("/sys/class/hwmon/hwmon0/device/pwm1_enable", mode);
_set_fan_mode("/sys/class/hwmon/hwmon0/device/pwm2_enable", mode);
}
static void _set_fan_speed(const char* const path, const unsigned char speed) {
int ret = file_write_uint(path, speed);
if (ret <= 0) {
fprintf(stderr, "ubnt-fan-speed: [ERR] Failed to write %s = %u (errno = %d, ret = %d)\n", path, speed, errno, ret);
}
}
void legacy_set_fan_speed(const unsigned char speed) {
_set_fan_speed("/sys/class/hwmon/hwmon0/pwm1", speed);
}
void set_fan_speed(const unsigned char speed) {
_set_fan_speed("/sys/class/hwmon/hwmon0/device/pwm1", speed);
_set_fan_speed("/sys/class/hwmon/hwmon0/device/pwm2", speed);
}
static unsigned char _get_fan_speed(const char* const path) {
unsigned int value = 255;
int ret = file_read_uint(path, &value);
if (ret <= 0) {
fprintf(stderr, "ubnt-fan-speed: [ERR] Failed to read %s (errno = %d, ret = %d)\n", path, errno, ret);
}
return value;
}
unsigned char legacy_get_fan_speed(void) {
return _get_fan_speed("/sys/class/hwmon/hwmon0/pwm1");
}
unsigned char get_fan_speed(void) {
return _get_fan_speed("/sys/class/hwmon/hwmon0/device/pwm1");
}