internal void onPositionUpdate(object sender, WebMessageArgs <WebHIDReport> args)
        {
            WebHIDReport hidReport = args.RawMessage;

            //TODO add syncro lock
            if (hidReport.index == this.index)
            {
                __lastHIDReport = hidReport;
            }
        }
Ejemplo n.º 2
0
 public void onRead(string message)
 {
     if (PositionUpdateEvent != null)
     {
         WebHIDReport report = (WebHIDReport)Json.Deserialize <WebHIDReport>(message);
         // Log("onJoyGetPos" + message);
         //Debug.Log("Send Event");
         PositionUpdateEvent(this, new WebMessageArgs <WebHIDReport>(report));
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Ons the position update.
        /// </summary>
        /// <param name="data">Data.</param>
        protected void onRead(object data)
        {
            WebHIDReport report = (WebHIDReport)data;

            // GenericHIDDevice info = Json.Deserialize(args.Message) as GenericHIDDevice;

            if (report.Status == HIDReport.ReadStatus.Success || report.Status == HIDReport.ReadStatus.Buffered)
            {
                JoystickDevice device = InputEx.Devices.GetDeviceAt(report.index) as JoystickDevice;


                // UnityEngine.Debug.Log("onPositionUpdate:Joy" + info.index);


                // UnityEngine.Debug.Log(device);
                // UnityEngine.Debug.Log(info.axes);
                // UnityEngine.Debug.Log(info.axes.Count + " " + device.Axis.Count);


                //UPDATING AXIS BUTTONS

                //UnityEngine.Debug.Log("buttons" + info.buttons.);
                // UnityEngine.Debug.Log("buttons" + info.buttons.Count);

                int i = 0;

                foreach (var obj in report.buttons)
                {
                    //if(i==0) {_webHidBehavior.Log("button:"+obj+" "+obj.GetType()+" "+Convert.ToSingle(obj));
                    //    device.Buttons[i++].value = Convert.ToSingle(obj);
                    //}

                    device.Buttons[i++].value = Convert.ToSingle(obj);
                }


//_webHidBehavior.Log(device.Buttons[0].value.ToString() + device.Buttons[1].value.ToString()+device.Buttons[2].value.ToString());


                i = 0;
                float value = 0;

                float dreadZone = 0.001f;//TODO this shouldn't be hard coded
                // string axisValues="";
                //  int numAxes=device.Axis.Count;


                //!!! FF gives 7 axis and the last 2 are POW on test Thrustmaster
                //!!! Chrome gives 10 axis and last 4 are POW 2 by 2 but they give some strange values

                foreach (var obj in report.axes)
                {
                    value = Convert.ToSingle(obj);
                    if (value < dreadZone && value > -dreadZone)
                    {
                        value = 0;
                    }

                    //LAST 4 axes are POV probably
                    //if (numAxes > 8)
                    //{
                    //    if (i == (int)JoystickAxis.AxisPovX)
                    //    {
                    //        device.Axis[numAxes - 2].value = Convert.ToSingle(Math.Min(1f, Math.Max(-1, value)));
                    //        i++;
                    //        continue;
                    //    }
                    //    else if (i == (int)JoystickAxis.AxisPovY)
                    //    {
                    //        device.Axis[numAxes - 1].value = Convert.ToSingle(Math.Min(1f, Math.Max(-1, value)));
                    //        i++;
                    //        continue;
                    //    }
                    //    else if (i == numAxes - 2)
                    //    {
                    //        device.Axis[JoystickAxis.AxisPovX].value = Convert.ToSingle(Math.Min(1f, Math.Max(-1, value)));
                    //        i++;
                    //        continue;
                    //    }
                    //    else if (i == numAxes - 1)
                    //    {
                    //        device.Axis[JoystickAxis.AxisPovY].value = Convert.ToSingle(Math.Min(1f, Math.Max(-1, value)));
                    //        i++;
                    //        continue;
                    //    }
                    //}



                    // UnityEngine.Debug.Log(obj.GetType());

                    device.Axis[i++].value = Convert.ToSingle(Math.Min(1f, Math.Max(-1, value)));
                    // axisValues
                    //  UnityEngine.Debug.Log("axes value:" +device.Axis[i-1].value);
                }
            }


            // switch(guess always the last axes are hats
            //if (numAxes > 8)
            //{
            //    value = device.Axis[JoystickAxis.AxisPovX].value;
            //    device.Axis[JoystickAxis.AxisPovX].value = device.Axis[numAxes - 2].value;
            //    device.Axis[numAxes - 2].value = value;

            //    value = device.Axis[JoystickAxis.AxisPovY].value;
            //    device.Axis[JoystickAxis.AxisPovY].value = device.Axis[numAxes - 1].value;
            //    device.Axis[numAxes - 1].value = value;

            //}


//_webHidBehavior.Log("numaxis: "+device.Axis[0].value.ToString()+device.Axis[1].value.ToString()+ device.Axis[2].value.ToString() + device.Axis[8].value.ToString()+device.Axis[9].value.ToString());

            //_webHidBehavior.Log("numaxis: "+ device.Axis[7].value.ToString() + device.Axis[8].value.ToString()+device.Axis[9].value.ToString());

            // UnityEngine.Debug.Log(device.Axis[0].value + " " + device.Axis[1].value);
            // device.isReady = true;
        }
 public GenericHIDDevice()
     : base(0, 0, 0,String.Empty, IntPtr.Zero, null, String.Empty)
 {
     __lastHIDReport = new WebHIDReport(this.index, CreateInputBuffer(),HIDReport.ReadStatus.NoDataRead);
 }
 public GenericHIDDevice()
     : base(0, 0, 0, String.Empty, IntPtr.Zero, null, String.Empty)
 {
     __lastHIDReport = new WebHIDReport(this.index, CreateInputBuffer(), HIDReport.ReadStatus.NoDataRead);
 }