Exemplo n.º 1
0
    private void DrivingInput()
    {
        if(LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0)){
            LogitechGSDK.LogiControllerPropertiesData actualProperties = new LogitechGSDK.LogiControllerPropertiesData();
            LogitechGSDK.DIJOYSTATE2ENGINES rec;
            rec = LogitechGSDK.LogiGetStateUnity(0);

            direction = Mathf.Lerp(/*wheelDegrees/2*/1,/*-wheelDegrees/2*/-1,(-rec.lX /32767f + 1f)/2f);
            steeringWheelDegrees = Mathf.Lerp(wheelDegrees/2,-wheelDegrees/2,(-rec.lX /32767f + 1f)/2f);
            gasPedal = Mathf.Lerp(0,1,( -rec.lY/32767f + 1)/2 );
            breakPedal = Mathf.Lerp(0,-1,( -rec.lRz/32767f + 1)/2);
            clutchPedal = Mathf.Lerp(0,1,( -rec.rglSlider[1]/32767f + 1)/2);
            gasbreak = gasPedal + breakPedal;
            gear = -1;
            for(int i = 8; i < 14; i++){
                if(rec.rgbButtons[i] == 128){
                    gear = i - 7;
                    if(gear == 6){
                        gear = 0;
                    }
                    break;
                }
                gear = -1;
            }

        }
    }
Exemplo n.º 2
0
    // Use this for initialization
    void Start()
    {
        LogitechGSDK.LogiSteeringInitialize(true);

        properties            = new LogitechGSDK.LogiControllerPropertiesData();
        properties.wheelRange = 900;

        LogitechGSDK.LogiSetPreferredControllerProperties(properties);

        wheelValue     = 0.0f;
        valveCurrState = IsWheelValveClosed = true;
        for (int i = 0; i < 10; i++)
        {
            if (LogitechGSDK.LogiIsConnected(i))
            {
                wheelIndex = i;
            }
        }

        joynames = new List <string>(Input.GetJoystickNames());
        if (joynames[0].Contains("G27"))
        {
            axesName = "Joystick" + 0;
        }
        else
        {
            axesName = "Joystick" + 1;
        }
    }
Exemplo n.º 3
0
    public static float LogiSteeringGetAngle(int index)
    {
        DIJOYSTATE2ENGINES state = LogiGetStateCSharp(index);

        LogitechGSDK.LogiControllerPropertiesData properties = new LogitechGSDK.LogiControllerPropertiesData();
        LogitechGSDK.LogiGetCurrentControllerProperties(index, ref properties);
        float angle = (float)state.lX / 65536 * properties.wheelRange;

        return(angle);
    }
Exemplo n.º 4
0
    public void wheelPropSetup(ref LogitechGSDK.LogiControllerPropertiesData prop)
    {
        /* set up wheel to allow full range of motion and set gains
         * input is pointer to struct to hold wheel properties */

        prop.wheelRange = 900;

        /* set gains for the steering wheel: */
        prop.forceEnable = true;
        prop.overallGain = 80;
        prop.springGain  = 80;
    }
Exemplo n.º 5
0
    private void Start()
    {
        Gear   = 0;
        Accel  = 0;
        Brake  = 0;
        Clutch = 1;

#if UNITY_STANDALONE_WIN
        if (LogitechGSDK.LogiSteeringInitialize(false))
        {
            Debug.Log("LogiSteering Initialized");
            LogitechGSDK.LogiControllerPropertiesData properties = new LogitechGSDK.LogiControllerPropertiesData();
            properties.forceEnable          = true;
            properties.overallGain          = 100;
            properties.springGain           = 100;
            properties.damperGain           = 100;
            properties.defaultSpringEnabled = true;
            properties.defaultSpringGain    = 100;
            properties.combinePedals        = false;
            properties.wheelRange           = 900;
            properties.gameSettingsEnabled  = false;
            properties.allowGameSettings    = false;
            LogitechGSDK.LogiSetPreferredControllerProperties(properties);
            for (int i = 0; ; i++)
            {
                if (!LogitechGSDK.LogiIsConnected(i))
                {
                    break;
                }
                if (LogitechGSDK.LogiIsDeviceConnected(i, LogitechGSDK.LOGI_DEVICE_TYPE_WHEEL))
                {
                    handleIndex = i;
                    StringBuilder deviceName = new StringBuilder(256);
                    LogitechGSDK.LogiGetFriendlyProductName(0, deviceName, 256);
                    Debug.Log(deviceName);
                    break;
                }
            }
        }
#endif
    }
Exemplo n.º 6
0
    // YC added
    void Awake()
    {
        ui = GameObject.Find("UISystem").GetComponent <UISystem> ();

        properties                      = new LogitechGSDK.LogiControllerPropertiesData();
        properties.forceEnable          = false;
        properties.overallGain          = 100;
        properties.springGain           = 100;
        properties.damperGain           = 100;
        properties.defaultSpringEnabled = true;
        properties.defaultSpringGain    = 100;
        properties.combinePedals        = false;
        properties.wheelRange           = WHEEL_RANGE;

        properties.gameSettingsEnabled = false;
        properties.allowGameSettings   = false;

        LogitechGSDK.LogiSetPreferredControllerProperties(properties);

        initflag = LogitechGSDK.LogiSteeringInitialize(false);
        Debug.Log("SteeringInit:" + initflag);
        Thread.Sleep(500);

        //
        // move the wheel to generate a read event
        //
        if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0))
        {
            LogitechGSDK.LogiPlayConstantForce(0, 40);
            Thread.Sleep(20);
        }


        // generate thread, run later.
        thread = new Thread(g29_control);
        thread.IsBackground = true;
    }
