コード例 #1
0
class PHIDGET_TEXTLCD(object):
    """ Phidget TextLCD with integrated InterfaceKit """
    def __init__(self, serialNumber=None, waitForAttach=1000, **kargs):

        self.textLCD = TextLCD()

        if 'remoteHost' in kargs:
            self.textLCD.openRemote(kargs['remoteHost'], serialNumber)
        else:
            self.textLCD.openPhidget(serialNumber)


        h = [
            'onAttachHandler',
            'onDetachHandler',
            'onErrorhandler'
            ]

        for event in h:
            self.__dict__[event] = None
            if event in kargs:
                self.__dict__[event] = kargs[event]

        self.textLCD.setOnAttachHandler(self.attached)
        self.textLCD.setOnDetachHandler(self.detached)

        if waitForAttach > 0:
            try:
                self.textLCD.waitForAttach(waitForAttach)
            except PhidgetException as e:
                #print("Phidget Exception %i: %s" % (e.code, e.details))
                try:
                    self.textLCD.closePhidget()
                except PhidgetException as e2:
                    pass
                raise e
    

    def attached(self, e):
        from Phidgets.Phidget import PhidgetID
        if e.device.getDeviceID()==PhidgetID.PHIDID_TEXTLCD_ADAPTER:
            e.device.setScreenIndex(0)
            e.device.setScreenSize(TextLCD.TextLCD_ScreenSize.PHIDGET_TEXTLCD_SCREEN_2x20)
        if self.onAttachHandler: self.onAttachHandler(e)

    def detached(self, e):
        if self.onDetachHandler: self.onDetachHandler(e)

    def error(self, e):
        error = {'code': e.eCode, 'description': e.description}
        if self.onErrorhandler: self.onErrorhandler(error, e)
コード例 #2
0
class csss_lcd:
	str_top = ""
	str_bottom = ""
	top_len = 0
	bot_len = 0
	textLCD = None
	
	def __init__(self):
		print("INIT: LCD")
		try:
			self.textLCD = TextLCD()
		except RuntimeError as e:
			print("RuntimeExceotion: %s" % e.details)
			print("Exiting....")
			exit(1)
		
		try:
			self.textLCD.setOnAttachHandler(TextLCDAttached)
			self.textLCD.setOnDetachHandler(TextLCDDetached)
			self.textLCD.setOnErrorhandler(TextLCDError)
		except PhidgetException as e:
			print("Phidget Exception %i: %s" % (e.code, e.details))
			print("Exiting....")
			exit(1)
		
		try:
			self.textLCD.openPhidget()
		except PhidgetException as e:
			print("Phidget Exception %i: %s" % (e.code, e.details))
			print("Exiting....")
			exit(1)	
		sleep(2)		
		return

	#Information Display Function
	def display(self, row, str):
			print("Displaying %s" % str)
			if len(str) > 20:
				self.scroll(row, str)
			try:
				if self.textLCD.getDeviceID()==PhidgetID.PHIDID_TEXTLCD_ADAPTER:
						self.textLCD.setScreenIndex(0)
						self.textLCD.setScreenSize(TextLCD_ScreenSize.PHIDGET_TEXTLCD_SCREEN_2x8)
				self.textLCD.setDisplayString(row, str)#bytes(str, 'utf-8'))
			except PhidgetException as e:
				print("Phidget Exception %i: %s" % (e.code, e.details))

	def displaySlow(self, row,str):
			self.display(row, str)
			sleep(0.75)

	def scroll(self, row, str):
			length = len(str)
			currIndex = 0
			endIndex = 20
			self.displaySlow(row, str[currIndex:endIndex])
			for currIndex in range (1,length):
				self.display(row,str[currIndex:endIndex])
				if endIndex < length:
					endIndex += 1
				sleep(0.22)
			self.clearRow(row)

	def clearRow(self, row):
			print("Clearing TextLCD")
			self.display(row, " ")

	def clearAll(self):
			self.clearRow(0)
			self.clearRow(1)

	def close(self):
		try:
			print("Closing TextLCD")
			self.textLCD.closePhidget()
		except PhidgetException as e:
			print("Phidget Exception &i: %s" % (e.code, e.details))
			print("Exiting....")
			exit(1)
コード例 #3
0
ファイル: thi2textlcd.py プロジェクト: kj1216/thi2textlcd
        interfaceKit.openPhidget()
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")
        exit(1)

    print("Waiting for attach....")

    try:
        textLCD.waitForAttach(10000)
        interfaceKit.waitForAttach(10000)
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        try:
            interfaceKit.closePhidget()
            textLCD.closePhidget()
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.details))
            print("Exiting....")
            exit(1)
        print("Exiting....")
        exit(1)
    else:
        displaylcdinfo()
        dispalyifkinfo()

    print("Setting the data rate for each sensor index to 4ms....")
    for i in range(interfaceKit.getSensorCount()):
        try:
            interfaceKit.setDataRate(i, 4)
        except PhidgetException as e:
#Open the textLCD
try:
    textLCD.openPhidget()
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    print("Exiting....")
    exit(1)

#Wait for the device to attach
try:
    textLCD.waitForAttach(10000)
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    try:
        textLCD.closePhidget()
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")
        exit(1)
    print("Exiting....")
    exit(1)

try:
    textLCD.setScreenIndex(0)

    #print("Writing to first row....")
    textLCD.setDisplayString(0, "Initialising...")
    sleep(2)

    textLCD.setBacklight(True)