Esempio n. 1
0
    def __init__(self, queue):
        Thread.__init__(self)
        self.daemon = True
        self.status = ''
        self._m_queue = queue
        self._text_shift = 0
        self._lcd = None
        self._manual_mode = False
        self._sleep_time = 0
        self._but1 = None  # Black
        self._but2 = None  # Red

        self._params = self.get_lcd_parms()
        self._but1 = OneButton.OneButton(
            gv.scontrol.board_gpio,
            self._params['but1_pin'],
            activeLow=self._params['but1_NormalOpen'])  # Black
        self._but2 = OneButton.OneButton(
            gv.scontrol.board_gpio,
            self._params['but2_pin'],
            activeLow=self._params['but2_NormalOpen'])  # Red
        self._lcd = pylcd2.lcd(self._params['lcd_adress'],
                               1 if get_rpi_revision() >= 2 else 0)
        self._but1.attachClick(self._butClick)
        self._but2.attachClick(self._butClick)

        self.start()
Esempio n. 2
0
def update_lcd(line1, line2=None):
    """Print messages to LCD 16x2"""

    if lcd_options['address'] == 0:
        find_lcd_address()

    if lcd_options['address'] != 0:
        import pylcd2  # Library for LCD 16x2 PCF8574

        lcd = pylcd2.lcd(lcd_options['address'],
                         0 if helpers.get_rpi_revision() == 1 else 1)
        # DF - alter RPi version test fallback to value that works on BBB
    else:
        lcd = dummy_lcd

    lcd.lcd_clear()
    sleep_time = 1
    while line1 is not None:
        lcd.lcd_puts(line1[:16], 1)

        if line2 is not None:
            lcd.lcd_puts(line2[:16], 2)

        if max(len(line1), len(line2)) <= 16:
            break

        if line1 is not None:
            if len(line1) > 16:
                line1 = line1[1:]

        if line2 is not None:
            if len(line2) > 16:
                line2 = line2[1:]

        time.sleep(sleep_time)
        sleep_time = 0.25
Esempio n. 3
0
def get_LCD_print(self, report):
    """Print messages to LCD 16x2"""
    datalcd = get_lcd_options()
    adr = 0x20
    if datalcd['adress'] == '0x20':  # range adress from PCF8574 or PCF 8574A
        adr = 0x20
    elif datalcd['adress'] == '0x21':
        adr = 0x21
    elif datalcd['adress'] == '0x22':
        adr = 0x22
    elif datalcd['adress'] == '0x23':
        adr = 0x23
    elif datalcd['adress'] == '0x24':
        adr = 0x24
    elif datalcd['adress'] == '0x25':
        adr = 0x25
    elif datalcd['adress'] == '0x26':
        adr = 0x26
    elif datalcd['adress'] == '0x27':
        adr = 0x27
    elif datalcd['adress'] == '0x38':
        adr = 0x38
    elif datalcd['adress'] == '0x39':
        adr = 0x39
    elif datalcd['adress'] == '0x3a':
        adr = 0x3a
    elif datalcd['adress'] == '0x3b':
        adr = 0x3b
    elif datalcd['adress'] == '0x3c':
        adr = 0x3c
    elif datalcd['adress'] == '0x3d':
        adr = 0x3d
    elif datalcd['adress'] == '0x3e':
        adr = 0x3e
    elif datalcd['adress'] == '0x3f':
        adr = 0x3f
    else:
        self.status = ''
        self.add_status('Error: Address is not range 0x20-0x27 or 0x38-0x3F!')
        self._sleep(5)
        return

    import pylcd2  # Library for LCD 16x2 PCF8574
    lcd = pylcd2.lcd(adr, 1 if get_rpi_revision() >= 2 else 0)  # Address for PCF8574 = example 0x20, Bus Raspi = 1 (0 = 256MB, 1=512MB)

    if report == 0:
        lcd.lcd_clear()
        lcd.lcd_puts("Open Sprinkler", 1)
        lcd.lcd_puts("Irrigation syst.", 2)
        self.add_status('Open Sprinkler. / Irrigation syst.')
    elif report == 1:
        lcd.lcd_clear()
        lcd.lcd_puts("Software ospi:", 1)
        lcd.lcd_puts(gv.ver_date, 2)
        self.add_status('Software ospi: / ' + gv.ver_date)
    elif report == 2:
        lcd.lcd_clear()
        ip = get_ip()
        lcd.lcd_puts("My IP is:", 1)
        lcd.lcd_puts(str(ip), 2)
        self.add_status('My IP is: / ' + str(ip))
    elif report == 3:
        lcd.lcd_clear()
        lcd.lcd_puts("Port IP:", 1)
        lcd.lcd_puts("8080", 2)
        self.add_status('Port IP: / 8080')
    elif report == 4:
        lcd.lcd_clear()
        temp = get_cpu_temp(gv.sd['tu']) + ' ' + gv.sd['tu']
        lcd.lcd_puts("CPU temperature:", 1)
        lcd.lcd_puts(temp, 2)
        self.add_status('CPU temperature: / ' + temp)
    elif report == 5:
        lcd.lcd_clear()
        da = time.strftime('%d.%m.%Y', time.gmtime(gv.now))
        ti = time.strftime('%H:%M:%S', time.gmtime(gv.now))
        lcd.lcd_puts(da, 1)
        lcd.lcd_puts(ti, 2)
        self.add_status(da + ' ' + ti)
    elif report == 6:
        lcd.lcd_clear()
        up = uptime()
        lcd.lcd_puts("System run time:", 1)
        lcd.lcd_puts(up, 2)
        self.add_status('System run time: / ' + up)
    elif report == 7:
        lcd.lcd_clear()
        if gv.sd['rs']:
            rain_sensor = "Active"
        else:
            rain_sensor = "Inactive"
        lcd.lcd_puts("Rain sensor:", 1)
        lcd.lcd_puts(rain_sensor, 2)
        self.add_status('Rain sensor: / ' + rain_sensor)
