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")
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)
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)