Exemplo n.º 1
0
        /// <summary>
        /// 初始化
        /// </summary>
        public void Init()
        {
            recdata = new DataPackReceivedHandler(DataCommunication_Move);
            this.setControlMaxAngle.Value = Convert.ToInt32(gp.RotationMax);
            this.setControlMinAngle.Value = Convert.ToInt32(-gp.RotationMin);
            this.setControlMaxAngle.MaxValue = Convert.ToInt32(gp.RotationMax);
            this.setControlMinAngle.MinValue = Convert.ToInt32(-gp.RotationMin);
            //GlobalVar.GameReturn+=GlobalVar_GameReturn;
            LumbarRobotController.RobotController.ControlCommand.DataPackRecieved += recdata;
            //LumbarRobotController.RobotController.Move += DataCommunication_Move;
            osc = OSCHandler.Instance;
            int Gameport = int.Parse(ConfigurationManager.AppSettings["ListenPort"]);
            if (Gameport > 0)
            {
                if (osc.Servers.Count < 1)
                {
                    osc.Init(Gameport);
                    GaReciveThread = new Thread(new ThreadStart(LumbarRobot.ModulesCommon.GlobalVar.GetData));
                    GaReciveThread.Start();
                }
               

            }



        }
Exemplo n.º 2
0
 // Use this for initialization
 void Start()
 {
     OSCHandler.Instance.Init();
     handler = OSCHandler.Instance;
     handler.CreateServer("WiiMote", port);
     servers = new Dictionary <string, ServerLog>();
 }
Exemplo n.º 3
0
        public void OnFrame(object sender, FrameEventArgs args)
        {
            // Get the most recent frame and report some basic information
            Frame frame = args.frame;
            Hand  h;

            if (frame.Hands.Count == 0)
            {
                return;
            }

            h = frame.Hands[0];
            Console.WriteLine(string.Format("Velocity is {0}", h.PalmVelocity));
            palm.Move(h.PalmPosition, h.PalmVelocity);
            if (palm.Stopped)
            {
                // check if this is the first time we're reading that the hand is stopped
                if (!handStopped)
                {
                    Console.WriteLine("Beat!");
                    handStopped = true;
                    // possible beat. get volume data, centroid of movement, and append the tempo to the queue
                    TimeSpan dur      = palm.PreviousDuration;
                    Vector   centroid = palm.Centroid;
                    Vector   startPos = palm.StartPosition;
                    Vector   stopPos  = palm.StopPosition;
                    oscHandler = new OSCHandler();
                    float estTempo = 60 * 1000 / dur.Milliseconds;
                    oscHandler.SendTempo((int)Math.Round(estTempo));

                    // X centroid of hand during movement = pan
                    Vector normCentroid = bounder.NormalizePoint(centroid);
                    oscHandler.SendPan((double)normCentroid.x);

                    // get normalized distance by normalizing the points
                    Vector startNorm = bounder.NormalizePoint(startPos);
                    Vector stopNorm  = bounder.NormalizePoint(stopPos);
                    oscHandler.SendVolume(stopNorm.DistanceTo(startNorm));
                }

                // otherwise, check if the hand meets fermata threshold
                else if (palm.DurationStopped > Listener.fermataThreshold)
                {
                    Console.WriteLine(string.Format("Duration stopped is {0}, threshold is {1}", palm.DurationStopped, Listener.fermataThreshold));
                    oscHandler = new OSCHandler();
                    oscHandler.SendFermata();
                }
            }
            else
            {
                // check if it was stopped previously
                if (handStopped)
                {
                    oscHandler = new OSCHandler();
                    oscHandler.SendTempo();
                }

                handStopped = false;
            }
        }
Exemplo n.º 4
0
 void Start()
 {
     if (_instance == null)
     {
         _instance = this;
     }
 }
 // Use this for initialization
 void Start()
 {
     OSCHandler.Instance.Init();
     handler = OSCHandler.Instance;
     handler.CreateServer( "WiiMote", port );
     servers = new Dictionary<string, ServerLog>();
 }
Exemplo n.º 6
0
 void SendReset()
 {
     if (osc == null)
     {
         osc = OSCHandler.Instance;
     }
     osc.SendMessageToClient <string>("MySelf", "/reset", "");
 }