Esempio n. 4
0
    def _lcd_print(self, report, txt=None):
        self._lcd.acquire()
        """Print messages to LCD 16x2"""
        datalcd = get_lcd_options()
        adr = 0x20
        if datalcd[
                'adress'] == '0x20':  # range adress from PCF8574 or PCF 8574A
            adr = 0x20
        elif datalcd['adress'] == '0x21':
            adr = 0x21
        elif datalcd['adress'] == '0x22':
            adr = 0x22
        elif datalcd['adress'] == '0x23':
            adr = 0x23
        elif datalcd['adress'] == '0x24':
            adr = 0x24
        elif datalcd['adress'] == '0x25':
            adr = 0x25
        elif datalcd['adress'] == '0x26':
            adr = 0x26
        elif datalcd['adress'] == '0x27':
            adr = 0x27
        elif datalcd['adress'] == '0x38':
            adr = 0x38
        elif datalcd['adress'] == '0x39':
            adr = 0x39
        elif datalcd['adress'] == '0x3a':
            adr = 0x3a
        elif datalcd['adress'] == '0x3b':
            adr = 0x3b
        elif datalcd['adress'] == '0x3c':
            adr = 0x3c
        elif datalcd['adress'] == '0x3d':
            adr = 0x3d
        elif datalcd['adress'] == '0x3e':
            adr = 0x3e
        elif datalcd['adress'] == '0x3f':
            adr = 0x3f
        else:
            self.status = ''
            self.add_status(
                'Error: Address is not range 0x20-0x27 or 0x38-0x3F!')
            self._sleep(5)
            return

        import pylcd2  # Library for LCD 16x2 PCF8574
        lcd = pylcd2.lcd(
            adr, 1 if get_rpi_revision() >= 2 else 0
        )  # Address for PCF8574 = example 0x20, Bus Raspi = 1 (0 = 256MB, 1=512MB)

        if report == 'name':
            lcd.lcd_clear()
            lcd.lcd_puts(gv.sd['name'], 1)
            lcd.lcd_puts("Irrigation syst.", 2)
            self.add_status('SIP. / Irrigation syst.')
        elif report == 'd_sw_version':
            lcd.lcd_clear()
            lcd.lcd_puts("Software SIP:", 1)
            lcd.lcd_puts(gv.ver_date, 2)
            self.add_status('Software SIP: / ' + gv.ver_date)
        elif report == 'd_ip':
            lcd.lcd_clear()
            ip = get_ip()
            lcd.lcd_puts("My IP is:", 1)
            lcd.lcd_puts(str(ip), 2)
            self.add_status('My IP is: / ' + str(ip))
        elif report == 'd_port':
            lcd.lcd_clear()
            lcd.lcd_puts("Port IP:", 1)
            lcd.lcd_puts(str(gv.sd['htp']), 2)
            self.add_status('Port IP: / {}'.format(gv.sd['htp']))
        elif report == 'd_cpu_temp':
            lcd.lcd_clear()
            temp = get_cpu_temp(gv.sd['tu']) + ' ' + gv.sd['tu']
            lcd.lcd_puts("CPU temperature:", 1)
            lcd.lcd_puts(temp, 2)
            self.add_status('CPU temperature: / ' + temp)
        elif report == 'd_date_time':
            lcd.lcd_clear()
            da = time.strftime('%d.%m.%Y', time.gmtime(gv.now))
            ti = time.strftime('%H:%M:%S', time.gmtime(gv.now))
            lcd.lcd_puts(da, 1)
            lcd.lcd_puts(ti, 2)
            self.add_status(da + ' ' + ti)
        elif report == 'd_uptime':
            lcd.lcd_clear()
            up = uptime()
            lcd.lcd_puts("System run time:", 1)
            lcd.lcd_puts(up, 2)
            self.add_status('System run time: / ' + up)
        elif report == 'd_rain_sensor':
            lcd.lcd_clear()
            if gv.sd['rs']:
                rain_sensor = "Active"
            else:
                rain_sensor = "Inactive"
            lcd.lcd_puts("Rain sensor:", 1)
            lcd.lcd_puts(rain_sensor, 2)
            self.add_status('Rain sensor: / ' + rain_sensor)
        elif report == 'd_running_stations':  # Report running Stations
            lcd.lcd_clear()
            if gv.pon is None:
                prg = 'Idle'
            elif gv.pon == 98:  # something is running
                prg = 'Run-once'
            elif gv.pon == 99:
                prg = 'Manual Mode'
            else:
                prg = "Prog: {}".format(gv.pon)

            s = ""
            if prg != "Idle":
                # Get Running Stations from gv.ps
                for i in range(len(gv.ps)):
                    p, d = gv.ps[i]
                    if p != 0:
                        s += "S{} ".format(str(i))
            lcd.lcd_puts(prg, 1)
            lcd.lcd_puts(s, 2)

        elif report == 'd_alarm_signal':  # ALARM!!!!
            lcd.lcd_clear()
            lcd.lcd_puts("ALARM", 1)
            lcd.lcd_puts(txt, 2)
            self.add_status('Alarm! / ' + txt)

        elif report == 'd_stat_schedule_signal':  # A program has been scheduled
            lcd.lcd_clear()
            lcd.lcd_puts("New Program", 1)
            txt = "Running"  # Do not Know what else to display
            lcd.lcd_puts(txt, 2)
            self.add_status('New Program Running / ' + txt)

        self._lcd.release()
