| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- from keyb import Keyboard # type: ignore
- import time, os, rtc, json, wifi, supervisor # type: ignore
- import board, busio, sdcardio, storage, terminalio, displayio # type: ignore
- from adafruit_display_text import label # type: ignore
- from adafruit_display_shapes.rect import Rect # type: ignore
-
- ### DEFAULT HOME PAGE # # # # # # # # # #
- def home():
- title_label.text = "Home"
- title_label.x = 10
- title_label.y = 14
-
- ip_label.text = my_ip
- ip_label.x = 160
- ip_label.y = 20
-
- page_label.text = """
- 1 - User Info
- 2 - Make Post
- """
- page_label.x = 5
- page_label.y = 30
-
- # # # # # # # # # # # # # # # # # #
-
- keyb = Keyboard()
-
-
- # SET UP DISPLAY & WIFI
- display = board.DISPLAY
- display_group = displayio.Group()
- display.root_group = display_group
-
- wifi_options = [[os.getenv("WIFI1"),os.getenv("WIFIPW1")],
- [os.getenv("WIFI2"),os.getenv("WIFIPW2")],
- [os.getenv("WIFI3"),os.getenv("WIFIPW3")]]
-
-
- h1 = label.Label(terminalio.FONT, text="Hello!", color=0xffffff, scale=2)
- h1.x = 10
- h1.y = 15
-
- count = 0
- menu_labs = []
- for option in wifi_options:
- if count == 0:
- menu_lab = label.Label(terminalio.FONT, text = "> " + option[0], color=0xffffff, scale=1)
- else:
- menu_lab = label.Label(terminalio.FONT, text = option[0], color=0xffffff, scale=1)
- menu_lab.x = 10
- menu_lab.y = 35 + count * 10
- display.root_group.append(menu_lab)
- menu_labs.append(menu_lab)
- count+=1
-
- display.root_group.append(h1)
-
- pos = 0
- while True:
- key = keyb.scan()
- if key == "UP":
- if pos == 0:
- pass
- else:
- menu_labs[pos].text = wifi_options[pos][0]
- pos -= 1
- menu_labs[pos].text = "> " + wifi_options[pos][0]
- elif key == "DOWN":
- if pos == len(wifi_options)-1:
- pass
- else:
- menu_labs[pos].text = wifi_options[pos][0]
- pos += 1
- menu_labs[pos].text = "> " + wifi_options[pos][0]
- elif key == "\n":
- WIFI_SSID = wifi_options[pos][0]
- WIFI_PASS = wifi_options[pos][1]
- break
-
- try:
- wifi.radio.connect(ssid=WIFI_SSID,
- password=WIFI_PASS)
- my_ip = str(wifi.radio.ipv4_address).strip()
- display.root_group.remove(h1)
- for lab in menu_labs:
- display.root_group.remove(lab)
- except ConnectionError as e:
- h1.text = "Aw..."
-
- for lab in menu_labs:
- display.root_group.remove(lab)
-
- txt = label.Label(terminalio.FONT, text = "", color=0xff0000, scale=1)
- txt.text = "Could not connect to " + WIFI_SSID
- txt.x = 10
- txt.y = 35
-
- txt2 = label.Label(terminalio.FONT, text = "", color=0x89a0a8, scale=1)
- txt2.text = "Press CTRL + C followed by CTRL + D\nto soft-reboot"
- txt2.x = 10
- txt2.y = 100
-
- display.root_group.append(txt)
- display.root_group.append(txt2)
-
- while True:
- pass
-
-
- # SET UP SD CARD
- spi = busio.SPI(board.SD_SCK, MOSI=board.SD_MOSI, MISO=board.SD_MISO)
- cs = board.SD_CS
-
- try:
- sdcard = sdcardio.SDCard(spi, cs)
- vfs = storage.VfsFat(sdcard)
-
- storage.mount(vfs, "/sd") # access files on sd card here
- except OSError:
- pass # SD card not inserted/found
-
-
-
-
- # Header Bar
- rect = Rect(0, 0, 238, 30, fill=0x1f4476)
- display.root_group.append(rect)
-
- # Page Title
- title_font = terminalio.FONT
- title_color = 0xffffff
- title_label = label.Label(title_font, text="Home", color=title_color, scale=2)
- display.root_group.append(title_label)
-
-
- # Page Text
- page_font = terminalio.FONT
- page_color = 0xffffff
- page_label = label.Label(page_font, text="page_text", color=page_color, scale=1)
- display.root_group.append(page_label)
-
- # IP Label
- ip_font = terminalio.FONT
- ip_color = 0x89a0a8
- ip_label = label.Label(ip_font, text="0.0.0.0", color=ip_color, scale=1)
- display.root_group.append(ip_label)
-
- home()
-
-
- ## PROGRAM MAIN LOOP (WORKS FROM HOME PAGE IF OTHER PAGES HAVE THEIR OWN LOOPS)
- while True:
- key = keyb.scan()
|