Add some battery stats
This commit is contained in:
parent
dd6b554248
commit
65d0468aeb
2 changed files with 74 additions and 3 deletions
15
main.py
15
main.py
|
@ -6,6 +6,8 @@ class Plugin:
|
|||
FAN_VOLTAGES = [0, 1000, 2000, 3000, 4000, 5000, 6000]
|
||||
|
||||
set_fan_voltage = None
|
||||
|
||||
# CPU stuff
|
||||
|
||||
# call from main_view.html with setCPUs(count, smt)
|
||||
async def set_cpus(self, count, smt=True) -> int:
|
||||
|
@ -69,6 +71,8 @@ class Plugin:
|
|||
freq = int(freq_maybe)
|
||||
return self.SCALING_FREQUENCIES.index(freq)
|
||||
|
||||
# Fan stuff
|
||||
|
||||
async def set_fan_tick(self, tick: int):
|
||||
self.set_fan_voltage = tick # cache voltage set to echo back in get_fan_tick()
|
||||
if tick >= len(self.FAN_VOLTAGES):
|
||||
|
@ -101,6 +105,17 @@ class Plugin:
|
|||
return i
|
||||
return len(self.FAN_VOLTAGES)-1 # any higher value is considered as highest manual setting
|
||||
|
||||
# Battery stuff
|
||||
|
||||
async def get_charge_now(self) -> int:
|
||||
return int(read_from_sys("/sys/class/hwmon/hwmon2/device/charge_now", amount=-1).strip())
|
||||
|
||||
async def get_charge_full(self) -> int:
|
||||
return int(read_from_sys("/sys/class/hwmon/hwmon2/device/charge_full", amount=-1).strip())
|
||||
|
||||
async def get_charge_design(self) -> int:
|
||||
return int(read_from_sys("/sys/class/hwmon/hwmon2/device/charge_full_design", amount=-1).strip())
|
||||
|
||||
# Asyncio-compatible long-running code, executed in a task when the plugin is loaded
|
||||
async def _main(self):
|
||||
pass
|
||||
|
|
|
@ -41,6 +41,18 @@
|
|||
function getFanTick() {
|
||||
return call_plugin_method("get_fan_tick", {});
|
||||
}
|
||||
|
||||
function getChargeNow() {
|
||||
return call_plugin_method("get_charge_now", {});
|
||||
}
|
||||
|
||||
function getChargeFull() {
|
||||
return call_plugin_method("get_charge_full", {});
|
||||
}
|
||||
|
||||
function getChargeDesign() {
|
||||
return call_plugin_method("get_charge_design", {});
|
||||
}
|
||||
|
||||
// other logic
|
||||
|
||||
|
@ -51,6 +63,7 @@
|
|||
selectNotch("cpuThreadsNotch", await getCPUs() - 1, 8);
|
||||
selectNotch("frequencyNotch", await getMaxBoost(), 3);
|
||||
selectNotch("fanNotch", await getFanTick(), 8);
|
||||
await updateBatteryStats();
|
||||
}
|
||||
|
||||
async function setCPUNotch(index) {
|
||||
|
@ -123,14 +136,24 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function updateBatteryStats() {
|
||||
let batCapacityNow = document.getElementById("batCapacityNow");
|
||||
let batCapacityFull = document.getElementById("batCapacityFull");
|
||||
let chargeNow = await getChargeNow();
|
||||
let chargeFull = await getChargeFull();
|
||||
let chargeDesign = await getChargeDesign();
|
||||
batCapacityNow.innerText = (7.7 * chargeNow / 1000000).toFixed(2).toString() + " Wh (" + (100 * chargeNow / chargeFull).toFixed(0).toString() + "%)";
|
||||
batCapacityFull.innerText = (7.7 * chargeFull / 1000000).toFixed(2).toString() + " Wh (" + (100 * chargeFull / chargeDesign).toFixed(0).toString() + "%)";
|
||||
}
|
||||
|
||||
</script>
|
||||
<style type="text/css" media="screen"></style>
|
||||
</head>
|
||||
<body onload="onReady()">
|
||||
<body onload="onReady()" style="/*margin:0px;padding:0px;*/">
|
||||
<!-- SMT toggle switch, roughly copied from https://github.com/SteamDeckHomebrew/ExtraSettingsPlugin/blob/main/main_view.html -->
|
||||
<!-- Due to a bug in MangoHud, this has been hidden for now -->
|
||||
<div class="quickaccessmenu_TabGroupPanel_1QO7b Panel Focusable" style="display:none;">
|
||||
<div class="quickaccessmenu_TabGroupPanel_1QO7b Panel Focusable" style="/*display:none;*/">
|
||||
<div class="quickaccesscontrols_PanelSectionRow_26R5w">
|
||||
<div class="quickaccesscontrols_PanelSectionRow_26R5w">
|
||||
<div class="gamepaddialog_Field_eKmEX gamepaddialog_WithFirstRow_2bDqk gamepaddialog_ExtraPaddingOnChildrenBelow_3nLNL gamepaddialog_StandardPadding_xIITX gamepaddialog_HighlightOnFocus_2HFrm Panel Focusable" style="--indent-level:0;">
|
||||
|
@ -145,10 +168,12 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="gamepaddialog_FieldDescription_1W1to">Disables odd-numbered CPUs</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- CPUs selector -->
|
||||
<div class="gamepaddialog_Field_eKmEX gamepaddialog_WithFirstRow_2bDqk gamepaddialog_WithChildrenBelow_37xzV gamepaddialog_InlineWrapShiftsChildrenBelow_3LCXh gamepaddialog_WithBottomSeparator_3YKpU gamepaddialog_ChildrenWidthFixed_ljcbL gamepaddialog_ExtraPaddingOnChildrenBelow_3nLNL gamepaddialog_StandardPadding_xIITX gamepaddialog_HighlightOnFocus_2HFrm Panel Focusable">
|
||||
<div class="gamepaddialog_FieldLabelRow_2VcTl">
|
||||
|
@ -214,10 +239,12 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="gamepaddialog_FieldDescription_1W1to">Allows the CPU to go above max frequency</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Frequency selector -->
|
||||
<div class="gamepaddialog_Field_eKmEX gamepaddialog_WithFirstRow_2bDqk gamepaddialog_WithChildrenBelow_37xzV gamepaddialog_InlineWrapShiftsChildrenBelow_3LCXh gamepaddialog_WithBottomSeparator_3YKpU gamepaddialog_ChildrenWidthFixed_ljcbL gamepaddialog_ExtraPaddingOnChildrenBelow_3nLNL gamepaddialog_StandardPadding_xIITX gamepaddialog_HighlightOnFocus_2HFrm Panel Focusable">
|
||||
<div class="gamepaddialog_FieldLabelRow_2VcTl">
|
||||
|
@ -253,7 +280,7 @@
|
|||
</div>
|
||||
|
||||
<!-- Fan RPM selector -->
|
||||
<!-- TODO: Make this is non-notched slider when PluginLoader PR#41 is merged -->
|
||||
<!-- TODO: Make this non-notched slider when PluginLoader PR#41 is merged -->
|
||||
<div class="gamepaddialog_Field_eKmEX gamepaddialog_WithFirstRow_2bDqk gamepaddialog_WithChildrenBelow_37xzV gamepaddialog_InlineWrapShiftsChildrenBelow_3LCXh gamepaddialog_WithBottomSeparator_3YKpU gamepaddialog_ChildrenWidthFixed_ljcbL gamepaddialog_ExtraPaddingOnChildrenBelow_3nLNL gamepaddialog_StandardPadding_xIITX gamepaddialog_HighlightOnFocus_2HFrm Panel Focusable">
|
||||
<div class="gamepaddialog_FieldLabelRow_2VcTl">
|
||||
<div class="gamepaddialog_FieldLabel_3jMlJ">Fan RPM</div>
|
||||
|
@ -303,5 +330,34 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Battery Info -->
|
||||
<div class="quickaccesscontrols_PanelSection_3gY0a">
|
||||
<div class="quickaccesscontrols_PanelSectionTitle_1IigU">
|
||||
<div class="quickaccesscontrols_Text_1cokl">Battery</div>
|
||||
</div>
|
||||
<div class="Panel Focusable" tabindex="0">
|
||||
<div class="quickaccesscontrols_PanelSectionRow_3LM_Z">
|
||||
<div class="gamepaddialog_Field_eKmEX gamepaddialog_WithFirstRow_2bDqk gamepaddialog_InlineWrapShiftsChildrenBelow_3LCXh gamepaddialog_StandardPadding_xIITX gamepaddialog_HighlightOnFocus_2HFrm Panel Focusable" style="--indent-level:0;">
|
||||
<div class="gamepaddialog_FieldLabelRow_2VcTl">
|
||||
<div class="gamepaddialog_FieldLabel_3jMlJ">Now</div>
|
||||
<div class="gamepaddialog_FieldChildren_2rhav">
|
||||
<div class="gamepaddialog_LabelFieldValue_3pteV" id="batCapacityNow"> ??? (??%) </div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="quickaccesscontrols_PanelSectionRow_3LM_Z">
|
||||
<div class="gamepaddialog_Field_eKmEX gamepaddialog_WithFirstRow_2bDqk gamepaddialog_InlineWrapShiftsChildrenBelow_3LCXh gamepaddialog_WithBottomSeparator_3YKpU gamepaddialog_StandardPadding_xIITX gamepaddialog_HighlightOnFocus_2HFrm Panel Focusable" style="--indent-level:0;">
|
||||
<div class="gamepaddialog_FieldLabelRow_2VcTl">
|
||||
<div class="gamepaddialog_FieldLabel_3jMlJ">Max</div>
|
||||
<div class="gamepaddialog_FieldChildren_2rhav">
|
||||
<div class="gamepaddialog_LabelFieldValue_3pteV" id="batCapacityFull"> ??? (??%) </div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue