示例#1
0
文件: myo_client.py 项目: HMTL/HMTL
    def on_pose(self, myo, timestamp, pose):
        print_('on_pose', pose)

        self.data["on_pose"] = { "timestamp" : timestamp, "data" : pose }

        msgs = []
        if pose == pose_t.double_tap:
            msgs += [ HMTLprotocol.get_rgb_msg(self.options.hmtladdress,
                                              1,
                                              255,0,255) ]
        elif pose == pose_t.rest:
            msgs += [
                HMTLprotocol.get_rgb_msg(self.options.hmtladdress,
                                         1,
                                         0,0,0),
                
                HMTLprotocol.get_value_msg(69,
                                           0,
                                           0),

                HMTLprotocol.get_value_msg(69,
                                           1,
                                           0)
            ]

        elif pose == pose_t.wave_in:
            msgs += [ HMTLprotocol.get_rgb_msg(self.options.hmtladdress,
                                               1,
                                               0,255,0) ]
        elif pose == pose_t.wave_out:
            msgs += [ HMTLprotocol.get_rgb_msg(self.options.hmtladdress,
                                               1,
                                               0,0,255) ]
        elif pose == pose_t.fist:
            msgs += [
                HMTLprotocol.get_rgb_msg(self.options.hmtladdress,
                                         1,
                                         255,0,0),
                HMTLprotocol.get_value_msg(69,
                                           1,
                                           255) 
            ]
        elif pose == pose_t.fingers_spread:
            msgs += [ 
                HMTLprotocol.get_rgb_msg(self.options.hmtladdress,
                                         1,
                                         255,255,255),
                HMTLprotocol.get_value_msg(69,
                                           0,
                                           128) 
                ]

        if (len(msgs) != 0):
            for msg in msgs:
                self.client.send_and_ack(msg, False)
            print("Sent and acked to client")
示例#2
0
 def blink(self, on_period, on_color, off_period, off_color):
     self.client.send_msg(
         HMTLprotocol.get_program_blink_msg(self.address,
                                            HMTLprotocol.OUTPUT_ALL_OUTPUTS,
                                            on_period, on_color, off_period,
                                            off_color))
     self.state = STATE_BLINK
示例#3
0
 def clear(self):
     """Send a message to clear any currently running program"""
     self.client.send_msg(
         HMTLprotocol.get_program_none_msg(self.address,
                                           HMTLprotocol.OUTPUT_ALL_OUTPUTS)
     )
     self.state = STATE_NONE
示例#4
0
def send_update(trig, val):
    trig_state[trig] = val

    print("Sending: trig=%d val=%d" % (trig, val))

    msg = HMTLprotocol.get_value_msg(HMTLprotocol.BROADCAST, trig, val)
    client.send_and_ack(msg)
示例#5
0
文件: Scan.py 项目: HMTL/HMTL
def handle_poll_resp(data, modules):
    (text, msg) = HMTLprotocol.decode_msg(data)
    if isinstance(msg, HMTLprotocol.PollHdr):
        print("Poll response: dev=%d addr=%d" % (msg.device_id, msg.address))
        modules.append(msg)
    else:
        print("Not a poll response, class: %s " % (msg.__class__.__name__))
示例#6
0
def send_configuration(config_data):
    print("***** Sending configuration *****")

    if (ser.send_command(HMTLprotocol.HMTL_CONFIG_START) == False):
        print("Failed to get ack from start message")
        exit(1)

    header_struct = HMTLprotocol.get_header_struct(config_data)
    ser.send_config('header', header_struct)

    for output in config_data["outputs"]:
        output_struct = HMTLprotocol.get_output_struct(output)
        ser.send_config(output["type"], output_struct)

    if (ser.send_command(HMTLprotocol.HMTL_CONFIG_END) == False):
        print("Failed to get ack from end message")
        exit(1)
示例#7
0
 def rgb(self, red, green, blue):
     """Set the module to the indicated color"""
     if is_program_state(self.state):
         self.clear()
     self.client.send_msg(
         HMTLprotocol.get_rgb_msg(self.address,
                                  HMTLprotocol.OUTPUT_ALL_OUTPUTS, red,
                                  green, blue))
     self.state = STATE_RGB
示例#8
0
 def blink(self, on_period, on_color, off_period, off_color):
     self.client.send_msg(
         HMTLprotocol.get_program_blink_msg(self.address,
                                  HMTLprotocol.OUTPUT_ALL_OUTPUTS,
                                            on_period,
                                            on_color,
                                            off_period,
                                            off_color)
     )
     self.state = STATE_BLINK
