コード例 #1
0
def test_init_sequence(monkeypatch):
    init_log = []

    def capture_write(value, path):
        init_log.append((value, path))

    monkeypatch.setattr(gpio, '_write_value', capture_write)

    gpio.initialize()

    expected_log = [
        # Enable output pins
        (gpio.OUTPUT_PINS['FRAME_LEDS'], "{}/export".format(gpio._path_prefix)
         ),  # NOQA
        (gpio.OUT, "{0}/gpio{1}/direction".format(
            gpio._path_prefix, gpio.OUTPUT_PINS['FRAME_LEDS'])),  # NOQA
        (gpio.OUTPUT_PINS['BLUE_BUTTON'],
         "{}/export".format(gpio._path_prefix)),  # NOQA
        (gpio.OUT, "{0}/gpio{1}/direction".format(
            gpio._path_prefix, gpio.OUTPUT_PINS['BLUE_BUTTON'])),  # NOQA
        (gpio.OUTPUT_PINS['HALT'],
         "{}/export".format(gpio._path_prefix)),  # NOQA
        (gpio.OUT,
         "{0}/gpio{1}/direction".format(gpio._path_prefix,
                                        gpio.OUTPUT_PINS['HALT'])),  # NOQA
        (gpio.OUTPUT_PINS['GREEN_BUTTON'],
         "{}/export".format(gpio._path_prefix)),  # NOQA
        (gpio.OUT, "{0}/gpio{1}/direction".format(
            gpio._path_prefix, gpio.OUTPUT_PINS['GREEN_BUTTON'])),  # NOQA
        (gpio.OUTPUT_PINS['AUDIO_ENABLE'],
         "{}/export".format(gpio._path_prefix)),  # NOQA
        (gpio.OUT, "{0}/gpio{1}/direction".format(
            gpio._path_prefix, gpio.OUTPUT_PINS['AUDIO_ENABLE'])),  # NOQA
        (gpio.OUTPUT_PINS['ISP'],
         "{}/export".format(gpio._path_prefix)),  # NOQA
        (gpio.OUT,
         "{0}/gpio{1}/direction".format(gpio._path_prefix,
                                        gpio.OUTPUT_PINS['ISP'])),  # NOQA
        (gpio.OUTPUT_PINS['RESET'],
         "{}/export".format(gpio._path_prefix)),  # NOQA
        (gpio.OUT,
         "{0}/gpio{1}/direction".format(gpio._path_prefix,
                                        gpio.OUTPUT_PINS['RESET'])),  # NOQA
        (gpio.OUTPUT_PINS['RED_BUTTON'],
         "{}/export".format(gpio._path_prefix)),  # NOQA
        (gpio.OUT, "{0}/gpio{1}/direction".format(
            gpio._path_prefix, gpio.OUTPUT_PINS['RED_BUTTON'])),  # NOQA
        # Enable input pins
        (gpio.INPUT_PINS['BUTTON_INPUT'], "{}/export".format(gpio._path_prefix)
         ),  # NOQA
        (gpio.IN, "{0}/gpio{1}/direction".format(
            gpio._path_prefix, gpio.INPUT_PINS['BUTTON_INPUT'])),  # NOQA
        (gpio.INPUT_PINS['WINDOW_INPUT'],
         "{}/export".format(gpio._path_prefix)),  # NOQA
        (gpio.IN, "{0}/gpio{1}/direction".format(
            gpio._path_prefix, gpio.INPUT_PINS['WINDOW_INPUT']))  # NOQA
    ]

    assert init_log == expected_log
コード例 #2
0
ファイル: conf_button.py プロジェクト: cristhoper/hack-a-tron
def button_states():
    gpio.initialize()
    gpio.set_button_light()  # this make lights off
    while True:
        pressed_time = __get_pressed_time()
        if __get_state() == STATES["PLUGIN"] and pressed_time > INIT_TIME:
            __run_startup()
        elif __get_state() == STATES["ACTIVE"] and pressed_time > HOLD_TIME:  # and time is less than 2 secs:
            set_error()
        elif __get_state() == STATES["ACTIVE"] and pressed_time < HOLD_TIME:  # and time is less than 2 secs:
            __run_pause()
        elif __get_state() == STATES["PAUSED"] and pressed_time < HOLD_TIME: # and time is less than 2 secs:
            set_active()
        elif __get_state() == STATES["PAUSED"] and pressed_time > HOLD_TIME:  # and time is more than 2 secs:
            set_ready()
コード例 #3
0
#!/usr/bin/env python
from time import sleep

from opentrons.drivers.rpi_drivers import gpio

# set the direction of each gpio (in or out)
gpio.initialize()

# audio-enable pin can stay HIGH always, unless there is noise coming
# from the amplifier, then we can set to LOW to disable the amplifier
gpio.set_high(gpio.OUTPUT_PINS['AUDIO_ENABLE'])

# smoothieware programming pins, must be in a known state (HIGH)
gpio.set_high(gpio.OUTPUT_PINS['HALT'])
gpio.set_high(gpio.OUTPUT_PINS['ISP'])
gpio.set_low(gpio.OUTPUT_PINS['RESET'])
sleep(0.25)
gpio.set_high(gpio.OUTPUT_PINS['RESET'])
sleep(0.25)

# turn light to blue
gpio.turn_on_blue_button_light()