Giter Club home page Giter Club logo

tpfancontrol-rs's Introduction

tpfancontrol-rs is a Linux TUI clone of troubadix's TPFanControl. It uses the sysfs interface exposed by the thinkpad_acpi kernel module to allow you to monitor and control the temperature and fan speeds of your Thinkpad.

Installation

  • To install from the Github repository directly, run:

     cargo install --git 'https://github.com/Arnavion/tpfancontrol-rs'

    This will compile the tpfancontrol binary and put it in ~/.cargo/bin/

  • Alternatively, clone this repo, then run:

     cargo build --release

    This will compile the tpfancontrol binary and put it in ./target/release/

Usage

  1. Ensure the thinkpad_acpi module has been loaded by the kernel.

    $ lsmod | grep '^thinkpad_acpi'
    
    thinkpad_acpi    122880 0
  2. Enable the fan_control=1 option for the module and reload the module.

    $ echo 'options thinkpad_acpi fan_control=1' | sudo tee /etc/modprobe.d/98-thinkpad_acpi.conf
    
    options thinkpad_acpi fan_control=1
    
    $ sudo modprobe -r thinkpad_acpi
    
    $ sudo modprobe thinkpad_acpi
    
    $ lsmod | grep '^thinkpad_acpi'
    
    thinkpad_acpi    122880 0

    If unloading the module fails, it's easiest and safest to just reboot.

  3. Copy the config.toml.example file in this repository to /etc/tpfancontrol/config.toml and edit it to match the sensors of your Thinkpad. This file contains custom names for the temperature sensors and a mapping of temperature to fan level.

    To discover the sensor numbers, find the hwmon node and enumerate the temp*_input files inside it. For example:

    $ grep -H 'thinkpad' /sys/class/hwmon/hwmon*/name
    
    /sys/class/hwmon/hwmon2/name:thinkpad
    
    $ ls -1 /sys/class/hwmon/hwmon2/temp*_input
    
    /sys/class/hwmon/hwmon2/temp1_input
    /sys/class/hwmon/hwmon2/temp2_input
    /sys/class/hwmon/hwmon2/temp3_input
    ...

    This means you have sensors numbered 1, 2, 3, and so on. Add them to the config file so tpfancontrol can monitor them. The names for the sensors are completely arbitrary and only used for display purposes, so you can name them whatever you like.

    (Note: It looks like some Thinkpads don't report any temperature sensors via the thinkpad_acpi module. See this issue for discussion.)

  4. Run the tpfancontrol binary that you compiled above.

    To allow the program to modify the fan speed, it must be run as root, such as with sudo. If the program is run as an unprivileged user, it cannot adjust the fan speed because the hwmon interface is only writable by root. In this case the program will not adjust the fan speed based on the temperature, and the manual controls for changing the fan speed will also be locked.

Notes

  • SMART mode does not have hysteresis. The fan speed will fluctuate when the temperature is near the boundary between two mappings. As a workaround, change your mapping so that the stable temperature of your Thinkpad is not near a boundary.

tpfancontrol-rs's People

Contributors

arnavion avatar smhmd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tpfancontrol-rs's Issues

Setup

What I did:

$ hub clone --depth 1 Arnavion/tpfancontrol-rs && cd tpfancontrol-rs/
$ cargo build # sudo ?
$ sudo mkdir /etc/tpfancontrol
$ sudo cp config.toml.example /etc/tpfancontrol/config.toml
$ cargo run # ran with error
$ sudo cargo run # ran with error as well

error:

Finished dev [unoptimized + debuginfo] target(s) in 0.03s
     Running `target/debug/tpfancontrol`
Error: sysfs error with /sys/class/hwmon/hwmon2/temp1_input: No such file or directory (os error 2)

Do I need to modify something in the conf file other than thresholds?

I'm not familiar with Rust; hopefully, I'm not doing something obviously wrong.

If I wanted to start tpfancontrol-rs on boot or login, should I run cargo run in the directory or there is a binary I'm missing? (could not find anything in ~/.cargo/bin)

Run on start using systemd

I have created systemd service:

[Unit]
Description=tpfancontrol-rs

[Service]
Type=oneshot
User=root
Environment="RUST_BACKTRACE=1"
ExecStart=/home/kobi/github/tpfancontrol-rs/target/release/tpfancontrol &

[Install]
WantedBy=multi-user.target

however service fails with:

● tpfancontrol-rs.service - tpfancontrol-rs
     Loaded: loaded (/etc/systemd/system/tpfancontrol-rs.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Mon 2021-03-15 11:54:24 CET; 5min ago
    Process: 65399 ExecStart=/home/kobi/github/tpfancontrol-rs/target/release/tpfancontrol & (code=exited, status=101)
   Main PID: 65399 (code=exited, status=101)

bře 15 11:54:24 pop-os tpfancontrol[65399]:    2: core::result::unwrap_failed
bře 15 11:54:24 pop-os tpfancontrol[65399]:              at ./build/rustc-n7HJ8w/rustc-1.47.0+dfsg1+llvm/library/core/src/result.rs:1220
bře 15 11:54:24 pop-os tpfancontrol[65399]:    3: cursive::backend::termion::Backend::init
bře 15 11:54:24 pop-os tpfancontrol[65399]:    4: cursive::cursive::Cursive::termion
bře 15 11:54:24 pop-os tpfancontrol[65399]:    5: tpfancontrol::main
bře 15 11:54:24 pop-os tpfancontrol[65399]: note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
bře 15 11:54:24 pop-os tpfancontrol[65399]: [6B blob data]
bře 15 11:54:24 pop-os systemd[1]: tpfancontrol-rs.service: Main process exited, code=exited, status=101/n/a
bře 15 11:54:24 pop-os systemd[1]: tpfancontrol-rs.service: Failed with result 'exit-code'.
bře 15 11:54:24 pop-os systemd[1]: Failed to start tpfancontrol-rs.

Can you please help me to run the binary at boot using systemd?

Doesn't build

mismatched types
--> /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive-0.10.0/src/backend/termion.rs:222:46
|
222 | let terminal = AlternateScreen::from(MouseTerminal::from(
| _____________________________________^
223 | | ::std::io::stdout().into_raw_mode().unwrap(),
224 | | ));
| |
^ expected struct AlternateScreen, found struct MouseTerminal
|
= note: expected struct AlternateScreen<_>
found struct MouseTerminal<RawTerminal<Stdout>>

For more information about this error, try rustc --explain E0308.
error: could not compile cursive due to previous error
warning: build failed, waiting for other jobs to finish...

Non-hardcoded temperature files

Invoking sudo tpfancontrol errors out:

Error: sysfs error with /sys/class/hwmon/hwmon2/temp1_input: No such file or directory (os error 2)

I don't understand the function of these monitors, but I'm pretty sure the better way to find these paths is to do:

$ find /sys/devices -type f -name "temp*_input"

In my device, the output is:

/sys/devices/platform/coretemp.0/hwmon/hwmon3/temp3_input
/sys/devices/platform/coretemp.0/hwmon/hwmon3/temp1_input
/sys/devices/platform/coretemp.0/hwmon/hwmon3/temp2_input
/sys/devices/virtual/thermal/thermal_zone0/hwmon0/temp1_input
/sys/devices/virtual/thermal/thermal_zone0/hwmon0/temp2_input

Thinkfan makes you include these in your config file, for instance. Other tools find them on their own.

My device is a ThinkPad L540 running Artix Linux using runit for init.

fan level not linked to fan speed

First of all: Well done, great tool! However, I have problems with mapping the fan levels.
At level = 0, the fan speed is ~2000 rpm, where the fan should actually be off, and for any level higher than 0, it is constantly 2400 rpm.
Any idea why this is?
I am running Linux Mint 20.2 (with Kernel 5.13.0-21) on a Thinkpad T495s.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.