Пример #1
0
def render():
    lcd.font(lcd.FONT_Default, transparent=True, fixedwidth=False)
    lcd.text(lcd.RIGHT, 220, "Loading...", lcd.DARKGREY)

    response = urequests.get(url)
    data = ujson.loads(response.text)

    temps = data["temps"]
    rains = data["rains"]
    icon_basename = data["icon_basename"]

    lcd.clear(color=lcd.WHITE)

    lcd.font(lcd.FONT_DejaVu24, transparent=True, fixedwidth=True)
    lcd.text(lcd.CENTER, 20, "%2s [%3s]" % (temps["max"], temps["max_diff"]),
             lcd.RED)
    lcd.text(lcd.CENTER, 50, "%2s [%3s]" % (temps["min"], temps["min_diff"]),
             lcd.BLUE)

    lcd.image(110, 85, "/flash/images/%s.jpg" % (icon_basename), 0, lcd.JPG)

    lcd.font(lcd.FONT_DefaultSmall, transparent=True, fixedwidth=True)
    lcd.text(lcd.CENTER, 160, "~06 | ~12 | ~18 | ~24 ", lcd.BLACK)
    lcd.text(
        lcd.CENTER, 180, "%3s | %3s | %3s | %3s " %
        (rains["t00_06"], rains["t06_12"], rains["t12_18"], rains["t18_24"]),
        lcd.BLACK)

    lcd.font(lcd.FONT_Default, transparent=True, fixedwidth=False)
    lcd.text(lcd.CENTER, 220,
             time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
             lcd.DARKGREY)
Пример #2
0
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)
Пример #3
0
def _httpHanderConfig(httpClient, httpResponse):
    formData = httpClient.GetRequestQueryParams()
    ssid = formData.get("ssid")
    password = formData.get("password")
    other_flg = formData.get("other")
    print(formData)
    content = ''
    is_connected = False

    if other_flg == 'true' or doConnect(ssid, password, False):
        is_connected = True
        saveWiFi(ssid, password)
        content = """<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><style>h1{text-align:center;margin-top:120px;font-size:1.4rem;color:#0064a0}p{text-align:center;font-size:1.1rem}div{width:200px;margin:0 auto;padding-left:60px}</style><title></title></head><body><h1>^_^ WiFi connection success</h1><div><span>Reset device now </span><span id="wating">...</span></div></body><script>var wating=document.getElementById("wating");setInterval(function(){if(wating.innerText==="..."){return wating.innerText="."}wating.innerText+="."},500);</script></html>"""
    else:
        content = """<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><style>h1{text-align:center;margin-top:120px;font-size:1.4rem;color:red}p{text-align:center;font-size:1.1rem}</style><title></title></head><body><h1>×_× WiFi connection failed</h1><p>Click <a href="/">here</a> return configure page.</p></body></html>"""

    httpResponse.WriteResponseOk(headers=None,
                                 contentType="text/html",
                                 contentCharset="UTF-8",
                                 content=content)

    if is_connected:
        lcd.image(0, 0, '/flash/img/1-3.jpg', type=lcd.JPG)
        time.sleep(3)
        wlan_ap.active(False)
        machine.reset()
Пример #4
0
def show_image(file):
    lcd.clear()
    (screen_width, screen_height) = lcd.screensize()
    image_width = 300 / 2
    image_height = 300 / 2
    lcd.image(int((screen_width - image_width) / 2),
              int((screen_height - image_height) / 2),
              file,
              scale=1,
              type=lcd.JPG)
Пример #5
0
    def _showOptions(self):
        buttonA.wasPressed(self._menu.show)
        lcd.image(50, 205, 'imgs/menu.bmp')

        buttonB.wasPressed(kippenstal.doorOpener.toggle)
        lcd.image(145, 205, 'imgs/door.bmp')

        buttonC.wasPressed(kippenstal.light.toggle)
        lcd.image(243, 205, 'imgs/lightbulb-outline.bmp')
