Beispiel #1
0
        private static void OnEffect(IntPtr data, IntPtr userData)
        {
            int      id    = 0;
            FFBPType type  = 0;
            int      DSize = 0;

            Byte[]     arr     = new Byte[20];
            UInt32     wType   = 0;
            IntPtr     bytes   = IntPtr.Zero;
            string     TypeStr = "";
            object     obj     = null;
            TesterForm form    = null;

            // Converting user data from pointer to object
            if (userData != IntPtr.Zero)
            {
                // Convert userData from pointer to object
                GCHandle handle2 = (GCHandle)userData;
                obj  = handle2.Target as object;
                form = obj as TesterForm;
            }


            // Get FFB packet raw data
            var result = joystick.Ffb_h_Packet(data, ref wType, ref DSize, ref arr);

            dlg.FfbTextBox_Write(String.Format("\r\n\r\n ============= FFB Packet size Size {0} =============", DSize + 8));

            // Get the ID of the device that this DDB packet refers to
            result = joystick.Ffb_h_DeviceID(data, ref id);
            dlg.FfbTextBox_Write(String.Format("\r\n > Device ID: {0}", id));

            // Get the type of the packet
            result = joystick.Ffb_h_Type(data, ref type);
            if (result == 0)
            {
                bool ok = PacketType2Str(type, ref TypeStr);
                if (!ok)
                {
                    dlg.FfbTextBox_Write(String.Format("\r\n > Packet Type: {0}", type));
                }
                else
                {
                    dlg.FfbTextBox_Write(String.Format("\r\n > Packet Type: {0}", TypeStr));
                }
            }
            ;

            // Get the index of the effect block (Always 1)
            int iBlock = 0;

            result = joystick.Ffb_h_EBI(data, ref iBlock);
            if (result == 0)
            {
                dlg.FfbTextBox_Write(String.Format("\r\n > Effect Block Index: {0}", iBlock));
            }

            // TODO: Add constant magnitude

            #region Effect Report
            // Effect Report
            vGen.FFB_EFF_REPORT Effect = new vGen.FFB_EFF_REPORT();
            result = joystick.Ffb_h_Eff_Report(data, ref Effect);
            if (result == 0)
            {
                ///// This is an Effect Block
                // Effect type
                if (!EffectType2Str(Effect.EffectType, ref TypeStr))
                {
                    dlg.FfbTextBox_Write(String.Format("\r\n >> Effect Report: {0}", Effect.EffectType));
                }
                else
                {
                    dlg.FfbTextBox_Write(String.Format("\r\n >> Effect Report: {0}", TypeStr));
                }

                // Effect Direction
                if (Effect.Polar)
                {
                    dlg.FfbTextBox_Write(String.Format("\r\n >> Direction: {0} deg ({1:D2})", Polar2Deg(Effect.Direction), Effect.Direction));
                }
                else
                {
                    dlg.FfbTextBox_Write(String.Format("\r\n >> X Direction: {0:X2}", Effect.DirX));
                    dlg.FfbTextBox_Write(String.Format("\r\n >> Y Direction: {0:X2}", Effect.DirY));
                };

                // Duration of the effect
                if (Effect.Duration == 0xFFFF)
                {
                    dlg.FfbTextBox_Write(String.Format("\r\n >> Duration: Infinit"));
                }
                else
                {
                    dlg.FfbTextBox_Write(String.Format("\r\n >> Duration: {0} MilliSec", (int)(Effect.Duration)));
                }

                // Trigger Repeat
                if (Effect.TrigerRpt == 0xFFFF)
                {
                    dlg.FfbTextBox_Write(String.Format("\r\n >> Trigger Repeat: Infinit"));
                }
                else
                {
                    dlg.FfbTextBox_Write(String.Format("\r\n >> Trigger Repeat: {0}", (int)(Effect.TrigerRpt)));
                }

                // Sample Period
                if (Effect.SamplePrd == 0xFFFF)
                {
                    dlg.FfbTextBox_Write(String.Format("\r\n >> Sample Period: Infinit"));
                }
                else
                {
                    dlg.FfbTextBox_Write(String.Format("\r\n >> Sample Period: {0}", (int)(Effect.SamplePrd)));
                }


                // Gain
                dlg.FfbTextBox_Write(String.Format("\r\n >> Gain: {0}%", Byte2Percent(Effect.Gain)));
            }
            ;

            #endregion   Effect Report

            #region PID Device Control
            // Device Control (Global controls such as Device Reset, Device Pause .....
            FFB_CTRL Control = FFB_CTRL.CTRL_STOPALL;
            string   CtrlStr = "";
            if ((0 == joystick.Ffb_h_DevCtrl(data, ref Control)) && DevCtrl2Str(Control, ref CtrlStr))
            {
                dlg.FfbTextBox_Write(String.Format("\r\n >> PID Device Control: {0}", CtrlStr));
            }

            #endregion

            #region Effect Operation
            vGen.FFB_EFF_OP Operation = new vGen.FFB_EFF_OP();
            string          EffOpStr  = "";
            if (0 == joystick.Ffb_h_EffOp(data, ref Operation) && EffectOpStr(Operation.EffectOp, ref EffOpStr))
            {
                dlg.FfbTextBox_Write(String.Format("\r\n >> Effect Operation: {0}", EffOpStr));
                if (Operation.LoopCount == 0xFF)
                {
                    dlg.FfbTextBox_Write(String.Format("\r\n >> Loop until stopped"));
                }
                else
                {
                    dlg.FfbTextBox_Write(String.Format("\r\n >> Loop {0} times", (int)(Operation.LoopCount)));
                }
            }
            ;
            #endregion

            #region Global Device Gain
            Byte Gain = 0;
            if (0 == joystick.Ffb_h_DevGain(data, ref Gain))
            {
                dlg.FfbTextBox_Write(String.Format("\r\n >> Global Device Gain: {0}", Byte2Percent(Gain)));
            }

            #endregion

            #region Condition
            vGen.FFB_EFF_COND Condition = new vGen.FFB_EFF_COND();
            if (0 == joystick.Ffb_h_Eff_Cond(data, ref Condition))
            {
                if (Condition.isY)
                {
                    dlg.FfbTextBox_Write(String.Format("\r\n >> Y Axis"));
                }
                else
                {
                    dlg.FfbTextBox_Write(String.Format("\r\n >> X Axis"));
                }
                dlg.FfbTextBox_Write(String.Format("\r\n >> Center Point Offset: {0}", Condition.CenterPointOffset));
                dlg.FfbTextBox_Write(String.Format("\r\n >> Positive Coefficient: {0}", Condition.PosCoeff));
                dlg.FfbTextBox_Write(String.Format("\r\n >> Negative Coefficient: {0}", Condition.NegCoeff));
                dlg.FfbTextBox_Write(String.Format("\r\n >> Positive Saturation: {0}", Condition.PosSatur));
                dlg.FfbTextBox_Write(String.Format("\r\n >> Negative Saturation: {0}", Condition.NegSatur));
                dlg.FfbTextBox_Write(String.Format("\r\n >> Dead Band: {0}", Condition.DeadBand));
            }
            #endregion

            #region Envelope
            vGen.FFB_EFF_ENVLP Envelope = new vGen.FFB_EFF_ENVLP();
            if (0 == joystick.Ffb_h_Eff_Envlp(data, ref Envelope))
            {
                dlg.FfbTextBox_Write(String.Format("\r\n >> Attack Level: {0}", Envelope.AttackLevel));
                dlg.FfbTextBox_Write(String.Format("\r\n >> Fade Level: {0}", Envelope.FadeLevel));
                dlg.FfbTextBox_Write(String.Format("\r\n >> Attack Time: {0}", (int)(Envelope.AttackTime)));
                dlg.FfbTextBox_Write(String.Format("\r\n >> Fade Time: {0}", (int)(Envelope.FadeTime)));
            }
            ;
            #endregion

            #region Periodic
            vGen.FFB_EFF_PERIOD EffPrd = new vGen.FFB_EFF_PERIOD();
            if (0 == joystick.Ffb_h_Eff_Period(data, ref EffPrd))
            {
                dlg.FfbTextBox_Write(String.Format("\r\n >> Magnitude: {0}", EffPrd.Magnitude));
                dlg.FfbTextBox_Write(String.Format("\r\n >> Offset: {0}", EffPrd.Offset));
                dlg.FfbTextBox_Write(String.Format("\r\n >> Phase: {0}", EffPrd.Phase));
                dlg.FfbTextBox_Write(String.Format("\r\n >> Period: {0}", (int)(EffPrd.Period)));
            }
            ;
            #endregion

            #region Effect Type
            FFBEType EffectType = FFBEType.ET_NONE;
            if (0 == joystick.Ffb_h_EffNew(data, ref EffectType))
            {
                if (EffectType2Str(EffectType, ref TypeStr))
                {
                    dlg.FfbTextBox_Write(String.Format("\r\n >> Effect Type: {0}", TypeStr));
                }
                else
                {
                    dlg.FfbTextBox_Write(String.Format("\r\n >> Effect Type: Unknown"));
                }
            }
            #endregion

            #region Ramp Effect
            vGen.FFB_EFF_RAMP RampEffect = new vGen.FFB_EFF_RAMP();
            if (0 == joystick.Ffb_h_Eff_Ramp(data, ref RampEffect))
            {
                dlg.FfbTextBox_Write(String.Format("\r\n >> Ramp Start: {0}", RampEffect.Start));
                dlg.FfbTextBox_Write(String.Format("\r\n >> Ramp End: {0}", RampEffect.End));
            }
            ;
            #endregion

            #region Constant Effect
            vGen.FFB_EFF_CONSTANT ConstantEffect = new vGen.FFB_EFF_CONSTANT();
            if (0 == joystick.Ffb_h_Eff_Constant(data, ref ConstantEffect))
            {
                dlg.FfbTextBox_Write(String.Format("\r\n >> Constant Magnitude: {0}", ConstantEffect.Magnitude));
            }
            ;

            #endregion

            dlg.FfbTextBox_Write(String.Format("\r\n ==============================================\r\n"));
        }