示例#9
0
 def rgb(self, red, green, blue):
     """Set the module to the indicated color"""
     if is_program_state(self.state):
         self.clear()
     self.client.send_msg(
         HMTLprotocol.get_rgb_msg(self.address,
                                  HMTLprotocol.OUTPUT_ALL_OUTPUTS,
                                  red, green, blue)
     )
     self.state = STATE_RGB
示例#10
0
文件: Scan.py 项目: HMTL/HMTL
def scan_every(client):
    modules = []
    for address in range(0, 128):
        print("Polling address: %d" % (address))
        msg = HMTLprotocol.get_poll_msg(address)
        ret = client.send_and_ack(msg, True)
        if ret:
            handle_poll_resp(ret, modules)
        else:
            print("No response from: %d" % (address))

    return modules
示例#11
0
文件: Scan.py 项目: HMTL/HMTL
def scan_broadcast(client):
    modules = []
    msg = HMTLprotocol.get_poll_msg(HMTLprotocol.BROADCAST)

    ret = client.send_and_ack(msg, False)
    while True:
        msg = client.get_response_data()
        if msg == None:
            break

        handle_poll_resp(msg, modules)

    return modules
示例#12
0
def main():

    handle_args()

    client = HMTLClient(options)

    msg = None
    expect_response = False

    if (options.commandtype == "value"):
        print("Sending value message.  Address=%d Output=%d Value=%d" %
              (options.hmtladdress, options.output, int(options.commandvalue)))
        msg = HMTLprotocol.get_value_msg(options.hmtladdress,
                                         options.output,
                                         int(options.commandvalue))
    elif (options.commandtype == "rgb"):
        (r,g,b) = options.commandvalue.split(",")
        print("Sending RGB message.  Address=%d Output=%d Value=%d,%d,%d" %
              (options.hmtladdress, options.output, int(r), int(g), int(b)))
        msg = HMTLprotocol.get_rgb_msg(options.hmtladdress,
                                       options.output,
                                       int(r), int(g), int(b))

    elif (options.commandtype == "blink"):
        (a,b,c,d, e,f,g,h) = options.commandvalue.split(",")
        print("Sending BLINK message. Address=%d Output=%d on_period=%d on_value=%s off_period=%d off_values=%s" % (options.hmtladdress, options.output, int(a), [int(b),int(c),int(d)],
                                         int(e), [int(f),int(g),int(h)]))
        msg = HMTLprotocol.get_program_blink_msg(options.hmtladdress,
                                         options.output,
                                         int(a), [int(b),int(c),int(d)],
                                         int(e), [int(f),int(g),int(h)])
    elif (options.commandtype == "timedchange"):
        (a, b,c,d, e,f,g,) = options.commandvalue.split(",")
        print("Sending TIMED CHANGE message. Address=%d Output=%d change_period=%d start_value=%s stop_values=%s" % (options.hmtladdress, options.output, int(a), [int(b),int(c),int(d)],
                                                                                                          [int(e),int(f),int(g)]))
        msg = HMTLprotocol.get_program_timed_change_msg(options.hmtladdress,
                                        options.output,
                                        int(a),
                                        [int(b),int(c),int(d)],
                                        [int(e),int(f),int(g)])
    elif (options.commandtype == "levelvalue"):
        print("Sending LEVEL VALUE message. Address=%d Output=%d" % (options.hmtladdress, options.output))
        msg = HMTLprotocol.get_program_level_value_msg(options.hmtladdress,
                                                       options.output)
    elif (options.commandtype == "soundvalue"):
        print("Sending SOUND VALUE message. Address=%d Output=%d" % (options.hmtladdress, options.output))
        msg = HMTLprotocol.get_program_sound_value_msg(options.hmtladdress,
                                                       options.output)

    elif (options.commandtype == "none"):
        print("Sending NONE message.  Output=%d" % (options.output))
        msg = HMTLprotocol.get_program_none_msg(options.hmtladdress,
                                                options.output)
    elif (options.commandtype == "poll"):
        print("Sending poll message.  Address=%d" %
              (options.hmtladdress))
        msg = HMTLprotocol.get_poll_msg(options.hmtladdress)
        expect_response = True
    elif (options.commandtype == "setaddr"):
        (device_id, new_address) = options.commandvalue.split(",")
        print("Sending set address message.  Address=%d Device=%d NewAddress=%d" %
              (options.hmtladdress, int(device_id), int(new_address)))
        msg = HMTLprotocol.get_set_addr_msg(options.hmtladdress, 
                                            int(device_id), int(new_address))
    elif (options.commandtype == "fade"):
        (a, b,c,d, e,f,g,) = options.commandvalue.split(",")
        print("Sending FADE message. Address=%d Output=%d fade_period=%d start_value=%s stop_values=%s" % 
              (options.hmtladdress, options.output,
               int(a), 
               [int(b),int(c),int(d)],
               [int(e),int(f),int(g)]))
        msg = HMTLprotocol.get_program_fade_msg(options.hmtladdress,
                                        options.output,
                                        int(a),
                                        [int(b),int(c),int(d)],
                                        [int(e),int(f),int(g)])


    if (msg != None):
        starttime = time.time()
        client.send_and_ack(msg, expect_response)
        endtime = time.time()
        print("Sent and acked in %.6fs" % (endtime - starttime))

    if (options.killserver):
        # Send an exit message to the server
        print("Sending EXIT message to server")
        client.send_exit()

    client.close()

    print("Done.")
    exit(0)
