Skip to content

Commit f994602

Browse files
committed
Avoid setting speed when already set to that speed
1 parent ac099c8 commit f994602

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/global.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct s_fans {
1919
char* path; // TODO: unused
2020
char* fan_output_path;
2121
char* fan_manual_path;
22+
int old_speed;
2223
struct s_fans *next;
2324
};
2425

src/mbpfan.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ t_fans *retrieve_fans()
272272
fan = (t_fans *) malloc( sizeof( t_fans ) );
273273
fan->fan_output_path = strdup(path_output);
274274
fan->fan_manual_path = strdup(path_manual);
275+
fan->old_speed = 0;
275276

276277
if (fans_head == NULL) {
277278
fans_head = fan;
@@ -373,13 +374,14 @@ void set_fan_speed(t_fans* fans, int speed)
373374
t_fans *tmp = fans;
374375

375376
while(tmp != NULL) {
376-
if(tmp->file != NULL) {
377+
if(tmp->file != NULL && tmp->old_speed != speed) {
377378
char buf[16];
378379
int len = snprintf(buf, sizeof(buf), "%d", speed);
379380
int res = pwrite(fileno(tmp->file), buf, len, /*offset=*/ 0);
380381
if (res == -1) {
381382
perror("Could not set fan speed");
382383
}
384+
tmp->old_speed = speed;
383385
}
384386

385387
tmp = tmp->next;

0 commit comments

Comments
 (0)