示例#1
0
 def wait_loop(self, context_to_watch):
     eh = ExitHelper(self.i, keys="*").start()
     while eh.do_run():
         sleep(self.sleep_time)
         self.refresh(context_to_watch)
     self.started_at = None
     return eh.last_key
示例#2
0
 def test_screen(self):
     # Testing the screen - drawing a "crosshair" to test screen edges and lines
     c = Canvas(self.o)
     c.line((0, 0, 10, 0))
     c.line(("-1", 0, "-10", 0))
     c.line((0, "-1", 10, "-1"))
     c.line(("-1", "-1", "-10", "-1"))
     c.line((0, 0, 0, 10))
     c.line((0, "-1", 0, "-10"))
     c.line(("-1", 10, "-1", 0))
     c.line(("-1", "-1", "-1", "-10"))
     c.line((0, 0, "-1", "-1"))
     c.line((0, "-1", "-1", 0))
     eh = ExitHelper(self.i, ["KEY_ENTER", "KEY_LEFT"]).start()
     c.display()
     sleep(1)
     for x in range(30):
         if eh.do_run():
             if x % 10 == 0:
                 c.invert()
                 c.display()
             sleep(0.1)
         else:
             break
     # Filling the screen (still using the same ExitHelper)
     c = Canvas(self.o)
     for x in range(60):
         if eh.do_run():
             if x % 20 == 0:
                 c.invert()
                 c.display()
             sleep(0.1)
         else:
             break
示例#3
0
 def wait_loop(self, last_key=None):
     # some key was pressed before that
     self.eh = ExitHelper(self.i, keys="*").start()
     if last_key:
         self.eh.last_key = last_key
         return
     while self.eh.do_run():
         sleep(self.sleep_time)
示例#4
0
文件: main.py 项目: joha2/pyLCI
def callback():
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(18, GPIO.IN)
    eh = ExitHelper(i).start()
    while eh.do_run():
        state = GPIO.input(18)
        if state:
            GraphicsPrinter(local_path("no_fire.png"), None, o, 0.1)
        else:
            GraphicsPrinter(local_path("fire.png"), None, o, 0.1)
示例#5
0
 def test_usb_port(self):
     from zerophone_hw import USB_DCDC
     eh = ExitHelper(self.i, ["KEY_LEFT", "KEY_ENTER"]).start()
     PrettyPrinter("Press Enter to test USB", None, self.o, 0)
     counter = 5
     for x in range(50):
         if eh.do_run():
             if x % 10 == 0: counter -= 1
             sleep(0.1)
         else:
             break
     if counter > 0:
         PrettyPrinter(
             "Insert or remove a USB device \n press Enter to skip", None,
             self.o, 0)
         dcdc = USB_DCDC()
         dcdc.on()
示例#6
0
 def test_charger(self):
     #Testing charging detection
     PrettyPrinter("Testing charger detection", self.i, self.o, 1)
     from zerophone_hw import Charger
     charger = Charger()
     eh = ExitHelper(self.i, ["KEY_LEFT", "KEY_ENTER"]).start()
     if charger.connected():
         PrettyPrinter(
             "Charging, unplug charger to continue \n Enter to bypass",
             None, self.o, 0)
         while charger.connected() and eh.do_run():
             sleep(1)
     else:
         PrettyPrinter(
             "Not charging, plug charger to continue \n Enter to bypass",
             None, self.o, 0)
         while not charger.connected() and eh.do_run():
             sleep(1)
示例#7
0
    def test_headphone_jack(self):
        #Testing audio jack sound
        PrettyPrinter("Testing audio jack", self.i, self.o, 1)
        if self.br:
            if self.br.running:
                PrettyPrinter(
                    "Audio jack test music not yet downloaded, waiting...",
                    None, self.o, 0)
                eh = ExitHelper(self.i, ["KEY_LEFT", "KEY_ENTER"]).start()
                while self.br.running and eh.do_run():
                    sleep(0.1)
                if eh.do_exit():
                    return
            elif self.br.failed:
                PrettyPrinter("Failed to download test music!", self.i, self.o,
                              1)
        disclaimer = [
            "Track used:"
            "", "Otis McDonald", "-", "Otis McMusic", "YT AudioLibrary"
        ]
        Printer([s.center(self.o.cols) for s in disclaimer], self.i, self.o, 3)
        PrettyPrinter("Press C1 to restart music, C2 to continue testing",
                      self.i, self.o)
        import pygame
        pygame.mixer.init()
        pygame.mixer.music.load(music_path)
        pygame.mixer.music.play()
        continue_event = Event()

        def restart():
            pygame.mixer.music.stop()
            pygame.mixer.init()
            pygame.mixer.music.load(music_path)
            pygame.mixer.music.play()

        def stop():
            pygame.mixer.music.stop()
            continue_event.set()

        self.i.clear_keymap()
        self.i.set_callback("KEY_F1", restart)
        self.i.set_callback("KEY_F2", stop)
        self.i.set_callback("KEY_ENTER", stop)
        continue_event.wait()
示例#8
0
 def game_loop(self):
     self.set_keymap()
     self.refresh()
     while self.game.get_game_state(
     ) == 'not over' and not self.do_exit.isSet():
         sleep(1)
     if self.do_exit.isSet():
         return
     #Waiting for player to click any of five primary keys
     #Then, prompting to restart the game
     eh = ExitHelper(self.i, keys=self.i.reserved_keys).start()
     while eh.do_run():
         sleep(0.1)
     do_restart = DialogBox("ync",
                            self.i,
                            self.o,
                            message="Restart the game?").activate()
     if do_restart is None:  #Cancel, leaving the playing field as-is
         return
     elif do_restart is False:  #No, not restarting, thus exiting the game
         self.do_exit.set()
     else:
         self.start_new_game(
         )  #Yes, restarting (game_loop will be entered once more from on_start() )
示例#9
0
def wait_for_connection():
    eh = ExitHelper(i).start()
    while eh.do_run() and init.running and not init.failed:
        sleep(1)
    eh.stop()
示例#10
0
文件: main.py 项目: hramrach/ZPUI
def callback():
    try:
        #Testing I2C - 0x12 should answer, 0x20 should raise IOError with busy errno
        from smbus import SMBus
        bus = SMBus(1)
        try:
            bus.read_byte(0x12)
        except IOError:
            PrettyPrinter("Keypad does not respond!", i, o)
        else:
            PrettyPrinter("Keypad found!", i, o)
        #Checking IO expander
        expander_ok = False
        try:
            bus.read_byte(0x20)
        except IOError as e:
            if e.errno == 16:
                PrettyPrinter("IO expander OK!", i, o)
                expander_ok = True
            elif e.errno == 121:
                PrettyPrinter("IO expander not found!", i, o)
        else:
            PrettyPrinter("IO expander driver not loaded!", i, o)
        #Launching splashscreen
        GraphicsPrinter("splash.png", i, o, 2)
        #Launching key_test app from app folder, that's symlinked from example app folder
        PrettyPrinter("Testing keypad", i, o, 1)
        import key_test
        key_test.init_app(i, o)
        key_test.callback()
        #Following things depend on I2C IO expander,
        #which might not be present:
        if expander_ok:
            #Testing charging detection
            PrettyPrinter("Testing charger detection", i, o, 1)
            from zerophone_hw import is_charging
            eh = ExitHelper(i, ["KEY_LEFT", "KEY_ENTER"]).start()
            if is_charging():
                PrettyPrinter(
                    "Charging, unplug charger to continue \n Enter to bypass",
                    None, o, 0)
                while is_charging() and eh.do_run():
                    sleep(1)
            else:
                PrettyPrinter(
                    "Not charging, plug charger to continue \n Enter to bypass",
                    None, o, 0)
                while not is_charging() and eh.do_run():
                    sleep(1)
            #Testing the RGB LED
            PrettyPrinter("Testing RGB LED", i, o, 1)
            from zerophone_hw import RGB_LED
            led = RGB_LED()
            for color in ["red", "green", "blue"]:
                led.set_color(color)
                Printer(color.center(o.cols), i, o, 3)
            led.set_color("none")
        #Testing audio jack sound
        PrettyPrinter("Testing audio jack", i, o, 1)
        if not downloaded.isSet():
            PrettyPrinter(
                "Audio jack test music not yet downloaded, waiting...", i, o)
            downloaded.wait()
        disclaimer = [
            "Track used:"
            "", "Otis McDonald", "-", "Otis McMusic", "YT AudioLibrary"
        ]
        Printer([s.center(o.cols) for s in disclaimer], i, o, 3)
        PrettyPrinter("Press C1 to restart music, C2 to continue testing", i,
                      o)
        import pygame
        pygame.mixer.init()
        pygame.mixer.music.load(music_path)
        pygame.mixer.music.play()
        continue_event = Event()

        def restart():
            pygame.mixer.music.stop()
            pygame.mixer.init()
            pygame.mixer.music.load(music_path)
            pygame.mixer.music.play()

        def stop():
            pygame.mixer.music.stop()
            continue_event.set()

        i.clear_keymap()
        i.set_callback("KEY_F1", restart)
        i.set_callback("KEY_F2", stop)
        i.set_callback("KEY_ENTER", stop)
        continue_event.wait()
        #Self-test passed, it seems!
    except:
        exc = format_exc()
        PrettyPrinter(exc, i, o, 10)
    else:
        PrettyPrinter("Self-test passed!", i, o, 3, skippable=False)
示例#11
0
文件: main.py 项目: hramrach/ZPUI
def callback():
    eh = ExitHelper(i)
    th = InputlessThrobber(i, o, message="Idle spinner")
    eh.set_callback(th.stop)
    eh.start()
    th.activate()