def main(): #print("\n" + "get sensor data") sensordata = np.array(sensor.pixels) sensordata = sensordata[:, ::-1] #for row in sensordata: # print (["{0:.1f}".format(temp) for temp in row]) print("\n") print(sensordata.max()) if sensordata.max() > basetemp: #pos =list(zip(*np.where(sensordata > sensordata.max() * 0.95))) pos = list(zip(*np.where(sensordata == sensordata.max()))) print(pos) msg = OscMessageBuilder(address="/pos") for i in pos: msg = OscMessageBuilder(address="/pos") x, y = i msg.add_arg(int(x)) msg.add_arg(int(y)) m = msg.build() print(m.address, m.params) client.send(m) time.sleep(0.05) else: print("nobody is here")
def callback(gpio_id): client = UDPClient(HOST, PORT) if GPIO.input(gpio_id) == 0: msg = OscMessageBuilder('/start').build() GPIO.output(LED, GPIO.HIGH) else: msg = OscMessageBuilder('/stop').build() GPIO.output(LED, GPIO.LOW) client.send(msg)
def send_knob(self, knob_num, knob_val): if self.verbose: print("knob %d: %f" % (knob_num, knob_val)) builder = OscMessageBuilder(address="/repatcher/knob" + str(knob_num)) builder.add_arg(knob_val) msg = builder.build() self.client.send(msg)
def get_message(self)-> OscMessage: """ returns the OSC message of the Blob with the TUIO spezification """ x, y = self.position X, Y = self.velocity w, h = self.dimension builder = OscMessageBuilder(address=TUIO_BLOB) for val in [ "set", self.session_id, float(x), float(y), float(self.angle), float(w), float(h), float(self.area), float(X), float(Y), float(self.velocity_rotation), float(self.motion_acceleration), float(self.rotation_acceleration) ]: builder.add_arg(val) return builder.build()
def oscReceive(unused_addr, bang): print('Receive Number: ' + bang) msg = OscMessageBuilder(address='/') msg.add_arg('is genius.') m = msg.build() client.send(m)
def sendMsg(self, msg): builder = OscMessageBuilder(address=self.address) for v in msg[0]: builder.add_arg(v) out = builder.build() # print("sent osc message to",self.ip,"on port",self.port,"with address",self.address) self.client.send(out)
def send_colors(r, g, b): msg = OscMessageBuilder(address='/CV07/color/r') msg.add_arg(r, 'i') m = msg.build() client.send(m) print(m.address, m.params) msg = OscMessageBuilder(address='/CV07/color/g') msg.add_arg(g, 'i') m = msg.build() client.send(m) print(m.address, m.params) msg = OscMessageBuilder(address='/CV07/color/b') msg.add_arg(b, 'i') m = msg.build() client.send(m) print(m.address, m.params)
def _build_message( msg_address: str, msg_parameters: Optional[Union[Sequence, Any]] = None) -> OscMessage: """Builds pythonsosc OSC message. Parameters ---------- msg_address : str SuperCollider address. msg_parameters : list, optional List of parameters to add to message. Returns ------- OscMessage Message ready to be sent. """ if msg_parameters is None: msg_parameters = [] elif not isinstance(msg_parameters, Sequence) or isinstance( msg_parameters, (str, bytes)): msg_parameters = [msg_parameters] if not msg_address.startswith("/"): msg_address = "/" + msg_address builder = OscMessageBuilder(address=msg_address) for msg_arg in msg_parameters: if isinstance(msg_arg, np.number): msg_arg = msg_arg.item() builder.add_arg(msg_arg) return builder.build()
async def send_message(self, node, client_address, *args, **kwargs): when = kwargs.get('when', time.time()) builder = OscMessageBuilder(address=node.osc_address) for arg in args: builder.add_arg(arg) msg = builder.build() await self.server.sendto(msg, client_address, when)
def publishSensorData(self, sensor_data, calibration_status): """Make the OSC sensor data package and publishes it.""" self.msg_builder = OscMessageBuilder("/sensordata") self.msg_builder.add_arg(int(1000 * (time() - self.current_time))) # current_time = time() self.addSensorData(sensor_data) self.addCalibrationStatus(calibration_status)
def osc_message(address, args=()): print(args) builder = OscMessageBuilder(address) if not isinstance(args, Iterable) or isinstance(args, (str, bytes)): args = [args] for arg in args: builder.add_arg(arg) return builder.build()
def send_color(r, g, b): msg = OscMessageBuilder(address='/CV06/pixel') #msg.add_arg(r, 'i') #msg.add_arg(g, 'i') msg.add_arg(b, 'i') m = msg.build() print(m.address, m.params) client.send(m)
def publish_sensor_data(self, sensor_data, calibration_status): """Makes the OSC sensor data package and publishes it""" self.msg_builder = OscMessageBuilder("/sensordata") self.msg_builder.add_arg(int(1000 * (time.time() - self.current_time))) # current_time = time() self.add_sensor_data(sensor_data) self.add_calibration_status(calibration_status) self.osc_udp_client.send(self.msg_builder.build())
def send_patch_bay(self, output_num, values): if self.verbose: print("bay %d: %s" % (output_num, str(values))) builder = OscMessageBuilder(address="/repatcher/output" + str(output_num)) for v in values: builder.add_arg(v) msg = builder.build() self.client.send(msg)
def publishSensorData(self, sensor_data, calibration_status, attributeToLog, elapsed, timeDifference, index): """Makes the OSC sensor data package and publishes it""" self.msg_builder = OscMessageBuilder("/sensordata") self.msg_builder.add_arg(int(1000 * (time() - self.current_time))) current_time = time() self.addSensorData(sensor_data) self.printSensorData(sensor_data, attributeToLog, elapsed, timeDifference) self.addCalibrationStatus(calibration_status) self.osc_udp_client.send(self.msg_builder.build())
def send(self, pose_id, pose_proba): if not self._is_running: return False msg = OscMessageBuilder(address=self.POSE_LABEL) msg.add_arg(pose_id) msg.add_arg(pose_proba) m = msg.build() self._client.send(m) return True
def main(): ip = '127.0.0.1' port = 6700 client = udp_client.UDPClient(ip, port) args = [0, 228, 123] data = OscMessageBuilder(address='/address') data.add_arg(args) data = data.build() client.send(data)
def send_message(self, address, value): builder = OscMessageBuilder(address=address) if value is None: values = [] elif isinstance(value, list): values = value else: values = [value] for val in values: builder.add_arg(val) msg = builder.build() self.socket.sendto(msg.dgram, self.xr_address)
def _build_alive(address, profile_list): """ builds a OSC which implements a alive message of TUIO returns the message """ builder = OscMessageBuilder(address=address) builder.add_arg("alive") for profile in profile_list: builder.add_arg(profile.session_id) ## add id of cursors alive_msg = builder.build() return alive_msg
def send_message(self, address, *args): msg = OscMessageBuilder(address) for arg in args: msg.add_arg(arg) data = msg.build().dgram if self.osc_spec == 1.0: length = len(data) data = struct.pack('>i', length) + data self._to_write.put_nowait(data) else: data = self._slip_driver.send(data) self._to_write.put_nowait(data)
def send_message(self, address, value): builder = OscMessageBuilder(address=address) if value != '': if not isinstance(value, Iterable) or isinstance( value, (str, bytes)): values = [value] else: values = value for val in values: builder.add_arg(val) msg = builder.build() self.send(msg)
def SendBPM(BPM): if BPM.isdecimal(): BPM=int(BPM) if 0<BPM<=960: msg = OscMessageBuilder(address='/BPM') msg.add_arg(int(BPM)) m = msg.build() print(m.address, m.params) client.send(m) else: print("error: 0<BPM<=960"); else: print ("error:Please enter the correct value")
def build_osc_message(self, address, value): """ composes OSC message in proper format for sending """ builder = OscMessageBuilder(address=address) if not isinstance(value, Iterable) or isinstance(value, (str, bytes)): values = [value] else: values = value for val in values: builder.add_arg(val) msg = builder.build() return msg.dgram
def send_pose(client: udp_client, landmark_list: landmark_pb2.NormalizedLandmarkList): if landmark_list is None: client.send_message(OSC_ADDRESS, 0) return # create message and send builder = OscMessageBuilder(address=OSC_ADDRESS) builder.add_arg(1) for landmark in landmark_list.landmark: builder.add_arg(landmark.x) builder.add_arg(landmark.y) builder.add_arg(landmark.z) builder.add_arg(landmark.visibility) msg = builder.build() client.send(msg)
def _convertMessageListToMessageBuilder( self, messageList: List[Any]) -> OscMessageBuilder: """ NB Remove elements set to None, but otherwise preserve order of MessageList. """ oscPath: str = messageList[0] messageBuilder: OscMessageBuilder = None self._validateOSCPath(oscPath) # Handle OSC path. messageBuilder = OscMessageBuilder(oscPath) for arg in messageList[1:]: # Handle OSC arguments. if None is arg: continue messageBuilder.add_arg(arg) return messageBuilder
def send_bundle(self): """Build :class:`OscMessage` from arguments and send to server Args: address: OSC address the message shall go to value: One or more arguments to be added to the message """ bundle_builder = OscBundleBuilder(0) # build alive message bundle_builder.add_content( TuioServer._build_alive(TUIO_CURSOR, self.cursors)) bundle_builder.add_content( TuioServer._build_alive(TUIO_BLOB, self.blobs)) bundle_builder.add_content( TuioServer._build_alive(TUIO_OBJECT, self.objects)) # set message of cursor for cursor in self.cursors: cursor_msg = cursor.get_message() bundle_builder.add_content(cursor_msg) # set message of blob for blob in self.blobs: blob_msg = blob.get_message() bundle_builder.add_content(blob_msg) # set message of object for o in self.objects: object_msg = o.get_message() bundle_builder.add_content(object_msg) # message fseq to end the bundle and send (optinal) frame id builder = OscMessageBuilder(address=TUIO_CURSOR) builder.add_arg("fseq") builder.add_arg(-1) fseq = builder.build() bundle_builder.add_content(fseq) # build bundle and send bundle = bundle_builder.build() self.send(bundle)
def send_hands(client: udp_client, detections: [landmark_pb2.NormalizedLandmarkList]): if detections is None: client.send_message(OSC_ADDRESS, 0) return # create message and send builder = OscMessageBuilder(address=OSC_ADDRESS) builder.add_arg(len(detections)) for detection in detections: for landmark in detection.landmark: builder.add_arg(landmark.x) builder.add_arg(landmark.y) builder.add_arg(landmark.z) builder.add_arg(landmark.visibility) msg = builder.build() client.send(msg)
def updateLines(lineName): if not lineName in lines: lines.append(lineName) msg = OscMessageBuilder(address='/tubeLines') msg.add_arg(lineName) #color if lineName in colorIndex: color = colorIndex[lineName] else: color = colorIndex['Others'] msg.add_arg(color) m = msg.build() client.send(m) print('sent a new line: {} ({})'. format(lineName, color))
def get_message(self)-> OscMessage: """ returns the OSC message of the Cursor with the TUIO spezification """ x, y = self.position X, Y = self.velocity builder = OscMessageBuilder(address=TUIO_CURSOR) for val in [ "set", self.session_id, float(x), float(y), float(X), float(Y), float(self.motion_acceleration) ]: builder.add_arg(val) return builder.build()
def send_message(self, address: str, value: Union[int, float, bytes, str, bool, tuple, list]) -> None: """Build :class:`OscMessage` from arguments and send to server Args: address: OSC address the message shall go to value: One or more arguments to be added to the message """ builder = OscMessageBuilder(address=address) if value is None: values = [] elif not isinstance(value, Iterable) or isinstance(value, (str, bytes)): values = [value] else: values = value for val in values: builder.add_arg(val) msg = builder.build() self.send(msg)