Exemplo n.º 7
0
 void SendData(string s)
 {
     if (osc == null)
     {
         osc = OSCHandler.Instance;
     }
     osc.SendMessageToClient <string>("MySelf", "/data", s);
 }
Exemplo n.º 8
0
 void Start()
 {
     handler = OSCHandler.Instance;
     handler.Init("Max", address, sendPort);
     handler.transform.SetParent(gameObject.transform);
     receiver = new OSCReceiver();
     receiver.Open(receivePort);
 }
Exemplo n.º 9
0
    public static OSCHandler ReInstance()
    {
        Destroy(_instance);
        _instance = null;
        _instance = new GameObject("OSCHandler").AddComponent <OSCHandler>();

        return(_instance);
    }
    // TODO 値が変わったら,もう一度initする.
    public void Restart()
    {
        //OSCHandler.ReInstance().Init(TargetAddr, OutGoingPort, InComingPort);
        OSCHandler.ReInstance().Reset();
        OSCHandler.Instance.Init(TargetAddr, OutGoingPort, InComingPort);

        servers = new Dictionary <string, ServerLog>();
        servers = OSCHandler.Instance.Servers;
    }
Exemplo n.º 11
0
 void SelfCheck()
 {
     InfoWindow.SetData("System Status");
     InfoWindow.SetData("");
     SelfCheckSub("Config File", ConfigFile.SelfCheck());
     SelfCheckSub("Data File", DummySender.SelfCheck());
     SelfCheckSub("Log File", OSCReceiver.SelfCheck());
     SelfCheckSub("OSC Server", OSCHandler.SelfCheck());
 }
Exemplo n.º 12
0
Arquivo: AMPM.cs Projeto: Potion/ampm
        static AMPM()
        {
            // Create a OSC Reciever to receive UDP messages
            _OscReceive = OSCHandler.Instance.CreateServer("AMPM", 3003);
            _OscHandler = OSCHandler.Instance;

            // Handle incoming OSC messages.
            _OscReceive.PacketReceivedEvent += Server_MessageReceived;

            ipAddress = GetLocalIPAddress();
            OSCHandler.Instance.CreateClient("AMPM", ipAddress, 3002);       // Creating a client to send messages on
        }
Exemplo n.º 13
0
    /// <summary>
    /// Ensure that the instance is destroyed when the game is stopped in the Unity editor
    /// Close all the OSC clients and servers
    /// </summary>
    void OnApplicationQuit()
    {
        foreach (KeyValuePair <string, ClientLog> pair in _clients)
        {
            pair.Value.client.Close();
        }

        foreach (KeyValuePair <string, ServerLog> pair in _servers)
        {
            pair.Value.server.Close();
        }

        _instance = null;
    }
Exemplo n.º 14
0
    /// <summary>
    /// Ensure that the instance is destroyed when the game is stopped in the Unity editor
    /// Close all the OSC clients and servers
    /// </summary>
    void OnApplicationQuit()
    {
        foreach (KeyValuePair <string, SenderLog> pair in _senders)
        {
            pair.Value.sender.Close();
        }

        foreach (KeyValuePair <string, ReceiverLog> pair in _receivers)
        {
            pair.Value.receiver.Close();
        }

        _instance = null;
    }
Exemplo n.º 15
0
    private void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
        }
        else
        {
            Destroy(gameObject);
            Debug.LogWarning("Singleton OSCHandler is already exists. new gameObject was destroyed.");
        }

        DontDestroyOnLoad(Instance);
    }
Exemplo n.º 16
0
    /// <summary>
    /// Ensure that the instance is destroyed when the game is stopped in the Unity editor
    /// Close all the OSC clients and servers
    /// </summary>
    public void Destroy()
    {
        foreach (KeyValuePair <string, ClientLog> pair in _clients)
        {
            pair.Value.client.Close();
        }

        foreach (KeyValuePair <string, ServerLog> pair in _servers)
        {
            pair.Value.server.Close();
        }

        _instance = null;
    }
Exemplo n.º 17
0
    public void Halt()
    {
        foreach (KeyValuePair <string, ClientLog> pair in _clients)
        {
            pair.Value.client.Close();
        }

        foreach (KeyValuePair <string, ServerLog> pair in _servers)
        {
            pair.Value.server.Close();
        }
        Destroy(_instance.gameObject);
        _instance = null;
    }
Exemplo n.º 18
0
        /// <summary>
        /// Centralized initializer for constructor overloads
        /// </summary>
        /// <param name="ip">The IP address to send OSC messages to</param>
        /// <param name="p">The port number to send OSC messages to</param>
        /// <param name="useRightHand">Whether or not the right hand should be detected.</param>
        private void Init(IPAddress ip, int p, bool useRightHand)
        {
            serverIP = ip;
            port     = p;

            xPositions            = new FixedQueue(1000);
            initialPosition       = new Vector();
            UseRightHand          = useRightHand;
            firstBeat             = true;
            oscHandler            = new OSCHandler(serverIP, port);
            estimatedTempos       = new FixedQueue(10);
            allPositions          = new List <Vector>(100);
            lastTwoBeatsPositions = new List <float>(100);
            BeatAmt = 0;
        }
Exemplo n.º 19
0
    /// <summary>
    /// Ensure that the instance is destroyed when the game is stopped in the Unity editor
    /// Close all the OSC clients and servers
    /// </summary>
    public void OnApplicationQuit()
    {
        OSCHandler.Instance.SendMessageToClient("PD", "/unity/trigger", 6);
        foreach (KeyValuePair <string, ClientLog> pair in _clients)
        {
            pair.Value.client.Close();
        }

        foreach (KeyValuePair <string, ServerLog> pair in _servers)
        {
            pair.Value.server.Close();
        }

        _instance = null;
    }
Exemplo n.º 20
0
    void OnDestroy()
    {
        if (DestroyEvent != null)
        {
            DestroyEvent();
        }
        foreach (KeyValuePair <string, ClientLog> pair in _clients)
        {
            pair.Value.client.Close();
        }

        foreach (KeyValuePair <string, ServerLog> pair in _servers)
        {
            pair.Value.server.Close();
        }

        _instance = null;
    }
Exemplo n.º 21
0
    /// <summary>
    /// Ensure that the instance is destroyed when the game is stopped in the Unity editor
    /// Close all the OSC clients and servers
    /// </summary>
    void OnDisable()
    {
        foreach (Thread t in InternalThreads)
        {
            t.Abort();
        }

        foreach (KeyValuePair <string, SenderLog> pair in _senders)
        {
            pair.Value.sender.Close();
        }

        foreach (KeyValuePair <string, ReceiverLog> pair in _receivers)
        {
            pair.Value.receiver.Close();
        }

        _instance = null;
    }
Exemplo n.º 22
0
    public OSCPacket ProcessPackets(OSCHandler h)
    {
        if (server.LastReceivedPacket != null)
        {
            //log.Clear ();
            //packets.Clear ();
            //Initialization for the first packet received

            if (packets.Count > 0)
            {
                if (server.LastReceivedPacket.TimeStamp
                    != packets [packets.Count - 1].TimeStamp)
                {
                    if (log.Count > h.LogLength - 1)
                    {
                        log.RemoveAt(0);
                        packets.RemoveAt(0);
                    }
                }
                else
                {
                    return(server.LastReceivedPacket);
                }
            }

            packets.Add(server.LastReceivedPacket);

            log.Add(String.Concat(DateTime.UtcNow.ToString(), ".",
                                  OSCHandler.FormatMilliseconds(DateTime.Now.Millisecond), " : ",
                                  server.LastReceivedPacket.Address, " ",
                                  OSCHandler.DataToString(server.LastReceivedPacket.Data)));
            if (OnPacketReceived != null)
            {
                OnPacketReceived(server.LastReceivedPacket.Address, server.LastReceivedPacket);
            }
            return(server.LastReceivedPacket);
        }
        else
        {
            return(null);
        }
    }
Exemplo n.º 23
0
    void Start()
    {
        Application.targetFrameRate = 60;

        // Initialize bounds
        m_Bounds_All   = new Bounds3D();
        m_Bounds_Upper = new Bounds3D();
        m_Bounds_Lower = new Bounds3D();

        // Set reference to the Bound in the GUI Bounds
        m_GUIBounds.m_Bounds = m_Bounds_All;

        m_OSCHandler = OSCHandler.Instance;

        // Get transforms if the group has any children
        if (transform.childCount != 0)
        {
            UpdateTransforms();
        }
    }
 void Start()
 {
     m_Tform      = transform;
     m_OSCHandler = OSCHandler.Instance;
 }