Exemplo n.º 7
0
        /// <summary>
        /// 启动定时器,轮询获取罗技G29模拟器数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer_Tick(object sender, EventArgs e)
        {
            int DeviceIndex = 0;

            if (LogitechGSDK.LogiUpdate())
            {
                if (LogitechGSDK.LogiIsConnected(DeviceIndex))
                {
                    var Properties = new LogitechGSDK.LogiControllerPropertiesData();
                    LogitechGSDK.LogiGetCurrentControllerProperties(DeviceIndex, ref Properties);

                    var State = LogitechGSDK.LogiGetStateCSharp(DeviceIndex);

                    realTimeData.index           = DeviceIndex;
                    realTimeData.AcceleratePedal = accleratePedal(State.lY).ToString();
                    realTimeData.BreakPedal      = breakPedal(State.lRz).ToString();
                    realTimeData.direction_flag  = directionFlag(State.lX);
                    realTimeData.gear            = 1;
                    realTimeData.SteeringAngle   = steeringAngle(State.lX).ToString();


                    string OutputTail = "Steering Angle: " + steeringAngle(State.lX).ToString() + "\r\n";
                    OutputTail += "Direction flag: " + directionFlag(State.lX).ToString() + "\r\n";
                    OutputTail += "Accelerate Pedal: " + accleratePedal(State.lY).ToString() + "\r\n";
                    OutputTail += "Break Pedal: " + breakPedal(State.lRz).ToString() + "\r\n";
                    OutputTail += "Clutch Pedal: " + State.rglSlider[0].ToString() + "\r\n";

                    string Output107 = realTimeData.AcceleratePedal + ','
                                       + realTimeData.BreakPedal + ','
                                       + realTimeData.direction_flag + ','
                                       + realTimeData.gear + ','
                                       + realTimeData.SteeringAngle;

                    this.Output.Text = OutputTail + "发送给云服务器的107协议: " + Output107;
                }
            }
        }
