Exemplo n.º 1
0
 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 __init__(self):
     self.lcd = LCD()
     self.lcd.clear()
Exemplo n.º 3
0
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
Exemplo n.º 4
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

Exemplo n.º 5
0
 def __init__(self):
     self.lcd = LCD()
Exemplo n.º 6
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")