Commit 653164b2 authored by Mikhail Karpenko's avatar Mikhail Karpenko

Add parameter enabling/disabling fan control

parent 36689810
...@@ -27,6 +27,7 @@ import sys ...@@ -27,6 +27,7 @@ import sys
import time import time
import subprocess import subprocess
import atexit import atexit
import getopt
from posix import EX_OSFILE, F_OK from posix import EX_OSFILE, F_OK
DEBUG = 0 DEBUG = 0
...@@ -59,10 +60,11 @@ out_fn = {"core_temp_fn": "core_temp", ...@@ -59,10 +60,11 @@ out_fn = {"core_temp_fn": "core_temp",
class temp_monitor(): class temp_monitor():
def __init__(self, ctrl_path_pref, ctrl_file_names, hwmon_path_pref, hwmon_fn, def __init__(self, ctrl_path_pref, ctrl_file_names, hwmon_path_pref, hwmon_fn,
out_path_prefix, out_fnames): out_path_prefix, out_fnames, control_fan):
self.is_fan_on = False self.is_fan_on = False
self.is_vp5_enabled = False self.is_vp5_enabled = False
self.is_10389_present = True self.is_10389_present = True
self.control_fan = control_fan
self.ctrl_path_prefix = ctrl_path_pref self.ctrl_path_prefix = ctrl_path_pref
self.ctrl_fnames = ctrl_file_names self.ctrl_fnames = ctrl_file_names
self.hwmon_path_prefix = hwmon_path_pref self.hwmon_path_prefix = hwmon_path_pref
...@@ -124,9 +126,12 @@ class temp_monitor(): ...@@ -124,9 +126,12 @@ class temp_monitor():
def fan_ctrl(self, ctrl): def fan_ctrl(self, ctrl):
""" """
Control fan by writing to sysfs files. Control fan (if this is allowed during script invocation) by writing to sysfs files.
@param ctrl: can be "on" or "off" to turn fan on or off @param ctrl: can be "on" or "off" to turn fan on or off
""" """
if self.control_fan is False:
return
if ctrl is "on": if ctrl is "on":
""" check if +5V is active and turn it on if it is not (it should not happen) """ """ check if +5V is active and turn it on if it is not (it should not happen) """
with open(self.ctrl_path_prefix + self.ctrl_fnames["vp5_en_fn"], "r+") as f: with open(self.ctrl_path_prefix + self.ctrl_fnames["vp5_en_fn"], "r+") as f:
...@@ -217,14 +222,40 @@ class temp_monitor(): ...@@ -217,14 +222,40 @@ class temp_monitor():
self.core_temp_params_f.write(str(key) + ": " + str(val) + "\n") self.core_temp_params_f.write(str(key) + ": " + str(val) + "\n")
self.core_temp_params_f.flush() self.core_temp_params_f.flush()
def print_help():
"""
Print usage information.
"""
print "tempmon.py [--control_fan on|off]"
print "'control_fan' parameter enables or disables camera fan control. Default value for this parameter is 'on'."
if __name__ == "__main__": if __name__ == "__main__":
if DEBUG: if DEBUG:
ctrl_path_pref = "" ctrl_path_pref = ""
hwmon_path_pref = "" hwmon_path_pref = ""
out_path_pref = "" out_path_pref = ""
tm = temp_monitor(ctrl_path_pref, ctrl_fn, hwmon_path_pref, hwmon_fn, out_path_pref, out_fn)
# parse command line options
try:
opts, args = getopt.getopt(sys.argv[1:], "h", ["control_fan="])
except:
print_help()
sys.exit(2)
control_fan = True
for opt, arg in opts:
if opt == "-h":
print_help()
sys.exit(0)
elif opt == "--control_fan":
if arg == "on":
control_fan = True
else:
control_fan = False
tm = temp_monitor(ctrl_path_pref, ctrl_fn, hwmon_path_pref, hwmon_fn, out_path_pref, out_fn, control_fan)
if tm.check_files(): if tm.check_files():
# unconditionally turn the fan on to set the driver to a known state # unconditionally turn the fan on to set the driver to a known state
if control_fan:
tm.fan_ctrl("on") tm.fan_ctrl("on")
tm.monitor() tm.monitor()
else: else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment