def _greetings(canvas, net, led): ui = MeteoUi(canvas, None, net) ui.repaint_welcome(led) write('display', (DISPLAY_REQUIRES_FULL_REFRESH, )) log('Going to deep sleep ...') deepsleep()
def repaint_config(self, led, volt): from config.spot import hotspot # After config we will need to repaint all write('display', (DISPLAY_REQUIRES_FULL_REFRESH, )) print('Drawing config ...') led.mode(led.DRAWING) self.canvas.fill(WHITE) qr_dr(self, Vect(0, 0), Vect(0, 0), ('WIFI:T:WPA;S:{};P:{};;'.format( hotspot.ssid, hotspot.passwd), 'WiFi', False)) url = 'http://{}:5555'.format(self.connection.ifconfig[0]) qr_dr(self, Vect(278, 178), Vect(0, 0), (url, 'Config URL', True)) url_dr(self, Vect(0, self.canvas.dim.y // 2), Vect(self.canvas.dim.x - 132, self.canvas.dim.y // 2), url) wifi_dr(self, Vect(200, 0), Vect(self.canvas.dim.x - 132, self.canvas.dim.y // 2), hotspot) vbat_dr(self, Vect(self.canvas.dim.x // 2 - 10, self.canvas.dim.y // 2), Vect(20, 10), volt) print('Flushing ...') led.mode(led.FLUSHING) self.canvas.flush()
def repaint_weather(self, led, volt): # Redraw display print('Drawing weather ...') led.mode(led.DRAWING) self.canvas.fill(WHITE) if self.connection is None: # No forecast when there is no connection. Just draw no-wifi # symbol into middle of screen and leave bitmap = self.bitmap(1, 'nowifi') self.canvas.bitmap(Vect(177, 0), bitmap) else: # We have forecast, so lets draw it on screen. Don't draw # always everything as forecast is changing not so often, # but temperature is. status = self.forecast.status if not status.refresh == TEMPERATURE: weather_dr(self, Vect(0, 0), Vect(400, 100)) l = outside_dr(self, Vect(105, 0), Vect(295, 50)) outtemp_dr(self, Vect(105, 0), Vect(295, 50)) if status.refresh == ALL: cal_dr(self, Vect(0, 100), Vect(400, 26)) if not status.refresh == TEMPERATURE: inside_dr(self, Vect(105, 50), Vect(295, 50), l, self.connection) vbat_dr(self, Vect(284, 87), Vect(14, 10), volt) intemp_dr(self, Vect(105, 50), Vect(295, 50)) if status.refresh == ALL: cal_dr(self, Vect(0, 176), Vect(400, _CHART_HEIGHT + 5), False) tempg_dr(self, Vect(0, 176), Vect(400, _CHART_HEIGHT)) icons_dr(self, Vect(0, 137), Vect(400, 40)) wind_dr(self, Vect(0, 282), Vect(400, 20)) rain_dr(self, Vect(0, 176), Vect(400, _CHART_HEIGHT)) tempt_dr(self, Vect(0, 176), Vect(400, _CHART_HEIGHT)) # Flush drawing on display (upper or all parts) print('Flushing ...') led.mode(led.FLUSHING) if self.connection is None: self.canvas.flush((180, 0, 32, 27)) elif status.refresh == TEMPERATURE: self.canvas.flush((124, 0, 92, 98)) elif status.refresh == WEATHER: self.canvas.flush((0, 0, 400, 98)) else: self.canvas.flush() # Display is repainted, so next can be just partial repaint write('display', (DISPLAY_JUST_REPAINT, ))
def repaint_lowbat(self, volt): if not display.DISPLAY_STATE == DISPLAY_DONT_REFRESH: print('Drawing lowbat ...') self.canvas.fill(WHITE) v = Vect(self.canvas.dim.x // 2 - 30, self.canvas.dim.y // 2) d = Vect(60, 30) vbat_dr(self, v, d, volt) print('Flushing ...') self.canvas.flush((v.x - 20, v.y - 26, d.x + 46, d.y + 40)) display.DISPLAY_STATE = DISPLAY_DONT_REFRESH write('display') else: print('Already painted ... saving battery')
def _allerts(forecast): if not alert.temp_balanced: return if temp.indoor_high > forecast.home.temp: return h = forecast.time.get_date_time(forecast.weather.dt)[3] if h == 13: write('alert', (False, )) return if not alert_var.ALREADY_TRIGGERED and forecast.home.temp > forecast.weather.temp: for i in range(3): play((4000, 30), (6000, 30), (4000, 30), (6000, 30), (4000, 30), (6000, 30), (4000, 30), (6000, 30), 500) write('alert', (True, ))
def _restart(msg): self.wdt.feed() log(msg) play((2093, 30), 120, (1568, 30), 120, (1319, 30), 120, (1047, 30)) write('mode', (1, ), force=True) deepsleep(1)
def page(web): play((2093, 30), 120, (1568, 30), 120, (1319, 30), 120, (1047, 30)) write('display', (DISPLAY_GREETINGS,)) reset()
def _perif(): # First of all we have to initialize watchdog if requested log('Initializing watchdog ...') from machine import WDT wdt = WDT(timeout=120000) # Reads internal temperature just after wake-up to reduce # influence of chip warm-up and use some kind of ambient # reduction to get more close to indoor temperature. This # value will be used when DTH22 or DHT11 sensor is # not found on selected pin. # # Just note that better is to connect DHT22/DTH11 for # more precise temperature measurement and also for information # about humidity. temp = ((raw_temperature() - 32) / 1.8) - 26.0 # There is LED driver for debugging purposes. LED control # is running on background and can be disabled to save # piece of battery capacity. However then there is no # other way how to signalizes in which state meteostation # is then UART. led = Led() # Disable LED when battery voltage is too low volt = battery.voltage if (volt < vbat.low_voltage): led.disable() # We shall checks if there is requested to toggle temperature alarm if jumpers.alert: alert.temp_balanced = not alert.temp_balanced if alert.temp_balanced: play((100, 50), (200, 50), (400, 50), (800, 50), (1600, 50), (3200, 50)) write('alert', (False, )) else: play((3200, 50), (1600, 50), (800, 50), (400, 50), (200, 50), (100, 50)) alert.flush() deepsleep(1) # As we uses E-Ink display, the most comfortable way # how to work with it is to define canvas object for # drawing objects and flushing them later on screen. led.mode(Led.WARM_UP) canvas = Canvas() # When battery voltage is too low, just draw low battery # error on screen and go to deep sleep. if (volt < vbat.low_voltage): led.mode(Led.ALERT) ui = MeteoUi(canvas, None, None) ui.repaint_lowbat(volt) log('Low battery !!!') _sleep(15) # Once we have canvas established (large object needs # to be created first to prevent from memory fragmentation), # we can establish WiFi connection and connect to network. led.mode(Led.DOWNLOAD) net = None try: net = Connection() log('Connected to network') except Exception as e: dump_exception('Network connection error', e) return temp, led, volt, canvas, net, wdt