示例#1
0
def on(relay_num, log=True, max_duration=None):
    pin = relays[relay_num]
    GPIO.output(pin, ON)
    cancel_timer(relay_num)
    if max_duration is not None:
        timers[relay_num] = util.delay(off, max_duration, [relay_num], {"log_extra": "via timer"})
    if log:
        log_action(relay_num, "turn on")
示例#2
0
文件: gpio.py 项目: mscalora/garage
def on(relay_num, log=True, max_duration=None):
    pin = relays[relay_num]
    GPIO.output(pin, ON)
    cancel_timer(relay_num)
    if max_duration is not None:
        timers[relay_num] = util.delay(off, max_duration, [relay_num],
                                       {"log_extra": "via timer"})
    if log:
        log_action(relay_num, "turn on")
示例#3
0
def toggle(relay_num, log=True, max_duration=None):
    pin = relays[relay_num]
    new_state = not bool(GPIO.input(pin))
    GPIO.output(pin, new_state)
    cancel_timer(relay_num)
    if new_state == ON and max_duration is not None:
        timers[relay_num] = util.delay(off, max_duration, [relay_num], {"log_extra": "via timer"})
    if log:
        log_action(relay_num, "toggle %s" % ('off' if new_state == OFF else 'on'))
    return new_state
示例#4
0
文件: gpio.py 项目: mscalora/garage
def toggle(relay_num, log=True, max_duration=None):
    pin = relays[relay_num]
    new_state = not bool(GPIO.input(pin))
    GPIO.output(pin, new_state)
    cancel_timer(relay_num)
    if new_state == ON and max_duration is not None:
        timers[relay_num] = util.delay(off, max_duration, [relay_num],
                                       {"log_extra": "via timer"})
    if log:
        log_action(relay_num,
                   "toggle %s" % ('off' if new_state == OFF else 'on'))
    return new_state
示例#5
0
文件: gpio.py 项目: mscalora/garage
def set_relay(relay_num, state):
    pin = relays[relay_num]
    GPIO.output(pin, state)
示例#6
0
文件: gpio.py 项目: mscalora/garage
def off(relay_num, log=True, log_extra=""):
    pin = relays[relay_num]
    GPIO.output(pin, OFF)
    cancel_timer(relay_num)
    if log:
        log_action(relay_num, "turn off %s" % log_extra)
示例#7
0
文件: gpio.py 项目: mscalora/garage
def all_off(log=True):
    for relay_num, pin in relays.iteritems():
        GPIO.output(pin, OFF)
    if log:
        log_action("all", "turn off")
示例#8
0
文件: gpio.py 项目: mscalora/garage
}

sensors = {1: 24}

timers = {}

ON = False
OFF = True

max_synchronous_delay = 0.10

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
for relay, pin_num in relays.iteritems():
    GPIO.setup(pin_num, GPIO.OUT)
    GPIO.output(pin_num, OFF)

for sensor, pin_num in sensors.iteritems():
    GPIO.setup(pin_num, GPIO.IN)


def log_action(device, action):
    print("GPIO Device: %s Action: %s" % (device, action))


def cancel_timer(relay_num, remove_only=False):
    if relay_num in timers:
        if not remove_only:
            timers[relay_num].cancel()
        del timers[relay_num]
示例#9
0
def off(relay_num, log=True, log_extra=""):
    pin = relays[relay_num]
    GPIO.output(pin, OFF)
    cancel_timer(relay_num)
    if log:
        log_action(relay_num, "turn off %s" % log_extra)
示例#10
0
def all_off(log=True):
    for relay_num, pin in relays.iteritems():
        GPIO.output(pin, OFF)
    if log:
        log_action("all", "turn off")
示例#11
0
def set_relay(relay_num, state):
    pin = relays[relay_num]
    GPIO.output(pin, state)
示例#12
0
}

timers = {

}

ON = False
OFF = True

max_synchronous_delay = 0.10

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
for relay, pin_num in relays.iteritems():
    GPIO.setup(pin_num, GPIO.OUT)
    GPIO.output(pin_num, OFF)

for sensor, pin_num in sensors.iteritems():
    GPIO.setup(pin_num, GPIO.IN)


def log_action(device, action):
    print("GPIO Device: %s Action: %s" % (device, action))


def cancel_timer(relay_num, remove_only=False):
    if relay_num in timers:
        if not remove_only:
            timers[relay_num].cancel()
        del timers[relay_num]