Ejemplo n.º 1
0
def main():
    # Monitor the button for events.
    global eventloop
    eventloop = EventLoop()
    eventloop.monitor_gpio_button(args.gpio_pin,
                                  button_handler,
                                  doubleclick_speed=0)

    say("Device is in Service Mode. Press button to navigate through the menu. "
        "Long press to enter the menu section or perform an action.")

    # Read current configuration values.
    with open(args.config_path) as config_file:
        for line in config_file:
            key, value = line.partition("=")[::2]

            # Ignore empty lines.
            key = key.strip()
            if key:
                config[key] = value.strip()

    logger.info('Current environment variables: %s', config)

    ready()

    # Run the event loop forever.
    eventloop.loop()
Ejemplo n.º 2
0
def main():
    # Load the database of items we know about.
    global db
    db = ImageDatabase(options)

    # Initialize the camera object we'll use to take pictures.
    global camera
    camera = Camera(options.video_source,
                    options.video_width,
                    options.video_height,
                    options.video_fps)

    with open(get_sound('shutter.raw'), 'rb') as f:
        global SHUTTER_TONE
        SHUTTER_TONE = f.read()

    # Set up the audio devices if they are configured
    if options.audio_out_device:
        audioutils.ALSA_SPEAKER = options.audio_out_device
    if options.audio_in_device:
        audioutils.ALSA_MICROPHONE = options.audio_in_device

    # If log path is set, make sure the corresponding directory exists.
    if options.log_path and not os.path.isdir(options.log_path):
        os.makedirs(options.log_path)

    # If --web-server was specified, run a web server in a separate process
    # to expose the files in that directory.
    # Note that we're using port 80, assuming we'll always run as root.
    if options.web_server:
        subprocess.Popen(['python', '-m', 'SimpleHTTPServer', '80'],
                         cwd=options.web_server_root)

    # Monitor the button for events
    global eventloop
    eventloop = EventLoop()
    eventloop.monitor_gpio_button(options.gpio_pin, button_handler,
                                  doubleclick_speed=0)

    # If you don't have a button, use --cmd-ui to monitor the keyboard instead.
    if options.cmd_ui:
        # Print instructions.
        keyboard_handler()
        # Monitor it on the event loop.
        eventloop.monitor_console(keyboard_handler, prompt="Command: ")

    # Let the user know we're ready
    ready()

    # Run the event loop forever
    eventloop.loop()
Ejemplo n.º 3
0
if __name__ == '__main__':

    from eventloop import EventLoop

    print('longpress to record')
    print('click to play back recording')
    print('doubleclick to quit')
    eventloop = EventLoop()

    recording = None

    def button_handler(event, pin):
        global recording
        if pin != 26:
            return
        if event == 'click':
            if recording:
                play(recording)
            else:
                print("long press to make a recording")
        elif event == 'longpress':
            play(start_recording_tone)
            time.sleep(0.1)  # don't pick up any of the tone in the mic
            recording = record()
            play(stop_recording_tone)
        elif event == 'doubleclick':
            eventloop.exit()

    eventloop.monitor_gpio_button(26, button_handler)
    eventloop.loop()