Esempio n. 5
0
#!/bin/python

import pylcd2

lcd = pylcd2.lcd(0x21,0,2)

lcd.lcd_clear()

#while(1):
lcd.lcd_puts(" hello ! ",1)
lcd.lcd_puts(" raspberry pi",2)

Esempio n. 6
0
def get_LCD_print(self, report):
    """Print messages to LCD 16x2"""
    datalcd = get_lcd_options()
    adr = 0x20
    if datalcd['adress'] == '0x20':  # range adress from PCF8574 or PCF 8574A
        adr = 0x20
    elif datalcd['adress'] == '0x21':
        adr = 0x21
    elif datalcd['adress'] == '0x22':
        adr = 0x22
    elif datalcd['adress'] == '0x23':
        adr = 0x23
    elif datalcd['adress'] == '0x24':
        adr = 0x24
    elif datalcd['adress'] == '0x25':
        adr = 0x25
    elif datalcd['adress'] == '0x26':
        adr = 0x26
    elif datalcd['adress'] == '0x27':
        adr = 0x27
    elif datalcd['adress'] == '0x38':
        adr = 0x38
    elif datalcd['adress'] == '0x39':
        adr = 0x39
    elif datalcd['adress'] == '0x3a':
        adr = 0x3a
    elif datalcd['adress'] == '0x3b':
        adr = 0x3b
    elif datalcd['adress'] == '0x3c':
        adr = 0x3c
    elif datalcd['adress'] == '0x3d':
        adr = 0x3d
    elif datalcd['adress'] == '0x3e':
        adr = 0x3e
    elif datalcd['adress'] == '0x3f':
        adr = 0x3f
    else:
        self.status = ''
        self.add_status('Error: Address is not range 0x20-0x27 or 0x38-0x3F!')
        self._sleep(5)
        return

    import pylcd2  # Library for LCD 16x2 PCF8574
    lcd = pylcd2.lcd(adr, 1 if get_rpi_revision() >= 2 else 0)  # Address for PCF8574 = example 0x20, Bus Raspi = 1 (0 = 256MB, 1=512MB)

    if report == 0:
        lcd.lcd_clear()
        lcd.lcd_puts("Open Sprinkler", 1)
        lcd.lcd_puts("Irrigation syst.", 2)
        self.add_status('Open Sprinkler. / Irrigation syst.')
    elif report == 1:
        lcd.lcd_clear()
        lcd.lcd_puts("Software ospi:", 1)
        lcd.lcd_puts(gv.ver_date, 2)
        self.add_status('Software ospi: / ' + gv.ver_date)
    elif report == 2:
        lcd.lcd_clear()
        ip = get_ip()
        lcd.lcd_puts("My IP is:", 1)
        lcd.lcd_puts(str(ip), 2)
        self.add_status('My IP is: / ' + str(ip))
    elif report == 3:
        lcd.lcd_clear()
        lcd.lcd_puts("Port IP:", 1)
        lcd.lcd_puts("8080", 2)
        self.add_status('Port IP: / 8080')
    elif report == 4:
        lcd.lcd_clear()
        temp = get_cpu_temp(gv.sd['tu']) + ' ' + gv.sd['tu']
        lcd.lcd_puts("CPU temperature:", 1)
        lcd.lcd_puts(temp, 2)
        self.add_status('CPU temperature: / ' + temp)
    elif report == 5:
        lcd.lcd_clear()
        da = time.strftime('%d.%m.%Y', time.gmtime(gv.now))
        ti = time.strftime('%H:%M:%S', time.gmtime(gv.now))
        lcd.lcd_puts(da, 1)
        lcd.lcd_puts(ti, 2)
        self.add_status(da + ' ' + ti)
    elif report == 6:
        lcd.lcd_clear()
        up = uptime()
        lcd.lcd_puts("System run time:", 1)
        lcd.lcd_puts(up, 2)
        self.add_status('System run time: / ' + up)
    elif report == 7:
        lcd.lcd_clear()
        if gv.sd['rs']:
            rain_sensor = "Active"
        else:
            rain_sensor = "Inactive"
        lcd.lcd_puts("Rain sensor:", 1)
        lcd.lcd_puts(rain_sensor, 2)
        self.add_status('Rain sensor: / ' + rain_sensor)
Esempio n. 7
0
def get_LCD_print(self, report):
    """Print messages to LCD 16x2"""
    
    find_i2c = 'True'
    lcd_adr = 0
    pcf_type = 'None'
 

    import pylcd2  # Library for LCD 16x2 PCF8574
    import smbus

    bus = smbus.SMBus(1 if get_rpi_revision() >= 2 else 0)

    # find i2c adress
    for addr in range(32, 39): # PCF8574 range 0x20-0x27 
      if (find_i2c == 'True'):  
         try:
            bus.write_quick(addr)
            lcd_adr = addr
            find_i2c = 'False'
            pcf_type = 'PCF8574'
            self.add_status('Find: ' + pcf_type + ' on adress 0x' + ('%02x' % lcd_adr))  
                
         except:
            find_i2c = 'True'
           

    for addr in range(56, 63): # PCF8574A range 0x38-0x3F
      if (find_i2c == 'True'):  
         try:
            bus.write_quick(addr)
            lcd_adr = addr
            find_i2c = 'False'
            pcf_type = 'PCF8574A'
            self.add_status('Find: ' + pcf_type + ' on adress 0x' + ('%02x' % lcd_adr))   
                
         except:
            find_i2c = 'True'
           
    if (find_i2c == 'False'):
      lcd = pylcd2.lcd(lcd_adr, 1 if get_rpi_revision() >= 2 else 0)  # Address for PCF8574 = example 0x20, Bus Raspi = 1 (0 = 256MB, 1=512MB)
      if report == 0:
        lcd.lcd_clear()
        lcd.lcd_puts("Open Sprinkler", 1)
        lcd.lcd_puts("Irrigation syst.", 2)
        self.add_status('Open Sprinkler / Irrigation syst.')
      elif report == 1:
        lcd.lcd_clear()
        lcd.lcd_puts("Software OSPy:", 1)
        lcd.lcd_puts(gv.ver_date, 2)
        self.add_status('Software OSPy: / ' + gv.ver_date)
      elif report == 2:
        lcd.lcd_clear()
        ip = get_ip()
        lcd.lcd_puts("My IP is:", 1)
        lcd.lcd_puts(str(ip), 2)
        self.add_status('My IP is: / ' + str(ip))
      elif report == 3:
        lcd.lcd_clear()
        lcd.lcd_puts("Port IP:", 1)
        lcd.lcd_puts("8080", 2)
        self.add_status('Port IP: / 8080')
      elif report == 4:
        lcd.lcd_clear()
        temp = get_cpu_temp(gv.sd['tu']) + ' ' + gv.sd['tu']
        lcd.lcd_puts("CPU temperature:", 1)
        lcd.lcd_puts(temp, 2)
        self.add_status('CPU temperature: / ' + temp)
      elif report == 5:
        lcd.lcd_clear()
        da = time.strftime('%d.%m.%Y', time.gmtime(gv.now))
        ti = time.strftime('%H:%M:%S', time.gmtime(gv.now))
        lcd.lcd_puts(da, 1)
        lcd.lcd_puts(ti, 2)
        self.add_status(da + ' ' + ti)
      elif report == 6:
        lcd.lcd_clear()
        up = uptime()
        lcd.lcd_puts("System run time:", 1)
        lcd.lcd_puts(up, 2)
        self.add_status('System run time: / ' + up)
      elif report == 7:
        lcd.lcd_clear()
        if gv.sd['rs']:
            rain_sensor = "Active"
        else:
            rain_sensor = "Inactive"
        lcd.lcd_puts("Rain sensor:", 1)
        lcd.lcd_puts(rain_sensor, 2)
        self.add_status('Rain sensor: / ' + rain_sensor)
      elif report == 8:
        lcd.lcd_clear()
        try: 
            from pressure_adj import get_check_pressure
            state_press = get_check_pressure()
            if state_press: 
                lcd.lcd_puts("Pressure sensor:", 1)
                lcd.lcd_puts("GPIO is HIGH", 2)
                self.add_status('Pressure sensor: / GPIO is HIGH')

            else:
                lcd.lcd_puts("Pressure sensor:", 1)
                lcd.lcd_puts("GPIO is LOW", 2)
                self.add_status('Pressure sensor: / GPIO is LOW')

        except:
                lcd.lcd_puts("Pressure sensor:", 1)
                lcd.lcd_puts("Not used", 2)
                self.add_status('Pressure sensor: / Not used')
      elif report == 9:
        lcd.lcd_clear()
        if gv.lrun[1] == 98:
           pgr = 'Run-once'
        elif gv.lrun[1] == 99:
           pgr = 'Manual'
        else:
           pgr = str(gv.lrun[1])
        stop = time.gmtime(gv.lrun[2])
        if pgr != '0':
             logline2 = 'P' + pgr + ' ' + timestr(gv.lrun[2])
        else:
             logline2 = 'None' 
        lcd.lcd_puts('Last program', 1)
        lcd.lcd_puts(logline2, 2)
        self.add_status('Last program / ' + logline2)
       
      #------- end text to 16x2 -----------------

      elif report == 100: # start text to 16x1
        lcd.lcd_clear()
        lcd.lcd_puts("Open Sprinkler", 1)
        self.add_status('Open Sprinkler')
      elif report == 101:
        lcd.lcd_clear()
        lcd.lcd_puts("Irrigation syst.", 1)
        self.add_status('Irrigation syst.')
      elif report == 102:
        lcd.lcd_clear()
        lcd.lcd_puts("Software OSPy:", 1)
        self.add_status('Software OSPy:')
      elif report == 103:
        lcd.lcd_clear()
        lcd.lcd_puts(gv.ver_date, 1)
        self.add_status(gv.ver_date)
      elif report == 104:
        lcd.lcd_clear()
        lcd.lcd_puts("My IP is:", 1)
        self.add_status('My IP is:')
      elif report == 105:
        lcd.lcd_clear()
        ip = get_ip()
        lcd.lcd_puts(str(ip), 1)
        self.add_status(str(ip))
      elif report == 106:
        lcd.lcd_clear()
        lcd.lcd_puts("Port IP:", 1)
        self.add_status('Port IP:')
      elif report == 107:
        lcd.lcd_clear()
        lcd.lcd_puts("8080", 1)
        self.add_status('8080')
      elif report == 108:
        lcd.lcd_clear()
        lcd.lcd_puts("CPU temperature:", 1)
        self.add_status('CPU temperature:')
      elif report == 109:
        lcd.lcd_clear()
        temp = get_cpu_temp(gv.sd['tu']) + ' ' + gv.sd['tu']
        lcd.lcd_puts(temp, 1)
        self.add_status(temp)
      elif report == 110:
        lcd.lcd_clear()
        da = time.strftime('%d.%m.%Y', time.gmtime(gv.now))
        lcd.lcd_puts("Date: " + da, 1)
        self.add_status('Date: ' + da)
      elif report == 111:
        lcd.lcd_clear()
        ti = time.strftime('%H:%M:%S', time.gmtime(gv.now))
        lcd.lcd_puts("Time: " + ti, 1)
        self.add_status('Time: ' + ti)
      elif report == 112:
        lcd.lcd_clear()
        lcd.lcd_puts("System run time:", 1)
        self.add_status('System run time:')
      elif report == 113:
        lcd.lcd_clear()
        up = uptime()
        lcd.lcd_puts(up, 1)
        self.add_status(up)
      elif report == 114:
        lcd.lcd_clear()
        lcd.lcd_puts("Rain sensor:", 1)
        self.add_status('Rain sensor:')
      elif report == 115:
        lcd.lcd_clear()
        if gv.sd['rs']:
            rain_sensor = "Active"
        else:
            rain_sensor = "Inactive"
        lcd.lcd_puts(rain_sensor, 1)
        self.add_status(rain_sensor)
      elif report == 116:
        lcd.lcd_clear()
        lcd.lcd_puts('Last program', 1)
        self.add_status('Last program')
      elif report == 117:
        lcd.lcd_clear()
        if gv.lrun[1] == 98:
           pgr = 'Run-once'
        elif gv.lrun[1] == 99:
           pgr = 'Manual'
        else:
           pgr = str(gv.lrun[1])
        stop = time.gmtime(gv.lrun[2])
        if pgr != '0':
             logline2 = 'P' + pgr + ' ' + timestr(gv.lrun[2])
        else:
             logline2 = 'none' 
        lcd.lcd_puts(logline2, 1)
        self.add_status(logline2)
      elif report == 118:
        lcd.lcd_clear()
        lcd.lcd_puts("Pressure sensor:", 1)
        self.add_status('Pressure sensor:')
      elif report == 119:
        lcd.lcd_clear()
        try: 
            from pressure_adj import get_check_pressure
            state_press = get_check_pressure()
            if state_press: 
                lcd.lcd_puts("GPIO is HIGH", 1)
                self.add_status('GPIO is HIGH')

            else:
                lcd.lcd_puts("GPIO is LOW", 1)
                self.add_status('GPIO is LOW')

        except:
                lcd.lcd_puts("Not used", 1)
                self.add_status('Not used')
 

    else:
      self.add_status('No find PCF8574 controller.')