Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebase Packaging/nix #77

Merged
merged 28 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9b9e9c7
Adding @Svenum as an assignee to nix-related issues (#43)
leopoldhub Jun 1, 2024
a8755fe
Fixing adding @Svenum as an assignee to nix-related issues (#44)
leopoldhub Jun 1, 2024
1bc4f60
Reload will report if config couldn't be parsed and the service keeps…
NAKlama Jun 6, 2024
d6e6186
Removing binary blobs from the project (#51)
leopoldhub Jun 21, 2024
6fa5e64
Fix README spelling/grammer, fix "FrameWork" capitalization in servic…
DeflateAwning Jun 27, 2024
dc6558e
Clarify behaviour on service stop or pause (#53) (#55)
leopoldhub Jul 6, 2024
d4b45c6
Separating FanController into different subclasses to allow HardwareC…
leopoldhub Jul 26, 2024
fcc85b2
fixing missing print for command execution (#63)
leopoldhub Aug 1, 2024
c9a57de
forcing utf-8 encoding for socket messages and usage of stopServerSoc…
leopoldhub Aug 9, 2024
2ef31c1
README.md documentation update (#65)
leopoldhub Aug 13, 2024
871566f
Command arguments refactoring Pt.1 (#66)
leopoldhub Aug 13, 2024
b4f87b6
finishing touches (#67)
leopoldhub Aug 13, 2024
80a239d
add no battery mode for mainboards without battery (#69)
saizo80 Aug 18, 2024
cc65f26
adding ectool sub-dependency to documentation (#70)
leopoldhub Aug 18, 2024
88590e3
typo "tempurature" => "temperature" (#71)
leopoldhub Aug 18, 2024
6d2d3de
typo "tempurature" => "temperature" (#72)
leopoldhub Aug 18, 2024
ec9a9ae
Add ToC + link to NixOS Documentation (#75)
Svenum Aug 24, 2024
fe98b44
add --no-sudo option (#76)
Svenum Aug 24, 2024
4a8a3a0
Add choice to print fan speed percentage (#78)
Speenah Aug 24, 2024
2a9828f
add missing no_sudo check (#79)
Svenum Aug 25, 2024
8446f9d
Add NixOS Flake (#26)
Svenum Jun 1, 2024
40f7b68
Update branch to main branch (#54)
Svenum Jun 30, 2024
56b86fa
Update to main branch + switch to fw-ectool (#61)
Svenum Aug 3, 2024
a3685fd
add doc + .gitignore
Svenum Aug 24, 2024
c2245bb
Add NixOS Flake (#26)
Svenum Jun 1, 2024
a3526c0
Update branch to main branch (#54)
Svenum Jun 30, 2024
1f2ccb7
Update to main branch + switch to fw-ectool (#61)
Svenum Aug 3, 2024
9a6bf4a
Merge branch 'packaging/nix' into packaging/nix
Svenum Aug 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report---packaging-windows.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
name: Bug report | packaging/windows
about: Report a bug involving the windows packaging
title: "[BUG] [packaging/windows]"
labels: bug, packaging/windows
assignees: 'leopoldhub'

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Error message**
```txt
If applicable, add the full error message.
```

**Environment (please complete the following information):**
- OS: [e.g. Windows 11]
- Version [e.g. commit 176d34b]
- Configuration file [config.json]

**Additional context**
Add any other context about the problem here.
178 changes: 89 additions & 89 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,111 +1,111 @@
# fw-fanctrl

This is a simple Python service for Linux that drives Framework Laptop's fan(s) speed according to a configurable speed/temp curve.
Its default configuration targets very silent fan operation, but it's easy to configure it for a different comfort/performance trade-off.
Its possible to specify two separate fan curves depending on whether the Laptop is charging/discharging.
Under the hood, it uses [ectool](https://gitlab.howett.net/DHowett/ectool) to change parameters in Framework's embedded controller (EC).
[![Static Badge](https://img.shields.io/badge/Linux%2FGlobal-FCC624?style=flat&logo=linux&logoColor=FFFFFF&label=Platform&link=https%3A%2F%2Fgithub.com%2FTamtamHero%2Ffw-fanctrl%2Ftree%2Fmain)](https://github.com/TamtamHero/fw-fanctrl/tree/main)
![Static Badge](https://img.shields.io/badge/no%20binary%20blobs-30363D?style=flat&logo=GitHub-Sponsors&logoColor=4dff61)

It is compatible with all kinds of 13" and 16" models, both AMD/Intel CPUs, with or without a discrete GPU.
[![Static Badge](https://img.shields.io/badge/Python__3.12-FFDE57?style=flat&label=Requirement&link=https%3A%2F%2Fwww.python.org%2Fdownloads)](https://www.python.org/downloads)

## Additional platforms:

[![Static Badge](https://img.shields.io/badge/NixOS-5277C3?style=flat&logo=nixos&logoColor=FFFFFF&label=Platform&link=https%3A%2F%2Fgithub.com%2FTamtamHero%2Ffw-fanctrl%2Ftree%2Fpackaging%2Fnix)](https://github.com/TamtamHero/fw-fanctrl/tree/packaging/nix/doc/nix-flake.md)

## Description

Fw-fanctrl is a simple Python CLI service that controls Framework Laptop's fan(s)
speed according to a configurable speed/temperature curve.

Its default strategy aims for very quiet fan operation, but you can choose amongst the other provided strategies, or
easily configure your own for a different comfort/performance trade-off.

It also is possible to assign separate strategies depending on whether the laptop is charging or discharging.

Under the hood, it uses [ectool](https://gitlab.howett.net/DHowett/ectool)
to change parameters in Framework's embedded controller (EC).

It is compatible with all 13" and 16" models, both AMD/Intel CPUs, with or without a discrete GPU.

If the service is paused or stopped, the fans will revert to their default behaviour.

# Install
For NixOS this repo contains an Flake. You could add it to your config like this:

```nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
fw-fanctrl = {
url = "github:TamtamHero/fw-fanctrl/packaging/nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {nixpkgs, fw-fanctrl}: {
nixosConfigurations.foo = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
fw-fanctrl.nixosModules.default
configuration.nix
];
};
}
}
```
and then add in your *configuration.nix*:
```nix
# Enable fw-fanctrl
programs.fw-fanctrl.enable = true;

# Add a custom config
programs.fw-fanctrl.config = {
defaultStrategy = "lazy";
strategies = {
"lazy" = {
fanSpeedUpdateFrequency = 5;
movingAverageInterval = 30;
speedCurve = [
{ temp = 0; speed = 15; }
{ temp = 50; speed = 15; }
{ temp = 65; speed = 25; }
{ temp = 70; speed = 35; }
{ temp = 75; speed = 50; }
{ temp = 85; speed = 100; }
];
};
};
};

# Add a custom config from an existing JSON file
programs.fw-fanctrl.config = builtins.fromJSON (builtins.readFile ./config.json)

# Or just change the default strategy form the default config
programs.fw-fanctrl.config.defaultStrategy = "medium";
```
## Table of Content

Non NixOS install is described [here](https://github.com/TamtamHero/fw-fanctrl/blob/main/README.md#Install)
- [Documentation](#documentation)
- [Installation](#installation)
* [Requirements](#requirements)
* [Dependencies](#dependencies)
* [Instructions](#instructions)
- [Update](#update)
- [Uninstall](#uninstall)

## Documentation

# Configuration
More documentation could be found [here](./doc/README.md).

The default config contains different strategies, ranked from the most silent to the noisiest. It is possible to specify two different strategies for charging/discharging allowing for different optimization goals.
On discharging one could have fan curve optimized for low fan speeds in order to save power while accepting a bit more heat.
On charging one could have a fan curve that focuses on keeping the CPU from throttling and the system cool, at the expense of fan noise.
You can add new strategies, and if you think you have one that deserves to be shared, feel free to make a PR to this repo :)
## Installation

Strategies can be configured with the following parameters:
### Other Platforms
| name | branch | documentation |
|-------|---------------|---------------|
| NixOS | [packaging/nix](https://github.com/TamtamHero/fw-fanctrl/tree/packaging/nix) | [packaging/nix/doc/nix-flake](https://github.com/TamtamHero/fw-fanctrl/tree/packaging/nix/doc/nix-flake.md) |

- **SpeedCurve**:
### Requirements

This is the curve points for `f(temperature) = fan speeds`
| name | version | url |
|--------|---------|----------------------------------------------------------------------|
| Python | 3.12.x | [https://www.python.org/downloads](https://www.python.org/downloads) |

`fw-fanctrl` measures the CPU temperature, compute a moving average of it, and then find an appropriate `fan speed` value by interpolation on the curve.
### Dependencies

- **FanSpeedUpdateFrequency**:
Dependencies are downloaded and installed automatically, but can be excluded from the installation script if you wish to
do this manually.

Time interval between every update to the fan's speed. `fw-fanctrl` measures temperature every second and add it to its moving average, but the actual update to fan speed is controlled using this configuration. This is for comfort, otherwise the speed is changed too often and it is noticeable and annoying, especially at low speed.
For a more reactive fan, you can lower this setting. **Defaults to 5 seconds.**
| name | version | url | sub-dependencies | exclusion argument |
|----------------|-----------|--------------------------------------------------------------------------------------|------------------|--------------------|
| DHowett@ectool | build#899 | [https://gitlab.howett.net/DHowett/ectool](https://gitlab.howett.net/DHowett/ectool) | libftdi | `--no-ectool` |

- **MovingAverageInterval**:
### Instructions

Number of seconds on which the moving average of temperature is computed. Increase it, and the fan speed will change more gradually. Lower it, and it will gain in reactivity. **Defaults to 20 seconds.**
First, make sure that you have disabled secure boot in your BIOS/UEFI settings.
(more details on why [here](https://www.howett.net/posts/2021-12-framework-ec/#using-fw-ectool))

## Charging/Discharging strategies
[Download the repo](https://github.com/TamtamHero/fw-fanctrl/archive/refs/heads/main.zip) and extract it manually, or
download/clone it with the appropriate tools:

The strategy active by default is the one specified in the `defaultStrategy` entry. Optionally a separate strategy only active during discharge can be defined, using the `strategyOnDischarging` entry. By default no extra strategy for discharging is provided, the default strategy is active during all times.
```shell
git clone "https://github.com/TamtamHero/fw-fanctrl.git"
```

# Commands
```shell
curl -L "https://github.com/TamtamHero/fw-fanctrl/archive/refs/heads/main.zip" -o "./fw-fanctrl.zip" && unzip "./fw-fanctrl.zip" -d "./fw-fanctrl" && rm -rf "./fw-fanctrl.zip"
```

Then run the installation script with administrator privileges

```bash
sudo ./install.sh
```

You can add a number of arguments to the installation command to suit your needs

| argument | description |
|---------------------------------------------------------------------------------|----------------------------------------------------|
| `--dest-dir <installation destination directory (defaults to /)>` | specify an installation destination directory |
| `--prefix-dir <installation prefix directory (defaults to /usr)>` | specify an installation prefix directory |
| `--sysconf-dir <system configuration destination directory (defaults to /etc)>` | specify a default configuration directory |
| `--no-ectool` | disable ectool installation and service activation |
| `--no-post-install` | disable post-install process |
| `--no-pre-uninstall` | disable pre-uninstall process |
| `--no-battery-sensors` | disable checking battery temperature sensors |

## Update

To update, you can download or pull the appropriate branch from this repository, and run the installation script again.

## Uninstall

To uninstall, run the installation script with the `--remove` argument, as well as other
corresponding [arguments if necessary](#instructions)

```bash
sudo ./install.sh --remove
```

| Option | Context | Description |
|-----------------------------|-----------------|-------------------------------------------------------------------------------|
| \<strategy> | run & configure | the name of the strategy to use |
| --run | run | run the service |
| --config | run | specify the configuration path |
| --no-log | run | disable state logging |
| --query, -q | configure | print the current strategy name |
| --list-strategies | configure | print the available strategies |
| --reload, -r | configure | reload the configuration file |
| --pause | configure | temporarily disable the service and reset the fans to their default behaviour |
| --resume | configure | resume the service |
| --hardware-controller, --hc | run | select the hardware controller. choices: ectool |
| --socket-controller, --sc | run & configure | select the socket controller. choices: unix |
6 changes: 6 additions & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Table of Content

- [Default Installation](../README.md#installation)
- [NixOS Flake](https://github.com/TamtamHero/fw-fanctrl/tree/packaging/nix/doc/nix-flake.md)
- [Commands](./commands.md)
- [Configuration](./configuration.md)
68 changes: 68 additions & 0 deletions doc/commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Commands

Here is a list of commands and options used to interact with the service.

the base of all commands is the following

```shell
fw-fanctrl [commands and options]
```

First, the global options

| Option | Optional | Choices | Default | Description |
|---------------------------|----------|---------|---------|--------------------------------------------------------------------------------|
| --socket-controller, --sc | yes | unix | unix | the socket controller to use for communication between the cli and the service |

**run**

run the service manually

If you have installed it correctly, the systemd `fw-fanctrl.service` service will do this for you, so you probably will
never need those.

| Option | Optional | Choices | Default | Description |
|-----------------------------|----------|----------------|----------------------|-----------------------------------------------------------------------------------|
| \<strategy> | yes | | the default strategy | the name of the strategy to use |
| --config | yes | \[CONFIG_PATH] | | the configuration file path |
| --silent, -s | yes | | | disable printing speed/temp status to stdout |
| --hardware-controller, --hc | yes | ectool | ectool | the hardware controller to use for fetching and setting the temp and fan(s) speed |
| --no-battery-sensors | yes | | | disable checking battery temperature sensors (for mainboards without batteries) |

**use**

change the current strategy

| Option | Optional | Description |
|-------------|----------|---------------------------------|
| \<strategy> | no | the name of the strategy to use |

**reset**

reset to the default strategy

**reload**

reload the configuration file

**pause**

pause the service

**resume**

resume the service

**print**

print the selected information

| Option | Optional | Choices | Default | Description |
|--------------------|----------|----------------------|---------|------------------------|
| \<print_selection> | yes | current, list, speed | current | what should be printed |

| Choice | Description |
|---------|----------------------------------|
| current | The current strategy being used |
| list | List available strategies |
| speed | The current fan speed percentage |
Loading