def __init__(self): threading.Thread.__init__(self) self.lcd = LCD.find_or_die() self.refresh_interval = 2 self.line0 = line0_default self.line1 = line1_default self.line2 = line2_default self.line3 = line3_default
def getOrWait(lcd: lcd2usb.LCD, timeout: int) -> int: """Check if OpenHardwareMonitor is running and wait if necessary. Returns ------- (int) the process ID of OHM. """ while True: proc = get_process() if not proc: logger.warning("OpenHardwareMonitor not running") lcd.clear() lcd.fill_center("Waiting for OHM...") proc = wait_for_process(timeout) if not (proc and proc.ProcessId): continue logger.info("Found OpenHardwareMonitor") return proc.ProcessId
def main(): print('-- LCD2USB test application --') print('-- (c) 2006 by Till Harbaum --') print('-- (c) 2013 by Xie Yanbo --') print('-- http://www.harbaum.org/till/lcd2usb --') list_usb() lcd = LCD.find_or_die() # make lcd interface return some bytes to test transfer reliability lcd_echo(lcd) # read some values from adaptor lcd_get_version(lcd) lcd_get_controller(lcd) lcd_get_keys(lcd) # adjust contrast and brightess lcd.set_contrast(200) lcd.set_brightness(255) # clear display lcd.clear() # write something on the screen msg = (' ' 'The quick brown fox jumps over the lazy dogs back ...' ' ') for i in range(len(msg) - 15): lcd.home() lcd.write(msg[i:i + 16]) # write 16 chars to display time.sleep(0.1) # have some fun with the brightness for i in range(255,-1,-1): lcd.set_brightness(i) time.sleep(0.01) lcd.clear() lcd.write('Bye bye!!!') for i in range(256): lcd.set_brightness(i) time.sleep(0.01) lcd.close()
def main(): print('-- LCD2USB test application --') print('-- (c) 2006 by Till Harbaum --') print('-- (c) 2013 by Xie Yanbo --') print('-- http://www.harbaum.org/till/lcd2usb --') list_usb() lcd = LCD.find_or_die() # make lcd interface return some bytes to test transfer reliability lcd_echo(lcd) # read some values from adaptor lcd_get_version(lcd) lcd_get_controller(lcd) lcd_get_keys(lcd) # adjust contrast and brightess lcd.set_contrast(200) lcd.set_brightness(255) # clear display lcd.clear() # write something on the screen msg = (' ' 'The quick brown fox jumps over the lazy dogs back ...' ' ') for i in range(len(msg) - 15): lcd.home() lcd.write(msg[i:i + 16]) # write 16 chars to display time.sleep(0.1) # have some fun with the brightness for i in range(255, -1, -1): lcd.set_brightness(i) time.sleep(0.01) lcd.clear() lcd.write('Bye bye!!!') for i in range(256): lcd.set_brightness(i) time.sleep(0.01) lcd.close()
def _ram(ram, lcd: lcd2usb.LCD): if ram: ram_used = ram.getSensor('Data', multiple=True).get(0, None) if ram_used: lcd.fill('RAM Used: {:.2f} GB'.format(ram_used.Value), 1) logger.debug("RAM Used Output") else: lcd.fill('RAM Used not detected') logger.warning("RAM Used not detected") else: lcd.fill("RAM not detected", 1) logger.warning("RAM not detected")
def _cpu(cpu, lcd: lcd2usb.LCD): if cpu: cpu_load = cpu.getSensor('Load', multiple=True).get(0, None) if cpu_load: lcd.fill('CPU Load: {:.2%}'.format(cpu_load.Value), 0) logger.debug("CPU Load Output") else: lcd.fill('CPU Load not detected', 0) logger.warning("CPU Load not detected") else: lcd.fill('CPU not detected', 0) logger.warning("CPU not detected")
def __init__(self): #list_usb() self.myLcd = LCD.find_or_die() # adjust contrast and brightess self.myLcd.set_contrast(200) self.myLcd.set_brightness(255) self.myLcd.clear() msg = "Starting ..." self.myLcd.write(msg) time.sleep(1) self.myLcd.clear() processesReady = False while (processesReady == False): process1Ready = self.checkProcessExists("TransMIDIfier.exe") if (process1Ready): msg = "TransMIDIfier OK" self.myLcd.clear() self.myLcd.write(msg) time.sleep(2) process2Ready = self.checkProcessExists("Omnisphere.exe") if (process2Ready): msg = "Omnisphere OK" self.myLcd.clear() self.myLcd.write(msg) time.sleep(2) processesReady = process1Ready and process2Ready time.sleep(1) msg = "Ready to Go!" self.myLcd.clear() self.myLcd.write(msg) time.sleep(1) self.monitorThread = LCDMonitorThread(self.myLcd) self.monitorThread.start() self.keyThread = LCDKeysThread(self.myLcd) self.keyThread.start()
def __init__(self, id, type, lines, columns, device, speed, color, brightness, contrast): print("Creating object VLUBScreen %s" % id) self.id = id self.lines = lines self.columns = columns self.__device = device self.__speed = speed self.__offset = 0 self.type = type if type == "LCD2USB": self.scr = LCD() self.scr.info() self.__device = "USB device" #self.__speed = "unknown speed" self.__speed = 0 else: self.scr = LcdBackpack(device, speed) self.color = color self.brightness = brightness self.contrast = contrast if type != "LCD2USB": self.scr.connect() self.scr.display_on() # Clear the screen self.scr.clear() if type != "LCD2USB": #set the blinking cursor to off - True for this ! self.scr.set_block_cursor(True) #set autoscrolling to off self.scr.set_autoscroll(False) if type == "LCD" or type == "LCD2USB": self.scr.set_brightness(brightness) self.scr.set_contrast(contrast) if type == "LCD": self.scr.set_backlight_rgb(color[0], color[1], color[2]) print("screen %d created - %dx%d on %s at %d" % (id, columns, lines, self.__device, self.__speed))
def _gpu(gpu, lcd: lcd2usb.LCD): if gpu: gpu_load = gpu.getSensor('Load', multiple=True).get(0, None) gpu_temp = gpu.getSensor('Temperature') msgs = ('GPU Load: {:.2%}'.format(gpu_load.Value) if gpu_load else 'GPU Load not detected', 'GPU Temp: {:.2f} C'.format(gpu_temp.Value) if gpu_temp else 'GPU Temp not detected') lcd.fill(msgs[0], 2) lcd.fill(msgs[1], 3) if gpu_load and gpu_temp: logger.debug("GPU Load/Temp Output") else: logger.warning("GPU Load/Temp not detected") else: lcd.fill("GPU not detected", 2) lcd.fill("", 3) logger.warning("GPU not detected")
def basic(lcd: lcd2usb.LCD): """Output basic LCD information and datetime.""" bus, dev = lcd.info(False) version = lcd.version now = datetime.datetime.now() lcd.clear() lcd.fill('LCD Version: {0}.{1}'.format(*version), 0) lcd.fill('Bus: {0:x}, Dev: {1:x}'.format(bus, dev), 1) lcd.fill(str(now), 2) lcd.fill_center('win10py3lcd2usb', 3)
def __init__(self): self.lcd = LCD() self.lcd.clear()
class MyPlugin(EventPlugin): PLUGIN_ID = "quodlibetlcdscreen" PLUGIN_NAME = "quodlibetLCDScreen" PLUGIN_DESC = "Display Artist/Title on external usb screen" PLUGIN_ICON = Icons.PREFERENCES_SYSTEM def __init__(self): self.lcd = LCD() self.lcd.clear() def enabled(self): self.current = 'Hello' self.current2 = getpass.getuser() self.lcd.clear() self.lcd.write(self.current, 0, 0) self.lcd.write(self.current2, 0, 1) def disabled(self): self.current = 'Bye' self.current2 = getpass.getuser() self.lcd.clear() self.lcd.write(self.current, 0, 0) self.lcd.write(self.current2, 0, 1) def plugin_on_song_started(self, song): if song: self.current = str(song['artist']) self.current2 = str(song['title']) else: self.current = '' self.current2 = '' self.lcd.clear() self.lcd.write(self.current.encode("ascii", "ignore"), 0, 0) self.lcd.write(self.current2.encode("ascii", "ignore"), 0, 1) def PluginPreferences(self, parent): def labelTitle(title): lbl = Gtk.Label(xalign=1, yalign=0, wrap=True, justify=Gtk.Justification.RIGHT, selectable=True) lbl.set_text(title) return lbl def labelValue(value): lbl = Gtk.Label(wrap=True, xalign=0, yalign=0, width_chars=25, selectable=True) lbl.set_text(value) return lbl def labelMarkup(value): lbl = Gtk.Label(wrap=True, xalign=0, yalign=0, width_chars=25, selectable=True) lbl.set_markup(value) return lbl vbox = Gtk.VBox(spacing=10) stack = Gtk.Stack() # setting tab gridSettings = Gtk.Grid(column_spacing=12, row_spacing=6) gridSettings.insert_row(0) # Plugin version lbl_lcb_version = labelTitle('USB LCD version : ') lblval_lcd_version = labelValue('%s.%s' % self.lcd.version) gridSettings.attach(lbl_lcb_version, 0, 0, 1, 1) gridSettings.attach(lblval_lcd_version, 1, 0, 1, 1) stack.add_titled(gridSettings, 'labelSettings', 'Settings') # about tab gridAbout = Gtk.Grid(column_spacing=12, row_spacing=6) gridAbout.insert_row(0) # Plugin version lbl_plugin_version = labelTitle('Version : ') lblval_plugin_version = labelValue('0.1') gridAbout.attach(lbl_plugin_version, 0, 0, 1, 1) gridAbout.attach(lblval_plugin_version, 1, 0, 1, 1) # Plugin licence lbl_plugin_licence = labelTitle('Licence : ') lblval_plugin_licence = labelValue('GPL-3.0') gridAbout.attach(lbl_plugin_licence, 0, 1, 1, 1) gridAbout.attach(lblval_plugin_licence, 1, 1, 1, 1) # Plugin author lbl_plugin_author = labelTitle('Author : ') lblval_plugin_author = labelValue('Francois B (Makoto)') gridAbout.attach(lbl_plugin_author, 0, 2, 1, 1) gridAbout.attach(lblval_plugin_author, 1, 2, 1, 1) # Plugin website lbl_plugin_website = labelTitle('Website : ') lblval_plugin_website = labelMarkup('<a href="https://makotonoblog.be/quodlibetLCDScreen">https://makotonoblog.be/quodlibetlcdscreen</a>') gridAbout.attach(lbl_plugin_website, 0, 3, 1, 1) gridAbout.attach(lblval_plugin_website, 1, 3, 1, 1) # Plugin repository lbl_plugin_gitrepo = labelTitle('Github repo : ') lblval_plugin_gitrepo = labelMarkup('<a href="https://github.com/shakasan/quodlibetLCDScreen">https://github.com/shakasan/quodlibetLCDScreen</a>') gridAbout.attach(lbl_plugin_gitrepo, 0, 4, 1, 1) gridAbout.attach(lblval_plugin_gitrepo, 1, 4, 1, 1) stack.add_titled(gridAbout, 'labelAbout', 'About this plugin') stack_switcher = Gtk.StackSwitcher() stack_switcher.set_stack(stack) vbox.pack_start(stack_switcher, True, True, 0) vbox.pack_start(stack, True, True, 0) return vbox
def main(): global lcd global layout global exit_flag global errors thread.start_new_thread(Key_Daemon, ()) RE_welcome = 0 errors = 0 lcd = LCD() while (True): try: if errors == 0: lcd = LCD() #lcd_echo(lcd) if (RE_welcome != 0): #re welcome if (RE_welcome < 6): RE_welcome = 0 if (RE_welcome > 5): Loading() RE_welcome = 0 if layout == 1: main_layout() #主程序界面 sleep(0.3) lcd.goto(19, 2) lcd.write(' ') elif layout == 2: Network_layout() sleep(0.9) elif layout == 0: reload_layout() sleep(0.9) except KeyboardInterrupt: exit_flag = 1 sleep(1) lcd.clear() lcd.goto(0, 1) lcd.write("Program End =w=") lcd.goto(0, 2) lcd.write(datetime.now().strftime('%m/%d %w %p %l:%M:%S')) lcd.set_brightness(10) lcd.close() print('\nProgram End =w=') break except: errors = 1 sleep(5) while errors != 0: USB = os.popen('lsusb') A = USB.read() #print A if (A.find("lcd2usb") == -1): print('NO device!') errors = 1 else: print('ok') errors = 0
errors += 1 if errors: print('ERROR: %d out of %d echo transfers failed!' % (errors, ECHO_NUM)) exit() else: print('Echo test successful!') USB = os.popen('lsusb') A = USB.read() if (A.find("lcd2usb") == -1): print('NO device!') exit() else: lcd = LCD() #lcd_echo(lcd) ################---变量区---############## briLD = 90 #亮度 conDBD = 164 #对比度 ########################################## ########设置########### lcd.set_brightness(briLD) lcd.set_contrast(conDBD) ####################### #lcd.clear() exit_flag = 0
def __init__(self): self.lcd = LCD()
class aqi_lcd: lcd = LCD() def __init__(self): self.lcd = LCD() def display_CF_iaqis(self, aqis): self.display_aqi(PM1_0_CF, aqis[0]) sleep(2) self.display_aqi(PM2_5_CF, aqis[1]) sleep(2) self.display_aqi(PM10_CF, aqis[2]) sleep(2) def display_iaqis(self, aqis): self.display_aqi(PM1_0_ATM, aqis[3]) sleep(2) self.display_aqi(PM2_5_ATM, aqis[4]) sleep(2) self.display_aqi(PM10_ATM, aqis[5]) sleep(2) def display_aqi(self, aqiType, aqi): self.lcd.clear() self.lcd.goto(0, 0) #date_str = datetime.now().strftime('%b %d %H:%M:%S\n') #print(date_str) str_aqi = self.get_aqi_display(aqiType) self.lcd.write(str_aqi) self.lcd.goto(0, 1) str_val = " " + str(aqi) + " ug/m3" if debug: print(str_val) self.lcd.write(str_val) def display_us_pm2_5_aqi(self, aqi_val, category): self.lcd.clear() self.lcd.goto(0, 0) #date_str = datetime.now().strftime('%b %d %H:%M:%S\n') if debug: print(category) self.lcd.write(category) self.lcd.goto(0, 1) str_val = "AQI US: " + aqi_val if debug: print(str_val) self.lcd.write(str_val) sleep(5) def display_chn_pm2_5_aqi(self, aqi_val, category): self.lcd.clear() self.lcd.goto(0, 0) #date_str = datetime.now().strftime('%b %d %H:%M:%S\n') if debug: print(category) self.lcd.write(category) self.lcd.goto(0, 1) str_val = "AQI CHN: " + aqi_val if debug: print(str_val) self.lcd.write(str_val) sleep(2) def get_aqi_display(self, aqiType): display_name = "==== AQI Monitor ====" if debug: print(aqiType) if aqiType == PM1_0_CF: display_name = "PM1_0(CF=1)" if aqiType == PM2_5_CF: display_name = "PM2.5(CF=1)" if aqiType == PM10_CF: display_name = "PM10(CF=1)" if aqiType == PM1_0_ATM: display_name = "PM1.0(ATM)" if aqiType == PM2_5_ATM: display_name = "PM2.5(ATM)" if aqiType == PM10_ATM: display_name = "PM10(ATM) " return display_name def display_ip_adress(self): #cmd = "ip addr show wlan0 | grep inet | awk '{print $2}' | cut -d/ -f1" cmd = "ip addr show eth0 | grep inet | awk '{print $2}' | cut -d/ -f1" self.lcd.clear() ipaddr = self.run_cmd(cmd) self.lcd.goto(0, 0) self.lcd.write('IP Address :') self.lcd.goto(0, 1) self.lcd.write('%s' % (ipaddr)) return ipaddr def display_all_adress(self, isWifi): if isWifi: cmd = "ip addr show wlan0 | grep inet | awk '{print $2}' | cut -d/ -f1" else: cmd = "ip addr show eth0 | grep inet | awk '{print $2}' | cut -d/ -f1" self.lcd.clear() ipaddr = self.run_cmd(cmd) self.lcd.goto(0, 0) if isWifi: self.lcd.write('wlan Address :') else: self.lcd.write('eth Address :') self.lcd.goto(0, 1) self.lcd.write('%s' % (ipaddr)) return ipaddr def run_cmd(self, cmd): p = Popen(cmd, shell=True, stdout=PIPE) output = p.communicate()[0] return output def display_cpu_info(self): self.lcd.clear() self.lcd.goto(0, 0) #first line s = subprocess.check_output(["/opt/vc/bin/vcgencmd", "measure_temp"]) s = s.split('=')[1][:-3] str_temp = "Cpu Temp=" + s + "C" if debug: print(str_temp) self.lcd.write(str_temp) #print CPU temp self.lcd.goto(0, 1) # second line str_usage = "Cpu Usage: " + str(psutil.cpu_percent(1)) + "%" if debug: print(str_usage) self.lcd.write(str_usage) #CPU usage def display_mem_info(self): phymem = psutil.virtual_memory() #phymem_usage() buffers = getattr(psutil, 'phymem_buffers', lambda: 0)() cached = getattr(psutil, 'cached_phymem', lambda: 0)() used = phymem.total - (phymem.free + buffers + cached) if debug: print(str(phymem.total)) if debug: print(str(used)) if debug: print(str(phymem.percent)) self.lcd.clear() self.lcd.goto(0, 0) self.lcd.write("Mem Usage: " + str(phymem.percent) + "%") self.lcd.goto(0, 1) self.lcd.write("Mem: " + str(int(used / 1024 / 1024)) + "M/" + str(int(phymem.total / 1024 / 1024)) + "M")
'''blink.py - blink simle face which defined with two custom smile symbol ''' import time from lcd2usb import LCD, SMILE_SYMBOL BLINK_SMILE = bytearray([0x00, 0x00, 0x0a, 0x00, 0x11, 0x0e, 0x00, 0x00]) def blink(lcd): lcd.hello() while True: time.sleep(1) lcd.define_char(0, BLINK_SMILE) time.sleep(0.3) lcd.define_char(0, SMILE_SYMBOL) if __name__ == '__main__': lcd = LCD.find_or_die() lcd.info() print 'version:', '%s.%s' % lcd.version try: blink(lcd) except KeyboardInterrupt: pass
elif avg1 < 100: load = '%.1f' % avg1 else: load = '%.0f' % avg1 if n % 5 == 0: load_bar = bar.update(avg1) else: load_bar = bar.get_value() n += 1 load_row = 'LOAD %s %s' % (load_bar, load) lcd.fill(load_row, 1) if days: row2 = 'UP %d Days' % days elif hours: row2 = 'UP %d Hours' % hours else: row2 = 'UP %d Mins' % mins row2 += ', %d Users' % users lcd.fill(row2, 2) time.sleep(2) if __name__ == '__main__': lcd = LCD.find_or_die() lcd.info() try: main(lcd) except KeyboardInterrupt: pass
from lcd2usb import LCD import time import os import psutil import RPi.GPIO as GPIO import threading import netifaces as ni ttyActive = False cnxSkip = False lcd = LCD() def checkIfProcessRunning(processName): ''' Check if there is any running process that contains the given name processName. ''' #Iterate over the all the running process for proc in psutil.process_iter(): try: # Check if process name contains the given name string. if processName.lower() in proc.name().lower(): return True except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess): pass
tmp += data[n] * (1<<(4-n)) r.append(tmp) udc.append(bytearray(r)) return udc def write_chinese(c, col, row): udc_array = get_udc_array(c) for i in xrange(0, 8): lcd.define_char(i, udc_array[i]) for j in xrange(0, 2): for i in xrange(0, 4): lcd.write(chr(j*4+i), col+i, row+j) lcd = LCD() print lcd.info() print lcd.version lcd.clear() lcd.write('', 0, 0) texts = [u'蒋悦心真棒', u'辛欣真漂亮'] while True: col = 0 row = 0 for text in texts: col = 0 lcd.clear() lcd.write('', 0, 0)