Skip to content

Instantly share code, notes, and snippets.

@AyumuKasuga
Created April 12, 2012 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AyumuKasuga/2367241 to your computer and use it in GitHub Desktop.
Save AyumuKasuga/2367241 to your computer and use it in GitHub Desktop.
backlight up/down on samsung R428
import sys
import os
class backlight():
def __init__(self, cmd):
self.path = "echo '%s' > /sys/class/backlight/samsung/brightness"
self.limit_down, self.limit_up = 1, 7
self.current = int(os.popen("cat /sys/class/backlight/samsung/brightness").read().strip())
self.cmd = cmd.strip()
self.setbacklight()
def setbacklight(self):
if self.cmd == 'up':
new_value = self.current + 1
if new_value <= self.limit_up:
os.popen(self.path % new_value).read()
print 'up to level: ' + str(new_value)
self.current = new_value
elif self.cmd == 'down':
new_value = self.current - 1
if new_value >= self.limit_down:
os.popen(self.path % new_value)
print 'down to level: ' + str(new_value)
self.current = new_value
try:
cmd = sys.argv[1]
backlight(cmd)
except IndexError:
print '''use: 'backlight up' or 'backlight down' '''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment