def __init__(self, data): self.log = logging.getLogger('airpi.lcdpanel') self.cols = int(data["cols"]) self.rows = int(data["rows"]) self.delay = float(data["delay"]) self.sl = [0, 1 ,1 ,1] # first line is static others scroll try: self.lcd = lcddriver.lcd() self.lcd.display_string(" Airpi LCD panel ", 2) self.lcd.display_string(" Init was a Success ", 3) # setup LcdScroller thread object data = (u" Airpi Sensor Info. ", u"Temp: Unknown, P: Unknown, RH: Unknown ", u"LL: Unknown, LLl: Unknown, Vol: Unknown ", u"NO2: Unknown, CO: Unknown ") self.scroller = LcdScroller(self.lcd, self.rows, self.cols, self.delay, self.sl, data) self.scroller.start() except Exception as e: self.log.error("Error initialising LCDpanel: {}".format(e)) raise else: self.log.debug("Initialised successfully")
class LCDpanel(output.Output): requiredData = ["cols", "rows", "delay"] optionalData = [] lcd = None def __init__(self, data): self.log = logging.getLogger('airpi.lcdpanel') self.cols = int(data["cols"]) self.rows = int(data["rows"]) self.delay = float(data["delay"]) self.sl = [0, 1 ,1 ,1] # first line is static others scroll try: self.lcd = lcddriver.lcd() self.lcd.display_string(" Airpi LCD panel ", 2) self.lcd.display_string(" Init was a Success ", 3) # setup LcdScroller thread object data = (u" Airpi Sensor Info. ", u"Temp: Unknown, P: Unknown, RH: Unknown ", u"LL: Unknown, LLl: Unknown, Vol: Unknown ", u"NO2: Unknown, CO: Unknown ") self.scroller = LcdScroller(self.lcd, self.rows, self.cols, self.delay, self.sl, data) self.scroller.start() except Exception as e: self.log.error("Error initialising LCDpanel: {}".format(e)) raise else: self.log.debug("Initialised successfully") def outputData(self, dataPoints): try: line1_str = line2_str = line3_str = line4_str = "" bl = 0 for i in dataPoints: self.log.debug(i) disp_str = "" # handle GPS data when available if i["type"] == "Location": disp_str = u"Location: Unknown; " if i["utc"] != None: # make line 1 scroll self.sl[0] = 1 if i["lat"] > float(0.0): if i["m/s"] != None: disp_str = u"{}-{}-{} {} UTC; {:.4f}{},{:.4f}{}; {:.1f} ft; {:.1f} mph; ".format(i["utc"][8:10], i["utc"][5:7], i["utc"][2:4], i["utc"][11:16], i["lat"], ds, i["lon"], ds, i["ele"] * ft_mult, i["m/s"] * mph_mult) else: disp_str = u"DT: {} {}; Posn: {:.4f}{}, {:.4f}{}; Alt: {} m; ".format(i["utc"][:10], i["utc"][11:19], i["lat"], ds, i["lon"], ds, i["ele"]) elif i["type"] == "Temperature": disp_str = u"{}: {:.1f}{}{}; ".format(abbr[i["type"]], i["value"], ds, i["symbol"]) else: disp_str = u"{}: {:.2f} {}; ".format(abbr[i["type"]], i["value"], i["symbol"]) # add to correct line string if i["type"] == "Location": line1_str += disp_str elif i["type"] == "Temperature": line2_str += disp_str elif i["type"] == "Pressure": line2_str += disp_str elif i["type"] == "Relative_Humidity": line2_str += disp_str elif i["type"] == "Light_Level": line3_str += disp_str elif i["type"] == "Light_Level_Lux": line3_str += disp_str if i["value"] < float(10.0): # enable backlight at low light levels bl = 1 elif i["type"] == "Volume": line3_str += disp_str else: line4_str += disp_str # update LcdScroller thread data self.scroller.updData(self.sl, (line1_str, line2_str, line3_str, line4_str), bl) except Exception as e: self.log.error("Error displaying string on LCD: {}".format(e)) raise else: return True def clearLCD(self): print("Stopping LcdScroller thread") self.log.info("Stopping LcdScroller thread {}".format(self.scroller.isAlive())) if self.scroller.isAlive(): self.scroller.stopScroller() self.scroller.join() print("Clearing LCD panel & turning off backlight") self.log.info("Clearing LCD panel & turning off backlight") self.lcd.clear(bl=0)