commands converted from C-program to python, now replacing all calls accordingly

This commit is contained in:
Florian Streibelt 2011-10-18 19:23:14 +02:00
parent 5c9d45b725
commit 0aad574f60
2 changed files with 58 additions and 9 deletions

View File

@ -1,8 +1,9 @@
import serial
class Display:
def __init__(self,portname="/dev/ttyUSB0"):
#code here
self.serialport=None
self.open_port(portname)
@ -13,13 +14,61 @@ class Display:
def open_port(self,portname):
self.serialport = serial.Serial(portname,9600,timeout=2,rtscts=True, dsrdtr=True)
self.reset_display()
self.send("Hello world")
print ("Initializing display:\n %s\n" % self.serialport )
self.cmd_reset()
self.write("Hello world")
def cmd_reset(self):
#reset the display
self.write("\x1b\x40")
def cmd_cursor_show(self,on=True):
#show or hide the cursor
if (on):
self.write("\x1f\x43\x01")
else:
self.write("\x1f\x43\x00")
def cmd_blink(self,rate=127):
self.write("\x1f\x45%c" % rate)
def cmd_display_on(self,on=True):
# blink-command:
# where the last value defines the blink rate,
# with 0=always on, 255=always off
if (on):
self.cmd_blink(0)
else:
self.cmd_blink(255)
def cmd_curmode_overwrite(self):
cmd_curmode(1)
def cmd_curmode_vscroll(self):
cmd_curmode(2)
def cmd_curmode_hscroll(self):
cmd_curmode(3)
def cmd_curmode(self,val=2):
self.write("\x1f%c" % val)
def cmd_clear(self):
self.write("\x0c")
def reset_display(self):
print ("Initializing display on port %s\n" % self.serialport )
#code here
def cmd_time(self):
# activate timer display in lower right corner.
# actual time has to be set via display_set_timer.
self.write("\x1f\x55")
def send(self,text):
def cmd_time_set(self,h,m):
# configures hour and minutes of the internal clock and
# displays the time in the lower right corner.
# turns off when something gets written into the line.
# two bytes have to follow with hour and minute
self.write("\x1F\x54%c%c" % (h,m) )
def write(self,text):
self.serialport.write(text)

View File

@ -581,7 +581,7 @@ def main():
global myDisplay
myDisplay = Display("/dev/ttyUSB0")
myDisplay.reset_display()
myDisplay.cmd_reset()
print_display("\x1b\x40\x1f\x43\x00")
start_new_thread(display_thread,(1,))