from keyb import Keyboard # type: ignore import time, os, rtc, json # 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 ### PAGE FUNCTIONS # # # # # # # # # # def home(): title_label.text = "Home" title_label.x = 95 title_label.y = 14 page_label.text = """ ESC = DOWNTIME TAB = SET CLOCK BACKSP = HERA SP = RT17 ENTER NUMBER FOR CHECK DIGITS """ page_label.x = 5 page_label.y = 30 time_label.text = strf_time() input_label.text = "" input_label.x = 100 input_label.y = 120 # # # # # # # # # # # # # # # # # # def strf_time(): r = rtc.RTC() current_time = r.datetime hour = current_time.tm_hour mint = current_time.tm_min return str(hour) + ":" + str(mint) def strf_date(): current_time = r.datetime day = current_time.tm_mday month = current_time.tm_mon year = current_time.tm_year return str(day) + "/" + str(month) + "/" + str(year) def set_datetime(): numbers = ["0","1","2","3","4","5","6","7","8","9"] cancel = False title_label.text = "Set Clock" title_label.x = 75 page_label.text = "Enter Hour\n" page_label.y = 45 hour = "" while not cancel: key = keyb.scan() if key in numbers: hour += key page_label.text += key elif key == "\n": break elif key == "ESC": cancel = True page_label.text += "\nEnter Minute\n" minute = "" while not cancel: key = keyb.scan() if key in numbers: minute += key page_label.text += key elif key == "\n": break elif key == "ESC": cancel = True page_label.text = "Enter Day\n" day = "" while not cancel: key = keyb.scan() if key in numbers: day += key page_label.text += key elif key == "\n": break elif key == "ESC": cancel = True page_label.text = "Enter Month\n" month = "" while not cancel: key = keyb.scan() if key in numbers: month += key page_label.text += key elif key == "\n": break elif key == "ESC": cancel = True page_label.text = "Enter Year\n" year = "" while not cancel: key = keyb.scan() if key in numbers: year += key page_label.text += key elif key == "\n": break elif key == "ESC": cancel = True if not cancel: h = int(hour) m = int(minute) d = int(day) mo = int(month) y = int(year) r.datetime = time.struct_time((y, mo, d, h, m, 0, 0, -1, -1)) page_label.text = strf_time() + " @ " + strf_date() + "\n(Tab to return)" while True: key = keyb.scan() if key == " ": home() break def get_digits(number): cd = "NULL" codes = {"3":"ZMZ", "5":"HYT", "6":"MRC", "9":"DAH", "10":"ITQ", "14":"PIZ", "15":"OIO", "16":"GIH", "18":"HDS", "19":"AIA", "20":"ZIJ", "21":"FGE", "23":"DTX", "24":"QQK", "26":"KQG", "27":"VKW", "28":"VZJ", "29":"CTK", "30":"WMD", "32":"ZOR", "33":"RQR", "34":"LRR", "35":"SBA", "36":"XVQ", "38":"NRX", "39":"HCM", "40":"MQG"} if number in codes: cd = codes[number] title_label.text = cd title_label.x = 75 page_label.text = "Check Digits for " + number page_label.y = 45 input_label.text="" while True: key = keyb.scan() if key == "ESC": home() break else: home() def show_barcodes(code): if code == "RT17": bmp = displayio.OnDiskBitmap("/barcodes/RT17.bmp") else: bmp = displayio.OnDiskBitmap("/barcodes/HERA.bmp") title_label.text = "" page_label.text = "" tile_grid = displayio.TileGrid(bmp, pixel_shader=bmp.pixel_shader) tile_grid.x = 30 tile_grid.y = 15 display_group.append(tile_grid) while True: key = keyb.scan() if key == "ESC": display_group.remove(tile_grid) home() break def downtime_page(): title_label.text = "Downtime" title_label.x = 75 default_page_text = """ ESC = QUIT OK = VIEW LOG 1) WAITING | 2) PROBLEM | 3) COMFORT 4) OTHER """ default_page_y = 30 page_label.text = default_page_text page_label.y = default_page_y while True: key = keyb.scan() if key == "ESC": home() break elif key == "\n": page_label.text = "" page_label.y = 40 for entry in downtime: dt = entry[0] hour = dt.tm_hour mint = dt.tm_min dt_time = str(hour) + ":" + str(mint) reason = entry[1] page_label.text += dt_time + " - " + reason + "\n" while True: key = keyb.scan() if key == "ESC": page_label.text = default_page_text page_label.y = default_page_y break elif key == "1" or key == "2" or key == "3": if key == "1": reason = "WAITING" elif key == "2": reason = "PROBLEM" elif key == "3": reason = "COMFORT" dt = current_time = r.datetime entry = [dt, reason] downtime.append(entry) page_label.text += "\n\nDowntime Recorded" time.sleep(3) page_label.text = default_page_text # 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 # SET UP DISPLAY display = board.DISPLAY display_group = displayio.Group() display.root_group = display_group # 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) # Time Label time_font = terminalio.FONT time_color = 0x89a0a8 time_label = label.Label(time_font, text="00:00", color=time_color, scale=1) time_label.x = 200 time_label.y = 24 display.root_group.append(time_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) # ip_label.x = 10 # ip_label.y = 24 # display.root_group.append(ip_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) # Numbers Input Text input_font = terminalio.FONT input_color = 0xffffff input_label = label.Label(input_font, text="", color=input_color, scale=2) display.root_group.append(input_label) home() keyb = Keyboard() downtime = [] r = rtc.RTC() #r.datetime = time.struct_time((2025, 10, 7, 23, 39, 0, 0, -1, -1)) # THIS LINE SETS THE RTC, first is year, then month, then day, then hour, then minute, (rest is unimportant) #current_time = r.datetime last_time = "00:00" ## PROGRAM MAIN LOOP (WORKS FROM HOME PAGE IF OTHER PAGES HAVE THEIR OWN LOOPS) numbers = ["0","1","2","3","4","5","6","7","8","9"] ninput = "" while True: time_label.text = strf_time() key = keyb.scan() if key == " ": set_datetime() elif key == "BACKSP": show_barcodes("HERA") elif key == " ": show_barcodes("RT17") elif key in numbers: input_label.text += key ninput += key elif key == "\n": get_digits(ninput) ninput = "" elif key == "ESC": downtime_page() # Homepage Clock # current_time = strf_time() # if last_time != current_time: # time_label.text = current_time # last_time = current_time #time_label.text = strf_time() # IDEA # # # current move -> move start time, array of intermediate move times like when replenning, end move time (last part of move like pallet store) # OR just button for every scan with time idk (strf and also actual time format so it can be calculated. ) # then display diff between times in a menu # #