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 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
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
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")
ttyRecentActivity = False ttyCount = 0 time.sleep(0.01) GPIO.setmode(GPIO.BCM) GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) print("launching TTY monitor thread") x = threading.Thread(target=ttyMonitor, args=(1, )) x.start() lcd.info() lcd.clear() lcd.write('Connecting', 0, 0) time.sleep(1) count = 0 ip_address = "" while 1: try: ip_address = ni.ifaddresses('eth0')[ni.AF_INET][0]['addr'] except KeyError: print("netif not yet available\n") print("IP address : ", ip_address) if (ip_address == "10.3.141.2"): lcd.clear() lcd.write('Connected !', 0, 0) time.sleep(2) break