#!/usr/bin/env python """ Copyright 2007 Martin T. Dengler Controls LG-37Z55 TV via serial (via pyserial). USAGE EXAMPLES Command line: python ./tv_control.py on python ./tv_control.py ison && python ./tv_control.py off python ./tv_control.py onoff python ./tv_control.py on input pc volume 30 python usage example: >>> import tv_control >>> tv = tv_control.tv(port=0) # also try port="/dev/ttyUSB1" for USB->serial >>> tv.on() >>> print tv.ison() True >>> tv.onoff() >>> print tv.ison() False Requires pyserial. SUPPORTED MODELS Will probably work for other LG models, but is completely untested. Access via USB-to-serial gateways should work fine. LICENSE This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. SOURCE The source code is available at http://www.martindengler.com/proj/tv_control.py """ import os import sys import time serial = "/dev/ttyUSB1" set = 0 SOURCE_TV = 10 SOURCE_AV1 = 20 SOURCE_AV2 = 21 SOURCE_AV3 = 22 SOURCE_SVIDEO = 30 SOURCE_COMPONENT = 40 SOURCE_RGB_PC = 50 SOURCE_HDMI_PC = 90 def on(): power(on=True) def off(): power(on=False) def power(on=True): command("ka %s %s" % (set, on and 1 or 0)) def input_tv(): input(source=SOURCE_TV) def input_dvd(): input(source=SOURCE_AV1) def input_wii(): input(source=SOURCE_SVIDEO) def input_pc(): input(source=SOURCE_HDMI_PC) def input(source=SOURCE_HDMI_PC): command("xb %s %s" % (set, source)) def mute(nosound=True): cmd = "ke %s %s" % (set, nosound and "0" or "1") command(cmd) command(cmd) #mute command seems sometimes to be ignored def volume(level=10): """valid levels are between 0 and 100 (decimal)""" command("kf %s %0x" % (set, level)) def command(s): cmd = '/bin/echo -e "%s\\n" > %s' % (s, serial) print "executing: %s" % (cmd.strip()) os.system(cmd) def pause(): print "pausing" time.sleep(5) def main(cmds): for cmd in cmds: if cmd in globals(): eval("%s()" % cmd) return 0 if __name__ == "__main__": sys.exit(main(sys.argv[1:]))