def show(self): super().show() lcd.print('Setup light from/to', lcd.CENTER, 85) self._lightSchedule = [ kippenstalConfig.getLight1From().split(':')[0], kippenstalConfig.getLight1From().split(':')[1], kippenstalConfig.getLight1To().split(':')[0], kippenstalConfig.getLight1To().split(':')[1], kippenstalConfig.getLight2From().split(':')[0], kippenstalConfig.getLight2From().split(':')[1], kippenstalConfig.getLight2To().split(':')[0], kippenstalConfig.getLight2To().split(':')[1], ] self._lightEditors = [ NumberEditor(0, self._lightSchedule[0], 0, 23, '{:02d}'), NumberEditor(1, self._lightSchedule[1], 0, 59, '{:02d}'), NumberEditor(2, self._lightSchedule[2], 0, 23, '{:02d}'), NumberEditor(3, self._lightSchedule[3], 0, 59, '{:02d}'), NumberEditor(4, self._lightSchedule[4], 0, 23, '{:02d}'), NumberEditor(5, self._lightSchedule[5], 0, 59, '{:02d}'), NumberEditor(6, self._lightSchedule[6], 0, 23, '{:02d}'), NumberEditor(7, self._lightSchedule[7], 0, 59, '{:02d}') ] lcd.setCursor(0, 125) self._print('Light 1: ', self._lightEditors[0], self._lightEditors[1], self._lightEditors[2], self._lightEditors[3]) lcd.setCursor(0, 155) self._print('Light 2: ', self._lightEditors[4], self._lightEditors[5], self._lightEditors[6], self._lightEditors[7]) self._lightEditors[0].startEditing(self)
def webserver_start(): global scanlist from microWebSrv import MicroWebSrv lcd.clear() lcd.setCursor(0, 0) ssid_name = "M5Stack-" + node_id[-4:] wlan_ap.active(True) wlan_ap.config(essid=ssid_name, authmode=network.AUTH_OPEN) addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1] print('WiFi AP WebServer Start!') print('Connect to Wifi SSID:' + ssid_name) print('And connect to esp via your web browser (like 192.168.4.1)') print('listening on', addr) lcd.image(0, 0, '/flash/img/1-1.jpg', type=lcd.JPG) lcd.font(lcd.FONT_DejaVu24) lcd.setTextColor(lcd.BLACK, lcd.WHITE) lcd.print('Wi-Fi SSID', 150, 145, lcd.BLACK) lcd.print(ssid_name, 125, 170, lcd.RED) webserver = MicroWebSrv(routeHandlers=routeHandlers) scanlist = wlan_sta.scan() if not wlan_sta.active(): wlan_sta.active(True) while True: if len(wlan_ap.status('stations')) > 0: break time.sleep_ms(200) lcd.image(0, 0, '/flash/img/1-2.jpg', type=lcd.JPG) webserver.Start(threaded=False)
def _print(self, cursor, editor1, editor2, editor3, separator): lcd.setCursor(cursor[0], cursor[1]) editor1.printToLcd() lcd.print(separator) editor2.printToLcd() lcd.print(separator) editor3.printToLcd()
def wifi(self, x, y, size, color=lcd.WHITE): lcd.setCursor(x, y) lcd.rect(x, int(y + .75 * size), int(size * .2), size - int(y + .75 * size), color, color) lcd.rect(int(x + .4 * size), int(y + .5 * size), int(size * .2), size - int(y + .5 * size), color, color) lcd.rect(int(x + .8 * size), int(y), int(size * .2), size, color, color)
def _tryingmine(httpClient, httpResponse,routeArgs): lcd.clear(0x000000) lcd.font('hp.fon') lcd.setCursor(0,0) lcd.print(routeArgs['message']) httpResponse.WriteResponseOk( headers = None, contentType = "text/html", contentCharset = "UTF-8", content = "OK" )
def show(self): super().show() lcd.print('Door Schedule On/Off', lcd.CENTER, 85) lcd.setCursor(160, 125) value = 'On' if kippenstalConfig.isDoorOpenerScheduleEnabled( ) else 'Off' self._stringSelector = StringSelector(value, ['On', 'Off']) self._stringSelector.printToLcd() self._stringSelector.startEditing(self)
def main(): start_wifi() print('started wifi and tools') # move to lowest line on M5STACK display lcd.setCursor(0, 227) lcd.setColor(lcd.WHITE) lcd.print("RTC Clock 1") # initiate rtc print("Synchronize time from NTP server with TZ=US Central ...") rtc.ntp_sync(server="hr.pool.ntp.org", tz="CST6CDT5,M4.1.0/2,M10.5.0/2") #https://prom-electric.ru/media/uclibc-zoneinfo-list.txt _thread.start_new_thread ("clock",watch, ())
def watch(): while True: # start position for Date if not rtc.synced(): # set color to sync status lcd.setColor(lcd.RED) else: lcd.setColor(lcd.GREEN) # lcd.setCursor(92, 227) # uncomment if you need date on display # lcd.print("Date {}".format(utime.strftime("%Y-%m-%d", utime.localtime()))) # uncomment if needed # start position for time only lcd.setCursor(213, 227) # uncomment if date active (see upper lines) lcd.print(" Time {}".format(utime.strftime('%H:%M:%S', utime.localtime()))) utime.sleep(1)
def update_clock(self): if self._isShown: if self._isSleeping: return elif self._lastInteraction + 120 < utime.time(): self._sleep() else: lcd.textClear(90, 85, ' ', lcd.WHITE) lcd.setCursor(105, 85) lcd.print("{}".format( utime.strftime('%H:%M:%S', utime.localtime()))) lcd.textClear(90, 115, ' ', lcd.WHITE) lcd.setCursor(112, 115) lcd.print("{} C".format(kippenstal.getTemperature()))
def app_txtReader(self, fname): lcd.clear() f = Framework('txtReader') f.drawNaviButton(strC='EXIT') lcd.font(lcd.FONT_DefaultSmall, transparent=False, fixedwidth=True) idx = 0 idx_s = [0] page = 0 while True: letter_current_page = 0 lcd.setCursor(0, 0) lcd.rect(0, 0, 320, 240 - f.h_bottom, lcd.BLACK, lcd.BLACK) with open(fname, 'r') as o: o.seek(idx) flag_end = False for row in range(20): for col in range(29): c = o.read(1) if not c: lcd.println('--- END ---') flag_end = True break if c != '\n': lcd.print(c) letter_current_page += 1 else: letter_current_page += 1 break lcd.print('\n') if flag_end: break while True: time.sleep(0.1) if buttonA.isPressed(): if page != 0: page -= 1 del (idx_s[-1]) idx = idx_s[-1] break elif buttonB.isPressed(): if c: idx += letter_current_page idx_s.append(idx) page += 1 break elif buttonC.isPressed(): return 0
def run(self): if self.fileCheck() < 0: return -1 self.drawNaviButton() lcd.setCursor(0,0) lcd.println('Press START to start') while not buttonA.isPressed(): if buttonC.isPressed(): return 0 time.sleep(.5) self.fname_save = self.fnameGen() lcd.println('Record into %s' % self.fname_save) self.scanner()
def printMenu(self): self._menuItems = self.__filterMenuItems(self.getMenuItems()) self._min = 1 self._max = len(self._menuItems) lcd.font(lcd.FONT_DejaVu24, transparent=True) lcd.rect(self.cursor[0], self.cursor[1], 320, 240, lcd.WHITE, lcd.WHITE) lcd.setCursor(self.cursor[0], self.cursor[1]) for i in range(self._max): selectedPrefix = ' ' if (i + 1) == self.value: selectedPrefix = '>' lcd.println('{} {}'.format(selectedPrefix, self._menuItems[i][0]))
def main(): import network from m5stack import lcd, buttonA import time try: while not buttonA.isPressed(): lcd.setCursor(0, 0) network.ftp.start(user="******", password="******", buffsize=1024, timeout=300) fs = network.ftp.status() lcd.println('Server IP: %s' % fs[4]) lcd.println('Server status: %s' % fs[2]) lcd.println('Data status: %s' % fs[3]) time.sleep(1) network.ftp.stop() except: pass
def app_pyLauncher(self, fname): print('Launch %s...' % uos.getcwd() + '/' + fname) lcd.setCursor(self.upleft[0] + 1, self.upleft[1] + 1) lcd.println('Now loading...') with open(fname, 'rb') as o: code = o.read() with open(PATH_CACHE, 'wb') as o: o.write(code) if 'cache' in sys.modules.keys(): del sys.modules['cache'] lcd.clear() import cache if code[:18] == b'# -*- advanced -*-': print('-*- This is an advanced program -*-') cache.Main().run() else: cache.main()
def __th_display(self, apresults): if self.FLAG_END == 0: print(self.strBuf+'---------------------') lcd.rect(0,0,320,210, lcd.BLACK, lcd.BLACK) lcd.setCursor(0,0) lcd.font(lcd.FONT_DefaultSmall) if len(apresults) < 15: i = 0 for apresult in apresults: resstr = '%02d, ch: %02d, rs: %d, %s\n' % (i+1, apresult[2], apresult[3], apresult[0].decode()) lcd.print(resstr,color = lcd.WHITE) i = i + 1 else: for i in range(0,15): apresult = apresults[i] resstr = '%02d, ch: %02d, rs: %d, %s\n' % (i+1, apresult[2], apresult[3], apresult[0].decode()) lcd.print(resstr,color = lcd.WHITE) return 0
def printToLcd(self): if self._coord == None: self._coord = lcd.getCursor() oldTxt = self._format.format(self._oldValue) + self._suffix oldTxtWidth = lcd.textWidth(oldTxt) txt = self._format.format(self.value) + self._suffix txtWidth = lcd.textWidth(txt) # erase lcd.textClear(self._coord[0], self._coord[1], oldTxt, lcd.WHITE) lcd.line(self._coord[0], self._coord[1] + 25, self._coord[0] + oldTxtWidth, self._coord[1] + 25, lcd.WHITE) # write lcd.setCursor(self._coord[0], self._coord[1]) lcd.print(txt) if self._editingActive: lcd.line(self._coord[0], self._coord[1] + 25, self._coord[0] + txtWidth, self._coord[1] + 25)
def __guiUpdate(self): lcd.setCursor(self.upleft[0] + 1, self.upleft[1] + 1) cp = int(self.index / self.MIOP) + 1 # Current page if self.currentPage != cp: # Which means that it is time to flip over self.currentPage = cp self.__drawBackground() self.__drawNaviBar(cp) sru = (cp - 1) * self.MIOP if len(self.selections) - sru >= self.MIOP: srd = sru + self.MIOP else: srd = len(self.selections) for i in range(sru, srd): if i == self.index: lcd.println(self.selections[i], color=lcd.GREEN) else: lcd.println(self.selections[i], color=lcd.WHITE)
def loadImage(): global ix, START_IX, LOAD_LIMIT, isTryingLoad isTryingLoad = True if ix < 0: ix = len(screens) - 1 if ix > len(screens) - 1 : START_IX += LOAD_LIMIT appendScreensIds() lcd.clear() lcd.setCursor(0, 0) lcd.setColor(lcd.WHITE) lcd.print('Top of ZXART.EE: #%s %s' % (ix + 1, screens[ix][1])) data = open(TEMP_FILE, 'wb') addr = ZX_ART_HOST % screens[ix][0] http_getFile(addr, data) loadedData = open(TEMP_FILE, 'rb').read() convertToScreen(loadedData) lcd.print(" << A Reload - B C >>", 0, 224)
def printToLcd(self): if self._coord == None: self._coord = lcd.getCursor() oldTxt = self._oldValue oldTxtWith = lcd.textWidth(oldTxt) txt = self.value txtWidth = lcd.textWidth(txt) # erase lcd.textClear(self._coord[0], self._coord[1], oldTxt, lcd.WHITE) lcd.line(self._coord[0], self._coord[1] + 25, self._coord[0] + oldTxtWith, self._coord[1] + 25, lcd.WHITE) # write x = (320 - (lcd.textWidth(self.value))) / 2 lcd.setCursor(int(x), self._coord[1]) self._coord = lcd.getCursor() lcd.print(txt) if self._editingActive: lcd.line(self._coord[0], self._coord[1] + 25, self._coord[0] + txtWidth, self._coord[1] + 25)
def resdisplay(apresults, n, time): lcd.rect(0, 0, 320, 24, lcd.BLUE, lcd.BLUE) lcd.font(lcd.FONT_Ubuntu, transparent=True) lcd.text(0, 2, 'N_AP:%d N_SCAN:%d TIME:%d' % (len(apresults), n, time), lcd.WHITE) lcd.rect(0, 24, 320, 186, lcd.BLACK, lcd.BLACK) lcd.setCursor(0, 24) lcd.font(lcd.FONT_DefaultSmall) if len(apresults) < 15: i = 0 for apresult in apresults: resstr = '%02d, ch: %02d, rs: %d, %s\n' % ( i + 1, apresult[2], apresult[3], apresult[0].decode()) lcd.print(resstr, color=lcd.WHITE) i = i + 1 else: for i in range(0, 15): apresult = apresults[i] resstr = '%02d, ch: %02d, rs: %d, %s\n' % ( i + 1, apresult[2], apresult[3], apresult[0].decode()) lcd.print(resstr, color=lcd.WHITE)
def main(): from m5stack import lcd, buttonA import network import json import time try: isConnected = False lcd.setCursor(0,0) sta_if = network.WLAN(network.STA_IF) if sta_if.active() == False: lcd.println('Connecting...') sta_if.active(True) wifi = json.load(open('/flash/etc/wlan.json', 'r')) ssid = wifi['wifi']['ssid'] pwd = wifi['wifi']['password'] sta_if.connect(ssid, pwd) # time.sleep(3) while not buttonA.isPressed(): ni = sta_if.ifconfig() if ni[0] == '0.0.0.0': time.sleep(1) else: isConnected = True lcd.println('ip: %s' % ni[0]) lcd.println('mask: %s' % ni[1]) lcd.println('gate: %s' % ni[2]) lcd.println('dns: %s' % ni[3]) break if isConnected: while not buttonA.isPressed(): time.sleep(.2) except: pass
def task(expires_date): global g_track_id global g_track_img global g_showing_spotify_logo try: now = utime.time() if now > expires_date: next_expire_delta = refresh_token_if_necessary() expires_date = now + next_expire_delta track = get_current_playing_track() if track is not None: track_item = track['item'] if track_item['id'] != g_track_id: image_url = get_image_url(track_item) lcd.clear() lcd.setCursor(0, 0) lcd.setColor(lcd.WHITE) if image_url and image_url != g_track_img: download_image_to_file(image_url, 'tmp.jpg') show_image('tmp.jpg') print_title(track_item) print_artist(track_item) g_track_id = track_item['id'] g_track_img = image_url g_showing_spotify_logo = False else: if g_showing_spotify_logo is False: lcd.clear() show_image('spotify.jpg') g_showing_spotify_logo = True return expires_date except Exception as e: lcd.print('Exception(task): ' + str(e)) import sys sys.print_exception(e) raise e
def main(): try: lcd.println('main') if not connect_wifi(WIFI_CONFIG): lcd.println('Failed to connect') return except Exception as e: lcd.println(str(e)) return expires_date = 0 lcd.clear() lcd.setCursor(0, 0) while True: try: gc.collect() expires_date = task(expires_date) utime.sleep(10) except Exception as e: lcd.println('Exception(main): ' + str(e)) import sys sys.print_exception(e) expires_date = 0 # Force to refresh key # anyway, retry connect connect_wifi(WIFI_CONFIG)
# ライブラリ導入 from m5stack import lcd # 初期化 lcd.clear() # フォント指定 lcd.font(lcd.FONT_Dejavu24) # フォント FONT_Dejavu24 に設定 # 画像挿入 lcd.image(lcd.CENTER, lcd.BOTTOM, file="/flash/icon.jpg") # 見出し lcd.setCursor(0, 0) lcd.setColor(lcd.WHITE, lcd.BLUE) fw, fh = lcd.fontSize() ww, wh = lcd.winsize() lcd.rect(0, 0, ww, fh + 1, lcd.BLUE, lcd.BLUE) lcd.println("N High School students Card") # 文字 lcd.setColor(lcd.WHITE, lcd.BLACK) lcd.print('Waricoma', 10, 30)
def clrscrn(rot=1): lcd.setRotation(rot) lcd.clear() lcd.font(lcd.FONT_DejaVu24) lcd.setTextColor(lcd.WHITE) lcd.setCursor(0,0)
lcd.init(lcd.M5STACK, width=320, height=240, mosi=23, miso=12, clk=18, cs=27, dc=26, rst_pin=5, invrot=0, bgr=True) lcd.orient(3) sta_if = network.WLAN(network.STA_IF) sta_if.active(True) sta_if.scan() # Scan for available access points sta_if.connect("login", "password") # Connect to an AP sta_if.isconnected() # Check for successful connection #rez = str(sta_if.ifconfig()) if not sta_if.isconnected(): sta_if.connect() print("Waiting for connection...") while not sta_if.isconnected(): utime.sleep(1) lcd.setCursor(0, 40) lcd.setColor() lcd.println(str(sta_if.ifconfig()))
def but_b(): lcd.clear(lcd.ORANGE) lcd.setCursor(100, 100) lcd.setColor(lcd.BLACK, lcd.ORANGE) lcd.print('World') return ()
def but_a(): lcd.clear(lcd.GREEN) lcd.setCursor(100, 100) lcd.setColor(lcd.BLACK, lcd.GREEN) lcd.print('Hello')
def resetScreen(self, cursor: [] = [0, 85]): lcd.rect(cursor[0], cursor[1], 320, 240, lcd.WHITE, lcd.WHITE) lcd.setCursor(cursor[0], cursor[1])
def drawBanner(self): lcd.rect(0, 0, self.W, self.h_banner, lcd.BLUE, lcd.BLUE) lcd.setCursor(self.W - lcd.textWidth(self.title) - 5, 5) lcd.print(self.title) th_m = _thread.start_new_thread('monitor', self.__th_statusMonitor, ())