-
Notifications
You must be signed in to change notification settings - Fork 0
/
OSCReceiver.cs
110 lines (100 loc) · 2.68 KB
/
OSCReceiver.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class OSCReceiver : MonoBehaviour
{
public string RemoteIP = "127.0.0.1";
public int SendToPort = 57131;
public int ListenerPort = 8000;
//public Transform controller;
private Osc handler;
string rr;
public Text _emg01;
public Text _emg02;
public Text _emg03;
public Text _emg04;
public Text _emg05;
public Text _emg06;
public Text _emg07;
public Text _emg08;
string[] str3;
// Use this for initialization
void Start()
{
//Initializes on start up to listen for messages
//make sure this game object has both UDPPackIO and OSC script attached
UDPPacketIO udp = GetComponent("UDPPacketIO") as UDPPacketIO;
udp.init(RemoteIP, SendToPort, ListenerPort);
handler = GetComponent("Osc") as Osc;
handler.init(udp);
handler.SetAddressHandler("/myo1/emg/scaled", Example1);
}
//these fucntions are called when messages are received
public void Example1(OscMessage oscMessage)
{
//How to access values:
//oscMessage.Values[0], oscMessage.Values[1], etc
//r01=(float)oscMessage.Values[1];
rr = Osc.OscMessageToString(oscMessage);
string str1 = rr.Replace("/myo1/emg/scaled ,ffffffff ", " ");
string str2 = str1.Replace(" ", "/");
str3 = str2.Split('/');
//Debug.Log (str2);
//Debug.Log("Called Example One > " + Osc.OscMessageToString(oscMessage));
}
//these fucntions are called when messages are received
public void Example2(OscMessage oscMessage)
{
//How to access values:
//oscMessage.Values[0], oscMessage.Values[1], etc
//Debug.Log("Called Example Two > " + Osc.OscMessageToString(oscMessage));
}
void Update()
{
_emg01.text = str3[0];
_emg02.text = str3[1];
_emg03.text = str3[2];
_emg04.text = str3[3];
_emg05.text = str3[4];
_emg06.text = str3[5];
_emg07.text = str3[6];
_emg08.text = str3[7];
if (Input.GetKeyDown(KeyCode.A))
{
handler.Send(Osc.StringToOscMessage("/imu"));
print("A key was pressed");
}
}
public float toemg01()
{
return float.Parse(str3[0]);
}
public float toemg02()
{
return float.Parse(str3[1]);
}
public float toemg03()
{
return float.Parse(str3[2]);
}
public float toemg04()
{
return float.Parse(str3[3]);
}
public float toemg05()
{
return float.Parse(str3[4]);
}
public float toemg06()
{
return float.Parse(str3[5]);
}
public float toemg07()
{
return float.Parse(str3[6]);
}
public float toemg08()
{
return float.Parse(str3[7]);
}
}