Exemplo n.º 8
0
    // Update is called once per frame
    void Update()
    {
        //All the test functions are called on the first device plugged in(index = 0)
        if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0))
        {
            //CONTROLLER PROPERTIES
            StringBuilder deviceName = new StringBuilder(256);
            LogitechGSDK.LogiGetFriendlyProductName(0, deviceName, 256);
            propertiesEdit  = "Current Controller : " + deviceName + "\n";
            propertiesEdit += "Current controller properties : \n\n";
            LogitechGSDK.LogiControllerPropertiesData actualProperties = new LogitechGSDK.LogiControllerPropertiesData();
            LogitechGSDK.LogiGetCurrentControllerProperties(0, ref actualProperties);
            propertiesEdit += "forceEnable = " + actualProperties.forceEnable + "\n";
            propertiesEdit += "overallGain = " + actualProperties.overallGain + "\n";
            propertiesEdit += "springGain = " + actualProperties.springGain + "\n";
            propertiesEdit += "damperGain = " + actualProperties.damperGain + "\n";
            propertiesEdit += "defaultSpringEnabled = " + actualProperties.defaultSpringEnabled + "\n";
            propertiesEdit += "combinePedals = " + actualProperties.combinePedals + "\n";
            propertiesEdit += "wheelRange = " + actualProperties.wheelRange + "\n";
            propertiesEdit += "gameSettingsEnabled = " + actualProperties.gameSettingsEnabled + "\n";
            propertiesEdit += "allowGameSettings = " + actualProperties.allowGameSettings + "\n";

            //CONTROLLER STATE
            actualState = "Steering wheel current state : \n\n";
            LogitechGSDK.DIJOYSTATE2ENGINES rec;
            rec          = LogitechGSDK.LogiGetStateUnity(0);
            actualState += "x-axis position :" + rec.lX + "\n";
            actualState += "y-axis position :" + rec.lY + "\n";
            actualState += "z-axis position :" + rec.lZ + "\n";
            actualState += "x-axis rotation :" + rec.lRx + "\n";
            actualState += "y-axis rotation :" + rec.lRy + "\n";
            actualState += "z-axis rotation :" + rec.lRz + "\n";
            actualState += "extra axes positions 1 :" + rec.rglSlider[0] + "\n";
            actualState += "extra axes positions 2 :" + rec.rglSlider[1] + "\n";
            switch (rec.rgdwPOV[0])
            {
            case (0): actualState += "POV : UP\n"; break;

            case (4500): actualState += "POV : UP-RIGHT\n"; break;

            case (9000): actualState += "POV : RIGHT\n"; break;

            case (13500): actualState += "POV : DOWN-RIGHT\n"; break;

            case (18000): actualState += "POV : DOWN\n"; break;

            case (22500): actualState += "POV : DOWN-LEFT\n"; break;

            case (27000): actualState += "POV : LEFT\n"; break;

            case (31500): actualState += "POV : UP-LEFT\n"; break;

            default: actualState += "POV : CENTER\n"; break;
            }

            //Button status :

            buttonStatus = "Button pressed : \n\n";
            for (int i = 0; i < 128; i++)
            {
                if (rec.rgbButtons[i] == 128)
                {
                    buttonStatus += "Button " + i + " pressed\n";
                }
            }

            /* THIS AXIS ARE NEVER REPORTED BY LOGITECH CONTROLLERS
             *
             * actualState += "x-axis velocity :" + rec.lVX + "\n";
             * actualState += "y-axis velocity :" + rec.lVY + "\n";
             * actualState += "z-axis velocity :" + rec.lVZ + "\n";
             * actualState += "x-axis angular velocity :" + rec.lVRx + "\n";
             * actualState += "y-axis angular velocity :" + rec.lVRy + "\n";
             * actualState += "z-axis angular velocity :" + rec.lVRz + "\n";
             * actualState += "extra axes velocities 1 :" + rec.rglVSlider[0] + "\n";
             * actualState += "extra axes velocities 2 :" + rec.rglVSlider[1] + "\n";
             * actualState += "x-axis acceleration :" + rec.lAX + "\n";
             * actualState += "y-axis acceleration :" + rec.lAY + "\n";
             * actualState += "z-axis acceleration :" + rec.lAZ + "\n";
             * actualState += "x-axis angular acceleration :" + rec.lARx + "\n";
             * actualState += "y-axis angular acceleration :" + rec.lARy + "\n";
             * actualState += "z-axis angular acceleration :" + rec.lARz + "\n";
             * actualState += "extra axes accelerations 1 :" + rec.rglASlider[0] + "\n";
             * actualState += "extra axes accelerations 2 :" + rec.rglASlider[1] + "\n";
             * actualState += "x-axis force :" + rec.lFX + "\n";
             * actualState += "y-axis force :" + rec.lFY + "\n";
             * actualState += "z-axis force :" + rec.lFZ + "\n";
             * actualState += "x-axis torque :" + rec.lFRx + "\n";
             * actualState += "y-axis torque :" + rec.lFRy + "\n";
             * actualState += "z-axis torque :" + rec.lFRz + "\n";
             * actualState += "extra axes forces 1 :" + rec.rglFSlider[0] + "\n";
             * actualState += "extra axes forces 2 :" + rec.rglFSlider[1] + "\n";
             */

            int    shifterTipe   = LogitechGSDK.LogiGetShifterMode(0);
            string shifterString = "";
            if (shifterTipe == 1)
            {
                shifterString = "Gated";
            }
            else if (shifterTipe == 0)
            {
                shifterString = "Sequential";
            }
            else
            {
                shifterString = "Unknown";
            }
            actualState += "\nSHIFTER MODE:" + shifterString;



            // FORCES AND EFFECTS
            activeForces = "Active forces and effects :\n";

            //Spring Force -> S
            if (Input.GetKeyUp(KeyCode.S))
            {
                if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_SPRING))
                {
                    LogitechGSDK.LogiStopSpringForce(0);
                    activeForceAndEffect[0] = "";
                }
                else
                {
                    LogitechGSDK.LogiPlaySpringForce(0, 50, 50, 50);
                    activeForceAndEffect[0] = "Spring Force\n ";
                }
            }

            //Constant Force -> C
            if (Input.GetKeyUp(KeyCode.C))
            {
                if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_CONSTANT))
                {
                    LogitechGSDK.LogiStopConstantForce(0);
                    activeForceAndEffect[1] = "";
                }
                else
                {
                    LogitechGSDK.LogiPlayConstantForce(0, 50);
                    activeForceAndEffect[1] = "Constant Force\n ";
                }
            }

            //Damper Force -> D
            if (Input.GetKeyUp(KeyCode.D))
            {
                if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_DAMPER))
                {
                    LogitechGSDK.LogiStopDamperForce(0);
                    activeForceAndEffect[2] = "";
                }
                else
                {
                    LogitechGSDK.LogiPlayDamperForce(0, 50);
                    activeForceAndEffect[2] = "Damper Force\n ";
                }
            }

            //Side Collision Force -> left or right arrow
            if (Input.GetKeyUp(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow))
            {
                LogitechGSDK.LogiPlaySideCollisionForce(0, 60);
            }

            //Front Collision Force -> up arrow
            if (Input.GetKeyUp(KeyCode.UpArrow))
            {
                LogitechGSDK.LogiPlayFrontalCollisionForce(0, 60);
            }

            //Dirt Road Effect-> I
            if (Input.GetKeyUp(KeyCode.I))
            {
                if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_DIRT_ROAD))
                {
                    LogitechGSDK.LogiStopDirtRoadEffect(0);
                    activeForceAndEffect[3] = "";
                }
                else
                {
                    LogitechGSDK.LogiPlayDirtRoadEffect(0, 50);
                    activeForceAndEffect[3] = "Dirt Road Effect\n ";
                }
            }

            //Bumpy Road Effect-> B
            if (Input.GetKeyUp(KeyCode.B))
            {
                if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_BUMPY_ROAD))
                {
                    LogitechGSDK.LogiStopBumpyRoadEffect(0);
                    activeForceAndEffect[4] = "";
                }
                else
                {
                    LogitechGSDK.LogiPlayBumpyRoadEffect(0, 50);
                    activeForceAndEffect[4] = "Bumpy Road Effect\n";
                }
            }

            //Slippery Road Effect-> L
            if (Input.GetKeyUp(KeyCode.L))
            {
                if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_SLIPPERY_ROAD))
                {
                    LogitechGSDK.LogiStopSlipperyRoadEffect(0);
                    activeForceAndEffect[5] = "";
                }
                else
                {
                    LogitechGSDK.LogiPlaySlipperyRoadEffect(0, 50);
                    activeForceAndEffect[5] = "Slippery Road Effect\n ";
                }
            }

            //Surface Effect-> U
            if (Input.GetKeyUp(KeyCode.U))
            {
                if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_SURFACE_EFFECT))
                {
                    LogitechGSDK.LogiStopSurfaceEffect(0);
                    activeForceAndEffect[6] = "";
                }
                else
                {
                    LogitechGSDK.LogiPlaySurfaceEffect(0, LogitechGSDK.LOGI_PERIODICTYPE_SQUARE, 50, 1000);
                    activeForceAndEffect[6] = "Surface Effect\n";
                }
            }

            //Car Airborne -> A
            if (Input.GetKeyUp(KeyCode.A))
            {
                if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_CAR_AIRBORNE))
                {
                    LogitechGSDK.LogiStopCarAirborne(0);
                    activeForceAndEffect[7] = "";
                }
                else
                {
                    LogitechGSDK.LogiPlayCarAirborne(0);
                    activeForceAndEffect[7] = "Car Airborne\n ";
                }
            }

            //Soft Stop Force -> O
            if (Input.GetKeyUp(KeyCode.O))
            {
                if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_SOFTSTOP))
                {
                    LogitechGSDK.LogiStopSoftstopForce(0);
                    activeForceAndEffect[8] = "";
                }
                else
                {
                    LogitechGSDK.LogiPlaySoftstopForce(0, 20);
                    activeForceAndEffect[8] = "Soft Stop Force\n";
                }
            }

            //Set preferred controller properties -> PageUp
            if (Input.GetKeyUp(KeyCode.PageUp))
            {
                //Setting example values
                properties.wheelRange           = 90;
                properties.forceEnable          = true;
                properties.overallGain          = 80;
                properties.springGain           = 80;
                properties.damperGain           = 80;
                properties.allowGameSettings    = true;
                properties.combinePedals        = false;
                properties.defaultSpringEnabled = true;
                properties.defaultSpringGain    = 80;
                LogitechGSDK.LogiSetPreferredControllerProperties(properties);
            }

            //Play leds -> P
            if (Input.GetKeyUp(KeyCode.P))
            {
                LogitechGSDK.LogiPlayLeds(0, 20, 20, 20);
            }

            for (int i = 0; i < 9; i++)
            {
                activeForces += activeForceAndEffect[i];
            }
        }
        else if (!LogitechGSDK.LogiIsConnected(0))
        {
            actualState = "PLEASE PLUG IN A STEERING WHEEL OR A FORCE FEEDBACK CONTROLLER";
        }
        else
        {
            actualState = "THIS WINDOW NEEDS TO BE IN FOREGROUND IN ORDER FOR THE SDK TO WORK PROPERLY";
        }
    }
Exemplo n.º 9
0
    private float visionDelay;      /* current amount of vision delay in seconds */

    void Start()
    {
        /* load variables from menu class */
        inputFilePath  = BeginButtonControl.inputFilePath;
        RecordFileName = BeginButtonControl.saveFileName;
        sensitivity    = 0.01f * BeginButtonControl.sensitivity;


        LoadTestParameters(ref trailPositionCurve, ref actionQuantizationCurve, ref visionDelayCurve, ref bumpSizeCurve, ref actionDelayCurve, ref visionQuantizationCurve);

        /**************************************
        * Initialize Logitech Steering Wheel *
        **************************************/

        /* allow full range of motion for the steering wheel & set steering wheel gains */
        logiIni = LogitechGSDK.LogiSteeringInitialize(false);
        LogitechGSDK.LogiControllerPropertiesData properties = new LogitechGSDK.LogiControllerPropertiesData();
        wheelPropSetup(ref properties);
        LogitechGSDK.LogiSetPreferredControllerProperties(properties); /* set properties of wheel */
        rec = LogitechGSDK.LogiGetStateCSharp(deviceIdx);

        /***********************
         * Set Up GUI Elements *
         **********************/

        /* create the horizontal axis line */
        horizontalLine.SetWidth(horizontalLineWidth, horizontalLineWidth);
        horizontalLine.SetVertexCount(2);
        horizontalLine.SetPositions(new Vector3[2] {
            new Vector3(-11, 0, 0), new Vector3(11, 0, 0)
        });
        horizontalLine.material = new Material(Shader.Find("Sprites/Default"));
        horizontalLine.SetColors(Color.magenta, Color.magenta);


        /* create path line */
        pathLine.SetWidth(pathLineWidth, pathLineWidth);
        pathLine.SetVertexCount(2);
        pathLine.SetPositions(new Vector3[2] {
            new Vector3(0, -pathLineHeight, 0), new Vector3(0, pathLineHeight, 0)
        });
        pathLine.material = new Material(Shader.Find("Sprites/Default"));
        pathLine.SetColors(Color.grey, Color.grey);
        pathHistory = 1f; /* amount of history of path shown in seconds */

        /* create vertical line that represents player position */
        playerLine.SetWidth(playerLineWidth, playerLineWidth);
        playerLine.SetVertexCount(2);
        playerLineXPos = 0;
        playerLine.SetPositions(new Vector3[2] {
            new Vector3(playerLineXPos, -playerLineHeight, 0), new Vector3(playerLineXPos, playerLineHeight, 0)
        });
        playerLine.material = new Material(Shader.Find("Sprites/Default"));
        playerLine.SetColors(Color.green, Color.green);
        playerLine.sortingOrder = 1;

        /******************************************
        * Set up Parameters for Game Experiments *
        ******************************************/

        saveFilePath = Path.GetDirectoryName(Application.dataPath);

        gameDate = DateTime.UtcNow.ToString("yyyyMMddhhmmss");

        gameIsRunning = true;
    }
    // Update is called once per frame
    void Update()
    {
        //All the test functions are called on the first device plugged in(index = 0)
        if(LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0)){

            //CONTROLLER PROPERTIES
            propertiesEdit = "Current Controller : "+LogitechGSDK.LogiSteeringGetFriendlyProductName(0)+"\n";
            propertiesEdit += "Current controller properties : \n\n";
            LogitechGSDK.LogiControllerPropertiesData actualProperties = new LogitechGSDK.LogiControllerPropertiesData();
            LogitechGSDK.LogiGetCurrentControllerProperties(0, ref actualProperties);
            propertiesEdit += "forceEnable = " + actualProperties.forceEnable + "\n";
            propertiesEdit += "overallGain = " + actualProperties.overallGain + "\n";
            propertiesEdit += "springGain = " + actualProperties.springGain + "\n";
            propertiesEdit += "damperGain = " + actualProperties.damperGain + "\n";
            propertiesEdit += "defaultSpringEnabled = " + actualProperties.defaultSpringEnabled + "\n";
            propertiesEdit += "combinePedals = " + actualProperties.combinePedals + "\n";
            propertiesEdit += "wheelRange = " + actualProperties.wheelRange + "\n";
            propertiesEdit += "gameSettingsEnabled = " + actualProperties.gameSettingsEnabled + "\n";
            propertiesEdit += "allowGameSettings = " + actualProperties.allowGameSettings + "\n";

            //CONTROLLER STATE
            actualState = "Steering wheel current state : \n\n";
            LogitechGSDK.DIJOYSTATE2ENGINES rec;
            rec = LogitechGSDK.LogiGetStateUnity(0);
            actualState += "x-axis position :" + rec.lX + "\n";
            actualState += "y-axis position :" + rec.lY + "\n";
            actualState += "z-axis position :" + rec.lZ + "\n";
            actualState += "x-axis rotation :" + rec.lRx + "\n";
            actualState += "y-axis rotation :" + rec.lRy + "\n";
            actualState += "z-axis rotation :" + rec.lRz + "\n";
            actualState += "extra axes positions 1 :" + rec.rglSlider[0] + "\n";
            actualState += "extra axes positions 2 :" + rec.rglSlider[1] + "\n";
            switch (rec.rgdwPOV[0])
            {
                case (0): actualState += "POV : UP\n"; break;
                case (4500): actualState += "POV : UP-RIGHT\n"; break;
                case (9000): actualState += "POV : RIGHT\n"; break;
                case (13500): actualState += "POV : DOWN-RIGHT\n"; break;
                case (18000): actualState += "POV : DOWN\n"; break;
                case (22500): actualState += "POV : DOWN-LEFT\n"; break;
                case (27000): actualState += "POV : LEFT\n"; break;
                case (31500): actualState += "POV : UP-LEFT\n"; break;
                default: actualState += "POV : CENTER\n"; break;
            }

            //Button status :

            buttonStatus = "Button pressed : \n\n";
            for (int i = 0; i < 128; i++)
            {
                if (rec.rgbButtons[i] == 128)
                {
                    buttonStatus += "Button " + i + " pressed\n";
                }

            }

            /* THIS AXIS ARE NEVER REPORTED BY LOGITECH CONTROLLERS
             *
             * actualState += "x-axis velocity :" + rec.lVX + "\n";
             * actualState += "y-axis velocity :" + rec.lVY + "\n";
             * actualState += "z-axis velocity :" + rec.lVZ + "\n";
             * actualState += "x-axis angular velocity :" + rec.lVRx + "\n";
             * actualState += "y-axis angular velocity :" + rec.lVRy + "\n";
             * actualState += "z-axis angular velocity :" + rec.lVRz + "\n";
             * actualState += "extra axes velocities 1 :" + rec.rglVSlider[0] + "\n";
             * actualState += "extra axes velocities 2 :" + rec.rglVSlider[1] + "\n";
             * actualState += "x-axis acceleration :" + rec.lAX + "\n";
             * actualState += "y-axis acceleration :" + rec.lAY + "\n";
             * actualState += "z-axis acceleration :" + rec.lAZ + "\n";
             * actualState += "x-axis angular acceleration :" + rec.lARx + "\n";
             * actualState += "y-axis angular acceleration :" + rec.lARy + "\n";
             * actualState += "z-axis angular acceleration :" + rec.lARz + "\n";
             * actualState += "extra axes accelerations 1 :" + rec.rglASlider[0] + "\n";
             * actualState += "extra axes accelerations 2 :" + rec.rglASlider[1] + "\n";
             * actualState += "x-axis force :" + rec.lFX + "\n";
             * actualState += "y-axis force :" + rec.lFY + "\n";
             * actualState += "z-axis force :" + rec.lFZ + "\n";
             * actualState += "x-axis torque :" + rec.lFRx + "\n";
             * actualState += "y-axis torque :" + rec.lFRy + "\n";
             * actualState += "z-axis torque :" + rec.lFRz + "\n";
             * actualState += "extra axes forces 1 :" + rec.rglFSlider[0] + "\n";
             * actualState += "extra axes forces 2 :" + rec.rglFSlider[1] + "\n";
             */

            int shifterTipe = LogitechGSDK.LogiGetShifterMode(0);
            string shifterString = "";
            if (shifterTipe == 1) shifterString = "Gated";
            else if (shifterTipe == 0) shifterString = "Sequential";
            else  shifterString = "Unknown";
            actualState += "\nSHIFTER MODE:" + shifterString;

            // FORCES AND EFFECTS
            activeForces = "Active forces and effects :\n";

            //Spring Force -> S
            if (Input.GetKeyUp(KeyCode.S)){
               if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_SPRING))
               {
                   LogitechGSDK.LogiStopSpringForce(0);
                   activeForceAndEffect[0] = "";
               }
               else
               {
                   LogitechGSDK.LogiPlaySpringForce(0, 50, 50, 50);
                   activeForceAndEffect[0] = "Spring Force\n ";
               }
            }

            //Constant Force -> C
            if (Input.GetKeyUp(KeyCode.C))
            {
                if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_CONSTANT))
                {
                    LogitechGSDK.LogiStopConstantForce(0);
                    activeForceAndEffect[1] = "";
                }
                else
                {
                    LogitechGSDK.LogiPlayConstantForce(0, 50);
                    activeForceAndEffect[1] = "Constant Force\n ";
                }
            }

            //Damper Force -> D
            if (Input.GetKeyUp(KeyCode.D))
            {
                if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_DAMPER))
                {
                    LogitechGSDK.LogiStopDamperForce(0);
                    activeForceAndEffect[2] = "";
                }
                else
                {
                    LogitechGSDK.LogiPlayDamperForce(0, 50);
                    activeForceAndEffect[2] = "Damper Force\n ";
                }
            }

            //Side Collision Force -> left or right arrow
            if (Input.GetKeyUp(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow))
            {
                LogitechGSDK.LogiPlaySideCollisionForce(0, 60);
            }

            //Front Collision Force -> up arrow
            if (Input.GetKeyUp(KeyCode.UpArrow))
            {
                LogitechGSDK.LogiPlayFrontalCollisionForce(0, 60);
            }

            //Dirt Road Effect-> I
            if (Input.GetKeyUp(KeyCode.I))
            {
                if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_DIRT_ROAD))
                {
                    LogitechGSDK.LogiStopDirtRoadEffect(0);
                    activeForceAndEffect[3] = "";
                }
                else
                {
                    LogitechGSDK.LogiPlayDirtRoadEffect(0, 50);
                    activeForceAndEffect[3] = "Dirt Road Effect\n ";
                }

            }

            //Bumpy Road Effect-> B
            if (Input.GetKeyUp(KeyCode.B))
            {
                if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_BUMPY_ROAD))
                {
                    LogitechGSDK.LogiStopBumpyRoadEffect(0);
                    activeForceAndEffect[4] = "";
                }
                else
                {
                    LogitechGSDK.LogiPlayBumpyRoadEffect(0, 50);
                    activeForceAndEffect[4] = "Bumpy Road Effect\n";
                }

            }

            //Slippery Road Effect-> L
            if (Input.GetKeyUp(KeyCode.L))
            {
                if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_SLIPPERY_ROAD))
                {
                    LogitechGSDK.LogiStopSlipperyRoadEffect(0);
                    activeForceAndEffect[5] = "";
                }
                else
                {
                    LogitechGSDK.LogiPlaySlipperyRoadEffect(0, 50);
                    activeForceAndEffect[5] = "Slippery Road Effect\n ";
                }
            }

            //Surface Effect-> U
            if (Input.GetKeyUp(KeyCode.U))
            {
                if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_SURFACE_EFFECT))
                {
                    LogitechGSDK.LogiStopSurfaceEffect(0);
                    activeForceAndEffect[6] = "";
                }
                else
                {
                    LogitechGSDK.LogiPlaySurfaceEffect(0, LogitechGSDK.LOGI_PERIODICTYPE_SQUARE, 50, 1000);
                    activeForceAndEffect[6] = "Surface Effect\n";
                }
            }

            //Car Airborne -> A
            if (Input.GetKeyUp(KeyCode.A))
            {
                if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_CAR_AIRBORNE))
                {
                    LogitechGSDK.LogiStopCarAirborne(0);
                    activeForceAndEffect[7] = "";
                }
                else
                {
                    LogitechGSDK.LogiPlayCarAirborne(0);
                    activeForceAndEffect[7] = "Car Airborne\n ";
                }
            }

            //Soft Stop Force -> O
            if (Input.GetKeyUp(KeyCode.O))
            {
                if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_SOFTSTOP))
                {
                    LogitechGSDK.LogiStopSoftstopForce(0);
                    activeForceAndEffect[8] = "";
                }
                else
                {
                    LogitechGSDK.LogiPlaySoftstopForce(0, 20);
                    activeForceAndEffect[8] = "Soft Stop Force\n";
                }
            }

            //Set preferred controller properties -> PageUp
            if (Input.GetKeyUp(KeyCode.PageUp))
            {
                //Setting example values
                properties.wheelRange = 90;
                properties.forceEnable = true;
                properties.overallGain = 80;
                properties.springGain = 80;
                properties.damperGain = 80;
                properties.allowGameSettings = true;
                properties.combinePedals = false;
                properties.defaultSpringEnabled = true;
                properties.defaultSpringGain = 80;
                LogitechGSDK.LogiSetPreferredControllerProperties(properties);

            }

            //Play leds -> P
            if (Input.GetKeyUp(KeyCode.P))
            {
                LogitechGSDK.LogiPlayLeds(0, 20, 20, 20);
            }

            for (int i = 0; i < 9; i++)
            {
                activeForces += activeForceAndEffect[i];
            }

        }
        else if(!LogitechGSDK.LogiIsConnected(0))
        {
             actualState = "PLEASE PLUG IN A STEERING WHEEL OR A FORCE FEEDBACK CONTROLLER";
        }
        else{
            actualState = "THIS WINDOW NEEDS TO BE IN FOREGROUND IN ORDER FOR THE SDK TO WORK PROPERLY";
        }
    }
