Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
45 changes: 44 additions & 1 deletion core/systems/performance/power_station.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,62 @@ class_name PowerStation
## Proxy interface to PowerStation over DBus
##
## Provides wrapper classes and methods for interacting with PowerStation over
## DBus to control CPU and GPU performance.
## DBus to control CPU and GPU performance and fans.

@export var instance: PowerStationInstance = load("res://core/systems/performance/power_station.tres") as PowerStationInstance

var settings_manager := load("res://core/global/settings_manager.tres") as SettingsManager

# Keep a reference to instances so they are not cleaned up automatically
var _cpu: Cpu
var _fan: Fan
var _gpu: Gpu
var logger := Log.get_logger("PowerStation")


func _ready() -> void:
_cpu = instance.get_cpu()
_fan = instance.get_fan()
_gpu = instance.get_gpu()
instance.started.connect(_load_fan_setting)
settings_manager.setting_changed.connect(_on_setting_changed)


func _on_setting_changed(section: String, _key: String, _value: Variant) -> void:
if section != "fan":
return
_load_fan_setting()


## Loads the fan profile chosen in the "fan" settings section. PowerStation
## does not save fan profiles, so this runs every time PowerStation starts.
func _load_fan_setting() -> void:
if not _fan:
return
var profile := settings_manager.get_value("fan", "profile", "") as String
if profile.is_empty():
return

var result: Error
match profile:
"automatic":
result = _fan.load_profile_json(JSON.stringify({"name": "Automatic", "fans": []}))
"manual":
result = _load_manual_fan_profile()
_:
result = _fan.load_profile(profile)
if result != OK:
logger.warn("Failed to load fan profile '" + profile + "': " + error_string(result))


## Runs every fan at the percentage saved in the "fan" settings section
func _load_manual_fan_profile() -> Error:
var percent := settings_manager.get_value("fan", "manual_percent", 50) as int
var sensors := _fan.get_sensors()
var fans: Array[Dictionary] = []
for id: String in _fan.get_fan_ids():
fans.append({"fan": id, "mode": "manual", "percent": percent, "sensors": sensors})
return _fan.load_profile_json(JSON.stringify({"name": "Manual", "fans": fans}))


func _process(_delta: float) -> void:
Expand Down
15 changes: 15 additions & 0 deletions core/ui/card_ui/quick_bar/fan_card.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[gd_scene load_steps=3 format=3]

[ext_resource type="PackedScene" path="res://core/ui/card_ui/quick_bar/qb_card.tscn" id="1_card"]
[ext_resource type="PackedScene" path="res://core/ui/common/quick_bar/fan_menu.tscn" id="2_menu"]

[node name="FanCard" instance=ExtResource("1_card")]
visible = false
title = "Fan"

[node name="SectionLabel" parent="MarginContainer/CardVBoxContainer" index="0"]
text = "Fan"

[node name="Fan" parent="MarginContainer/CardVBoxContainer/ContentContainer" index="0" instance=ExtResource("2_menu")]
layout_mode = 2
size_flags_vertical = 0
6 changes: 5 additions & 1 deletion core/ui/card_ui/quick_bar/quick_bar_menu.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=30 format=3 uid="uid://hroo3ll4inrb"]
[gd_scene load_steps=31 format=3 uid="uid://hroo3ll4inrb"]

[ext_resource type="Script" uid="uid://3sik128fffg7" path="res://core/ui/card_ui/quick_bar/quick_bar_menu.gd" id="1_56jo7"]
[ext_resource type="PackedScene" uid="uid://shvyhrv5sx3v" path="res://core/systems/state/state_watcher.tscn" id="2_6rvrx"]
Expand Down Expand Up @@ -29,6 +29,7 @@
[ext_resource type="PackedScene" uid="uid://bjy50kdrebgre" path="res://core/ui/card_ui/quick_bar/notifications_card.tscn" id="19_pppbi"]
[ext_resource type="PackedScene" uid="uid://dxaeufuk7ump2" path="res://core/ui/card_ui/quick_bar/quick_settings_card.tscn" id="20_17ks0"]
[ext_resource type="PackedScene" uid="uid://dycb7m0oj13ly" path="res://core/ui/card_ui/quick_bar/performance_card.tscn" id="21_uw510"]
[ext_resource type="PackedScene" path="res://core/ui/card_ui/quick_bar/fan_card.tscn" id="22_fan"]

[node name="QuickBarMenu" type="Control" groups=["quick-bar"]]
z_index = 20
Expand Down Expand Up @@ -235,3 +236,6 @@ layout_mode = 2

