Automatically disable jupiter-fan-control when Fantastic is enabled

This commit is contained in:
NGnius (Graham) 2022-05-27 20:52:32 -04:00
parent 10c66f00c0
commit 4458092c3d
2 changed files with 53 additions and 19 deletions

54
main.py
View file

@ -3,6 +3,7 @@ import os
import asyncio import asyncio
import time import time
import pathlib import pathlib
import subprocess
HOME_DIR = str(pathlib.Path(os.getcwd()).parent.parent.resolve()) HOME_DIR = str(pathlib.Path(os.getcwd()).parent.parent.resolve())
@ -38,10 +39,12 @@ class Plugin:
settings = None settings = None
is_changed = False is_changed = False
plot_width = 1; plot_width = 1
plot_height = 1; plot_height = 1
period_s = 1.0; period_s = 1.0
jupiter_fan_control_was_disabled = False
async def set_curve(self, curve): async def set_curve(self, curve):
await self.wait_for_ready(self) await self.wait_for_ready(self)
@ -78,7 +81,7 @@ class Plugin:
async def set_enable(self, enable: bool): async def set_enable(self, enable: bool):
await self.wait_for_ready(self) await self.wait_for_ready(self)
self.settings["enable"] = enable self.settings["enable"] = enable
on_set_enable(enable) self.on_set_enable(self)
self.is_changed = True self.is_changed = True
async def get_enable(self) -> bool: async def get_enable(self) -> bool:
@ -108,10 +111,39 @@ class Plugin:
async def set_poll_period(self, period): async def set_poll_period(self, period):
self.period_s = period self.period_s = period
def on_set_enable(self):
if self.settings["enable"]:
self.disable_jupiter_fan_control(self)
on_enable()
else:
self.enable_jupiter_fan_control(self)
on_disable()
def disable_jupiter_fan_control(self):
active = subprocess.Popen(["systemctl", "is-active", "jupiter-fan-control.service"]).wait() == 0
if active:
logging.info("Stopping jupiter-fan-control.service so it doesn't interfere")
# only disable if currently active
self.jupiter_fan_control_was_disabled = True
stop_p = subprocess.Popen(["systemctl", "stop", "jupiter-fan-control.service"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stop_p.wait()
logging.debug("systemctl stop jupiter-fan-control.service stdout:\n" + stop_p.stdout.read().decode())
logging.debug("systemctl stop jupiter-fan-control.service stderr:\n" + stop_p.stderr.read().decode())
def enable_jupiter_fan_control(self):
if self.jupiter_fan_control_was_disabled:
logging.info("Starting jupiter-fan-control.service so it doesn't interfere")
# only re-enable if I disabled it
self.jupiter_fan_control_was_disabled = False
start_p = subprocess.Popen(["systemctl", "start", "jupiter-fan-control.service"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
start_p.wait()
logging.debug("systemctl start jupiter-fan-control.service stdout:\n" + start_p.stdout.read().decode())
logging.debug("systemctl start jupiter-fan-control.service stderr:\n" + start_p.stderr.read().decode())
def save(self): def save(self):
if not os.path.exists(DATA_SAVE_FOLDER): if not os.path.exists(DATA_SAVE_FOLDER):
os.mkdir(DATA_SAVE_FOLDER) os.mkdir(DATA_SAVE_FOLDER)
with open(DATA_SAVE_PATH, "w") as data_file : with open(DATA_SAVE_PATH, "w") as data_file:
json.dump(self.settings, data_file) json.dump(self.settings, data_file)
async def wait_for_ready(self): async def wait_for_ready(self):
@ -172,7 +204,7 @@ class Plugin:
else: else:
self.settings = dict(DEFAULT_DATA) self.settings = dict(DEFAULT_DATA)
try: try:
self.settings["version"] str(self.settings["version"])
except: except:
self.settings = dict(DEFAULT_DATA) self.settings = dict(DEFAULT_DATA)
while self.settings["version"] != DEFAULT_DATA["version"]: while self.settings["version"] != DEFAULT_DATA["version"]:
@ -182,14 +214,14 @@ class Plugin:
self.settings["interpolate"] = DEFAULT_DATA["interpolate"] self.settings["interpolate"] = DEFAULT_DATA["interpolate"]
self.settings["curve"] = DEFAULT_DATA["curve"] self.settings["curve"] = DEFAULT_DATA["curve"]
self.is_changed = True self.is_changed = True
on_set_enable(self.settings["enable"]) self.on_set_enable(self)
last_time = time.time() last_time = time.time()
# work loop # work loop
while True: while True:
if (time.time() - last_time) * 0.9 > self.period_s: if (time.time() - last_time) * 0.9 > self.period_s:
# detect sleep # detect sleep
logging.debug("Detected resume from sleep, overriding fan again") logging.debug("Detected resume from sleep, overriding fan again")
on_set_enable(self.settings["enable"]) self.on_set_enable(self)
last_time = time.time() last_time = time.time()
if self.is_changed: if self.is_changed:
self.save(self) self.save(self)
@ -225,9 +257,3 @@ def on_disable():
with open("/sys/class/hwmon/hwmon5/recalculate", "w") as f: with open("/sys/class/hwmon/hwmon5/recalculate", "w") as f:
f.write("0") f.write("0")
# TODO restart system fan control # TODO restart system fan control
def on_set_enable(enable):
if enable:
on_enable()
else:
on_disable()

View file

@ -132,7 +132,6 @@
// common // common
function buildCurvePlot(curve_points) { function buildCurvePlot(curve_points) {
// TODO
let graphDiv = document.getElementById("graphDiv"); let graphDiv = document.getElementById("graphDiv");
let newStr = "<span style=\"font-size:x-small;position:absolute;left:1px;top:-1px;\">100%</span><span style=\"font-size:x-small;position:absolute;left:1px;bottom:-1px;\">0</span><span style=\"font-size:x-small;position:absolute;left:-2px;bottom:50%;writing-mode:vertical-lr;text-orientation:mixed;\">Fan</span><span style=\"font-size:x-small;position:absolute;right:1px;bottom:-1px;\">100</span><span style=\"font-size:x-small;position:absolute;left:35%;bottom:-1px;\">Temperature (°C)</span>"; let newStr = "<span style=\"font-size:x-small;position:absolute;left:1px;top:-1px;\">100%</span><span style=\"font-size:x-small;position:absolute;left:1px;bottom:-1px;\">0</span><span style=\"font-size:x-small;position:absolute;left:-2px;bottom:50%;writing-mode:vertical-lr;text-orientation:mixed;\">Fan</span><span style=\"font-size:x-small;position:absolute;right:1px;bottom:-1px;\">100</span><span style=\"font-size:x-small;position:absolute;left:35%;bottom:-1px;\">Temperature (°C)</span>";
for (let i = 0; i < curve_points.length; i++) { for (let i = 0; i < curve_points.length; i++) {
@ -142,7 +141,9 @@
newStr += "width:8px;height:8px;background-color:#1a9fff;border-radius:4px\" id=\"plotPoint"; newStr += "width:8px;height:8px;background-color:#1a9fff;border-radius:4px\" id=\"plotPoint";
newStr += i.toString() + "\" onclick=\"onclick_plotPoint(event," + i.toString() + ")\"></span>"; newStr += i.toString() + "\" onclick=\"onclick_plotPoint(event," + i.toString() + ")\"></span>";
} }
//graphDiv.innerHTML = "";
graphDiv.innerHTML = newStr; graphDiv.innerHTML = newStr;
console.log("Fan graph redrawn");
} }
function pollStats() { function pollStats() {
@ -202,10 +203,17 @@
</script> </script>
</head> </head>
<body onload="onload_body()" style="overflow-x:hidden;margin:0px;"> <body onload="onload_body()" style="overflow-x:hidden;margin:0px;">
<!-- Spacer (moves top out of shadow above it) -->
<div class="quickaccessmenu_TabGroupPanel_1QO7b">
<div class="quickaccesscontrols_PanelSection_2C0g0" style="margin-bottom:6px;">
<!--<div class="quickaccesscontrols_PanelSectionRow_2VQ88">
</div>-->
</div>
</div>
<div class="quickaccessmenu_TabGroupPanel_1QO7b Panel Focusable"> <div class="quickaccessmenu_TabGroupPanel_1QO7b Panel Focusable">
<div class="quickaccesscontrols_PanelSection_2C0g0" style="padding:0px 4px;"> <div class="quickaccesscontrols_PanelSection_2C0g0" style="padding:0px 4px;">
<div class="quickaccesscontrols_PanelSectionRow_2VQ88"> <div class="quickaccesscontrols_PanelSectionRow_2VQ88">
<div class="gamepaddialog_Field_S-_La gamepaddialog_WithFirstRow_qFXi6 gamepaddialog_VerticalAlignCenter_3XNvA gamepaddialog_WithDescription_3bMIS gamepaddialog_WithBottomSeparator_1lUZx gamepaddialog_ExtraPaddingOnChildrenBelow_5UO-_ gamepaddialog_StandardPadding_XRBFu gamepaddialog_HighlightOnFocus_wE4V6 Panel Focusable" style="--indent-level:0;"> <div class="gamepaddialog_Field_S-_La gamepaddialog_WithFirstRow_qFXi6 gamepaddialog_VerticalAlignCenter_3XNvA gamepaddialog_WithDescription_3bMIS gamepaddialog_WithBottomSeparatorStandard_3s1Rk gamepaddialog_ExtraPaddingOnChildrenBelow_5UO-_ gamepaddialog_StandardPadding_XRBFu gamepaddialog_HighlightOnFocus_wE4V6 Panel Focusable" style="--indent-level:0;">
<div class="gamepaddialog_FieldLabelRow_H9WOq"> <div class="gamepaddialog_FieldLabelRow_H9WOq">
<div class="gamepaddialog_FieldLabel_3b0U-"> <div class="gamepaddialog_FieldLabel_3b0U-">
Custom Fan Curve Custom Fan Curve
@ -232,7 +240,7 @@
<div class="quickaccessmenu_TabGroupPanel_1QO7b Panel Focusable"> <div class="quickaccessmenu_TabGroupPanel_1QO7b Panel Focusable">
<div class="quickaccesscontrols_PanelSection_2C0g0" style="padding:0px 4px;"> <div class="quickaccesscontrols_PanelSection_2C0g0" style="padding:0px 4px;">
<div class="quickaccesscontrols_PanelSectionRow_2VQ88"> <div class="quickaccesscontrols_PanelSectionRow_2VQ88">
<div class="gamepaddialog_Field_S-_La gamepaddialog_WithFirstRow_qFXi6 gamepaddialog_VerticalAlignCenter_3XNvA gamepaddialog_WithDescription_3bMIS gamepaddialog_WithBottomSeparator_1lUZx gamepaddialog_ExtraPaddingOnChildrenBelow_5UO-_ gamepaddialog_StandardPadding_XRBFu gamepaddialog_HighlightOnFocus_wE4V6 Panel Focusable" style="--indent-level:0;"> <div class="gamepaddialog_Field_S-_La gamepaddialog_WithFirstRow_qFXi6 gamepaddialog_VerticalAlignCenter_3XNvA gamepaddialog_WithDescription_3bMIS gamepaddialog_WithBottomSeparatorStandard_3s1Rk gamepaddialog_ExtraPaddingOnChildrenBelow_5UO-_ gamepaddialog_StandardPadding_XRBFu gamepaddialog_HighlightOnFocus_wE4V6 Panel Focusable" style="--indent-level:0;">
<div class="gamepaddialog_FieldLabelRow_H9WOq"> <div class="gamepaddialog_FieldLabelRow_H9WOq">
<div class="gamepaddialog_FieldLabel_3b0U-"> <div class="gamepaddialog_FieldLabel_3b0U-">
Linear Interpolation Linear Interpolation
@ -257,7 +265,7 @@
</div>--> </div>-->
<div class="Panel Focusable" tabindex="0"> <div class="Panel Focusable" tabindex="0">
<div class="quickaccesscontrols_PanelSectionRow_2VQ88"> <div class="quickaccesscontrols_PanelSectionRow_2VQ88">
<div class="gamepaddialog_Field_S-_La gamepaddialog_WithFirstRow_qFXi6 gamepaddialog_VerticalAlignCenter_3XNvA gamepaddialog_InlineWrapShiftsChildrenBelow_pHUb6 gamepaddialog_WithBottomSeparator_1lUZx gamepaddialog_StandardPadding_XRBFu gamepaddialog_HighlightOnFocus_wE4V6 Panel Focusable" style="--indent-level:0;padding-left:0px;padding-right:0px;"> <div class="gamepaddialog_Field_S-_La gamepaddialog_WithFirstRow_qFXi6 gamepaddialog_VerticalAlignCenter_3XNvA gamepaddialog_InlineWrapShiftsChildrenBelow_pHUb6 gamepaddialog_WithBottomSeparatorStandard_3s1Rk gamepaddialog_StandardPadding_XRBFu gamepaddialog_HighlightOnFocus_wE4V6 Panel Focusable" style="--indent-level:0;padding-left:0px;padding-right:0px;">
<div class="gamepaddialog_FieldLabelRow_H9WOq"> <div class="gamepaddialog_FieldLabelRow_H9WOq">
<div class="gamepaddialog_FieldLabel_3b0U-">Current Fan Speed</div> <div class="gamepaddialog_FieldLabel_3b0U-">Current Fan Speed</div>
<div class="gamepaddialog_FieldChildren_14_HB"> <div class="gamepaddialog_FieldChildren_14_HB">
@ -269,7 +277,7 @@
</div> </div>
<div class="Panel Focusable" tabindex="0"> <div class="Panel Focusable" tabindex="0">
<div class="quickaccesscontrols_PanelSectionRow_2VQ88"> <div class="quickaccesscontrols_PanelSectionRow_2VQ88">
<div class="gamepaddialog_Field_S-_La gamepaddialog_WithFirstRow_qFXi6 gamepaddialog_VerticalAlignCenter_3XNvA gamepaddialog_InlineWrapShiftsChildrenBelow_pHUb6 gamepaddialog_WithBottomSeparator_1lUZx gamepaddialog_StandardPadding_XRBFu gamepaddialog_HighlightOnFocus_wE4V6 Panel Focusable" style="--indent-level:0;padding-left:0px;padding-right:0px;"> <div class="gamepaddialog_Field_S-_La gamepaddialog_WithFirstRow_qFXi6 gamepaddialog_VerticalAlignCenter_3XNvA gamepaddialog_InlineWrapShiftsChildrenBelow_pHUb6 gamepaddialog_WithBottomSeparatorStandard_3s1Rk gamepaddialog_StandardPadding_XRBFu gamepaddialog_HighlightOnFocus_wE4V6 Panel Focusable" style="--indent-level:0;padding-left:0px;padding-right:0px;">
<div class="gamepaddialog_FieldLabelRow_H9WOq"> <div class="gamepaddialog_FieldLabelRow_H9WOq">
<div class="gamepaddialog_FieldLabel_3b0U-">Current Temperature</div> <div class="gamepaddialog_FieldLabel_3b0U-">Current Temperature</div>
<div class="gamepaddialog_FieldChildren_14_HB"> <div class="gamepaddialog_FieldChildren_14_HB">