1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
| import network import random import time import ntptime import Pico_ePaper29 as epd29
ssid = 'aaa' pswd = 'xxx'
wlan = network.WLAN(network.STA_IF) wlan.active(True) wlan.connect(ssid, pswd)
status = wlan.ifconfig() print('wifi={} ip={}'.format(ssid, status[0])) print(time.localtime())
try: ntptime.host = 'cn.pool.ntp.org' ntptime.settime() except Exception as e: print('NTPTIME ERROR', e, ntptime.host)
def get_mnist_font(num): SIZE = 98 NUM = 100 f = open('font_lib_{}.bin'.format(num), 'rb') f.seek(random.randrange(0, NUM) * SIZE) mf_bin = f.read(SIZE) f.close() mf_str = ''.join(['{:08b}'.format(mf_bin[i]) for i in range(SIZE)]) return mf_str
epd = epd29.EPD_2in9_Landscape()
def YMD(draw, ymd, wid): draw.fill(0xff) draw.fill_rect(5, 5, 95, 8, 0xff) draw.text(wid, 5, 5, 0x00) draw.fill_rect(100, 5, 120, 8, 0xff) draw.text(ymd, 100, 5, 0x00) def HMS(draw, txt): draw.fill_rect(240, 5, 50, 8, 0xff) draw.text(txt, 240, 5, 0x00)
def DOT(draw): draw.fill_rect(144, 60, 7, 7, 0x00) draw.fill_rect(144, 80, 7, 7, 0x00)
def MNIST(draw, mf, i): c0 = [2, 72, 154, 224] r0 = [20, 20, 20, 20] nR = 100 nC = 70
for r in range(nR): for c in range(nC): color = mf[ int(28*r/nR) * 28 + int(28*c/nC) ] color = 0x00 if color == '1' else 0xff draw.pixel(c + c0[i], r + r0[i], color) def MNIST_clear(draw): draw.fill_rect(0, 20, 296, 100, 0xff) draw.fill_rect(240, 5, 50, 8, 0xff)
last_time = [-1, -1, -1, -1] while (True): wifi_id = ssid if wlan.status()==3 else 'no wifi' now = time.localtime(time.time() + 8*3600) year, mon, day = now[0], now[1], now[2] hour, mnt, sec = now[3], now[4], now[5] week = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] weekday = week[now[6]] now_time = [hour//10, hour%10, mnt//10, mnt%10] print(now, wifi_id, last_time, now_time) if -1 in last_time or (mnt%10==0 and sec<5): print('full update') epd.Clear(0xff) epd.delay_ms(100) YMD(epd, '{:04d}-{:02d}-{:02d} {}'.format(year, mon, day, weekday), wifi_id) epd.display(epd.buffer) epd.delay_ms(100) MNIST_clear(epd) epd.display_Partial(epd.buffer) epd.delay_ms(100) last_time = [-1, -1, -1, -1] for i in range(4): if last_time[i] != now_time[i]: print('partial update', last_time, now_time) last_time[i] = now_time[i] mnist = get_mnist_font(now_time[i]) HMS(epd, '{:02d}:{:02d}'.format(hour, mnt)) MNIST(epd, mnist, i) epd.display_Partial(epd.buffer) epd.delay_ms(100) if i == 1: DOT(epd) epd.display_Partial(epd.buffer) epd.delay_ms(100) time.sleep(5)
|