[node name="PerformanceCard" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/ScrollContainer/Viewport" instance=ExtResource("21_uw510")]
layout_mode = 2

[node name="FanCard" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/ScrollContainer/Viewport" instance=ExtResource("22_fan")]
layout_mode = 2
74 changes: 74 additions & 0 deletions core/ui/common/quick_bar/fan_menu.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
extends VBoxContainer

## Quick bar menu to choose a PowerStation fan profile
##
## Saves the choice in the "fan" settings section. [PowerStation] loads it.

var power_station := load("res://core/systems/performance/power_station.tres") as PowerStationInstance
var settings_manager := load("res://core/global/settings_manager.tres") as SettingsManager

# Setting value for each dropdown item: "automatic", profile paths, then "manual"
var _profiles := PackedStringArray()

@onready var focus_group := $%FocusGroup as FocusGroup
@onready var profile_dropdown := $%ProfileDropdown as Dropdown
@onready var manual_slider := $%ManualSlider as ValueSlider
@onready var apply_timer := $%ApplyTimer as Timer


func _ready() -> void:
manual_slider.value = settings_manager.get_value("fan", "manual_percent", 50) as int
_update()
power_station.started.connect(_update)
power_station.stopped.connect(_update)
profile_dropdown.item_selected.connect(_on_profile_selected)
manual_slider.value_changed.connect(_on_manual_changed)
apply_timer.timeout.connect(_on_apply_timer_timeout)


## Lists the fan profiles for this device. Hides the card if PowerStation
## cannot control any fans.
func _update() -> void:
var fan := power_station.get_fan()
var has_fans := fan != null and not fan.get_fan_ids().is_empty()
var card := owner as Control
if card:
card.visible = has_fans
if not has_fans:
return

_profiles = PackedStringArray(["automatic"])
_profiles.append_array(fan.get_profiles())
_profiles.append("manual")
profile_dropdown.clear()
for profile: String in _profiles:
profile_dropdown.add_item(_get_label(profile))

var current := settings_manager.get_value("fan", "profile", "automatic") as String
profile_dropdown.select(maxi(_profiles.find(current), 0))
manual_slider.visible = current == "manual"
focus_group.recalculate_focus.call_deferred()


func _get_label(profile: String) -> String:
if profile == "automatic":
return "Automatic"
if profile == "manual":
return "Manual"
return profile.get_file().get_basename().capitalize()


func _on_profile_selected(index: int) -> void:
if index < 0 or index >= _profiles.size():
return
var profile := _profiles[index]
manual_slider.visible = profile == "manual"
settings_manager.set_value("fan", "profile", profile)


func _on_manual_changed(_value: float) -> void:
apply_timer.start()


func _on_apply_timer_timeout() -> void:
settings_manager.set_value("fan", "manual_percent", int(manual_slider.value))
1 change: 1 addition & 0 deletions core/ui/common/quick_bar/fan_menu.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://cpwcj2kv0yv37
32 changes: 32 additions & 0 deletions core/ui/common/quick_bar/fan_menu.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[gd_scene load_steps=6 format=3]

[ext_resource type="Script" path="res://core/ui/common/quick_bar/fan_menu.gd" id="1_fan"]
[ext_resource type="PackedScene" path="res://core/systems/input/focus_group.tscn" id="2_focus"]
[ext_resource type="Resource" path="res://core/ui/card_ui/quick_bar/quick_bar_menu_focus.tres" id="3_stack"]
[ext_resource type="PackedScene" path="res://core/ui/components/dropdown.tscn" id="4_dropdown"]
[ext_resource type="PackedScene" path="res://core/ui/components/slider.tscn" id="5_slider"]

[node name="Fan" type="VBoxContainer"]
anchors_preset = 10
anchor_right = 1.0
grow_horizontal = 2
script = ExtResource("1_fan")

[node name="FocusGroup" parent="." instance=ExtResource("2_focus")]
unique_name_in_owner = true
focus_stack = ExtResource("3_stack")

[node name="ApplyTimer" type="Timer" parent="."]
unique_name_in_owner = true
one_shot = true

[node name="ProfileDropdown" parent="." instance=ExtResource("4_dropdown")]
unique_name_in_owner = true
layout_mode = 2
title = "Fan Profile"

[node name="ManualSlider" parent="." instance=ExtResource("5_slider")]
unique_name_in_owner = true
visible = false
layout_mode = 2
text = "Fan Speed (%)"
1 change: 1 addition & 0 deletions docs/class-reference/.nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ nav:
- ./EventDevice.md
- ./ExpandableCard.md
- ./FadeEffect.md
- ./Fan.md
- ./Feature.md
- ./FeatureFlags.md
- ./FifoReader.md
Expand Down
95 changes: 95 additions & 0 deletions docs/class-reference/Fan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Fan

**Inherits:** [Resource](https://docs.godotengine.org/en/stable/classes/class_resource.html)


## Methods

| Returns | Signature |
| ------- | --------- |
| [String](https://docs.godotengine.org/en/stable/classes/class_string.html) | [get_dbus_path](./#get_dbus_path)() |
| [PackedStringArray](https://docs.godotengine.org/en/stable/classes/class_packedstringarray.html) | [get_fan_ids](./#get_fan_ids)() |
| [String](https://docs.godotengine.org/en/stable/classes/class_string.html) | [get_profile_name](./#get_profile_name)() |
| [String](https://docs.godotengine.org/en/stable/classes/class_string.html) | [get_profile_path](./#get_profile_path)() |
| [PackedStringArray](https://docs.godotengine.org/en/stable/classes/class_packedstringarray.html) | [get_profiles](./#get_profiles)() |
| [PackedStringArray](https://docs.godotengine.org/en/stable/classes/class_packedstringarray.html) | [get_sensors](./#get_sensors)() |
| [int](https://docs.godotengine.org/en/stable/classes/class_int.html) | [load_profile](./#load_profile)(path: [String](https://docs.godotengine.org/en/stable/classes/class_string.html)) |
| [int](https://docs.godotengine.org/en/stable/classes/class_int.html) | [load_profile_json](./#load_profile_json)(json: [String](https://docs.godotengine.org/en/stable/classes/class_string.html)) |


------------------

## Method Descriptions

### `get_dbus_path()`


[String](https://docs.godotengine.org/en/stable/classes/class_string.html) **get_dbus_path**()


!!! note
There is currently no description for this method. Please help us by contributing one!

### `get_fan_ids()`


[PackedStringArray](https://docs.godotengine.org/en/stable/classes/class_packedstringarray.html) **get_fan_ids**()


!!! note
There is currently no description for this method. Please help us by contributing one!

### `get_profile_name()`


[String](https://docs.godotengine.org/en/stable/classes/class_string.html) **get_profile_name**()


!!! note
There is currently no description for this method. Please help us by contributing one!

### `get_profile_path()`


[String](https://docs.godotengine.org/en/stable/classes/class_string.html) **get_profile_path**()


!!! note
There is currently no description for this method. Please help us by contributing one!

### `get_profiles()`


[PackedStringArray](https://docs.godotengine.org/en/stable/classes/class_packedstringarray.html) **get_profiles**()


!!! note
There is currently no description for this method. Please help us by contributing one!

### `get_sensors()`


[PackedStringArray](https://docs.godotengine.org/en/stable/classes/class_packedstringarray.html) **get_sensors**()


!!! note
There is currently no description for this method. Please help us by contributing one!

### `load_profile()`


[int](https://docs.godotengine.org/en/stable/classes/class_int.html) **load_profile**(path: [String](https://docs.godotengine.org/en/stable/classes/class_string.html))


!!! note
There is currently no description for this method. Please help us by contributing one!

### `load_profile_json()`


[int](https://docs.godotengine.org/en/stable/classes/class_int.html) **load_profile_json**(json: [String](https://docs.godotengine.org/en/stable/classes/class_string.html))


!!! note
There is currently no description for this method. Please help us by contributing one!

12 changes: 11 additions & 1 deletion docs/class-reference/PowerStation.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
Proxy interface to PowerStation over DBus
## Description

Provides wrapper classes and methods for interacting with PowerStation over DBus to control CPU and GPU performance.
Provides wrapper classes and methods for interacting with PowerStation over DBus to control CPU and GPU performance and fans.
## Properties

| Type | Name | Default |
| ---- | ---- | ------- |
| [PowerStationInstance](../PowerStationInstance) | [instance](./#instance) | <unknown> |
| [SettingsManager](../SettingsManager) | [settings_manager](./#settings_manager) | <unknown> |
| [CustomLogger](../CustomLogger) | [logger](./#logger) | <unknown> |


Expand All @@ -25,6 +26,15 @@ Provides wrapper classes and methods for interacting with PowerStation over DBus
[PowerStationInstance](../PowerStationInstance) instance


!!! note
There is currently no description for this property. Please help us by contributing one!

### `settings_manager`


[SettingsManager](../SettingsManager) settings_manager


!!! note
There is currently no description for this property. Please help us by contributing one!

Expand Down
10 changes: 10 additions & 0 deletions docs/class-reference/PowerStationInstance.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
| Type | Name | Default |
| ---- | ---- | ------- |
| [Cpu](../Cpu) | [cpu](./#cpu) | |
| [Fan](../Fan) | [fan](./#fan) | |
| [Gpu](../Gpu) | [gpu](./#gpu) | |

## Methods
Expand All @@ -28,6 +29,15 @@
[Cpu](../Cpu) cpu


!!! note
There is currently no description for this property. Please help us by contributing one!

### `fan`


[Fan](../Fan) fan


!!! note
There is currently no description for this property. Please help us by contributing one!

Expand Down
2 changes: 2 additions & 0 deletions extensions/core/src/dbus/powerstation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ pub mod card;
pub mod connector;
pub mod core;
pub mod cpu;
pub mod fan;
pub mod fan_device;
pub mod gpu;
pub mod tdp;
Loading
Loading