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

master
Florian Streibelt 13 years ago
parent 5c9d45b725
commit 0aad574f60

@ -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 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 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 reset_display(self):
print ("Initializing display on port %s\n" % self.serialport )
#code here
def send(self,text):
def write(self,text):
self.serialport.write(text)

@ -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,))

Loading…
Cancel
Save