Skip to content

Commit b9a704b

Browse files
committed
Avoid setting speed when already set to that speed
1 parent 237eae7 commit b9a704b

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
@@ -273,6 +273,7 @@ t_fans *retrieve_fans()
273273
fan = (t_fans *) malloc( sizeof( t_fans ) );
274274
fan->fan_output_path = strdup(path_output);
275275
fan->fan_manual_path = strdup(path_manual);
276+
fan->old_speed = 0;
276277

277278
if (fans_head == NULL) {
278279
fans_head = fan;
@@ -374,10 +375,11 @@ void set_fan_speed(t_fans* fans, int speed)
374375
t_fans *tmp = fans;
375376

376377
while(tmp != NULL) {
377-
if(tmp->file != NULL) {
378+
if(tmp->file != NULL && tmp->old_speed != speed) {
378379
char buf[16];
379380
int len = snprintf(buf, sizeof(buf), "%d", speed);
380381
pwrite(fileno(tmp->file), buf, len, /*offset=*/ 0);
382+
tmp->old_speed = speed;
381383
}
382384

383385
tmp = tmp->next;

0 commit comments

Comments
 (0)