Skip to content

Commit

Permalink
Allow applying fan curve from tray.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfan committed Aug 27, 2023
1 parent 6bdbbb7 commit 644ac89
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
4 changes: 0 additions & 4 deletions python/legion_linux/legion_linux/legion.py
Original file line number Diff line number Diff line change
Expand Up @@ -1515,7 +1515,3 @@ def run_monitors(self, period_s):
time.sleep(period_s)
except KeyboardInterrupt:
print('Monitor Interrupted!')


# def start_rpc(legion_facade):
# jsonrpyc.RPC(legion_facade)
54 changes: 54 additions & 0 deletions python/legion_linux/legion_linux/legion_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,35 @@ def update_view_from_feature(self):
log_error(ex)


class PresetTrayController:
action: List[QAction]
model: LegionModelFacade
dependent_controllers: List

def __init__(self, model: LegionModelFacade, actions: List[QAction]):
self.actions = actions
self.model = model
self.dependent_controllers = []
self.update_view_from_feature()

def update_view_from_feature(self):
for i, action in enumerate(self.actions):
name = list(self.model.fancurve_repo.get_names())[i]
action.setText(f"Apply preset {name}")
action.setCheckable(False)
action.setDisabled(not self.model.fancurve_repo.does_exists_by_name(name))

# Connect function to set respective preset and
# take current value of name into closure
def callback(_, pname = name):
self.on_action_click(pname)
action.triggered.connect(callback)

def on_action_click(self, name):
log.info("Setting preset %s from tray action", name)
self.model.fancurve_write_preset_to_hw(name)


def set_dependent(controller1, controller2):
controller1.dependent_controllers.append(controller2)
controller2.dependent_controllers.append(controller1)
Expand Down Expand Up @@ -481,6 +510,7 @@ class LegionController:
# tray
batteryconservation_tray_controller: BoolFeatureTrayController
rapid_charging_tray_controller: BoolFeatureTrayController
preset_tray_controller: PresetTrayController

def __init__(self, app:QApplication, expect_hwmon=True, use_legion_cli_to_write=False):
self.model = LegionModelFacade(
Expand Down Expand Up @@ -651,6 +681,16 @@ def init_tray(self):
self.rapid_charging_tray_controller)
self.rapid_charging_tray_controller.update_view_from_feature()

self.preset_tray_controller = PresetTrayController(self.model,
[self.tray.preset1_action,
self.tray.preset2_action,
self.tray.preset3_action,
self.tray.preset4_action,
self.tray.preset5_action,
self.tray.preset6_action,
self.tray.preset7_action,
self.tray.preset8_action])

def update_fan_additional_gui(self):
self.lockfancontroller_controller.update_view_from_feature()
self.maximumfanspeed_controller.update_view_from_feature()
Expand Down Expand Up @@ -1409,6 +1449,20 @@ def __init__(self, icon, main_window:QMainWindow, controller:LegionController):
self.menu.addAction(self.rapid_charging_action)
# ---
self.menu.addSeparator()
def add_preset_action():
act = QAction("Preset")
self.menu.addAction(act)
return act
self.preset1_action = add_preset_action()
self.preset2_action = add_preset_action()
self.preset3_action = add_preset_action()
self.preset4_action = add_preset_action()
self.preset5_action = add_preset_action()
self.preset6_action = add_preset_action()
self.preset7_action = add_preset_action()
self.preset8_action = add_preset_action()
# ---
self.menu.addSeparator()
self.star_action = QAction(
"Help giving a star to the github repo (click here)")
self.star_action.triggered.connect(open_star_link)
Expand Down

0 comments on commit 644ac89

Please sign in to comment.