def __init__(self, manager): self.manager = manager if on_RPI: for x in range(6): touch.on(x, handler=self.manager.btn_handler) else: self.command_q = Queue() self.screen_drawer = VirtualScreenDrawer(self.command_q, self.manager.btn_handler) self.screen_drawer.start()
def __init__(self, timeout=30): self.homescreen = HomeScreen() self._screens = [] # Array of additionally added screens self._active = 0 self.timeout = timeout # Timeout time in seconds self.timed_out = False # Are we currently timed out? self.last_interaction_time = time.time( ) # Time of last user interaction for x in range(6): touch.set_led(x, 0) touch.on(x, self.touch_handler)
def Menu(): global menuOptions, cur menuOptions = addOptions() ShowOption(menuOptions[cur]) for x in range(6): touch.on(x, handler) try: signal.pause() except KeyboardInterrupt: for x in range(6): backlight.set_pixel(x, 0, 0, 0) touch.set_led(x, 0) backlight.show() lcd.clear() lcd.show()
def main(): soma = SomaFM() media_player = MediaPlayer() screen = Screen() # command handler # execute commands after finger has moved off of the button (the release event) def handler(channel, event): # print("Got {} on channel {}".format(event, channel)) if event == "release": buttonMappings[channel].execute() # assign the command handler to the buttons for x in range(6): touch.on(x, handler) # my commands up = SomaCommand(media_player=media_player, station=soma.stations['space_station'], screen=screen) down = SomaCommand(media_player=media_player, station=soma.stations['drone_zone'], screen=screen) left = SomaCommand(media_player=media_player, station=soma.stations['groove_salad'], screen=screen) minus = SomaCommand(media_player=media_player, station=soma.stations['lush'], screen=screen) home = PausePlayCommand(media_player=media_player, station=soma.stations['lush'], screen=screen) plus = ShutdownCommand(media_player=media_player, station=soma.stations['lush'], screen=screen) # map channels (button index) to commands buttonMappings = {0: up, 1: down, 2: left, 3: minus, 4: home, 5: plus} signal.pause() # https://docs.python.org/2/library/signal.html
def test_attach_handler(cap1xxx): """Test that both handler modes call Cap1166.on().""" from gfxhat import touch decorator = touch.on([1]) def handler(): pass decorator(handler) cap1xxx.Cap1166().on.assert_has_calls([ mock.call(channel=1, event='press', handler=handler), mock.call(channel=1, event='release', handler=handler), mock.call(channel=1, event='held', handler=handler), ]) touch.on([0], handler=handler) cap1xxx.Cap1166().on.assert_has_calls([ mock.call(channel=0, event='press', handler=handler), mock.call(channel=0, event='release', handler=handler), mock.call(channel=0, event='held', handler=handler), ])
def __init__(self, controller, options_dict): print("""menu-options.py This example shows how you might store a list of menu options associated with functions and navigate them on GFX HAT. Press Ctrl+C or select "Exit" to exit. """) self.width, self.height = lcd.dimensions() self.font = ImageFont.truetype(fonts.BitbuntuFull, 10) self.image = Image.new('P', (self.width, self.height)) self.draw = ImageDraw.Draw(self.image) self.controller = controller self.slept = False self.sleep_timer = 0 self.fade = 255 self.is_playing = controller.get_playing_state() for x in range(6): touch.set_led(x, 0) self.set_backlight() touch.on(x, self.handler) backlight.show() atexit.register(self.cleanup) self.menu_options = [] for key in options_dict: self.menu_options.append( MenuOption(key, controller.change_station, self.font, (options_dict[key], True, key))) self.current_menu_option = 1 self.trigger_action = False
if not started: init() started = True else: pass else: if ch == 0 or ch == 1: paddle1_vel = 0 elif ch == 3 or ch == 5: paddle2_vel = 0 else: pass for x in range(6): touch.on(x, handler) while True: if not started and won: time.sleep(5) won = False if started: image = Image.new('P', (WIDTH, HEIGHT)) canvas = ImageDraw.Draw(image) draw(canvas) else: image = Image.open("pong-start-screen.png") for x in range(WIDTH): for y in range(HEIGHT): pixel = image.getpixel((x, y))
def initialize_button(self): touch.on(0, self.previous) touch.on(1, self.next) touch.on(2, self.backlight_screen) touch.on(3, self.illuminate) touch.on(4, self.actual_choice) touch.on(5, self.launch_radio)
def draw_cursor(image, x, y, direction): y = y if direction else y + 2 image.putpixel((x + 2, y), 1) y = y + 1 if direction else y - 1 for p in range(3): image.putpixel((x + 1 + p, y), 1) y = y + 1 if direction else y - 1 for p in range(5): image.putpixel((x + p, y), 1) for x in range(6): touch.on(x, handle_input) def clear(): lcd.clear() lcd.show() backlight.set_all(0, 0, 0) backlight.show() atexit.register(clear) while running: img = src.copy() draw = ImageDraw.Draw(img)
def on_touch(button: int, handler): touch.on(button, handler)
def init_handler(self): self.player_stmt = False self.backlight = True self.data = { "NRJ": "http://cdn.nrjaudio.fm/audio1/fr/40102/aac_576.mp3", "France Info": "http://direct.franceinfo.fr/live/franceinfo-midfi.mp3", "Voltage": "http://start-voltage.ice.infomaniak.ch/start-voltage-high.mp3" } self.choices = list(self.data.values()) self.radios = list(self.data.keys()) self.current_choice_index = 0 touch.on(0, self.previous) touch.on(1, self.next) touch.on(2, self.backlight_screen) touch.on(3, self.illuminate) touch.on(4, self.actual_choice) touch.on(5, self.launch_radio)
def init_screen(self): for x in range(6): touch.set_led(x, 0) backlight.set_pixel(x, 255, 255, 255) touch.on(x, self.handler)
y = y - 1 if y < 0: y = 63 lcd.set_pixel(x, y, 1) elif (channel == 3 and event == 'press'): # LEFT # print('LEFT') x = x - 1 if x < 0: x = 127 lcd.set_pixel(x, y, 1) elif (channel == 5 and event == 'press'): # RIGHT # print('RIGHT') x = x + 1 if x > 127: x = 0 lcd.set_pixel(x, y, 1) lcd.show() return True for z in range(6): print(status) touch.on(z, handler) print(status) if (status == False): print(status) break signal.pause()
def __init__(self, config, display): # self.playing = False self.myConfig = config self.myDisplay = display for x in range(6): backlight.set_pixel(x, 0, 128, 0) backlight.show() def handlerVolumeUp(ch, event): if event == 'press': logging.info("Volume Up") volume = self.myConfig.getVolume() volume = volume + 5 os.system("mpc volume %d" % (volume)) self.myDisplay.drawVolume(volume) self.myConfig.setVolume(volume) def handlerVolumeDown(ch, event): if event == 'press': logging.info("Volume Down") volume = self.myConfig.getVolume() volume = volume - 5 os.system("mpc volume %d" % (volume)) self.myDisplay.drawVolume(volume) self.myConfig.setVolume(volume) def handler2(ch, event): if event == 'press': logging.info("Press on button 2") def handler3(ch, event): if event == 'press': logging.info("Press on button 3") def handlerOnOff(ch, event): if event == 'press': if not self.myConfig.getPlayState(): # if logging.info("On") #os.system("mpc play") self.myConfig.setPlayState(True) self.setPlaying(self.myConfig.getPlayState()) else: logging.info("Off") #os.system("mpc stop") self.myConfig.setPlayState(False) self.setPlaying(self.myConfig.getPlayState()) def handlerOff(ch, event): if event == 'press': logging.info("Off") os.system("mpc stop") logging.info("Registering button handlers....") touch.on(0, handlerVolumeUp) touch.on(1, handlerVolumeDown) touch.on(2, handler2) touch.on(3, handler3) touch.on(4, handlerOnOff) touch.on(5, handlerOff) self.setPlaying(True)