heleft = HallEffectPair(int(he['leftopen']), int(he['leftclosed']), mode) heright = HallEffectPair(int(he['rightopen']), int(he['rightclosed']), mode) relay = Relay(int(re['red']), int(re['yellow']), int(re['green']), mode) def leftopen(channel): print "left door open" relay.turn_on_only(relay.green) def leftclosed(channel): print "left door closed" relay.turn_on_only(relay.red) def rightopen(channel): print "right door open" relay.turn_on_only(relay.green) relay.turn_on(relay.yellow) def rightclosed(channel): print "right door closed" relay.turn_on_only(relay.red) relay.turn_on(relay.yellow) heleft.add_event_detect(channel=heleft.open_door, callback=leftopen) heleft.add_event_detect(channel=heleft.closed_door, callback=leftclosed) heright.add_event_detect(channel=heright.open_door, callback=rightopen) heright.add_event_detect(channel=heright.closed_door, callback=rightclosed) while 1: time.sleep(5)
def wait_for_door(): halleffectpair = HallEffectPair() halleffectpair.add_event_detect(channel=halleffectpair.OPENDOOR, callback=park_assist) while 1: time.sleep(600)
mode = GPIO.BCM elif mode == "board": mode = GPIO.BOARD else: mode = "" he = ConfigSectionMap("HallEffect") us = ConfigSectionMap("UltraSonic") re = ConfigSectionMap("Relay") halleffectleft = HallEffectPair(int(he["leftopen"]), int(he["leftclosed"]), mode) halleffectright = HallEffectPair(int(he["rightopen"]), int(he["rightclosed"]), mode) ultrasonicleft = USonic(int(us["lefttrigger"]), int(us["leftecho"]), mode) ultrasonicright = USonic(int(us["righttrigger"]), int(us["rightecho"]), mode) relay = Relay(int(re["red"]), int(re["yellow"]), int(re["green"]), mode) halleffectleft.add_event_detect(channel=halleffectleft.open_door, callback=set_left_time) halleffectright.add_event_detect(channel=halleffectright.open_door, callback=set_right_time) while 1: left_threshold = distance_threshold(left_open_time, ultrasonicleft) right_threshold = distance_threshold(right_open_time, ultrasonicright) thresholds = [left_threshold, right_threshold] threshold = min(thresholds) if threshold == 1: # red light relay.turn_on_only(relay.red) elif threshold == 2: # yellow light relay.turn_on_only(relay.yellow) elif threshold == 3: