Esempio n. 1
0
def main():
    global activated
    activated = False

    print('button_test       :' + Fore.CYAN + ' INFO  : starting test...' + Style.RESET_ALL)

    _pin = 12
    _button = Button(_pin, callback_method, Level.INFO)

    try:
        while not activated:
            print(Fore.BLACK + 'waiting for button press on pin {:d}...'.format(_pin) + Style.RESET_ALL)
            time.sleep(1.0)
    except KeyboardInterrupt:
        print(Fore.RED + "caught Ctrl-C." + Style.RESET_ALL)
    finally:
        print("closing button...")
        _button.close()
Esempio n. 2
0
def main():

    print('button_test       :' + Fore.CYAN + ' INFO  : starting test...' +
          Style.RESET_ALL)

    print('button_test       :' + Fore.BLUE + Style.BRIGHT +
          ' INFO  : to pass test, press button for both ON and OFF states...' +
          Style.RESET_ALL)

    # read YAML configuration
    _loader = ConfigLoader(Level.INFO)
    filename = 'config.yaml'
    _config = _loader.configure(filename)

    _message_factory = MessageFactory(Level.INFO)
    _queue = MessageQueue(_message_factory, Level.INFO)
    _button = Button(_config, _queue, _message_factory, threading.Lock())
    _button.start()

    while not _button.get():
        print('button_test       : ' + Fore.RED + Style.BRIGHT + "button OFF" +
              Fore.CYAN + Style.NORMAL + ' (press button to turn ON)' +
              Style.RESET_ALL)
        time.sleep(1)
    while _button.get():
        print('button_test       : ' + Fore.GREEN + Style.BRIGHT +
              "button ON" + Fore.CYAN + Style.NORMAL +
              ' (press button to turn OFF)' + Style.RESET_ALL)
        time.sleep(1)
    while not _button.get():
        print('button_test       : ' + Fore.RED + Style.BRIGHT + "button OFF" +
              Fore.CYAN + Style.NORMAL + ' (press button to turn ON)' +
              Style.RESET_ALL)
        time.sleep(1)

    print("button task close()")
    _button.close()