summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Peter Nilsson <peppe@pappkartong.se>2011-02-26 13:30:15 +0100
committerJan-Peter Nilsson <peppe@pappkartong.se>2011-02-26 13:30:15 +0100
commit5a888ca16cae9abbf2ac66cc398fd8596a0b347d (patch)
tree807ae7f1ad0b7d7c94a3369259b2000b9dc1ce17
parent6e0fd204b3e46ccfc318cceb60d2672751f738cf (diff)
Break parts into a module
-rw-r--r--.gitignore1
-rw-r--r--LgTV.py51
-rwxr-xr-xtv54
3 files changed, 54 insertions, 52 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0d20b64
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.pyc
diff --git a/LgTV.py b/LgTV.py
new file mode 100644
index 0000000..789e2fa
--- /dev/null
+++ b/LgTV.py
@@ -0,0 +1,51 @@
+import serial
+import time
+
+
+class LgTV:
+ InputDTV = 0 << 4
+ InputAnalogue = 1 << 4
+ InputAV = 2 << 4
+ InputComponent = 4 << 4
+ InputRGB = 6 << 4
+ InputHDMI = 8 << 4
+
+ def __init__(self, parDevice):
+ self.ser = serial.Serial(parDevice, 9600, serial.EIGHTBITS, serial.PARITY_NONE, serial.STOPBITS_ONE, xonxoff=0, rtscts=0, dsrdtr=0, timeout=5)
+
+ def __del__(self):
+ self.ser.close()
+
+ def setValue(self, parSet, parCmd, parValue):
+ cmd = "%s %02X %02X\r" % (parCmd, parSet, parValue)
+ print cmd
+ self.ser.write(cmd)
+ self.ser.write("\r\r")
+ #self.ser.flush()
+
+ def readResponse(self):
+ print "In waiting: "+str(self.ser.inWaiting())
+ if(self.ser.inWaiting() > 9):
+ print self.ser.readline()
+
+ def getValue(self, parSet, parCmd):
+ for i in range(0,1):
+ self.setValue(parSet, parCmd, 0xFF)
+ time.sleep(0.5)
+ print "In waiting: "+str(self.ser.inWaiting())
+ if(self.ser.inWaiting() > 9):
+ return self.ser.read(10)
+ time.sleep(1)
+ return None
+
+ def power(self, parSet):
+ return self.getValue(parSet, "ka")
+
+ def power(self, parSet, parWantedState):
+ self.setValue(parSet, "ka", parWantedState)
+
+ def mute(self, parSet, parWantedState):
+ self.setValue(parSet, "ke", not parWantedState)
+
+ def input(self, parSet, parGroup, parInput):
+ self.setValue(parSet, "xb", parGroup | parInput)
diff --git a/tv b/tv
index 86052aa..76372e3 100755
--- a/tv
+++ b/tv
@@ -1,60 +1,10 @@
#!/usr/bin/python
import sys
-import serial
-import time
+import LgTV
-class LgTV:
- InputDTV = 0 << 4
- InputAnalogue = 1 << 4
- InputAV = 2 << 4
- InputComponent = 4 << 4
- InputRGB = 6 << 4
- InputHDMI = 8 << 4
-
- def __init__(self, parDevice):
- self.ser = serial.Serial(parDevice, 9600, serial.EIGHTBITS, serial.PARITY_NONE, serial.STOPBITS_ONE, xonxoff=0, rtscts=0, dsrdtr=0, timeout=5)
-
- def __del__(self):
- self.ser.close()
-
- def setValue(self, parSet, parCmd, parValue):
- cmd = "%s %02X %02X\r" % (parCmd, parSet, parValue)
- print cmd
- self.ser.write(cmd)
- self.ser.write("\r\r")
- #self.ser.flush()
-
- def readResponse(self):
- print "In waiting: "+str(self.ser.inWaiting())
- if(self.ser.inWaiting() > 9):
- print self.ser.readline()
-
- def getValue(self, parSet, parCmd):
- for i in range(0,1):
- self.setValue(parSet, parCmd, 0xFF)
- time.sleep(0.5)
- print "In waiting: "+str(self.ser.inWaiting())
- if(self.ser.inWaiting() > 9):
- return self.ser.read(10)
- time.sleep(1)
- return None
-
- def power(self, parSet):
- return self.getValue(parSet, "ka")
-
- def power(self, parSet, parWantedState):
- self.setValue(parSet, "ka", parWantedState)
-
- def mute(self, parSet, parWantedState):
- self.setValue(parSet, "ke", not parWantedState)
-
- def input(self, parSet, parGroup, parInput):
- self.setValue(parSet, "xb", parGroup | parInput)
-
-
-tv = LgTV("/dev/ttyUSB0")
+tv = LgTV.LgTV("/dev/ttyUSB0")
#tv.setValue(01, "xb", 0x00)
#print tv.getValue(01, "xb")
#tv.setValue(01, "xb", 0x80)