示例#13
0
def send_device_id(device_id):
    print("***** Setting device_id to %d *****" % (device_id))

    ser.send_command(HMTLprotocol.HMTL_CONFIG_START)
    ser.send_config("device_id", HMTLprotocol.get_device_id_struct(device_id))
    ser.send_command(HMTLprotocol.HMTL_CONFIG_END)
示例#14
0
def send_baud(baud):
    print("***** Setting baud to %d *****" % (baud))

    ser.send_command(HMTLprotocol.HMTL_CONFIG_START)
    ser.send_config("baud", HMTLprotocol.get_baud_struct(baud))
    ser.send_command(HMTLprotocol.HMTL_CONFIG_END)
示例#15
0
def send_address(address):
    print("***** Setting address to %d *****" % (address))

    ser.send_command(HMTLprotocol.HMTL_CONFIG_START)
    ser.send_config("address", HMTLprotocol.get_address_struct(address))
    ser.send_command(HMTLprotocol.HMTL_CONFIG_END)
示例#16
0
文件: Triangles.py 项目: HMTL/HMTL
def main():
    options = parse_options()

    client = HMTLClient(address=options.address,
                        port=options.port,
                        hmtladdress=options.hmtladdress,
                        verbose=options.verbose)

    msg = None
    expect_response = False

    if options.commandtype == "rgb":
        if not options.foreground:
            print("RGB command requires foreground color")
            exit(1)
        fg = [ int(x) for x in options.foreground.split(",") ]
        print("Sending RGB message.  Address=%d Output=%d fg=%s" %
              (options.hmtladdress, options.output, fg))
        msg = HMTLprotocol.get_rgb_msg(options.hmtladdress,
                                       options.output,
                                       fg[0], fg[1], fg[2])

    if options.commandtype == "static":
        if not options.foreground or not options.background or not options.period or (options.threshold == None):
            print("STATIC command requires foreground, background, period, and threshold")
            exit(1)
        fg = [ int(x) for x in options.foreground.split(",") ]
        bg = [ int(x) for x in options.background.split(",") ]
        print("Sending STATIC message.  Address=%d Output=%d period=%d fg=%s bg=%s threshold=%d" %
              (options.hmtladdress, options.output, options.period, fg, bg,
               options.threshold))
        static = TriangleStatic(options.period, fg, bg,
                                options.threshold)
        msg = static.msg(options.hmtladdress, options.output)

    elif options.commandtype == "snake":
        if not options.background or not options.period or \
                (options.colormode == None):
            print("SNAKE command requires background, colormode, and period")
            exit(1)
        bg = [ int(x) for x in options.background.split(",") ]
        print("Sending SNAKE message.  Address=%d Output=%d period=%d bg=%s colormode=%d" %
              (options.hmtladdress, options.output, options.period, bg,
               options.colormode))
        snake = TriangleSnake(options.period, bg, options.colormode)
        msg = snake.msg(options.hmtladdress, options.output)


    elif options.commandtype == "none":
        print("Sending NONE message.  Output=%d" % (options.output))
        msg = HMTLprotocol.get_program_none_msg(options.hmtladdress,
                                                options.output)

    if (msg != None):
        starttime = time.time()
        client.send_and_ack(msg, expect_response)
        endtime = time.time()
        print("Sent and acked in %.6fs" % (endtime - starttime))

    client.close()

    print("Done")
    exit(0)
示例#17
0
 def clear(self):
     """Send a message to clear any currently running program"""
     self.client.send_msg(
         HMTLprotocol.get_program_none_msg(self.address,
                                           HMTLprotocol.OUTPUT_ALL_OUTPUTS))
     self.state = STATE_NONE