Last active
January 13, 2022 15:29
-
-
Save wagyourtail/9062735314ac0fc20347076fed6d740c to your computer and use it in GitHub Desktop.
toggle fan boost for acer predator helios 300 2019 edition, tested on PH315-52-78VL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author Wagyourtail | |
* @version 1.1 | |
* @date 2022-01-13 | |
* @license MIT | |
* | |
* Toggles the fan boost bit | |
*/ | |
#include <fcntl.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
int main(int argc, const char * argv[]) { | |
if (getuid() != 0) { | |
printf("You must be root to run this program\n"); | |
return 1; | |
} | |
// if /sys/kernel/debug/ec/ec0/io doesn't exist, tell the user to run the following command | |
// modprobe -r ec_sys | |
// modprobe ec_sys write_support=1 | |
if (access("/sys/kernel/debug/ec/ec0/io", F_OK) == -1) { | |
printf("You must run the following commands to enable writing to the EC:\n"); | |
printf("modprobe -r ec_sys\n"); | |
printf("modprobe ec_sys write_support=1\n"); | |
return 1; | |
} | |
// open /sys/kernel/debug/ec/ec0/io to read/write the fan boost bit | |
int fd = open("/sys/kernel/debug/ec/ec0/io", O_RDWR); | |
if (fd < 0) { | |
perror("open"); | |
return 1; | |
} | |
// read the current value of the fan boost bit (0x40 bit of the 0xF5 byte) | |
char buf[1]; | |
pread(fd, buf, 1, 0xF5); | |
if (buf[0] & 0x40) { | |
printf("Fan boost is currently on (0x%02x)\n", buf[0]); | |
} else { | |
printf("Fan boost is currently off (0x%02x)\n", buf[0]); | |
} | |
printf("Toggling fan boost...\n"); | |
// toggle the fan boost bit | |
buf[0] ^= 0x40; | |
pwrite(fd, buf, 1, 0xF5); | |
// read the current value of the fan boost bit (0x40 bit of the 0xF5 byte) | |
pread(fd, buf, 1, 0xF5); | |
if (buf[0] & 0x40) { | |
printf("Fan boost is now on (0x%02x)\n", buf[0]); | |
} else { | |
printf("Fan boost is now off (0x%02x)\n", buf[0]); | |
} | |
close(fd); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment