diff --git a/src/global.h b/src/global.h
index 19db7c1..9f73014 100644
--- a/src/global.h
+++ b/src/global.h
@@ -19,6 +19,7 @@ struct s_fans {
char* path; // TODO: unused
char* fan_output_path;
char* fan_manual_path;
+ int old_speed;
struct s_fans *next;
};
diff --git a/src/mbpfan.c b/src/mbpfan.c
index 8a4ac1e..1a7d385 100644
--- a/src/mbpfan.c
+++ b/src/mbpfan.c
@@ -272,6 +272,7 @@ t_fans *retrieve_fans()
fan = (t_fans *) malloc( sizeof( t_fans ) );
fan->fan_output_path = strdup(path_output);
fan->fan_manual_path = strdup(path_manual);
+ fan->old_speed = 0;
if (fans_head == NULL) {
fans_head = fan;
@@ -373,13 +374,14 @@ void set_fan_speed(t_fans* fans, int speed)
t_fans *tmp = fans;
while(tmp != NULL) {
- if(tmp->file != NULL) {
+ if(tmp->file != NULL && tmp->old_speed != speed) {
char buf[16];
int len = snprintf(buf, sizeof(buf), "%d", speed);
int res = pwrite(fileno(tmp->file), buf, len, /*offset=*/ 0);
if (res == -1) {
perror("Could not set fan speed");
}
+ tmp->old_speed = speed;
}
tmp = tmp->next;
Avoid setting speed when already set to that speed
e58a67f630c2d22370381aabbac3fe47da6b87d1
Andrew Gaul <andrew@gaul.org> · 2017-07-14T02:30 ·
browse files at this commit
parents:
ac099c8