Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
Use 'samsung-laptop' kernel module in system backend and drop support…
Browse files Browse the repository at this point in the history
… for 'easy-slow-down-manager'.
  • Loading branch information
voria committed Oct 12, 2011
1 parent 8bd4ec8 commit 6bd9f5e
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 129 deletions.
9 changes: 4 additions & 5 deletions backends/globals.py
Expand Up @@ -98,11 +98,10 @@
SCRIPT_BLUETOOTH_OFF = "/etc/samsung-tools/scripts/bluetooth-off"
SCRIPT_WIRELESS_ON = "/etc/samsung-tools/scripts/wireless-on"
SCRIPT_WIRELESS_OFF = "/etc/samsung-tools/scripts/wireless-off"
# Easy slow down manager interface
ESDM_MODULE = "easy_slow_down_manager"
ESDM_PATH_BACKLIGHT = "/proc/easy_backlight"
ESDM_PATH_FAN = "/proc/easy_slow_down_manager"
ESDM_PATH_WIRELESS = "/proc/easy_wifi_kill"
# samsung-laptop interface
SL_MODULE = "samsung-laptop"
SL_PATH_BACKLIGHT = "/sys/devices/platform/samsung/backlight/samsung/bl_power"
SL_PATH_PERFORMANCE = "/sys/devices/platform/samsung/performance_level"
# Temperature
CPU_TEMPERATURE_PATH = "/sys/class/thermal/thermal_zone0/temp"
# sysctl configuration file
Expand Down
46 changes: 23 additions & 23 deletions backends/system/backlight.py
Expand Up @@ -31,29 +31,29 @@ class Backlight(dbus.service.Object):
""" Control backlight """
def __init__(self, conn = None, object_path = None, bus_name = None):
dbus.service.Object.__init__(self, conn, object_path, bus_name)
# Check if easy-slow-down-manager is available for controlling backlight.
# Check if samsung-laptop is available for controlling backlight.
# If not, fallback to using vbetool.
if self.__load_esdm_module():
self.method = "esdm"
if self.__load_sl_module():
self.method = "sl"
else:
self.method = "vbetool"

def __load_esdm_module(self):
""" Load the easy-slow-down-manager kernel module. """
def __load_sl_module(self):
""" Load the samsung-laptop kernel module. """
""" Return 'True' on success, 'False' otherwise. """
if os.path.exists(ESDM_PATH_BACKLIGHT):
if os.path.exists(SL_PATH_BACKLIGHT):
return True # already loaded
command = COMMAND_MODPROBE + " " + ESDM_MODULE
command = COMMAND_MODPROBE + " " + SL_MODULE
try:
process = subprocess.Popen(command.split(), stdout = subprocess.PIPE, stderr = subprocess.PIPE)
process.communicate()
if process.returncode != 0:
systemlog.write("WARNING: 'Backlight.__load_esdm_module()' - COMMAND: '" + command + "' FAILED.")
systemlog.write("WARNING: 'Backlight.__load_sl_module()' - COMMAND: '" + command + "' FAILED.")
return False
else:
return True
except:
systemlog.write("WARNING: 'Backlight.__load_esdm_module()' - COMMAND: '" + command + "' - Exception thrown.")
systemlog.write("WARNING: 'Backlight.__load_sl_module()' - COMMAND: '" + command + "' - Exception thrown.")
return False

