def runBox(boxUid): host = ConsoleHost() agnostic.collect() #TODO CH remove these test lines screen.clear() font.draw_generator(generatorFactory(), plotter) screen.redraw() agnostic.collect() boxUid = str(boxUid) # handle case of passing a number boxEngine = Engine(box=story.lookupBox(boxUid)) boxEngine.registerStory(story) agnostic.collect() while True: agnostic.report_collect() try: tagUid = vault.awaitPresence() try: cardDict = vault.readJson(tagUid=tagUid) if "storyUid" not in cardDict or cardDict["storyUid"] is not loader.storyUid: cardDict = None # existing card data incompatible except Exception as e: if type(e) is KeyboardInterrupt: raise e else: print(e) cardDict = None # couldn't read card for some reason if cardDict is not None: print("JSON Good") card = dictToCard(tagUid, cardDict) else: print("JSON Bad") card = story.createBlankCard(tagUid) agnostic.collect() boxEngine.handleCard(card, host) print("Handled Card") vault.writeJson(cardToDict(card), tagUid=tagUid, unselect=True) print("Written JSON") vault.awaitAbsence() print("Card removed") except AssertionError as ae: print(type(ae).__name__ + str(ae)) except KeyboardInterrupt: break
def __init__(self, *a, **k): super().__init__(*a, **k) # get boxes from story registry, create+store an engine for each boxTable = self.story._get_table(Box) self.engines = dict() for boxUid, box in boxTable.items(): engine = Engine(box=box) engine.registerStory(self.story) self.engines[boxUid] = engine # for each card, register it with the emulator cardIds = "a" for cardId in cardIds: card = self.story.createBlankCard(cardId) self.registerCard(card) self.currentCard = None
keyState = KeyboardState(story) hosts = dict() screens = list() hostThreads = list() boxUids = list(boxTable.keys()) boxUids.sort() for boxUid in boxUids: box = story.lookupBox(boxUid) rfid = keyState.create_rfid(boxUid) # TODO can simplify by creating window last, or does RFID need window beforehand? screen = st7920Emulator.PillowScreen() blackPlotter = screen.create_plotter(True) whitePlotter = screen.create_plotter(False) engine = Engine(box=box) engine.registerStory(story) host = Host( story = story, box = boxTable[boxUid], engine=engine, screen=screen, rfid = rfid, smallFont=smallFont, bigFont=bigFont, blackPlotter=blackPlotter, whitePlotter=whitePlotter, powerPin = None ) hosts[boxUid] = host screens.append(screen) hostRun = host.createRunnable()