How to use signal_on method in avocado

Best Python code snippet using avocado_python

rx.py

Source:rx.py Github

copy

Full Screen

1import socket2import argparse3from pynput.keyboard import Key, Controller45keyboard = Controller()67s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)8s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)9s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)1011def control(signals):12 for signal in signals["signal_release"]:13 keyboard.release(signal)1415 keyboard.press(signals["signal_on"])1617def main(host, port):18 print(f"host: {host}, port: {port}")1920 s.bind((host, int(port)))2122 while True:23 try:24 BYTE = 819225 message, address = s.recvfrom(BYTE)26 LIST_DATA = str(message).split(",")27 rcvd_length = len(LIST_DATA)28 EXPECTED_LEN = 1729 if rcvd_length == EXPECTED_LEN:30 gravity_data = LIST_DATA[-3:]31 for idx, gravity in enumerate(gravity_data):32 gravity_data[idx] = float(gravity.strip()[:-1])33 g_x, g_y, g_z = gravity_data3435 print(f"current state: {g_x}, {g_y}, {g_z}")36 # halt 37 if (-3 < g_x < 3) and (-3 < g_y < 3):38 print("HALT")39 signals = {"signal_release": [Key.up, Key.down, Key.left, Key.right], 40 "signal_on": Key.space}41 control(signals)4243 # forward44 elif (-3 > g_x) and (-3 < g_y < 3):45 print("FORWARD")46 signals = {"signal_release": [Key.space, Key.down, Key.left, Key.right], 47 "signal_on": Key.up}48 control(signals)4950 # retreat51 elif (3 < g_x) and (-3 < g_y < 3):52 print("RETREAT")53 signals = {"signal_release": [Key.up, Key.space, Key.left, Key.right], 54 "signal_on": Key.down}55 control(signals)5657 # left58 elif (-3 < g_x < 3) and (-3 > g_y):59 print("LEFT TURN")60 signals = {"signal_release": [Key.up, Key.down, Key.space, Key.right], 61 "signal_on": Key.left}62 control(signals)6364 # right65 elif (-3 < g_x < 3) and (3 < g_y):66 print("RIGHT TURN")67 signals = {"signal_release": [Key.up, Key.down, Key.left, Key.space], 68 "signal_on": Key.right}69 control(signals)707172 except (KeyboardInterrupt, SystemExit):73 raise74 except Exception as e:75 print(e)767778if __name__ == '__main__':79 args = argparse.ArgumentParser()80 args.add_argument('--port', default=5555)81 args.add_argument('--host', default="192.168.43.217")82 parsed_args = args.parse_args() ...

Full Screen

Full Screen

connector.py

Source:connector.py Github

copy

Full Screen

1from pycomm.ab_comm.slc import Driver as SlcDriver2from datetime import datetime, timedelta3import sqlite34conn = sqlite3.connect('signal.sqlite',5 detect_types=sqlite3.PARSE_DECLTYPES)6cursor = conn.cursor()7def table_create(cursor, table):8 try:9 cursor.execute("CREATE TABLE {0}(ID INT PRIMARY KEY NOT NULL, "10 "signal_diff REAL, "11 "sig_datetime timestamp)".format(table))12 except sqlite3.OperationalError:13 pass14def initialize_signal(signal):15 c = conn.cursor()16 c.execute("select * FROM conveyor_signal WHERE ID={}".format(signal))17 signal_check = c.fetchall()18 print(signal_check)19 if signal_check == []:20 now = datetime.now()21 c = conn.cursor()22 print c.execute("INSERT INTO conveyor_signal (ID, signal_diff, "23 "sig_datetime) "24 "VALUES (?, 0, ?)", (signal, now))25def update_signal(cursor, table, values):26 cursor.execute("UPDATE {} SET ID=?, signal_diff=?, sig_datetime=? "27 "WHERE ID=?".format(table), values)28 conn.commit()29table_create(cursor, 'conveyor_signal')30initialize_signal(0)31initialize_signal(1)32c = SlcDriver()33if c.open('128.1.0.123'):34 signal_on = None35 signal_off = None36 now = None37 signal_on_time = None38 signal_off_time = None39 conveyor_time = timedelta(0, 0, 0)40 cycle_time = timedelta(0, 0, 0)41 while True:42 start_time = datetime.now()43 tag = c.read_tag('B3:0/2')44 if tag and signal_off:45 signal_off = False46 if signal_on_time is None:47 signal_on_time = datetime.now()48 else:49 signal_on_time = datetime.now()50 conveyor_time = signal_on_time - signal_off_time51 update_signal(cursor, 'conveyor_signal',52 (1, conveyor_time.total_seconds(),53 signal_on_time, 1))54 elif not tag and signal_on:55 signal_on = False56 if signal_on_time is None:57 signal_off_time = datetime.now()58 else:59 signal_off_time = datetime.now()60 cycle_time = signal_off_time - signal_on_time61 update_signal(cursor, 'conveyor_signal',62 (0, cycle_time.total_seconds(),63 signal_off_time, 0))64 elif tag:65 signal_on = True66 elif not tag:...

Full Screen

Full Screen

day07.py

Source:day07.py Github

copy

Full Screen

...3class HashableDict(dict):4 def __hash__(self):5 return hash(tuple(sorted(self.items())))6@cache7def signal_on(wire, wires):8 if wire.isnumeric():9 return int(wire)10 val = wires[wire]11 if val.isnumeric():12 return int(val)13 if val.isalpha():14 return signal_on(val, wires)15 if "NOT" in val:16 return ~signal_on(val.lstrip("NOT "), wires) & 0xFFFF17 lhs, op, rhs = val.split()18 return {"LSHIFT": lshift, "RSHIFT": rshift, "AND": and_, "OR": or_,}[19 op20 ](signal_on(lhs, wires), signal_on(rhs, wires))21def parse_wires(txt):22 return dict(reversed(line.split(" -> ")) for line in txt.splitlines())23def parta(txt: str):24 wires = HashableDict(parse_wires(txt))25 return signal_on("a", wires)26def partb(txt: str):27 wires = HashableDict(parse_wires(txt))28 wires["b"] = str(signal_on("a", wires))29 return signal_on("a", wires)30def main(txt: str):31 print(f"parta: {parta(txt)}")32 print(f"partb: {partb(txt)}")33if __name__ == "__main__":34 from aocd import data...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful