Exemple #1
0
def open_door(SWITCH, LED):
    print('Door Opened!')

    # 문 열기 - 모터 등을 연결해서 실제 움직임 표현한다면 이곳에.
    pass

    # 노란불은 끄고 초록불 켜고
    GPIO_UTIL.led_onoff(GPIO_UTIL.search_pin_led(LED, 'LED_Y'), OFF)
    GPIO_UTIL.led_onoff(GPIO_UTIL.search_pin_led(LED, 'LED_G'), ON)

    # 비번변경 키 비활성화
    GPIO_UTIL.event_disable(GPIO_UTIL.search_pin_switch(SWITCH, 'MODE'))

    # Enter키가 눌릴때까지 아무것도 하지 않는다.
    while (True):
        if GPIO.event_detected(GPIO_UTIL.search_pin_switch(SWITCH,
                                                           'ENTER')) is True:
            break
        else:
            time.sleep(0.1)

    # 비번변경 키 활성화
    GPIO_UTIL.event_enable(GPIO_UTIL.search_pin_switch(SWITCH, 'MODE'))

    # 노란불은 켜고 초록불 끄고
    GPIO_UTIL.led_onoff(GPIO_UTIL.search_pin_led(LED, 'LED_Y'), ON)
    GPIO_UTIL.led_onoff(GPIO_UTIL.search_pin_led(LED, 'LED_G'), OFF)
Exemple #2
0
def lock_door(SWITCH, LED, locktime):
    time_count = 0

    # 모든 키 비활성화
    GPIO_UTIL.event_disable(GPIO_UTIL.search_pin_switch(SWITCH, 'MODE'))
    GPIO_UTIL.event_disable(GPIO_UTIL.search_pin_switch(SWITCH, 'ENTER'))

    # 노랑 LED는 끄자
    GPIO_UTIL.led_onoff(GPIO_UTIL.search_pin_led(LED, 'LED_Y'), OFF)

    # 카메라 촬ㅋ영ㅋ
    # 일부러 비워놈
    pass

    # 빨간 LED를 마구 점멸시켜서 정신분산
    while (True):
        # LED 점멸: 0.1초당 1번
        if (time_count <= locktime):
            GPIO_UTIL.toggle_led(GPIO_UTIL.search_pin_led(LED, 'LED_R'))

        # 시간 경과
        else:
            break

        time_count += 0.1
        time.sleep(0.1)

    # 경고 시간이 지났다면 Ready로 돌아감.
    GPIO_UTIL.led_onoff(GPIO_UTIL.search_pin_led(LED, 'LED_R'), OFF)
    mode_ready(SWITCH, LED)
Exemple #3
0
def doorlock(SWITCH, LED):
    print('Doorlock started')

    # Ready 모드 설정
    STATES.mode_ready(SWITCH, LED)

    # 무한루프 (Ready 모드에서 시작)
    while (True):
        # check_events(SWITCH)

        # 조건 검색 및 분기

        # 입력이면 비번확인 모드로 진입.
        check_pin = GPIO_UTIL.search_pin_switch(SWITCH, 'ENTER')
        if GPIO.event_detected(check_pin) is True:
            pwd_result = STATES.check_password(SWITCH, LED, PASSWORD)

            # 성공시 open 모드로 진입.
            if pwd_result is True:
                STATES.open_door(SWITCH, LED)

            # 실패시 lock 모드로 진입.
            else:
                STATES.lock_door(SWITCH, LED, LOCKTIME)  # locktime 10초

            print("Ready Mode")

        # 비번변경이면 비번변경 모드로 진입.
        check_pin = GPIO_UTIL.search_pin_switch(SWITCH, 'MODE')
        if GPIO.event_detected(check_pin) is True:
            #비번변경 모드
            STATES.change_pwd(SWITCH, LED)

        # 100미리동안 쉬기
        time.sleep(0.1)  # 100ms sleep
Exemple #4
0
def mode_ready(SWITCH, LED):
    print("Set Ready Mode")

    # LED Y ON
    GPIO_UTIL.led_onoff(GPIO_UTIL.search_pin_led(LED, 'LED_Y'), ON)

    # Event Enable: Enter and CHMOD button
    #    for pin in SWITCH:
    #        if SWITCH[pin]['name'] is 'ENTER' or SWITCH[pin]['name'] is 'MODE':
    #            event_enable(pin)

    GPIO_UTIL.event_enable(GPIO_UTIL.search_pin_switch(SWITCH, 'ENTER'))
    GPIO_UTIL.event_enable(GPIO_UTIL.search_pin_switch(SWITCH, 'MODE'))
Exemple #5
0
def check_password(SWITCH, LED, PASSWORD):
    print("Enter Password")

    # 번호키 활성화
    GPIO_UTIL.event_enable(GPIO_UTIL.search_pin_switch(SWITCH, '0'))
    GPIO_UTIL.event_enable(GPIO_UTIL.search_pin_switch(SWITCH, '1'))
    GPIO_UTIL.event_enable(GPIO_UTIL.search_pin_switch(SWITCH, '2'))

    # 비번변경 키 비활성화
    GPIO_UTIL.event_disable(GPIO_UTIL.search_pin_switch(SWITCH, 'MODE'))

    #    print("chkpwd entered")
    #    check_events(SWITCH)

    num_of_keypress = 0
    keypress_pattern = [0, 0, 0, 0]
    time_count = 0

    # 키가 눌릴때마다 키패턴에 저장
    while (True):
        # 번호확인
        if GPIO.event_detected(GPIO_UTIL.search_pin_switch(SWITCH,
                                                           'ENTER')) is True:
            break  # exit keypress
        elif GPIO.event_detected(GPIO_UTIL.search_pin_switch(SWITCH,
                                                             '0')) is True:
            if num_of_keypress < 4:
                keypress_pattern[num_of_keypress] = 0
            num_of_keypress += 1
        elif GPIO.event_detected(GPIO_UTIL.search_pin_switch(SWITCH,
                                                             '1')) is True:
            if num_of_keypress < 4:
                keypress_pattern[num_of_keypress] = 1
            num_of_keypress += 1
        elif GPIO.event_detected(GPIO_UTIL.search_pin_switch(SWITCH,
                                                             '2')) is True:
            if num_of_keypress < 4:
                keypress_pattern[num_of_keypress] = 2
            num_of_keypress += 1

        # LED 점멸: 1초당 1번
        if (time_count >= 0.5):
            GPIO_UTIL.toggle_led(GPIO_UTIL.search_pin_led(LED, 'LED_Y'))
            time_count = 0

        time_count += 0.1
        time.sleep(0.1)

    # Enter키가 눌렸다면 비번확인 모드 종료

    # 번호키 비활성화
    GPIO_UTIL.event_disable(GPIO_UTIL.search_pin_switch(SWITCH, '0'))
    GPIO_UTIL.event_disable(GPIO_UTIL.search_pin_switch(SWITCH, '1'))
    GPIO_UTIL.event_disable(GPIO_UTIL.search_pin_switch(SWITCH, '2'))

    # 비번변경 키 활성화
    GPIO_UTIL.event_enable(GPIO_UTIL.search_pin_switch(SWITCH, 'MODE'))

    # LED Y ON
    GPIO_UTIL.led_onoff(GPIO_UTIL.search_pin_led(LED, 'LED_Y'), ON)

    # 결과 리턴
    if keypress_pattern == PASSWORD and num_of_keypress == 4:
        print('PASSWORD correct')
        return True
    else:
        print('PASSWORD wrong')
        return False