def __save_status(self, status):
Expand All @@ -75,18 +75,18 @@ def __save_status(self, status):
def IsEnabled(self, sender = None, conn = None):
""" Check if backlight is enabled. """
""" Return 'True' if enabled, 'False' if disabled. """
if self.method == "esdm":
# Make sure the 'esdm' module is loaded
self.__load_esdm_module()
if self.method == "sl":
# Make sure the 'sl' module is loaded
self.__load_sl_module()
try:
with open(ESDM_PATH_BACKLIGHT, 'r') as file:
with open(SL_PATH_BACKLIGHT, 'r') as file:
status = int(file.read(1))
if status == 1:
if status == 0:
return True
else:
return False
except:
systemlog.write("ERROR: 'Backlight.IsEnabled()' - cannot read from '" + ESDM_PATH_BACKLIGHT + "'.")
systemlog.write("ERROR: 'Backlight.IsEnabled()' - cannot read from '" + SL_PATH_BACKLIGHT + "'.")
return True
else: # self.method == "vbetool":
if os.path.exists(LAST_DEVICE_STATUS_BACKLIGHT):
Expand All @@ -101,13 +101,13 @@ def Enable(self, sender = None, conn = None):
""" Return 'True' on success, 'False' otherwise. """
if self.IsEnabled():
return True
if self.method == "esdm":
if self.method == "sl":
try:
with open(ESDM_PATH_BACKLIGHT, 'w') as file:
file.write('1')
with open(SL_PATH_BACKLIGHT, 'w') as file:
file.write('0')
return True
except:
log_system.write("ERROR: 'Backlight.Enable()' - cannot write to '" + ESDM_PATH_BACKLIGHT + "'.")
log_system.write("ERROR: 'Backlight.Enable()' - cannot write to '" + SL_PATH_BACKLIGHT + "'.")
return False
else: # self.method == "vbetool"
command = COMMAND_VBETOOL + " dpms on"
Expand All @@ -131,13 +131,13 @@ def Disable(self, sender = None, conn = None):
""" Return 'True' on success, 'False' otherwise. """
if not self.IsEnabled():
return False
if self.method == "esdm":
if self.method == "sl":
try:
with open(ESDM_PATH_BACKLIGHT, 'w') as file:
file.write('0')
with open(SL_PATH_BACKLIGHT, 'w') as file:
file.write('1')
return True
except:
systemlog.write("ERROR: 'Backlight.Disable()' - cannot write to '" + ESDM_PATH_BACKLIGHT + "'.")
systemlog.write("ERROR: 'Backlight.Disable()' - cannot write to '" + SL_PATH_BACKLIGHT + "'.")
return False
else: # self.method == "vbetool":
command = COMMAND_VBETOOL + " dpms off"
Expand Down
54 changes: 27 additions & 27 deletions backends/system/fan.py
Expand Up @@ -28,7 +28,7 @@
from backends.globals import *

class Fan(dbus.service.Object):
""" Control CPU Fan through easy-slow-down-manager interface """
""" Control CPU Fan through the samsung-laptop interface """
def __init__(self, conn = None, object_path = None, bus_name = None):
dbus.service.Object.__init__(self, conn, object_path, bus_name)

Expand All @@ -50,9 +50,9 @@ def __save_last_status(self, status):
def IsAvailable(self, sender = None, conn = None):
""" Check if the fan control is available. """
""" Return 'True' if available, 'False' otherwise. """
if os.path.exists(ESDM_PATH_FAN):
if os.path.exists(SL_PATH_PERFORMANCE):
return True # already loaded
command = COMMAND_MODPROBE + " " + ESDM_MODULE
command = COMMAND_MODPROBE + " " + SL_MODULE
try:
process = subprocess.Popen(command.split(), stdout = subprocess.PIPE, stderr = subprocess.PIPE)
process.communicate()
Expand Down Expand Up @@ -85,28 +85,28 @@ def RestoreLastStatus(self, sender = None, conn = None):
elif laststatus == "silent":
self.SetSilent()
else:
self.SetSpeed()
self.SetOverclock()

@dbus.service.method(SYSTEM_INTERFACE_NAME, in_signature = None, out_signature = 'i',
sender_keyword = 'sender', connection_keyword = 'conn')
def Status(self, sender = None, conn = None):
""" Get current fan mode. """
"""Return 0 if 'normal', 1 if 'silent', 2 if 'speed'. """
"""Return 0 if 'normal', 1 if 'silent', 2 if 'overclock'. """
""" Return 3 if any error. """
if not self.IsAvailable():
return 3
try:
with open(ESDM_PATH_FAN, 'r') as file:
status = int(file.read(1))
if status == 0:
self.__save_last_status("normal")
elif status == 1:
self.__save_last_status("silent")
with open(SL_PATH_PERFORMANCE, 'r') as file:
status = file.read()[0:-1]
self.__save_last_status(status)
if status == "normal":
return 0
elif status == "silent":
return 1
else:
self.__save_last_status("speed")
return status
return 2
except:
systemlog.write("ERROR: 'Fan.Status()' - cannot read from '" + ESDM_PATH_FAN + "'.")
systemlog.write("ERROR: 'Fan.Status()' - cannot read from '" + SL_PATH_PERFORMANCE + "'.")
return 3

@dbus.service.method(SYSTEM_INTERFACE_NAME, in_signature = None, out_signature = 'b',
Expand All @@ -117,12 +117,12 @@ def SetNormal(self, sender = None, conn = None):
if not self.IsAvailable():
return False
try:
with open(ESDM_PATH_FAN, 'w') as file:
file.write('0')
with open(SL_PATH_PERFORMANCE, 'w') as file:
file.write("normal")
self.__save_last_status("normal")
return True
except:
systemlog.write("ERROR: 'Fan.SetNormal()' - cannot write to '" + ESDM_PATH_FAN + "'.")
systemlog.write("ERROR: 'Fan.SetNormal()' - cannot write to '" + SL_PATH_PERFORMANCE + "'.")
return False

@dbus.service.method(SYSTEM_INTERFACE_NAME, in_signature = None, out_signature = 'b',
Expand All @@ -133,28 +133,28 @@ def SetSilent(self, sender = None, conn = None):
if not self.IsAvailable():
return False
try:
with open(ESDM_PATH_FAN, 'w') as file:
file.write('1')
with open(SL_PATH_PERFORMANCE, 'w') as file:
file.write("silent")
self.__save_last_status("silent")
return True
except:
systemlog.write("ERROR: 'Fan.SetSilent()' - cannot write to '" + ESDM_PATH_FAN + "'.")
systemlog.write("ERROR: 'Fan.SetSilent()' - cannot write to '" + SL_PATH_PERFORMANCE + "'.")
return False

@dbus.service.method(SYSTEM_INTERFACE_NAME, in_signature = None, out_signature = 'b',
sender_keyword = 'sender', connection_keyword = 'conn')
def SetSpeed(self, sender = None, conn = None):
""" Set fan to 'speed' mode. """
def SetOverclock(self, sender = None, conn = None):
""" Set fan to 'overclock' mode. """
""" Return 'True' on success, 'False' otherwise. """
if not self.IsAvailable():
return False
try:
with open(ESDM_PATH_FAN, 'w') as file:
file.write('2')
self.__save_last_status("speed")
with open(SL_PATH_PERFORMANCE, 'w') as file:
file.write("overclock")
self.__save_last_status("overclock")
return True
except:
systemlog.write("ERROR: 'Fan.SetSpeed()' - cannot write to '" + ESDM_PATH_FAN + "'.")
systemlog.write("ERROR: 'Fan.SetOverclock()' - cannot write to '" + SL_PATH_PERFORMANCE + "'.")
return False

@dbus.service.method(SYSTEM_INTERFACE_NAME, in_signature = None, out_signature = 'b',
Expand All @@ -168,7 +168,7 @@ def Cycle(self, sender = None, conn = None):
if current == 0:
return self.SetSilent()
if current == 1:
return self.SetSpeed()
return self.SetOverclock()
if current == 2:
return self.SetNormal()
return False
2 changes: 1 addition & 1 deletion backends/system/util/config.py
Expand Up @@ -33,7 +33,7 @@
BLUETOOTH_INITIAL_STATUS_ACCEPTED_VALUES = ['on', 'off', 'last']
WEBCAM_INITIAL_STATUS_ACCEPTED_VALUES = ['on', 'off', 'last']
WIRELESS_INITIAL_STATUS_ACCEPTED_VALUES = ['on', 'off', 'last']
CPUFAN_INITIAL_STATUS_ACCEPTED_VALUES = ['normal', 'silent', 'speed', 'last']
CPUFAN_INITIAL_STATUS_ACCEPTED_VALUES = ['normal', 'silent', 'overclock', 'last']

class SystemConfig():
""" Manage system service configuration file """
Expand Down

0 comments on commit 6bd9f5e

Please sign in to comment.