Пример #6
0
# ライブラリ導入
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)
Пример #7
0
def main():
    ########## 初期化 ##########
    # 液晶画面を初期化する
    lcd.setColor(color, background_color)
    lcd.clear()

    # センサーを初期化する
    sensor = DHT12()

    # 温度計、湿度計の表示を初期化する
    temperature_view = ThermometerView(10, 10, min_value=-15, max_value=45)
    humidity_view = ThermometerView(80,
                                    10,
                                    min_value=0,
                                    max_value=100,
                                    color=lcd.BLUE,
                                    label='%')

    # SDカードのマウント
    uos.mountsd()

    # 背景の描画
    temperature_view.init()
    humidity_view.init()

    ########## 無限ループ ##########
    while not buttonC.isPressed():
        # センサーで温度と湿度を計測する
        sensor.measure()
        temperature = sensor.temperature()
        humidity = sensor.humidity()

        # デバッグ用
        print("Temperature: {} `C, Humidity: {} %".format(
            temperature, humidity))

        # 温度計、湿度計の表示を更新する
        temperature_view.update(temperature)
        humidity_view.update(humidity)

        # WBGT値を求める
        try:
            wbgt = calc_wbgt(temperature, humidity)
        except ValueError:
            wbgt = None

        # WBGT値を画面に表示する
        lcd.font(lcd.FONT_Default, color=color, transparent=False)
        lcd.textClear(160, 30, 'WBGT: Unknown')
        if wbgt is not None:
            lcd.text(160, 30, 'WBGT: {}'.format(wbgt))
        else:
            lcd.text(160, 30, 'WBGT: Unknown')

        image_path = None

        # WBGT値に応じて画像を描画する
        # 31度以上          : 危険
        # 28度以上31度未満  : 厳重警戒
        # 25度以上28度未満  : 警戒
        # 25度未満          : 注意
        if temperature >= 21 and wbgt is not None:
            if wbgt >= 31:
                # 危険
                image_path = image_path_kiken
            elif wbgt >= 28:
                # 厳重警戒
                image_path = image_path_genjukeikai
            elif wbgt >= 25:
                # 警戒
                image_path = image_path_keikai

        # 湿度に応じてインフルエンザ注意情報を表示する
        # 湿度40%未満 : インフルエンザ感染注意
        if humidity < 40:
            image_path = image_path_influenza

        if image_path is not None:
            # 画像を描画する
            lcd.image(image_x, image_y, image_path)
        else:
            # 画像を描画した領域を背景色で塗りつぶす
            lcd.rect(image_x, image_y, image_width, image_height,
                     background_color, background_color)

        # 表示の更新間隔
        utime.sleep(interval)
Пример #8
0
from m5stack import lcd
from m5stack import buttonA
from m5stack import buttonC
import uos
import utime

imageList = [
    "/sd/image1.jpg", "/sd/image2.jpg", "/sd/image3.jpg", "/sd/image4.jpg"
]
position = 0

uos.mountsd()

lcd.clear()
lcd.image(0, 0, file=imageList[0], scale=0, type=lcd.JPG)

while True:
    if buttonA.wasPressed():
        position = position + 1
        lcd.clear()
        lcd.image(0,
                  0,
                  file=imageList[position % len(imageList)],
                  scale=0,
                  type=lcd.JPG)
    if buttonC.wasPressed():
        position = position - 1
        lcd.clear()
        lcd.image(0,
                  0,
                  file=imageList[position % len(imageList)],
Пример #9
0
        if argument == 1:
            if self.index == 0:
                self.index=len(self.applist)-1
            else:
                self.index-=1
            self.draw(self.index)
        elif argument == 2:
            return self.index
        elif argument == 3:
            if self.index == len(self.applist)-1:
                self.index = 0
            else:
                self.index +=1
            self.draw(self.index)
        return -1
lcd.image(0,0,'m5stack.jpg')
utime.sleep(3)
lcd.clear(lcd.BLACK)
lcd.font('/flash/font/ep60.fon', fixedwidth=0)
lcd.setColor(lcd.RED,lcd.BLACK)
lcd.text(int((320-lcd.textWidth('APP'))/2),1,'APP')

appchose=List(applist)

while True:
    if buttonA.wasPressed():
        temp = appchose.event(1)
        if temp == -1:
            pass
        else:
            if applist[temp][0] == '/flash':