Ejemplo n.º 1
0
    def test_empty_init(self):
        "Test the default Keypad creation"

        # 1. Create default Keypad object
        myobj = keypad.Keypad()

        # 2. Make sure it has the default values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(myobj.text, None)
        self.assertEqual(myobj.keypad[myobj.location], '5')

        # 3. Check methods
        self.assertEqual(myobj.at(), '5')
        self.assertEqual(myobj.can_go('U'), True)
        self.assertEqual(myobj.can_go('D'), True)
        self.assertEqual(myobj.can_go('L'), True)
        self.assertEqual(myobj.can_go('R'), True)
        self.assertEqual(myobj.move('U'), True)
        self.assertEqual(myobj.at(), '2')
        self.assertEqual(myobj.move('U'), False)
        self.assertEqual(myobj.at(), '2')
        self.assertEqual(myobj.move('L'), True)
        self.assertEqual(myobj.at(), '1')
        self.assertEqual(myobj.move('L'), False)
        self.assertEqual(myobj.at(), '1')
        self.assertEqual(myobj.one_line("RRDDD"), '9')
Ejemplo n.º 2
0
def run():
    password_path = "./pass.txt"
    pad = keypad.Keypad()
    pad.setup()
    #testpad = keypad_test.Keypad()
    ledboard = led.LEDboard()
    #testledboard = led_test.LEDboard()
    ledboard.setup()
    kpc = kpc_agent.KPCAgent(pad, ledboard, password_path)
    #kpc = KPCAgent.KPCAgent(testpad, testledboard, password_path)

    thefsm = fsm.Fsm(kpc)
    # Add fsm rules
    thefsm.addRule("S-init", "S-read", fsm.signal_is_symbol, kpc.reset_password_accumulator)
    thefsm.addRule("S-read", "S-read", fsm.signal_is_digit, kpc.append_next_password_digit)
    thefsm.addRule("S-read", "S-verify", "*", kpc.verify_password)
    thefsm.addRule("S-read", "S-init", fsm.signal_is_symbol, kpc.reset_agent)
    thefsm.addRule("S-verify", "S-active", "Y", kpc.fully_activate_agent)
    thefsm.addRule("S-verify", "S-init", fsm.signal_is_symbol, kpc.reset_agent)
    thefsm.addRule("S-active", "S-led", fsm.signal_less_than_six, kpc.set_lid)  # sett led
    thefsm.addRule("S-active", "S-password", "*", None)  # Begynn passordendring
    thefsm.addRule("S-active", "S-logout", "#", None)
    thefsm.addRule("S-led", "S-time", "*", None)  # Begynn Sett tid, kanskje None
    thefsm.addRule("S-time", "S-time", fsm.signal_is_digit, kpc.append_next_time_digit)  # Legg til på tid
    thefsm.addRule("S-time", "S-active", "*", kpc.light_one_led)
    thefsm.addRule("S-password", "S-password", fsm.signal_is_digit,
                   kpc.append_next_password_digit)  # Legg til på endret passord
    thefsm.addRule("S-password", "S-active", "*", kpc.validate_password)
    thefsm.addRule("S-logout", "S-done", "#", kpc.exit_action)
    thefsm.addRule("S-logout", "S-active", fsm.signal_is_symbol, None)
    thefsm.addRule("S-done", "S-read", fsm.signal_is_symbol, kpc.reset_agent())

    thefsm.set_start_state("S-init")
    # fsm.set_end_state("S-end")#Har ingen end state foreløpig
    thefsm.main_loop()
Ejemplo n.º 3
0
    def test_part_two(self):
        "Test part two example of Keypad object"

        # 1. Create Keypad object from text
        myobj = keypad.Keypad(part2=True, text=aoc_02.from_text(PART_TWO_TEXT))

        # 2. Check the part two result
        self.assertEqual(myobj.part_two(verbose=False), PART_TWO_RESULT)
Ejemplo n.º 4
0
    def test_part_one(self):
        "Test part one example of Keypad object"

        # 1. Create Keypad object from text
        myobj = keypad.Keypad(text=aoc_02.from_text(PART_ONE_TEXT))

        # 2. Check the part one result
        self.assertEqual(myobj.part_one(verbose=False), PART_ONE_RESULT)
Ejemplo n.º 5
0
def loop():
    
    keypad1 = Keypad.Keypad(keys,rowPins,colsPins,ROWS,COLS)
    keypad1.setDebounceTime(50)
    while(True):
        key = keypad1.getKey() # keeps looping through until it gets a key
        if(key != keypad1.NULL):
            print ("your pressed key: %c"%(key))
Ejemplo n.º 6
0
    def test_text_init(self):
        "Test the Keypad object creation from text"

        # 1. Create Keypad object from text
        myobj = keypad.Keypad(text=aoc_02.from_text(EXAMPLE_TEXT))

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(len(myobj.text), 4)
        self.assertEqual(keypad.KEYPAD_ONE[myobj.location], '5')

        # 3. Check methods
        self.assertEqual(myobj.get_code(), "1985")
Ejemplo n.º 7
0
def main():
    # dsp = display_b.Display()
    dsp = display_b.Display()
    dsp.log("George's MK 52")

    kbd = keypad.Keypad(24, 23, 22, 21, 19, 18, 16, 15, 13, 12, 11, 10, 8, 7)

    with emulator.Emulator("ws://localhost:8080/",
                           on_display=dsp.show,
                           on_log=dsp.log) as em:
        for x, y, txt in kbd.get_key_presses():
            em.press_button(x, y)
            time.sleep(0.1)
Ejemplo n.º 8
0
def part_two(args, input_lines):
    "Process part two of the puzzle"

    # 1. Create the puzzle solver
    solver = keypad.Keypad(part2=True, text=input_lines)

    # 2. Determine the solution for part two
    solution = solver.part_two(verbose=args.verbose, limit=args.limit)
    if solution is None:
        print("There is no solution")
    else:
        print("The solution for part two is %s" % (solution))

    # 3. Return result
    return solution is not None
Ejemplo n.º 9
0
    def __init__(self, keypad_read_timeout=1.5):
        self.routes = {'parts': {}}
        self.debug_mode = os.environ.get('PHREAK_ENVIRONMENT')

        self.dialtone = None
        self.ringing_tone = None
        self.mode = 'normal'

        self.keypad_read_timeout = keypad_read_timeout

        self.keypad = keypad.Keypad()
        self.keypad.set_callback(self.handle)
        self.keypad.start()

        self.listening = False
        self.keypad_buffer = ''
        self.listen_timer = None

        self.tts = pyttsx3.init()
        self.tts.setProperty('rate', 175)
        self.tts.setProperty('volume', 3.0)
Ejemplo n.º 10
0
                resp = my_keypad.handle_message(item)
                if k_id != '10':
                    # ser.write(resp)

                    if ser.out_waiting > 0:
                        print('Waiting to write {}'.format(ser.out_waiting))

                    print('Wrote: {}'.format(resp))

            # elif item[0:2] in filter and item not in exclude:
            elif item not in exclude:
                print(item)


if __name__ == '__main__':
    my_keypad = keypad.Keypad(0x10)

    pqueue_raw = Queue()  # writer() writes to pqueue from _this_ process
    pqueue_command = Queue()

    serial_reader_p = Process(target=serial_reader, args=(
        ser,
        pqueue_raw,
    ))
    serial_reader_p.daemon = True
    serial_reader_p.start()

    raw_processor_p = Process(target=raw_processor,
                              args=(pqueue_raw, pqueue_command))
    raw_processor_p.daemon = True
    raw_processor_p.start()
Ejemplo n.º 11
0
import RPi.GPIO as GPIO
import time
import get_time
from datetime import datetime
import keypad

GPIO.setmode(GPIO.BCM)

pad = keypad.Keypad()

times = [3,2]

for slot in times:
    GPIO.setup(slot, GPIO.OUT)
    GPIO.output(slot, 0)

segments = [11,10,27,4,22,9,17]

#top 27
#top right 4
#bottom right 22
#bottom 9
#bottom left 11
#top left 10
#middle 17

for segment in segments:
    GPIO.setup(segment, GPIO.OUT)
    GPIO.output(segment, 0)

digits = [14,15,18,23,24,25,8,1,7,12,16,20]
Ejemplo n.º 12
0
    if sys.argv[1] == "test":
        testing = True
cont = test_controller if testing else controller
state = cont.init_state()

# setup DS18B20 external temp sensor
ext_temp_sensor = W1ThermSensor()
ext_temp = None

# load settings
with open('settings.json', 'r') as f:
    settings = json.load(f)

# initialize keypad
KEYPAD = keypad.Keypad(settings["keypad_characters"],
                       settings["keypad_row_pins"],
                       settings["keypad_col_pins"])

# initialize PIR
GPIO.setup(settings["pir_pin"], GPIO.IN)

# initialize twilio
# TWILIO_CLIENT = Client(settings["twilio_account_sid"], settings["twilio_auth_token"])

# initialize gas sensor
GAS_SENSOR = DigitalInputDevice(settings["gas_pin"])

# initialize LCD
LCD = lcd.LCD(settings["lcd_rs"], settings["lcd_e"], settings["lcd_d4"],
              settings["lcd_d5"], settings["lcd_d6"], settings["lcd_d7"],
              settings["lcd_chr"], settings["lcd_cmd"], settings["lcd_chars"],
Ejemplo n.º 13
0
 def __init__(self):
     self.check_password = ''
     self.Keypad = keypad.Keypad()
Ejemplo n.º 14
0
import os

#os.chdir("/home/pi/Documents/Python/ir/Resources/")
sys.path.append("./Resources")
from CodeManager import CodeManager
import keypad

GPIO_BUTTON = 19
GPIO_LED = 8
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(GPIO_BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(GPIO_LED, GPIO.OUT)
GPIO.output(GPIO_LED, GPIO.LOW)
keypad = keypad.Keypad([37, 35, 33, 31], [40, 38, 36, 32],
                       [["1", "2", "3", "A"], ["4", "5", "6", "B"],
                        ["7", "8", "9", "C"], ["*", "0", "#", "D"]], [19])

codeManager = CodeManager()


def Flash(amount):
    for i in range(amount):
        GPIO.output(GPIO_LED, GPIO.HIGH)
        time.sleep(.2)
        GPIO.output(GPIO_LED, GPIO.LOW)
        time.sleep(.2)


Flash(3)
Ejemplo n.º 15
0
import keypad

with open("input.txt", "r") as file:
    code = []
    last = None
    for line in file:
        k = keypad.Keypad(last)
        k.executeInstructions(line)
        code.append(k.current)
        last = k.current

print code