def get_display(width=28, height=13, fallback=Fallback.SIMULATOR): try: import fffserial return fffserial.SerialDisplay( width=width, height=height, serial_device=configuration.flipdotdisplay['serialdevice'], baud=configuration.flipdotdisplay['serialbaudrate'], buffered=configuration.flipdotdisplay['buffered']) except Exception as e: print("Unable to create FlipDotDisplay:", e, "\nFalling back to", fallback.name) if fallback == Fallback.SIMULATOR: import flipdotsim return flipdotsim.FlipDotSim(width=width, height=height) elif fallback == Fallback.REMOTE_DISPLAY: import net return net.RemoteDisplay(width=width, height=height) elif fallback == Fallback.DUMMY: return DisplayBase(width=width, height=height) elif fallback == Fallback.I2C: import flipdotdisplay return flipdotdisplay.FlipDotDisplay(width=width, height=height) else: raise Exception("No display and no fallback!")
def test_networking(): import flipdotsim import threading import time fdd = flipdotsim.FlipDotSim(width=15, height=15) ds = DisplayServer(fdd) th = threading.Thread(target=ds.start, kwargs={'host': '127.0.0.1'}) th.setDaemon(True) th.start() time.sleep(0.2) # wait for server to start remote_display = RemoteDisplay(host="127.0.0.1", width=15, height=15) remote_display.px(1, 1, True) remote_display.px(2, 1, True) remote_display.show() time.sleep(0.5) import demos demo = demos.RotatingPlasmaDemo(remote_display) demo.fps = 30 # reduce fps for networking demo.run(2) ds.server_running = False th.join(2) fdd.close()
def test_text_scroller(): import flipdotsim import time fdd = flipdotsim.FlipDotSim() font = small_font() tsc = TextScroller(fdd, "Hallo", font) fdd.show() time.sleep(0.5) fdd.close()
def test_presenter(): tiled_map = TiledMap2(PRESENTATION_FILE) fdd = flipdotsim.FlipDotSim(width=WIDTH, height=HEIGHT) p = Presenter(fdd, tiled_map, DISPLAY_FPS) assert not p.on_map(-1, -1) for i in "wasdrq": print("testing input", i) p.handle_input(i) p.display() fdd.close()
def test_rotating_plasma(): # create simulator and let mqtt messages update the display import flipdotsim fdd_sim = flipdotsim.FlipDotSim(width=configuration.WIDTH, height=configuration.HEIGHT) mqtt2disp = Mqtt2Display(BROKER, TOPIC_DISPLAY, TOPIC_INFO, fdd_sim) mqtt2disp.run(background=True) # create mqttdisplay and let demo publish messages into the display topic import demos fdd_mqtt = MqttDisplay(configuration.WIDTH, configuration.HEIGHT, BROKER, TOPIC_DISPLAY) demo = demos.RotatingPlasmaDemo(fdd_mqtt) demo.run(runtime=2) fdd_sim.close()
def main(): tiled_map = TiledMap2(PRESENTATION_FILE) # init display: serial interface or simulator as fallback. try: import fffserial fdd = fffserial.SerialDisplay( width=WIDTH, height=HEIGHT, serial_device=configuration.flipdotdisplay['serialdevice'], baud=configuration.flipdotdisplay['serialbaudrate']) except Exception as e: print(e, "FALLBACK: Using simulator") fdd = flipdotsim.FlipDotSim(width=WIDTH, height=HEIGHT) presenter = Presenter(fdd, tiled_map, DISPLAY_FPS) presenter.run()
def test_demos(): import flipdotsim fdd = flipdotsim.FlipDotSim() demos = [ PlasmaDemo(fdd), SwirlDemo(fdd), PingPong(fdd), RandomDot(fdd), RotatingPlasmaDemo(fdd), GameOfLife(fdd), # SnakeGame(fdd), # FlappyDot(fdd), BinaryClock(fdd), # rogueflip.Game(fdd), PygameSurfaceDemo(fdd) ] for demo in demos: print(demo) demo.run(runtime=2) fdd.close()
def test_roguegame(): import flipdotsim import threading import pygame.event def user_event_generator(): print("creating events") # run to the next screen for k in 'waaasssssdssssasssssssssssssddddddddd': key = ord(k) print("posting key event", key) pygame.event.post( pygame.event.Event(pygame.KEYDOWN, key=key)) time.sleep(0.1) g.game_running = False fdd = flipdotsim.FlipDotSim() g = Game(fdd, 'ressources/rogueflip_testworld.tmx') th = threading.Thread(target=user_event_generator) th.start() g.run()
import flipdotsim import time # Create a Simulator with the given dimension display = flipdotsim.FlipDotSim(width=16, height=8) # turn some pixels on in the top left corner display.px(0, 0, True) display.px(1, 0, True) display.px(0, 1, True) # The display will not change until the show method is invoked display.show() time.sleep(2) # Lets run one dot from top left to bottom right for y in range(display.height): for x in range(display.width): display.px(x, y, True) display.show() time.sleep(0.1) display.px(x, y, False)
def run_simulator(): print("running a sample game in the simulator") import configuration as conf import flipdotsim fdd = flipdotsim.FlipDotSim(width=conf.WIDTH, height=conf.HEIGHT) run_with_flipdotdisplay(fdd)