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()
import json import time import sys import traceback import web import gv # Get access to ospi's settings from urls import urls # Get access to ospi's URLs from ospy import template_render from webpages import ProtectedPage from helpers import get_rpi_revision # I2C bus Rev Raspi RPI=1 rev1 RPI=0 rev0 try: import smbus # for PCF 8591 ADC = smbus.SMBus(1 if get_rpi_revision() >= 2 else 0) except ImportError: ADC = None # Add a new url to open the data entry page. urls.extend(['/pcf', 'plugins.pcf_8591_adj.settings', '/pcfj', 'plugins.pcf_8591_adj.settings_json', '/pcfa', 'plugins.pcf_8591_adj.update', '/pcfl', 'plugins.pcf_8591_adj.pcf_log', '/pcfr', 'plugins.pcf_8591_adj.delete_log']) # Add this plugin to the home page plugins menu gv.plugin_menu.append(['PCF8591 voltage and temperature settings ', '/pcf']) ################################################################################ # Main function loop: #
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)
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()
import time import sys import traceback import web import gv # Get access to SIP's settings from urls import urls # Get access to SIP's URLs from sip import template_render from webpages import ProtectedPage from helpers import get_rpi_revision # I2C bus Rev Raspi RPI=1 rev1 RPI=0 rev0 try: import smbus # for PCF 8591 ADC = smbus.SMBus(1 if get_rpi_revision() >= 2 else 0) except ImportError: ADC = None # Add a new url to open the data entry page. urls.extend([ "/pcf", "plugins.pcf_8591_adj.settings", "/pcfj", "plugins.pcf_8591_adj.settings_json", "/pcfa", "plugins.pcf_8591_adj.update", "/pcfl", "plugins.pcf_8591_adj.pcf_log", "/pcfr", "plugins.pcf_8591_adj.delete_log",
def _lcd_print(self, report, txt=None): self._lcd_lock.acquire() # Print messages to LCD 16x2 datalcd = get_lcd_options() adr = int(datalcd[u"adress"], 0) if adr not in self._addresses: self.status = "" self.add_status( u"Error: Address is not range 0x20-0x27 or 0x38-0x3F!") self._lcd_lock.release() self._sleep(5) return # If the address has changed: Turn off the backlight and clear the LCD then forget the pylcd object. if self._lcd is not None and self._lcd.lcd_device.addr != adr: self._lcd.backlight = 0 # takes effect during next update call on self._lcd self._lcd.lcd_clear() self._lcd = None # Create a pylcd object if necessary if self._lcd is None: self._lcd = pylcd.lcd( adr, (1 if get_rpi_revision() >= 2 else 0), 1 ) # Address for PCF8574 = example 0x20, Bus Raspi = 1 (0 = 256MB, 1=512MB) if self._lcd.error is not None: self.status = u"" self.add_status(u"Error: [Errno " + str(self._lcd.error.errno) + u"] Display not found at address " + datalcd[u"adress"]) self._lcd = None self._lcd_lock.release() self._sleep(5) return if report == u"name": self._lcd.lcd_clear() self._lcd.lcd_puts(gv.sd[u"name"], 1) self._lcd.lcd_puts(u"Irrigation syst.", 2) self.add_status(u"SIP. / Irrigation syst.") elif report == u"d_sw_version": self._lcd.lcd_clear() self._lcd.lcd_puts(u"Software SIP:", 1) self._lcd.lcd_puts(gv.ver_date, 2) self.add_status(u"Software SIP: / " + gv.ver_date) elif report == u"d_ip": self._lcd.lcd_clear() ip = get_ip() self._lcd.lcd_puts(u"My IP is:", 1) self._lcd.lcd_puts(str(ip), 2) self.add_status(u"My IP is: / " + str(ip)) elif report == u"d_port": self._lcd.lcd_clear() self._lcd.lcd_puts(u"Port IP:", 1) self._lcd.lcd_puts(str(gv.sd[u"htp"]), 2) self.add_status(u"Port IP: / {}".format(gv.sd[u"htp"])) elif report == u"d_cpu_temp": self._lcd.lcd_clear() temp = str(get_cpu_temp()) + u" " + gv.sd[u"tu"] self._lcd.lcd_puts(u"CPU temperature:", 1) self._lcd.lcd_puts(temp, 2) self.add_status(u"CPU temperature: / " + temp) elif report == u"d_date_time": self._lcd.lcd_clear() da = time.strftime(u"%d.%m.%Y", time.gmtime(gv.now)) ti = time.strftime(u"%H:%M:%S", time.gmtime(gv.now)) self._lcd.lcd_puts(da, 1) self._lcd.lcd_puts(ti, 2) self.add_status(da + " " + ti) elif report == u"d_uptime": self._lcd.lcd_clear() up = uptime() self._lcd.lcd_puts(u"System run time:", 1) self._lcd.lcd_puts(up, 2) self.add_status(u"System run time: / " + up) elif report == u"d_rain_sensor": self._lcd.lcd_clear() if gv.sd[u"rs"]: rain_sensor = u"Active" else: rain_sensor = u"Inactive" self._lcd.lcd_puts(u"Rain sensor:", 1) self._lcd.lcd_puts(rain_sensor, 2) self.add_status(u"Rain sensor: / " + rain_sensor) elif report == u"d_running_stations": # Report running Stations self._lcd.lcd_clear() if gv.pon is None: prg = u"Idle" elif gv.pon == 98: # something is running prg = u"Run-once" elif gv.pon == 99: prg = u"Manual Mode" else: prg = u"Prog: {}".format(gv.pon) s = "" if prg != u"Idle": # Get Running Stations from gv.ps for i in range(len(gv.ps)): p, d = gv.ps[i] if p != 0: s += u"S{} ".format(str(i + 1)) self._lcd.lcd_puts(prg, 1) self._lcd.lcd_puts(s, 2) elif report == u"d_alarm_signal": # ALARM!!!! self._lcd.lcd_clear() self._lcd.lcd_puts(u"ALARM", 1) self._lcd.lcd_puts(txt, 2) self.add_status(u"Alarm! / " + txt) elif report == u"d_stat_schedule_signal": # A program has been scheduled self._lcd.lcd_clear() self._lcd.lcd_puts(u"New Program", 1) txt = u"Running" # Do not Know what else to display self._lcd.lcd_puts(txt, 2) self.add_status(u"New Program Running / " + txt) self._lcd_lock.release()
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.')