Added hw-sensors
This commit is contained in:
parent
4dc41aec27
commit
e041125c20
2 changed files with 53 additions and 4 deletions
46
scripts/hw-sensors
Executable file
46
scripts/hw-sensors
Executable file
|
|
@ -0,0 +1,46 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Wizard Kit: Hardware Sensors"""
|
||||||
|
# vim: sts=2 sw=2 ts=2
|
||||||
|
|
||||||
|
import platform
|
||||||
|
|
||||||
|
import wk
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Show sensor data on screen."""
|
||||||
|
sensors = wk.hw.sensors.Sensors()
|
||||||
|
if platform.system() == 'Darwin':
|
||||||
|
wk.std.clear_screen()
|
||||||
|
while True:
|
||||||
|
print('\033[100A', end='')
|
||||||
|
sensors.update_sensor_data()
|
||||||
|
wk.std.print_report(sensors.generate_report('Current', 'Max'))
|
||||||
|
wk.std.sleep(1)
|
||||||
|
elif platform.system() == 'Linux':
|
||||||
|
proc = wk.exe.run_program(cmd=['mktemp'])
|
||||||
|
sensors.start_background_monitor(
|
||||||
|
out_path=proc.stdout.strip(),
|
||||||
|
exit_on_thermal_limit=False,
|
||||||
|
temp_labels=('Current', 'Max'),
|
||||||
|
)
|
||||||
|
watch_cmd = [
|
||||||
|
'watch',
|
||||||
|
'--color',
|
||||||
|
'--exec',
|
||||||
|
'--no-title',
|
||||||
|
'--interval', '1',
|
||||||
|
'cat',
|
||||||
|
proc.stdout.strip(),
|
||||||
|
]
|
||||||
|
wk.exe.run_program(watch_cmd, check=False, pipe=False)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
try:
|
||||||
|
main()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
except SystemExit:
|
||||||
|
raise
|
||||||
|
except: #pylint: disable=bare-except
|
||||||
|
wk.std.major_exception()
|
||||||
|
|
@ -115,7 +115,9 @@ class Sensors():
|
||||||
# Done
|
# Done
|
||||||
return report
|
return report
|
||||||
|
|
||||||
def monitor_to_file(self, out_path, temp_labels=None, thermal_action=None):
|
def monitor_to_file(
|
||||||
|
self, out_path,
|
||||||
|
exit_on_thermal_limit=True, temp_labels=None, thermal_action=None):
|
||||||
"""Write report to path every second until stopped.
|
"""Write report to path every second until stopped.
|
||||||
|
|
||||||
thermal_action is a cmd to run if ThermalLimitReachedError is caught.
|
thermal_action is a cmd to run if ThermalLimitReachedError is caught.
|
||||||
|
|
@ -127,7 +129,7 @@ class Sensors():
|
||||||
# Start loop
|
# Start loop
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
self.update_sensor_data()
|
self.update_sensor_data(exit_on_thermal_limit)
|
||||||
except ThermalLimitReachedError:
|
except ThermalLimitReachedError:
|
||||||
if thermal_action:
|
if thermal_action:
|
||||||
run_program(thermal_action, check=False)
|
run_program(thermal_action, check=False)
|
||||||
|
|
@ -160,7 +162,8 @@ class Sensors():
|
||||||
source_data[temp_label] = sum(temps) / len(temps)
|
source_data[temp_label] = sum(temps) / len(temps)
|
||||||
|
|
||||||
def start_background_monitor(
|
def start_background_monitor(
|
||||||
self, out_path, temp_labels=None, thermal_action=None):
|
self, out_path,
|
||||||
|
exit_on_thermal_limit=True, temp_labels=None, thermal_action=None):
|
||||||
"""Start background thread to save report to file.
|
"""Start background thread to save report to file.
|
||||||
|
|
||||||
thermal_action is a cmd to run if ThermalLimitReachedError is caught.
|
thermal_action is a cmd to run if ThermalLimitReachedError is caught.
|
||||||
|
|
@ -171,7 +174,7 @@ class Sensors():
|
||||||
self.out_path = pathlib.Path(out_path)
|
self.out_path = pathlib.Path(out_path)
|
||||||
self.background_thread = start_thread(
|
self.background_thread = start_thread(
|
||||||
self.monitor_to_file,
|
self.monitor_to_file,
|
||||||
args=(out_path, temp_labels, thermal_action),
|
args=(out_path, exit_on_thermal_limit, temp_labels, thermal_action),
|
||||||
)
|
)
|
||||||
|
|
||||||
def stop_background_monitor(self):
|
def stop_background_monitor(self):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue