예제 #1
0
def on_message(client, userdata, msg):
    # Called when a MQTT message is received.
    print('{0}: {1}'.format(msg.topic, str(msg.payload)))
    # Handle a target request.
    if msg.topic == TOPIC_TARGET:
        # Try to parse out two numbers from the payload.  These are the
        # screen x and screen y coordinates for the target command.
        result = parse.parse('{:d},{:d}', msg.payload.decode('ascii'))
        if result is not None:
            # Got a valid pair of numbers, use the laser model to target that
            # position.
            model.target(result[0], result[1])
예제 #2
0
def on_message(client, userdata, msg):
    # Called when a MQTT message is received.
    print('{0}: {1}'.format(msg.topic, str(msg.payload)))
    # Handle a target request.
    if msg.topic == TOPIC_TARGET:
        # Try to parse out two numbers from the payload.  These are the
        # screen x and screen y coordinates for the target command.
        result = parse.parse('{:d},{:d}', msg.payload.decode('ascii'))
        if result is not None:
            # Got a valid pair of numbers, use the laser model to target that
            # position.
            model.target(result[0], result[1])
    elif msg.topic == TOPIC_RELATIVE:
        # Try to parse out two numbers from the payload.  These are the
        # relative coordinates for the relative target command.
        result = parse.parse('{:d},{:d}', msg.payload.decode('ascii'))
        if result is not None:
            # Got a valid pair of numbers, use the laser model to target that
            # position.
            model.target_relative(result[0], result[1])
    elif msg.topic == TOPIC_PATH:
        lines = msg.payload.decode("ascii")
        lines = lines.split(";")
        path_list = []
        for line in lines:
            result = parts.parse("{:d},{:d}", line)
            if result is not None:
                path_list.append((result[0], result[1]))
        model.target_path(path_list)
    elif msg.topic == TOPIC_LASER:
        mess = msg.payload.decode('ascii')
        if mess == "ON":
            model.Laser_On()
        elif mess == "OFF":
            model.Laser_Off()
        else:
            model.Toggle_Laser()
예제 #3
0
def target(x, y):
    model.target(x, y)
    return successNoResponse()
예제 #4
0
client.connect(MQTT_SERVER, MQTT_PORT, 60)

# Run a loop in the foreground that waits for MQTT events/messages and processes
# them appropriately with the callbacks above.  The loop_forever call will never
# return!
print('Press Ctrl-C to quit...')
client.loop_forever()

print("Welcome to the cat laser toy!")
print("- D-pad: Move")
print("- B: Laser on/off")
print("- L/R bumper: fast mode")
print("- Start: sleep")
print("- A: keep track of movement")
print("- X: play back movement")
model.target(305, 305)
move_list = []
is_laser_on = True
up = False
down = False
left = False
right = False
to_break = False
l_trig = False
r_trig = False
change_laser_on = False
keep_track = False
play_moves = False
while True:
    if to_break:
        while to_break:
예제 #5
0
def target(x, y):
	model.target(x, y)
	return successNoResponse()