Exemplo n.º 11
0
    private int gameLength;  /* gameLength in seconds */

    void Start()
    {
        /* get file interaction & sensitivity values from menu class */
        RecordFileName = BeginButtonControl.saveFileName;
        inputFilePath  = BeginButtonControl.inputFilePath;
        sensitivity    = 0.1f * ValSensitivity.sensitivity;


        LoadTestParameters(ref distances, ref widths);

        /**************************************
        * Initialize Logitech Steering Wheel *
        **************************************/

        /* allow full range of motion for the steering wheel & set steering wheel gains */
        wheelProp = "";
        logiIni   = LogitechGSDK.LogiSteeringInitialize(false);
        LogitechGSDK.LogiControllerPropertiesData properties = new LogitechGSDK.LogiControllerPropertiesData();
        wheelPropSetup(ref properties);
        LogitechGSDK.LogiSetPreferredControllerProperties(properties);
        rec = LogitechGSDK.LogiGetStateCSharp(deviceIdx);  /*responsible for recording state of the wheel*/


        /* create the horizontal axis line */
        horizontalLine.SetWidth(0.1f, 0.1f);
        horizontalLine.SetVertexCount(2);
        horizontalLine.SetPositions(new Vector3[2] {
            new Vector3(-11, 0, 0), new Vector3(11, 0, 0)
        });
        horizontalLine.material = new Material(Shader.Find("Sprites/Default"));
        horizontalLine.SetColors(Color.magenta, Color.magenta);


        /* create vertical line that represents player position */
        playerLine.SetWidth(0.05f, 0.05f);
        playerLine.SetVertexCount(2);
        playerLineXPos = 0;
        playerLine.SetPositions(new Vector3[2] {
            new Vector3(playerLineXPos, -playerLineHeight, 0), new Vector3(playerLineXPos, playerLineHeight, 0)
        });
        playerLine.material = new Material(Shader.Find("Sprites/Default"));
        playerLine.SetColors(Color.green, Color.green);
        playerLine.sortingOrder = 2;

        /*create fat line that represent goal zone*/
        goalLineWidth = widths.Evaluate(0.1f);
        goalLine.SetWidth(goalLineWidth, goalLineWidth);
        goalLine.SetVertexCount(2);
        goalLineHeight = 10;
        goalLineXPos   = distances.Evaluate(0.1f);
        goalLine.SetPositions(new Vector3[2] {
            new Vector3(goalLineXPos, -goalLineHeight, 0), new Vector3(goalLineXPos, goalLineHeight, 0)
        });
        goalLine.material = new Material(Shader.Find("Sprites/Default"));
        goalLine.SetColors(Color.gray, Color.gray);
        goalLine.sortingOrder = 1;


        errorData = new List <string>();

        DateTime nowDate = DateTime.UtcNow;

        gameDate = nowDate.ToString("yyyyMMddhhmmss");


        /******************************************
        * Set up Parameters for Game Experiments *
        ******************************************/
        saveFilePath  = Path.GetDirectoryName(Application.dataPath);
        gameIsRunning = true;
    }
    private void DrivingInput()
    {
        if(LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0)){
            LogitechGSDK.LogiControllerPropertiesData actualProperties = new LogitechGSDK.LogiControllerPropertiesData();
            LogitechGSDK.DIJOYSTATE2ENGINES rec;
            rec = LogitechGSDK.LogiGetStateUnity(0);

            direction = Mathf.Lerp(/*wheelDegrees/2*/1,/*-wheelDegrees/2*/-1,(-rec.lX /32767f + 1f)/2f);
            steeringWheelDegrees = Mathf.Lerp(wheelDegrees/2,-wheelDegrees/2,(-rec.lX /32767f + 1f)/2f);
            gasPedal = Mathf.Lerp(0,1,( -rec.lY/32767f + 1)/2 );
            breakPedal = Mathf.Lerp(0,-1,( -rec.lRz/32767f + 1)/2);
            clutchPedal = Mathf.Lerp(0,1,( -rec.rglSlider[1]/32767f + 1)/2);
            gasbreak = gasPedal + breakPedal;
            gear = -1;
            for(int i = 8; i < 14; i++){
                if(rec.rgbButtons[i] == 128){
                    gear = i - 7;
                    if(gear == 6){
                        gear = 0;
                    }
                    break;
                }
                gear = -1;
            }

        }
    }
Exemplo n.º 13
0
    void ProcessInput()
    {
        //Logitech Steering wheel car input

        if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0))
        {
            StringBuilder deviceName = new StringBuilder(256);
            LogitechGSDK.LogiGetFriendlyProductName(0, deviceName, 256);
            propertiesEdit  = "Current Controller : " + deviceName + "\n";
            propertiesEdit += "Current controller properties : \n\n";
            LogitechGSDK.LogiControllerPropertiesData actualProperties = new LogitechGSDK.LogiControllerPropertiesData();
            LogitechGSDK.LogiGetCurrentControllerProperties(0, ref actualProperties);



            LogitechGSDK.DIJOYSTATE2ENGINES rec;
            rec = LogitechGSDK.LogiGetStateUnity(0);

            float xaxis = (float)rec.lX;
            steeringWheel = xaxis / 32000.0f;
            gasPedal      = Mathf.InverseLerp(32000, -32000, rec.lY);
            brakePedal    = Mathf.InverseLerp(32000, -32000, rec.lRz);



            for (int i = 0; i < 128; i++)
            {
                switch (i)
                {
                case 1:
                    break;

                case 2:
                    break;

                case 3:
                    break;

                case 4:
                    break;

                case 5:
                    break;

                case 6:
                    break;

                case 7:
                    break;

                case 8:
                    break;

                case 9:
                    break;

                case 10:
                    break;

                case 11:
                    break;

                case 12:
                    if (rec.rgbButtons[i] == 128)
                    {
                        if (gearUpReleased)
                        {
                            gearUpReleased = false;
                            gearUp         = true;
                        }
                    }
                    else if (rec.rgbButtons[i] != 128)
                    {
                        gearUpReleased = true;
                    }
                    break;

                case 13:
                    if (rec.rgbButtons[i] == 128)
                    {
                        if (gearDownReleased)
                        {
                            gearDownReleased = false;
                            gearDown         = true;
                        }
                    }
                    else if (rec.rgbButtons[i] != 128)
                    {
                        gearDownReleased = true;
                    }
                    break;

                case 14:     //start engine
                    if (rec.rgbButtons[i] == 128)
                    {
                        startEngine = true;
                    }
                    break;
                }
            }
        }

#if UNITY_EDITOR //Mouse and keyboard input
        float turningRate = 1f;

        if (!LogitechGSDK.LogiIsConnected(0))
        {
            if (Input.GetKeyDown(KeyCode.W))
            {
                gasPedal = 1f;
            }

            if (Input.GetKeyUp(KeyCode.W))
            {
                gasPedal = 0f;
            }


            if (Input.GetKeyDown(KeyCode.S))
            {
                brakePedal = 1f;
            }

            if (Input.GetKeyUp(KeyCode.S))
            {
                brakePedal = 0f;
            }

            if (Input.GetKey(KeyCode.A))
            {
                if (steeringWheel > -1)
                {
                    steeringWheel -= turningRate * Time.deltaTime;
                }
            }
            if (Input.GetKey(KeyCode.D))
            {
                if (steeringWheel < 1)
                {
                    steeringWheel += turningRate * Time.deltaTime;
                }
            }


            if (!Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D))
            {
                steeringWheel = 0;
            }



            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                gearUp = true;
            }

            if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                gearDown = true;
            }

            if (Input.GetKeyDown(KeyCode.K))
            {
                startEngine = true;
            }



            if (Input.GetKeyDown(KeyCode.Q))
            {
                blinkerLeft = true;
            }

            if (Input.GetKeyDown(KeyCode.E))
            {
                blinkerRight = true;
            }

            if (Input.GetKeyDown(KeyCode.X))
            {
                longLights = true;
            }


            if (Input.GetKeyDown(KeyCode.Z))
            {
                lightsModeLeft = true;
            }

            if (Input.GetKeyDown(KeyCode.C))
            {
                lightsModeRight = true;
            }
        }
#endif
    }