Exemplo n.º 25
0
        /// <summary>
        /// 初始化
        /// </summary>
        public void Init()
        {

            if(UserID!=null)
            {
                //var LeftRang = from eva in MySession.Query<EvaluteDetail>() where eva.PatientID == UserID && eva.ActionId==(int)EvaluateActionEnum.RotationRangeLeft orderby eva.EvaluteDate descending select eva;
                //if (LeftRang.Count() > 0)
                //{
                //    gp.RandMax = LeftRang.First().MaxV;
                //}
                //else
                //{
                //    MessageBox.Show("该患者没有评测记录,请返回评测");
                //    this.Game1.IsEnabled = false;
                //    return;
                //}
                //var RightRang = from eva in MySession.Query<EvaluteDetail>() where eva.PatientID == UserID && eva.ActionId == (int)EvaluateActionEnum.RotationRangeRight orderby eva.EvaluteDate descending select eva;
                //if (LeftRang.Count() > 0)
                //{
                //    gp.RanMin = RightRang.FirstOrDefault().MaxV;
                //}
                //else
                //{
                //    MessageBox.Show("该患者没有评测记录,请返回评测");
                //    this.Game1.IsEnabled = false;
                //    return;
                //}
                //var BendRang = from eva in MySession.Query<EvaluteDetail>() where eva.PatientID == UserID && eva.ActionId == (int)EvaluateActionEnum.RangeBend orderby eva.EvaluteDate descending select eva;
                //if (BendRang.Count()>0)
                //{
                //    gp.ProtrusiveMax = BendRang.FirstOrDefault().MaxV;
                //}else
                //{
                //    MessageBox.Show("该患者没有评测记录,请返回评测");
                //    this.Game1.IsEnabled = false;
                //    return;
                //}
                //var ProtrusiveRange = from eva in MySession.Query<EvaluteDetail>() where eva.PatientID == UserID && eva.ActionId == (int)EvaluateActionEnum.RangeProtrusive orderby eva.EvaluteDate descending select eva;
                //if (ProtrusiveRange.Count() > 0)
                //{
                //    gp.ProtrusiveMin = ProtrusiveRange.FirstOrDefault().MaxV;
                //}
                //else
                //{
                //    MessageBox.Show("该患者没有评测记录,请返回评测");
                //    this.Game1.IsEnabled = false;
                //    return;
                //}
                //this.MaxValue.Text = gp.ProtrusiveMax.ToString();
                //this.MinValue.Text = gp.ProtrusiveMin.ToString();
                
            }
            else
            {

                MessageBox.Show("请选择患者!");
                this.Close();
                return;
            }
            //GlobalVar.GameReturn+=GlobalVar_GameReturn;
            LumbarRobotController.RobotController.ControlCommand.DataPackRecieved += new DataPackReceivedHandler(DataCommunication_Move);
            //LumbarRobotController.RobotController.Move += DataCommunication_Move;
             osc = OSCHandler.Instance;
            int Gameport = int.Parse(ConfigurationManager.AppSettings["ListenPort"]);
            if (Gameport > 0)
            {
                if (osc.Servers.Count < 1)
                {
                    osc.Init(Gameport);
                    GaReciveThread = new Thread(new ThreadStart(LumbarRobot.ModulesCommon.GlobalVar.GetData));
                    GaReciveThread.Start();
                }
               
            }
         
           
            
        }
Exemplo n.º 26
0
 public void OnConnect(object sender, DeviceEventArgs args)
 {
     oscHandler = new OSCHandler(); // todo: this needs to pass in any optional address or port
     Console.WriteLine("Connected");
 }
Exemplo n.º 27
0
        // --------------------------------------------------------------------------------------------------------------------
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            _sendOscMessagesZero();

            SerialHandler.shutdown();
            core.Disconnect();
            oscHandler.shutdown();
            oscHandler = null;
            _saveSettings();
        }
Exemplo n.º 28
0
 public OSCHandler()
 {
     _instance = this;
 }